Changeset 27481 for gs2-extensions
- Timestamp:
- 2013-05-27T12:27:31+12:00 (11 years ago)
- Location:
- gs2-extensions/parallel-building/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/bin/script/test_fileutils.pl
r27480 r27481 10 10 my $display_errors = 0; 11 11 12 my $test_localfs = 1;12 my $test_localfs = 0; 13 13 my $test_hdthriftfs = 1; 14 my $test_hdfsshell = 1;14 my $test_hdfsshell = 0; 15 15 16 16 # Globals … … 467 467 $pass_count += &testAction(\$test_count, 'makeDirectory() to create a new directory', 1, &FileUtils::makeDirectory($path)); 468 468 $pass_count += &testAction(\$test_count, 'makeDirectory() for an existing directory', 1, &FileUtils::makeDirectory($path)); 469 470 my $multiple_dirs_path = $path . '/foo/bar/wibble'; 471 $pass_count += &testAction(\$test_count, 'makeAllDirectories() to create several nested directories', 1, &FileUtils::makeAllDirectories($multiple_dirs_path)); 472 &FileUtils::removeFilesRecursive($path . '/foo'); 469 473 } 470 474 -
gs2-extensions/parallel-building/trunk/src/perllib/FileUtils.pm
r27421 r27481 398 398 399 399 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 # 406 sub 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 400 448 ## @function sanitizePath() 401 449 # … … 543 591 ## isSymbolicLink() 544 592 545 # /** @function makeAllDirectories546 # */547 sub makeAllDirectories548 {549 my $path = shift(@_);550 my $driver = &FileUtils::_determineDriver($path);551 return &FileUtils::_callFunction($driver, 'makeAllDirectories', $path);552 }553 # /** makeAllDirectories() **/554 593 555 594 # /** -
gs2-extensions/parallel-building/trunk/src/perllib/FileUtils/HDThriftFS.pm
r27478 r27481 130 130 if ($path !~ /HDThriftFS:\/\//) 131 131 { 132 & _printError('Not a valid thrift URI: ' . $path);132 &FileUtils::printError('Not a valid thrift URI: ' . $path); 133 133 } 134 134 else -
gs2-extensions/parallel-building/trunk/src/perllib/FileUtils/LocalFS.pm
r27422 r27481 215 215 } 216 216 # /** 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 apparently222 # slightly faster (surprisingly) - Stefan.223 #224 sub makeAllDirectories225 {226 my ($dir) = @_;227 228 # use / for the directory separator, remove duplicate and229 # trailing slashes230 $dir=~s/[\\\/]+/\//g;231 $dir=~s/[\\\/]+$//;232 233 # ensure the directory doesn't already exist234 if (-e $dir)235 {236 return 0;237 }238 239 # make sure the cache directory exists240 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 266 217 267 218 ## @function makeDirectory()
Note:
See TracChangeset
for help on using the changeset viewer.