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.pm

    r27421 r27481  
    398398
    399399
     400## @function makeAllDirectories()
     401#
     402# in case anyone cares - I did some testing (using perls Benchmark module)
     403# on this subroutine against File::Path::mkpath (). mk_all_dir() is apparently
     404# slightly faster (surprisingly) - Stefan.
     405#
     406sub makeAllDirectories
     407{
     408  my ($raw_dir) = @_;
     409  # use / for the directory separator, remove duplicate and
     410  # trailing slashes
     411  &sanitizePath($raw_dir);
     412  # ensure the directory doesn't already exist
     413  if (&directoryExists($raw_dir))
     414  {
     415    return 0;
     416  }
     417  if ($raw_dir =~ /^(.+?:\/\/)(.*)/)
     418  {
     419    my $dirsofar = '';
     420    if (defined $1)
     421    {
     422      $dirsofar = $1;
     423    }
     424    my $dir = $2;
     425    my $first = 1;
     426    foreach my $dirname (split ("/", $dir))
     427    {
     428      $dirsofar .= "/" unless $first;
     429      $first = 0;
     430      $dirsofar .= $dirname;
     431      next if $dirname =~ /^(|[a-z]:)$/i;
     432      if (!-e $dirsofar)
     433      {
     434        my $mkdir_ok = &makeDirectory($dirsofar);
     435        if (!$mkdir_ok)
     436        {
     437          &FileUtils::printError('Could not create directory: ' . $dirsofar);
     438          return 0;
     439        }
     440      }
     441    }
     442  }
     443  return (&directoryExists($raw_dir));
     444}
     445## makeAllDirectories()
     446
     447
    400448## @function sanitizePath()
    401449#
     
    543591## isSymbolicLink()
    544592
    545 # /** @function makeAllDirectories
    546 #  */
    547 sub makeAllDirectories
    548 {
    549   my $path = shift(@_);
    550   my $driver = &FileUtils::_determineDriver($path);
    551   return &FileUtils::_callFunction($driver, 'makeAllDirectories', $path);
    552 }
    553 # /** makeAllDirectories() **/
    554593
    555594# /**
Note: See TracChangeset for help on using the changeset viewer.