Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: File permissions problem (updated)

by wdhammond (Novice)
on Dec 15, 2016 at 23:21 UTC ( [id://1177896]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1177896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found