[Chicago-talk] CGI umask
lembark at wrkhors.com
Wed Mar 3 18:08:38 CST 2004
-- jason scott gessner <jason at multiply.org>
> On Wed, 2004-03-03 at 13:50, Steven Lembark wrote:
>> As a general approach, you can mkdir the new one, chmod
>> it to the appropriate mods, then stat it. That allows for
>> existing directories + ones you don't own that have the
>> correct mod's anyway.
> I'm not sure I follow you, Steven. What does stat'ing it do? And by
> that do you simply mean doing a file test (-d, -r, etc?).
mkdir may fail if the directory already exists.
chmod may fail if the directory has another owner.
This may leave you with a perfectly workable directory,
however. Using die in this case may leave your code
exiting in a situation where it really can run properly.
When the mkdir and chmod have been issued, stat the file
and check its mods. If the stat fails for any reason or
if the mods are not sufficient for your needs then die
based on the circumstances (vs. the failed mkdir or chmod).
perldoc the stat call, one of the return values are the
mods in octal. These can be bit-masked (or checked with
>= in most cases) to check for a wrieable directory.
The -blah file tests are really a stat call with some
further checking on the return value. That's why the '_'
argument was added to avoid multiple stat's. You can do
the same thing with a single explicit stat and a check
of the appropriate argument in the array returned.
Note: being unable to stat the file is a q&d test for
nonexistant/inaccessable directories and after the
mkdir/chmod steps is a clear indication that something
Steven Lembark 2930 W. Palmer
Workhorse Computing Chicago, IL 60647
+1 888 359 3508
More information about the Chicago-talk