From 9b34c3e59ee77136f100c2514524e841c4b30eab Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Aug 2017 18:34:02 +0100 Subject: [PATCH] playground refactoring: Dgit.pm: Provide ensure_a_playground dgit wants to make a lot of temporary things in .git/dgit. That's like a playground, but dgit doesn't want it wiped. Signed-off-by: Ian Jackson --- Debian/Dgit.pm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 473c01e6..de37261d 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -64,7 +64,8 @@ BEGIN { # implicitly uses $main::us %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)], playground => [qw(record_maindir $maindir $local_git_cfg - fresh_playground $playground)]); + fresh_playground $playground + ensure_a_playground)]); @EXPORT_OK = ( @{ $EXPORT_TAGS{policyflags} }, @{ $EXPORT_TAGS{playground} } ); } @@ -491,6 +492,11 @@ sub git_slurp_config_src ($) { # createing different playgrounds; but $playground global can # refer only to one, obv. # +# ensure_a_playground SUBDIR_PATH_COMPONENTS +# like fresh_playground except: +# merely ensures the directory exists; does not delete an existing one +# never sets global $playground +# # then can use # # changedir $playground @@ -515,12 +521,25 @@ sub record_maindir () { our $playground; -sub fresh_playground ($) { +sub ensure_a_playground_parent ($) { my ($spc) = @_; record_maindir(); $spc = ".git/$spc"; my $parent = dirname $spc; mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!"; + return $spc; +} + +sub ensure_a_playground ($) { + my ($spc) = @_; + $spc = ensure_a_playground_parent $spc; + mkdir $spc or $!==EEXIST or fail "failed to mkdir a playground $spc: $!"; + return $spc; +} + +sub fresh_playground ($) { + my ($spc) = @_; + $spc = ensure_a_playground_parent $spc; rmtree $spc; mkdir $spc or die "$spc $!"; return $playground = "$maindir/$spc"; -- 2.30.2