bronto has asked for the wisdom of the Perl Monks concerning the following question:
Dear Fellow monks
I'm writing a small script to move a lot of data from a file server to another, and I plan to use two piped tars. I'm going to make the script run something like
( cd $sourcefs && tar cpsf - . ) | ( cd $destfs && tar xvpsf - )
The script will then continue and do some chown/chgrp here and there.
Even if I won't have to worry about this script's security, a question arose in my head
As we know, it's a good practice, when you have to chdir to a directory, to leave out any preliminary test on the existence of the directory before chdir; instead, it's better to chdir directly and check the return value to see if it succeeded; this helps to avoid race conditions.
But when you need to chdir and read data in one directory and pipe it to another process, that should chdir, read your data and write it back down to the disk, what would you do to stay on the safe side?
Thanks in advance for your wisdom
Ciao!
--bronto
PS: I know the -C option of GNU tar. Don't worry too much about tar, the question is general and not restricted to my script
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chdir and security
by bluto (Curate) on Sep 10, 2002 at 17:55 UTC | |
|
Re: chdir and security
by sauoq (Abbot) on Sep 10, 2002 at 22:22 UTC | |
|
Re: chdir and security
by belden (Friar) on Sep 10, 2002 at 21:13 UTC |