Reputation: 30597
When I call make_path
(from the core File::Path
module, supplying a mode, the directory that is created does not have the mode I requested:
$ perl -MFile::Path=make_path -e 'make_path("foobar", { mode=>0770 });'
$ ls -ld foobar/
drwxr-x--- 2 itk itkadm 4096 Sep 19 11:10 foobar/
I was expecting to see:
drwxrwx--- 2 itk itkadm 4096 Sep 19 11:07 foobar/
Upvotes: 3
Views: 1076
Reputation: 30597
I missed this detail in the make_path
documentation:
mode: The numeric permissions mode to apply to each created directory (defaults to 0777), to be modified by the current umask.
I was not expecting this because the shell equivalent (mkdir -m 0770 -p foobar
) does not consider umask
.
This works as expected:
$ perl -MFile::Path=make_path -e 'umask(0); make_path("foobar", { mode=>0770 });'
$ ls -ld foobar/
drwxrwx--- 2 itk itkadm 4096 Sep 19 11:13 foobar/
Note the umask(0)
.
As pointed out by Evan Carroll, the version of File::Path
supplued with newer perl versions (>=5.24) have a chmod
option which may be a more convenient way to set the mode of created directories.
Upvotes: 2
Reputation: 1
Rather than setting the permissions for the directory to 0
. Try instead just using the chmod
option to File::Path::make_path
perl -MFile::Path=make_path -e 'make_path("foobar", { chmod=>0770 });'
Upvotes: 2