chiark / gitweb /
git-cache-proxy: housekeeping: check errno value from stat after deletion
[chiark-utils.git] / scripts / git-cache-proxy
index 2f38de1..b0c9502 100755 (executable)
@@ -408,14 +408,23 @@ sub housekeeping () {
        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";
+                   }
+               }
                my $errs;
-               remove_tree($dir, { safe=>1, error=>\$errs });
-               if (stat $dir) {
+               remove_tree($tdir, { safe=>1, error=>\$errs });
+               if (!stat $tdir) {
                    foreach my $err (@$errs) {
                        my ($file, $message) = %$err;
                        logm 'info', "problem deleting: $file: $message";
                    }
                    die "$dir: problem deleting file(s)\n";
+               } elsif ($! != ENOENT) {
+                   die "$tdir: cannot stat after deletion: $!\n";
                }
            }
        };