chiark / gitweb /
git-cache-proxy: housekeeping: Rename main dir to tmp before deleting to preserve...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Jul 2014 14:22:37 +0000 (15:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Jul 2014 14:22:37 +0000 (15:22 +0100)
scripts/git-cache-proxy

index 2f38de1..0c6ba55 100755 (executable)
@@ -408,9 +408,16 @@ 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";