From eef059ae5ff0e743684d9502448ce543eeefa4ef Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Fri, 4 Nov 2022 23:09:45 -0500 Subject: [PATCH] Add helper procedure implementing "mkdir -p" in Perl --- gatekeeper.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gatekeeper.pl b/gatekeeper.pl index 0a0672b..b9feffe 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -2315,6 +2315,26 @@ sub check_files { # - [EX] Execution # +=item mkdir_p ( $base, @directory ) + +Ensure that DIRECTORY (expressed as returned by File::Spec->splitdir) +exists under the BASE directory. + +=cut + +sub mkdir_p { + # @_ is directory name elements + + my @dir_steps; # list of intermediate dirs needed + # for example, creating bar/baz/quux in an empty /foo populates this list + # with qw( bar bar/baz bar/baz/quux ) + + for (@dir_steps = (); @_ && ! -d File::Spec->catdir(@_); pop) + { unshift @dir_steps, File::Spec->catdir(@_) } + + mkdir $_ or die "mkdir($_): $!" for @dir_steps; +} + sub archive { my $dir = shift; my $subdir = shift; -- 2.25.1