jmmistrot has asked for the wisdom of the Perl Monks concerning the following question:

Fellow wisdom seekers... I am having problems with this actually working... I mirror a path structure that has locked permission. I then iterate over the new structure with File::find setting the permission as I go.. and ouila diddley squat! Here is what I got:
sub changemod { chmod 0777, $File::Find::name; } eval{ mirror($arg{template_path} , $arg{outpath}); ## this doesn't seem to work find(\&changemod, $arg{outpath}); }; if($@){ print STDOUT "Couldn't create $arg{outpath}: $@"; return 0; }
any advice tips tricks admonishments? -jm

Replies are listed 'Best First'.
Re: File::Find and recursive chmod on Win32?
by goibhniu (Hermit) on Sep 12, 2007 at 18:48 UTC

    Windows file systems don't have all thos bits. perlfunc says:

    Perl was born in Unix and can therefore access all common Unix system calls. In non-Unix environments, the functionality of some Unix system calls may not be available, or details of the available functionality may differ slightly. The Perl functions affected by this are:

    -X, binmode, chmod, chown, . . .

    For more information about the portability of these functions, see perlport and other available platform-specific documentation.

    perlport says chmod is . . .

    Only good for changing "owner" read-write access, "group", and "other" bits are meaningless. (Win32)

    Update: I misunderstood and apologize for the pedantry. I'll keep looking and let you know if I find something.


    I humbly seek wisdom.
      Thanks for the response... My issue isn't the number of available bits and Unix parity.. Coming from a Unix background I do understand the vagaries of Win32 vs. *nix file systems.. it is rather and issue of chmod working as advertised in the context of the File::Find helper function as documented on CPAN (perldocs)... If I use chmod on its own it behaves as expected (only setting the owner bits ala Win32)... If I wrap chmod in a helper function, as in my posted example, and pass the function pointer to File::Find no bits are set at all... The function is getting called.. but no effect.
Re: File::Find and recursive chmod on Win32? ($_,$!)
by tye (Sage) on Sep 13, 2007 at 01:50 UTC

    $File::Find::name would only work if you gave an absolute path to find() (and then would still be slower). Use $_ instead. If you did what you should always do when calling such system functions, you would have probably already figured this out:

    chmod 0777, $File::Find::name or warn "Can't chmod 077, $File::Find::name: $!\n";

    - tye