[Israel.pm] File permissions and File::Copy
oron at actcom.co.il
Mon May 31 14:30:13 PDT 2004
On Monday 31 May 2004 17:15, Offer Kaye wrote:
> What can I do to make File::Copy preserve the file permissions when copying?
> Is this a bug or a feature? :-)
A feature of course... in Unix/Linux every process has a umask field
that is inherited by its child processes. Whenever a file is created by
a process, its initial permission is calculated by *binary substraction*
of the umask value from the permissions asked by the application.
This let the user set a simple "policy" to restrict the default permissions
of files/directories created. You use the shell 'umask' command to view or
set the current umask value and the shell passes this value to all
subprocesses it creates later.
- A process has a umask of 027
- An application creates (via open) a file with mode 666 (-rw-rw-rw-).
- The resulting file is 640 (-rw-r-----).
- Now an application creates a directory with mode 777 (-rwxrwxrwx).
- The resulting directory is 750 (-rwxr-x---).
As you already answered yourself, you may "copy" the persmissions
from the old file to the new file (stat + chmod). This is exactly what
the '-p' option of the Unix/Linux 'cp' command does.
> And no, I don't want to use the shell's copy...
Your latest code fragment is equivalent... good. It was nice
if File::Copy had an *option* to this effect.
Oron Peled Voice/Fax: +972-4-8228492
oron at actcom.co.il http://www.actcom.co.il/~oron
"UNIX was not designed to stop you from doing stupid things, because
that would also stop you from doing clever things."
More information about the Perl