X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=scripts%2Fgit-cache-proxy;h=52e01d0203b0e210200119cb42b57eea76ff7dbb;hp=2f38de1154be164d316d7fb06579a22841d521c1;hb=ba11d4679a8024bc26066ec7fd6bc30bb54967c8;hpb=eede02a315ee2d05bfada0e62f5a9746046d3492 diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy index 2f38de1..52e01d0 100755 --- a/scripts/git-cache-proxy +++ b/scripts/git-cache-proxy @@ -29,7 +29,8 @@ # git-cache-proxy # Copyright 2010 Tony Finch -# Copyright 2013 Ian Jackson +# Copyright 2013,2014 Ian Jackson +# Copyright 2017 Citrix # # git-cache-proxy is free software; you can redistribute it and/or # modify them under the terms of the GNU General Public License as @@ -64,8 +65,9 @@ our $us = 'git-cache-proxy'; our $debug = 0; our $housekeepingeverydays = 1; our $treeexpiredays = 21; -our $fetchtimeout = 1800; -our $maxfetchtimeout = 3600; +our $fetchtimeout = 3600; +our $maxfetchtimeout = 7200; +our $servetimeout = 3600; our $cachedir = '/var/cache/git-cache-proxy'; our $housekeepingonly = 0; @@ -171,6 +173,7 @@ for (;;) { $cachedir = $1; } elsif (s/^--( max-fetch-timeout | fetch-timeout + | serve-timeout | tree-expire-days | housekeeping-interval-days )=(\d+)$//x) { @@ -360,6 +363,7 @@ sub clonefetch () { servinfo "fetch/clone failed: $fetchfail"; } } + alarm 0; if (!$exists) { rename $tmpd, $gitd or fail "rename fresh $tmpd to $gitd: $!"; @@ -408,14 +412,18 @@ sub housekeeping () { eval { foreach my $suffix (qw(tmp git)) { my $dir = "${subdir}\\.$suffix"; - my $errs; - remove_tree($dir, { safe=>1, error=>\$errs }); - if (stat $dir) { - foreach my $err (@$errs) { - my ($file, $message) = %$err; - logm 'info', "problem deleting: $file: $message"; + my $tdir = "${subdir}\\.tmp"; + if ($dir ne $tdir) { + if (!rename $dir,$tdir) { + next if $! == ENOENT; + die "$dir: cannot rename to $tdir: $!\n"; } - die "$dir: problem deleting file(s)\n"; + } + system qw(rm -rf --), $tdir; + if (stat $tdir) { + die "$dir: problem deleting file(s), rm exited $?\n"; + } elsif ($! != ENOENT) { + die "$tdir: cannot stat after deletion: $!\n"; } } }; @@ -452,8 +460,10 @@ sub housekeepingcheck ($$) { } if ($dofork) { my $child = fork; - defined $child or hkfail "fork: $!"; + defined $child or fail "fork: $!"; if (!$child) { + open STDERR, "|logger -p daemon.warning -t '$us(housekeeping)'" + or die "fork: logger $!"; housekeeping(); exit 0; } @@ -469,7 +479,7 @@ sub runcommand () { chdir $gitd or fail "chdir $gitd: $!"; - exec qw(git-upload-pack --strict --timeout=1000 .) + exec qw(git-upload-pack --strict), "--timeout=$servetimeout", qw(.) or fail "exec git-upload-pack: $!"; }