Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: File::Path and mode with sgid

by Eliya (Vicar)
on Apr 27, 2012 at 09:12 UTC ( #967560=note: print w/ replies, xml ) Need Help??


in reply to File::Path and mode with sgid

The mode is an octal number, so you need 02750 (note the leading zero).


Comment on Re: File::Path and mode with sgid
Download Code
Re^2: File::Path and mode with sgid
by Hena (Friar) on Apr 27, 2012 at 09:16 UTC
    That won't produce proper permissions.
    $ perl -e 'BEGIN{use File::Path qw(make_path)} make_path("foo/bar", { +mode => 02750 })' $ ls -lh total 4.0K drwxr-x--- 3 hena hena 4.0K 2012-04-27 12:14 foo $ mkdir faa $ chmod 2750 faa $ ls -lh total 8.0K drwxr-s--- 2 hena hena 4.0K 2012-04-27 12:15 faa drwxr-x--- 3 hena hena 4.0K 2012-04-27 12:14 foo

      Well, it seems File::Path::make_path uses plain mkdir calls under the hood, which don't honor special bits.1  I.e., the following wouldn't work either

      $ perl -e 'mkdir "foo", 02750' $ ls -ld foo drwxr-x--- 2 eliya eliya 4096 Apr 27 11:40 foo/

      while chmod does

      $ perl -e 'mkdir "foo", 0750; chmod 02750, "foo"' $ ls -ld foo drwxr-s--- 2 eliya eliya 4096 Apr 27 11:41 foo/

      ___

      1 This is OS specific; it has nothing to do with Perl.  Perl just passes through the mode value to the mkdir system call (see man 2 mkdir).

      The command mkdir -pm2750 foo also has to apply a chmod after having used mkdir:

      $ strace mkdir -pm2750 foo ... mkdir("foo", 02750) = 0 open("foo", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3 fstat(3, {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0 fchmod(3, 02750) = 0 <--- ...
        You are right. Using mkdir -pm2750 foo/faa creates faa with correct permissions and foo with wrong permissions. How annoying. Essentially:
        mkdir -pm2750 foo/bar $ ls -lh total 4.0K drwxrwxr-x 3 hena hena 4.0K 2012-04-27 14:30 foo $ ls -lh foo/ total 4.0K drwxr-s--- 2 hena hena 4.0K 2012-04-27 14:30 bar

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-11-26 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (173 votes), past polls