diff options
Diffstat (limited to 'MDK')
-rw-r--r-- | MDK/Common/File.pm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/MDK/Common/File.pm b/MDK/Common/File.pm index 9b6ee0b..7f6bd09 100644 --- a/MDK/Common/File.pm +++ b/MDK/Common/File.pm @@ -32,6 +32,10 @@ array context it returns the lines creates a file and outputs the list (if the file exists, it is clobbered) +=item mkdir_p(DIRNAME) + +creates the directory (make parent directories as needed) + =item linkf(SOURCE, DESTINATION) =item symlinkf(SOURCE, DESTINATION) @@ -84,7 +88,7 @@ package MDK::Common::File; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); @ISA = qw(Exporter); -@EXPORT_OK = qw(dirname basename cat_ cat__ output linkf symlinkf renamef touch all glob_ substInFile expand_symlinks openFileMaybeCompressed catMaybeCompressed); +@EXPORT_OK = qw(dirname basename cat_ cat__ output linkf symlinkf renamef mkdir_p touch all glob_ substInFile expand_symlinks openFileMaybeCompressed catMaybeCompressed); %EXPORT_TAGS = (all => [ @EXPORT_OK ]); sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' } @@ -97,6 +101,18 @@ sub symlinkf { unlink $_[1]; symlink $_[0], $_[1] } sub renamef { unlink $_[1]; rename $_[0], $_[1] } +sub mkdir_p { + my ($dir) = @_; + if (-d $dir) { + # nothing to do + } elsif (-e $dir) { + die "mkdir: error creating directory $dir: $root is a file and i won't delete it\n"; + } else { + mkdir_p(dirname($dir)); + mkdir($dir, 0755) or die "mkdir: error creating directory $_: $!\n"; + } +} + sub touch { my ($f) = @_; unless (-e $f) { |