SPUG: Re: Using mkpath

Jeremy Devenport jeremy at weezel.com
Sun Mar 3 20:57:57 CST 2002


BZZZT! Wrong.

The snippet below is the only part of File::Path (the 5.6.1 version)
that calls croak. Notice that it specifically doesn't croak if the
directory exists, it's even commented. The documentation also doesn't
say that it croaks if the directory exists. And I just ran a test and it
didn't croak.

        unless (mkdir($path,$mode)) {
            my $e = $!;
            # allow for another process to have created it meanwhile
            croak "mkdir $path: $e" unless -d $path;
        }

It even skips trying to make the directory in the first place if it
already exists a few lines farther up, the unless -d $path just handles
TOCTOU race conditions.

I don't understand why there is so much confusion on this list about
this module. Sure the documentation is incomplete but it's only about 35
lines of code. perldoc -m File::Path will bring up the code in a hurry
if you don't want to go looking for it.

Jeremy

-----Original Message-----
From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org] On Behalf
Of John Labovitz
Sent: Sunday, March 03, 2002 5:30 PM
To: Yitzchak Scott-Thoennes; spug-list at pm.org
Cc: richard at richard-anderson.org
Subject: Re: SPUG: Re: Using mkpath


On 3/3/02 10:24 AM, "Yitzchak Scott-Thoennes" <sthoenna at efn.org> wrote:

> In article <001201c1c189$12e32180$1a88ddd1 at aciwin>,
> "Richard Anderson" <richard at richard-anderson.org> wrote:
>> In fact, if
>> mkpath encounters a permissions problem, etc. it does NOT return a 
>> list of directories, it throws a runtime error and the calling 
>> routine never gets the list of directories.
> 
> Fair enough.  (Though it seems to me that would only happen with a 
> disk filling up between making paths--or as a race condition).

It also croaks if the directories already exist -- a fairly common
situation.

-- 
John Labovitz
johnl at johnlabovitz.com
www.johnlabovitz.com


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your
Email-address  For daily traffic, use spug-list for LIST ;  for weekly,
spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list