chiark / gitweb /
git-cache-proxy: Tidy up copyright licence info
[chiark-utils.git] / scripts / git-cache-proxy
index d12bdb3a3c1c7de8c30d9a14a46883a7c52b0942..3e57a4f5530e2971794dd3a82612590421624c8e 100755 (executable)
@@ -2,6 +2,12 @@
 #
 # git caching proxy
 
+# Suitable only for exposing to semi-trusted clients: clients are not
+# supposed to be able to take over the server.  However, clients can
+# probably deny service to each other because the current
+# implementation is not very good at handling various out-of-course
+# situations (notably, clients which are too slow).
+
 # usage: run it on some port, and then clone or fetch
 #  "git://<realhost>:<realport>/<real-git-url>[ <options>]"
 # where <real-git-url> is http://<host>/... or git://<host>/...
@@ -23,7 +29,7 @@
 
 # git-cache-proxy
 # Copyright 2010 Tony Finch
-# Copyright 2013 Ian Jackson
+# Copyright 2013,2014 Ian Jackson
 # 
 # git-cache-proxy is free software; you can redistribute it and/or
 # modify them under the terms of the GNU General Public License as
@@ -399,21 +405,28 @@ sub housekeeping () {
            next;
        }
        logm 'info', "housekeeping: subdirs $subdir: cleaning";
-       my $ok = 1;
-       foreach my $suffix (qw(tmp git)) {
-           my $dir = "${subdir}\\.$suffix";
-           my $errs;
-           remove_tree($dir, { safe=>1, error=>\$errs });
-           if (stat $dir) {
-               $ok = 0;
-               logm 'warning', "housekeeping: $dir: problems with".
-                   "deletion prevent cleanup:";
-               foreach my $err (@$errs) {
-                   logm 'info', "problem deleting: $err->[0]: $err->[1]";
+       eval {
+           foreach my $suffix (qw(tmp git)) {
+               my $dir = "${subdir}\\.$suffix";
+               my $tdir = "${subdir}\\.tmp";
+               if ($dir ne $tdir) {
+                   if (!rename $dir,$tdir) {
+                       next if $! == ENOENT;
+                       die "$dir: cannot rename to $tdir: $!\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";
                }
            }
-       }
-       if ($ok) {
+       };
+       if (length $@) {
+           chomp $@;
+           logm 'warning', "housekeeping: $subdir: cleanup prevented: $@";
+       } else {
            unlink $lock or hkfail "remove $lock: $!";
        }
     }
@@ -443,8 +456,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;
        }