in reply to Why does File::Find try to chdir to $PWD (and fail) even if $PWD is not itself in search list?
When the program exits, any path changes will be lost anyway. Your prompt will still come back to your shell's current working directory since environment changes do not flow upstream.
I recommend using chdir to change to the root directory for sake of portability, but you could make it any other directory the account can access.
Below is some example code. I can run this as root in root's home directory without any errors. It changes to my non-root account, changes to the root ('/', not to be confused with '/root') directory, searches a directory my non--root account can access (and actually owns in this case, but that's not important), and File::Find returns to '/' when it's done.
use File::Find; $< = $> = 500; sub w { print $_ . "\n" } chdir q(/); find( \&w, qw( /home/chris/Pictures ) );
There's no reason for File::Find not to return to the directory from which it started. There's also no reason to have it return to a directory where the user account under which it is operating has no privileges. No code that might be executed afterward would have rights to that directory either anyway.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does File::Find try to chdir to $PWD (and fail) even if $PWD is not itself in search list?
by puterboy (Scribe) on Nov 26, 2008 at 07:24 UTC | |
by mr_mischief (Monsignor) on Nov 26, 2008 at 15:45 UTC |