Make_path does not set the mode as stated

When I call make_path

(from the main File::Path

module, supplying the mode, the directory being 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 expected to see:

drwxrwx--- 2 itk itkadm 4096 Sep 19 11:07 foobar/



source to share

2 answers

I missed this detail in make_path


mode: Numeric permission mode for each created directory (default is 0777), to change 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/


Pay attention to umask(0)


As Evan Carroll pointed out, the version File::Path

shipped with newer versions of perl (> = 5.24) has an option chmod

that might be a more convenient way to set the mode of the generated directories.



Instead of setting directory permissions to 0

. Try using the parameter chmod


perl -MFile::Path=make_path -e 'make_path("foobar", { chmod=>0770 });'




All Articles