Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: File::Path and mode with sgid

by Hena (Friar)
on Apr 27, 2012 at 09:16 UTC ( [id://967562]=note: print w/replies, xml ) Need Help??


in reply to Re: File::Path and mode with sgid
in thread File::Path and mode with sgid

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

Replies are listed 'Best First'.
Re^3: File::Path and mode with sgid
by Eliya (Vicar) on Apr 27, 2012 at 09:44 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://967562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found