Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: using File::Spec effectively

Reply
Thread Tools

Re: using File::Spec effectively

 
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-10-2013
Cal Dershowitz <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      10-16-2013
Cal Dershowitz <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      10-18-2013
Cal Dershowitz <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: using HTML::Template effectively Rainer Weikusat Perl Misc 4 07-07-2012 04:56 AM
Re: using HTML::Template effectively Peter Makholm Perl Misc 0 06-27-2012 07:25 AM
Re: using HTML::Template effectively J. Gleixner Perl Misc 0 06-26-2012 08:25 PM
How to control order of spec execution in "spec specs/* " ? Andrew Chen Ruby 1 03-25-2008 12:36 PM
Effectively using Magic and Range in Runescape virgolds_comrsgold Computer Support 0 06-11-2007 08:20 AM



Advertisments