Changeset 27682

Show
Ignore:
Timestamp:
21.06.2013 12:19:57 (6 years ago)
Author:
jmt12
Message:

Copying makeAllDirectories() from vanilla FileUtils?.pm

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/perllib/FileUtils/LocalFS.pm

    r27638 r27682  
    240240} 
    241241# /** linkFile() **/ 
     242 
     243 
     244## @function makeAllDirectories() 
     245# 
     246# in case anyone cares - I did some testing (using perls Benchmark module) 
     247# on this subroutine against File::Path::mkpath (). mk_all_dir() is apparently 
     248# slightly faster (surprisingly) - Stefan. 
     249# 
     250sub makeAllDirectories 
     251{ 
     252  my ($dir) = @_; 
     253 
     254  # use / for the directory separator, remove duplicate and 
     255  # trailing slashes 
     256  $dir=~s/[\\\/]+/\//g; 
     257  $dir=~s/[\\\/]+$//; 
     258 
     259  # make sure the cache directory exists 
     260  my $dirsofar = ""; 
     261  my $first = 1; 
     262  foreach my $dirname (split ("/", $dir)) 
     263  { 
     264    $dirsofar .= "/" unless $first; 
     265    $first = 0; 
     266 
     267    $dirsofar .= $dirname; 
     268 
     269    next if $dirname =~ /^(|[a-z]:)$/i; 
     270    if (!-e $dirsofar) 
     271    { 
     272      my $store_umask = umask(0002); 
     273      my $mkdir_ok = mkdir ($dirsofar, 0777); 
     274      umask($store_umask); 
     275      if (!$mkdir_ok) 
     276      { 
     277        print STDERR "FileUtils::makeAllDirectories() could not create directory $dirsofar\n"; 
     278        return; 
     279      } 
     280    } 
     281  } 
     282 return 1; 
     283} 
     284## makeAllDirectories() 
     285 
    242286 
    243287## @function makeDirectory()