diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2001-09-16 17:12:16 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2001-09-16 17:12:16 +0000 |
commit | 06109fc763f8d7de926d353f3147ddc7d2b60471 (patch) | |
tree | 995aabbcfeeccaa4602aee7125ad1d864774cc6b | |
parent | 3de91380695cfe656e7adc7dfa3d6e513758e18f (diff) | |
download | perl-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
-rw-r--r-- | MDK/Common/File.pm | 18 | ||||
-rw-r--r-- | perl-MDK-Common.spec | 5 |
2 files changed, 21 insertions, 2 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) { diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec index 82d0033..05b2305 100644 --- a/perl-MDK-Common.spec +++ b/perl-MDK-Common.spec @@ -2,7 +2,7 @@ # do not change the version here, change in MDK/Common.pm.pl %define version THEVERSION -%define release 4mdk +%define release 5mdk %define perl_sitelib %(eval "`perl -V:installsitelib`"; echo $installsitelib) Summary: Various simple functions @@ -50,6 +50,9 @@ rm -rf $RPM_BUILD_ROOT # MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common %changelog +* Sun Sep 16 2001 Pixel <pixel@mandrakesoft.com> 1.0.2-5mdk +- add mkdir_p + * Mon Sep 10 2001 Pixel <pixel@mandrakesoft.com> 1.0.2-4mdk - DataStructure::uniq : keep the order - String::warp_text : fixed |