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, Wayne

In reply to File permissions problem by wdhammond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.