Ignore:
Timestamp:
2013-05-27T12:27:31+12:00 (11 years ago)
Author:
jmt12
Message:

Adding makeAllDirectories() (which I'd only implemented in LocalFS) to FileUtils (which in turn calls the Driver specific makeDirectory() recursively) and added test for this function

File:
1 edited

Legend:

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

    r27422 r27481  
    215215}
    216216# /** linkFile() **/
    217 
    218 ## @function makeAllDirectories()
    219 #
    220 # in case anyone cares - I did some testing (using perls Benchmark module)
    221 # on this subroutine against File::Path::mkpath (). mk_all_dir() is apparently
    222 # slightly faster (surprisingly) - Stefan.
    223 #
    224 sub makeAllDirectories
    225 {
    226   my ($dir) = @_;
    227 
    228   # use / for the directory separator, remove duplicate and
    229   # trailing slashes
    230   $dir=~s/[\\\/]+/\//g;
    231   $dir=~s/[\\\/]+$//;
    232 
    233   # ensure the directory doesn't already exist
    234   if (-e $dir)
    235   {
    236     return 0;
    237   }
    238 
    239   # make sure the cache directory exists
    240   my $dirsofar = "";
    241   my $first = 1;
    242   foreach my $dirname (split ("/", $dir))
    243   {
    244     $dirsofar .= "/" unless $first;
    245     $first = 0;
    246 
    247     $dirsofar .= $dirname;
    248 
    249     next if $dirname =~ /^(|[a-z]:)$/i;
    250     if (!-e $dirsofar)
    251     {
    252       my $store_umask = umask(0002);
    253       my $mkdir_ok = mkdir ($dirsofar, 0777);
    254       umask($store_umask);
    255       if (!$mkdir_ok)
    256       {
    257         &FileUtils::printError('Could not create directory: ' . $dirsofar);
    258         return 0;
    259       }
    260     }
    261   }
    262   return (-e $dir);
    263 }
    264 ## makeAllDirectories()
    265 
    266217
    267218## @function makeDirectory()
Note: See TracChangeset for help on using the changeset viewer.