summaryrefslogtreecommitdiffstats
path: root/MDK
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2001-09-16 17:12:16 +0000
committerPascal Rigaux <pixel@mandriva.com>2001-09-16 17:12:16 +0000
commit06109fc763f8d7de926d353f3147ddc7d2b60471 (patch)
tree995aabbcfeeccaa4602aee7125ad1d864774cc6b /MDK
parent3de91380695cfe656e7adc7dfa3d6e513758e18f (diff)
downloadperl-MDK-Common-06109fc763f8d7de926d353f3147ddc7d2b60471.tar
perl-MDK-Common-06109fc763f8d7de926d353f3147ddc7d2b60471.tar.gz
perl-MDK-Common-06109fc763f8d7de926d353f3147ddc7d2b60471.tar.bz2
perl-MDK-Common-06109fc763f8d7de926d353f3147ddc7d2b60471.tar.xz
perl-MDK-Common-06109fc763f8d7de926d353f3147ddc7d2b60471.zip
add File::mkdir_p
Diffstat (limited to 'MDK')
-rw-r--r--MDK/Common/File.pm18
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) {