chiark / gitweb /
Dgit.pm: Provide `ensurepath'
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jul 2019 02:14:34 +0000 (03:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Jul 2019 02:15:55 +0000 (03:15 +0100)
Like `ensuredir' but also a bit like a more controlled `mkdir -p'.

We use make_path from File::Path.  It dies on failure.

No caller yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm

index 348f608..2004fe1 100644 (file)
@@ -29,7 +29,7 @@ use Config;
 use Digest::SHA;
 use Data::Dumper;
 use IPC::Open2;
-use File::Path;
+use File::Path qw(:DEFAULT make_path);
 use File::Basename;
 use Dpkg::Control::Hash;
 use Debian::Dgit::ExitStatus;
@@ -51,7 +51,8 @@ BEGIN {
                      server_branch server_ref
                       stat_exists link_ltarget rename_link_xf
                      hashfile
-                      fail failmsg ensuredir must_getcwd executable_on_path
+                      fail failmsg ensuredir ensurepath
+                     must_getcwd executable_on_path
                       waitstatusmsg failedcmd_waitstatus
                      failedcmd_report_cmd failedcmd
                       runcmd shell_cmd cmdoutput cmdoutput_errok
@@ -309,6 +310,12 @@ sub ensuredir ($) {
     confess "mkdir $dir: $!";
 }
 
+sub ensurepath ($$) {
+    my ($firsttocreate, $subdir) = @_; # creates necessary bits of $subidr
+    ensuredir $firsttocreate;
+    make_path "$firsttocreate/$subdir";
+}
+
 sub must_getcwd () {
     my $d = getcwd();
     defined $d or fail f_ "getcwd failed: %s\n", $!;