From 62a48a2db8c1e4eb201d31137f012cb2edb26b9b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 11 Feb 2020 18:32:49 +0000 Subject: [PATCH] git-cache-proxy: Use open-coded fork/exec for git gc This allows us to handle ENOENT from chdir specially. We want to tolerate this, because it can happen if the previous lockholder cleaned it all up. Signed-off-by: Ian Jackson --- scripts/git-cache-proxy | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy index 636ebfe..ec5ff7f 100755 --- a/scripts/git-cache-proxy +++ b/scripts/git-cache-proxy @@ -447,12 +447,19 @@ sub housekeeping () { $mode_action = sub { my $gclog = "$subdir/gc.log"; unlink $gclog or $!==ENOENT or hkfail "remove $gclog: $!"; - my $r = system qw(sh -ec), - 'cd "$1"; shift; exec "$@"', 'x', "$subdir\\.git", - qw(git gc --quiet); - if ($r) { + my $child = fork // hkfail "fork (for $subdir): $!"; + if (!$child) { + if (!chdir "$subdir\\.git") { + exit 0 if $!==ENOENT; + die "for gc: chdir $subdir: $!\n"; + } + exec qw(git gc --quiet); + die "exec git gc (for $subdir): $!\n"; + } + waitpid($child, 0) == $child or hkfail "waitpid failed! $!"; + if ($?) { logm 'err', - "housekeeping: subdirs $subdir: gc failed (status $r)"; + "housekeeping: subdirs $subdir: gc failed (wait status $?)"; } else { update_gcstamp("$subdir\\.git"); logm 'debug', -- 2.30.2