Re: using File::Spec effectively

Discussion in 'Perl Misc' started by Ben Bacarisse, Oct 10, 2013.

  1. Cal Dershowitz <> writes:
    <snip searching for questions...>

    > unless(-e $path_to_images or mkdir($path_to_images, 0755)) {
    > die "Unable to create $to\n";
    > };

    <snip>

    > Q1 = shift; that is, is there something less-kludgy than pasting
    > together paths with what the method call of File::Spec rootdir()
    > returns?


    catfile. There's no guarantee that rootdir() can be used to join path
    components. Did you not see catfile (and the related catdir) in the
    documentation?

    > Q2 I've been reading the development in the alpaca book and was pretty
    > sure that I could create a regex that would know that I want to have
    > an or among pm css and tmpl, but I couldn't achieve as a lexical
    > variable. Instead I have 3 pretty fortranny-looking controls. They
    > might be cute as a first effort, but I'd like to see what an old perl
    > pro might write instead.


    I can't tell what this means.

    > Q3) Do I set permissions correctly? Since I set them to 755, what
    > situations would I do as well? For example, I could grant others in
    > the group write priveleges. What number would that entail, and how is
    > that best represented in perl?


    There's lots to say here but it's not clear what you really want to
    know. It looks like you might not have read the documentation for mkdir
    which tells you that the mask you give it does not directly set the
    permissions. It also directs you to the discussion of permissions in
    the description of umask. Are still left with questions after reading
    those two?

    --
    Ben.
     
    Ben Bacarisse, Oct 10, 2013
    #1
    1. Advertising

  2. Re: using File::Spec to figure out that Path::Class is really what I want

    Cal Dershowitz <> writes:

    [...]

    >> There's lots to say here but it's not clear what you really want to
    >> know. It looks like you might not have read the documentation for mkdir
    >> which tells you that the mask you give it does not directly set the
    >> permissions. It also directs you to the discussion of permissions in
    >> the description of umask. Are still left with questions after reading
    >> those two?
    >>

    >
    > I would like to honestly say that I had no more questions about it,
    > but that wouldn't be true. I man'ed mkdir and chased the explanation
    > for umask, and to read it made it sound like an adjustment to what the
    > OS might give you.


    The traditional way to deal with permissions when creating a new
    filesystem object would be to specify the maximally useful permission in
    the creating call, ie

    mkdir('/tmp/aktenordner', 0777);

    and leave it to the user to use a umask value requesting that the bits
    he doesn't like will be disabled. For the common umask value of 022
    (disable other and group write permission), the call above would end up
    creating a directory with 0755 permissions.

    If you wanted the permissions to be exactly what was given in the mkdir,
    you'd have to clear the umask first. It is usually sensible to use a
    code sequence a la

    my $omask;

    $omask = umask(0);
    mkdir('/tmp/aktendurcheinanderer', 0764);
    umask($omask);

    to avoid unintended interactions with code following the traditional
    convention.

    The umask can also be used to control the effective permissions of a
    filesystem object created by some system call which doesn't take an
    explicit permission argument but implicitly uses 0777. In this case, the
    umask can be set to the inverse of the desired permission set in order
    to create the directory entry with the desired permisson set. Eg,

    --------
    use Socket;

    my $sk;

    socket($sk, PF_UNIX, SOCK_DGRAM, 0);
    umask(~0660);
    bind($sk, pack_sockaddr_un('/tmp/strangers_no_trespass'));
    --------

    can be used to create a directory entry for a UNIX-domain socket which
    won't be world-writeable.
     
    Rainer Weikusat, Oct 16, 2013
    #2
    1. Advertising

  3. Re: using File::Spec to figure out that Path::Class is really what I want

    Cal Dershowitz <> writes:
    > On 10/16/2013 05:39 AM, Rainer Weikusat wrote:
    >
    >> The traditional way to deal with permissions when creating a new
    >> filesystem object would be to specify the maximally useful permission in
    >> the creating call, ie
    >>
    >> mkdir('/tmp/aktenordner', 0777);
    >>
    >> and leave it to the user to use a umask value requesting that the bits
    >> he doesn't like will be disabled. For the common umask value of 022
    >> (disable other and group write permission), the call above would end up
    >> creating a directory with 0755 permissions.

    >
    > Alright, I get now that umask IS a mask.
    >
    > $ umask
    > 0022
    > $ umask -S
    > u=rwx,g=rx,o=rx
    > $ mkdir rumpelstiltskin
    > $ ls -l
    > total 16
    > drwxr-xr-x 2 fred automation 4096 Oct 17 15:27 rumpelstiltskin
    > $
    >
    > These numbers would add to EEEE octal. Where's the room for the
    > sticky bits?


    'Octal' means 'base 8', hence, octal digits run from 0 - 7. Assuming all
    bits were set, the numerical equivalent would be 0777. The next three
    bits are used for 'special permission bits',

    01000 - sticky bit
    02000 - setgid bit
    04000 - setuid bit
     
    Rainer Weikusat, Oct 18, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Chen
    Replies:
    1
    Views:
    199
    David Chelimsky
    Mar 25, 2008
  2. J. Gleixner

    Re: using HTML::Template effectively

    J. Gleixner, Jun 26, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    467
    J. Gleixner
    Jun 26, 2012
  3. Peter Makholm

    Re: using HTML::Template effectively

    Peter Makholm, Jun 27, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    448
    Peter Makholm
    Jun 27, 2012
  4. Rainer Weikusat

    Re: using HTML::Template effectively

    Rainer Weikusat, Jun 27, 2012, in forum: Perl Misc
    Replies:
    4
    Views:
    481
    Ivan Shmakov
    Jul 7, 2012
  5. Mart van de Wege

    Re: using cpan effectively

    Mart van de Wege, Aug 15, 2012, in forum: Perl Misc
    Replies:
    6
    Views:
    1,845
    Rainer Weikusat
    Aug 26, 2012
Loading...

Share This Page