use Socket;
use Sys::Syslog;
use Fcntl qw(:flock SEEK_SET);
+use File::Path qw(remove_tree);
our $us = 'git-cache-proxy';
#---------- argument parsing ----------
+our $housekeepingthreshdays = 1;
+our $treeexpiredays = 21;
our $fetchtimeout = 1800;
our $maxfetchtimeout = 3600;
our $cachedir = '/var/cache/git-cache-proxy';
return 0;
}
+sub housekeeping () {
+ foreach $lock (<[a-z]*\\.lock>) {
+ if (!lstat $lock) {
+ $! == ENOENT or fail "housekeeping: $lock: stat: $!";
+ next;
+ }
+ if (-M _ <= $treeexpiredays) {
+ logm 'debug', "housekeeping: $lock: not too old";
+ next;
+ }
+ my $subdir = $lock; $subdir =~ s/\\.lock$//;
+ my $ok = 1;
+ foreach my $suffix (qw(tmp git)) {
+ my $dir = "${subdir}\\.$suffix";
+ my $errs;
+ remove_tree($dir, { safe=>1, error=>\$errs });
+ $ok = 0 if @$errs;
+ foreach my $err (@$errs) {
+ logm 'warning', "problem deleting: $err[0]: $err[1]";
+ }
+ }
+ if ($ok) {
+
+
+sub housekeepingcheck ($$) {
+ my ($dofork, $force) = @_;
+ open HLOCK, "+>", "Housekeeping.lock"
+ or fail "open/create Housekeeping.lock: $!";
+ if (!$force) {
+ if (flock HLOCK, LOCK_EX|LOCK_NB) {
+ logm 'debug', "housekeeping lock taken, not running";
+ close HLOCK;
+ return 0;
+ }
+ }
+ if ($force) {
+ logm 'info', "housekeeping forced";
+ } elsif (!lstat "Housekeeping.stamp") {
+ $! == ENOENT or fail "stat housekeeping.stamp: $!";
+ logm 'info', "housekeeping stamp missing, will run";
+ } elsif (-M _ <= $housekeepingthreshdays) {
+ logm 'debug', "housekeeping done recently";
+ close HLOCK;
+ return 0;
+ }
+ if ($dofork) {
+ my $child = fork;
+ defined $child or fail "fork for housekeeping: $!";
+ if (!$child) {
+ housekeeping();
+ exit 0;
+ }
+ return 1;
+ } else {
+ housekeeping();
+ return 1;
+ }
+}
+
sub runcommand () {
servinfo "servicing";
exec qw(git-upload-pack --strict --timeout=1000 .)