I am trying to troubleshoot a pretty robust application that has some functions that don't work properly. The application has a "savefile" function that combines with a "fileisreadonly". The files saved using "savefile" function always end up as 0600 permissions instead of 0644 in normal OS file saves. The code is as follows:
sub savefile { # Determine which save routine to use and then use i +t my ( $textwindow, $top ) = ( $::textwindow, $::top ); ::hidepagenums(); my $filename = $::lglobal{global_filename}; if ( $filename =~ /No File Loaded/ ) { unless ( ::isedited() ) { return; } my ($name); $name = $textwindow->getSaveFile( -title => 'Save As', -initialdir => $::globallastpath ); if ( defined($name) and length($name) ) { $textwindow->SaveUTF($name); $name = ::os_normal($name); ::_recentupdate($name); } else { return; } } else { my $ans = !fileisreadonly($filename) || 'Yes' eq $top->message +Box( -icon => 'warning', -title => 'Confirm save?', -type => 'YesNo', -default => 'no', -message => "File $filename is write-protected. Remove write-protect +ion and save anyway?", ); return unless $ans; $::top->Busy( -recurse => 1 ); if ($::autobackup) { if ( -e $filename ) { if ( -e "$filename.bk2" ) { unlink "$filename.bk2"; } if ( -e "$filename.bk1" ) { rename( "$filename.bk1", "$filename.bk2" ); } rename( $filename, "$filename.bk1" ); } } $textwindow->SaveUTF; $::top->Unbusy( -recurse => 1 ); } $textwindow->ResetUndo; #necessary to reset edited flag ::_bin_save(); ::setedited(0); ::set_autosave() if $::autosave; ::update_indicators(); } sub fileisreadonly { my $name = shift; my $mode = (stat($name))[2]; return 0 if ( $mode & 0200 ); return 1; }
I must note here that an accompanying file generated by the application saves with 0644 permissions.
I noticed in another post on your site that "stat" does not return a value unless "File::stat" in included. Is this the issue?
Regards, WayneIn reply to File permissions problem by wdhammond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |