2
0

mkdir-p.pl 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #! /usr/bin/env perl
  2. # Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # On some systems, the -p option to mkdir (= also create any missing parent
  9. # directories) is not available.
  10. my $arg;
  11. foreach $arg (@ARGV) {
  12. $arg =~ tr|\\|/|;
  13. &do_mkdir_p($arg);
  14. }
  15. sub do_mkdir_p {
  16. local($dir) = @_;
  17. $dir =~ s|/*\Z(?!\n)||s;
  18. if (-d $dir) {
  19. return;
  20. }
  21. if ($dir =~ m|[^/]/|s) {
  22. local($parent) = $dir;
  23. $parent =~ s|[^/]*\Z(?!\n)||s;
  24. do_mkdir_p($parent);
  25. }
  26. unless (mkdir($dir, 0777)) {
  27. if (-d $dir) {
  28. # We raced against another instance doing the same thing.
  29. return;
  30. }
  31. die "Cannot create directory $dir: $!\n";
  32. }
  33. print "created directory `$dir'\n";
  34. }