my $old_umask = umask; umask 0777; mkdir $dump_dir or die "Couldn't create '$dump_dir': $!"; umask $old_umask;

This actually does the opposite of what the OP asked for. A permissive umask is a smaller number (IE: less bits turned on) than a non-permissive mask. Setting the umask to 0777 ensures that no permissions are assigned, regardless of what mode you set for mkdir (or if you leave it as the default, as above). The number in the umask is applied to the mode bits of a created file with the following logic:

MODE & ~MASK

So, for the mode bits 0777 and a umask of 0777:

perl -e'printf "%o\n", 0777 & ~0777' =>0 (or 0000)

For a umask of 0000:

perl -e'printf "%o\n", 0777 & ~0000' =>777 (or 0777)

By default (at least it is here), the umask is set to 022. If we use the logic above with this knowledge, we can see why the OP's mode argument to mkdir didn't take affect:

$ perl -e'printf "umask: %04o\n", umask; printf "mode: %04o\n", 0777; +printf "masked mode : %04o\n", 0777 & ~umask' umask: 0022 mode: 0777 masked mode: 0755 $

In short, the answer to the OP's question is to set the umask to 0. Note the following:

$ perl -e'umask 0; printf "umask: %04o\n", umask; printf "mode: %04o\n +", 0777; printf "ma sked mode: %04o\n", 0777 & ~umask' umask: 0000 mode: 0777 masked mode: 0777 $ perl -e'umask 0; mkdir "FOO", 0777' $ ls -dl FOO drwxrwxrwx 2 matt matt 6 Apr 13 20:07 FOO $

umask is slightly counter-intuitive, but I found that when I saw the boolean math it helped me to understand it much better. I hope this helps.

Best Regards

m.att


In reply to Re^2: Permission problem in creating directory! by m.att
in thread Permission problem in creating directory! by madtoperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.