Re: Saving permissions on files/folders (perl)

From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 11/17/04


Date: Wed, 17 Nov 2004 15:54:57 +0000

2004-11-17, 15:28(+00), Gnarlodious:
> Entity Stephane CHAZELAS spoke thus:
>
>> using perl may be the best and most portable solution.
> It seems like it, for OSX
>
>> perl -MFile::Find -l0e '
>> $,=$\;
>> find sub {
>> @s=lstat($_);print ($File::Find::name,@s[2,4,5]) unless -l _;
>> }, "."' > /some/file
>
> OK, good. I don't understand perl, but the file I get looks like this:
>
> /Network/AFP/MountedDisks3318850180/Network/AFP/MountServer3318850180/Networ
> k/AFP/Ping Manhattan3326150180
>
> etc.
> I don't see any delimiters in this data, which may be why the Restore script
> errors.

They are delimited by NUL characters. A cat -vte should show
them as ^@.

>> Then, to restore:
>>
>> perl -0 -le '
>> while ($f=<>,$m=<> & 07777,$u=<>,$g=<>) {
>> chown $u, $g, $f
>> chmod $m, $f
>> }' < /some/file
>
> syntax error at -e line 4, near "$f
> chmod"
> Execution of -e aborted due to compilation errors.

This looks like a quoting problem of your shell. Are you using
csh or tcsh by any chance?

If you have problem with you shell, try putting the above
command in a file:

while ($f=<>,$m=<> & 07777,$u=<>,$g=<>) {
  chown $u, $g, $f
  chmod $m, $f
}

Then run perl -l0 the-file.pl < /some/file

>
> How would the first script insert a newLine after each entry (say, ascii 13)
> and a space between path and permission set?
[...]

newLine and space are valid characters in a filename so should
not be used to delimit file names. That's why I used the NUL
character.

-- 
Stephane


Relevant Pages

  • Re: chown recursively
    ... utterly dwarves the overhead of starting another process. ... '$gid' and '$dir' contain characters that are special to ... shell, no shell will be started by perl - perl will call chown directly). ...
    (comp.lang.perl.misc)
  • Re: qx() wont accept over (about) 128,000 characters
    ... I submit such a program to the operating system using Perl's ... Unfortunately, giving qxover 128,420 characters (about and can vary ... $ perl -e' ... When it is saved as a file the shell ignores the comment lines. ...
    (perl.beginners)
  • Re: splitting a very large file based on characters in a record (performance)
    ... Each record is of length 250 characters and does not ... > have delimiters. ... I have to split each record into 2 separate records ... But since Perl is more flexible than shell and awk, ...
    (comp.unix.shell)
  • Re: Saving permissions on files/folders (perl)
    ... >> I don't see any delimiters in this data, which may be why the Restore script ... > They are delimited by NUL characters. ... > This looks like a quoting problem of your shell. ... > not be used to delimit file names. ...
    (comp.unix.shell)
  • Re: Reading HTTP response body that is gzipd *and* in UTF-8
    ... The reason I'm not using PerlIO::gzip is mostly just ignorance. ... BM> anything that's visible at the Perl level. ... BM> meaningless to apply gzip to a stream of characters. ... BM> Encode the value of the charset MIME parameter). ...
    (comp.lang.perl.misc)