in reply to Re^2: File permissions problem (updated)
in thread File permissions problem

Hi Wayne,

As far as I can tell from the code you posted, the actual code that opens the file and writes to it is probably somewhere in the SaveUTF method.

The two examples I showed can be used to check the umask from the command line like so:

$ umask 0022 $ perl -e 'printf "%04o\n", umask;' 0022

Or, the best thing is probably to put the statement printf "%04o\n", umask; somewhere in your Perl script, maybe something like warn sprintf("umask is %04o\n",umask); so that it's printed to STDERR.

Update: In your OP you wrote "I must note here that an accompanying file generated by the application saves with 0644 permissions." That makes it a little less likely to be a umask problem; perhaps the application uses sysopen with explicit perms set. But without having the code to look at these are all guesses.

Hope this helps,
-- Hauke D

Update: Replaced "an explicit mode" with "explicit perms" since that's the terminology used in sysopen.

Replies are listed 'Best First'.
Re^4: File permissions problem (updated)
by wdhammond (Novice) on Dec 15, 2016 at 23:21 UTC

    I found this sub in another module (TextUnicode):

    # Custom file save routine to handle unicode files sub SaveUTF { my ( $w, $filename ) = @_; $filename = $w->FileName unless defined $filename; my $dir = dirname($filename); my $perms = ( stat($dir) )[2] & 07777; unless ( $perms & 0200 ) { $perms = $perms | 0200; chmod $perms, $dir or $w->BackTrace("Can not write to directory $dir: $!\n") and return; } my ( $tempfh, $tempfilename ) = tempfile( DIR => $dir ); my $status; my $count = 0; my $index = '1.0'; my $progress; my $fileend = $w->index('end -1c'); my ($lines) = $fileend =~ /^(\d+)\./; my $unicode = ::currentfileisunicode(); # No BOM please #if ($unicode) { # my $bom = "\x{FEFF}"; # utf8::encode($bom); # print $tempfh $bom; #} while ( $w->compare( $index, '<', $fileend ) ) { my $end = $w->index("$index lineend +1c"); my $line = $w->get( $index, $end ); $line =~ s/[\t \xA0]+$//; #$line = ::eol_whitespace($line); $line =~ s/\cM\cJ|\cM|\cJ/\cM\cJ/g if (OS_Win); utf8::encode($line) if $unicode; $w->BackTrace("Cannot write to temp file:$!\n") and return unless print $tempfh $line; $index = $end; if ( ( $count++ % 1000 ) == 0 ) { $progress = $w->TextUndoFileProgress( Saving => $filename, $count, $count, $lines ); } } $progress->withdraw if defined $progress; close $tempfh; if ( -e $filename ) { chmod 0777, $filename; unlink $filename; } if ( rename( $tempfilename, $filename ) ) { #$w->ResetUndo; #serves no purpose to reset undo $w->FileName($filename); return 1; } else { my $msg = "Cannot save $filename:$!. Text is in the temporary +file $tempfilename."; $w->messageBox( -icon => 'warning', -title => 'Warning', -type => 'OK', -message => $msg.(OS_Win?" (Are you using Windows Explorer + Preview?)":""), ); $w->BackTrace($msg); return 0; } }
    Regards, Wayne
Re^4: File permissions problem (updated)
by wdhammond (Novice) on Dec 15, 2016 at 22:57 UTC

    Thanks again Hauke.

    The complete application is open source and available here: https://sourceforge.net/projects/guiguts/

    I have it installed in Fedora 25 with Padre as a troubleshooting aid.

    There are a couple of other problems too, but I thought this one would be the easiest one to troubleshoot.

    Regards, Wayne

      Hi Wayne,

      So what's the result of running those commands to check on your umask setting? Update: Oh, I misunderstood your post because of the formatting! (missing <code> tags; I just considered the node for editing)

      Taking a look a the function SaveUTF from the source that you also posted in your other reply, it appears the module is saving files by using File::Temp to create a new file, and then replacing the old file with an unlink and a rename. File::Temp apparently sets the files it creates to mode 0600. I don't see an option to change that, so it'd probably be necessary to chmod the files after creation. You could simply set it to an explicit mode like 0640, or you could use the current umask like so: chmod(0666&~umask,$filename);

      Regards,
      -- Hauke D

        Hi Hauke,

        Sorry about the delay in responding, lost this response. I need to respond linearly to the comments.

        The response to umask command is 0002 which gives file permissions 0664. I should have looked at the permissions before responding instead of relying on my memory.:)

        There is a section that appears similar to your possible fix:

        # Custom file save routine to handle unicode files sub SaveUTF { my ( $w, $filename ) = @_; $filename = $w->FileName unless defined $filename; my $dir = dirname($filename); my $perms = ( stat($dir) )[2] & 07777; unless ( $perms & 0200 ) { $perms = $perms | 0200; chmod $perms, $dir or $w->BackTrace("Can not write to directory $dir: $!\n") and return; }
        Regards, Wayne