chiark / gitweb /
git-cache-proxy: housekeeping: Use eval, not ad-hoc thing involving $ok
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Jul 2014 14:18:56 +0000 (15:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Jul 2014 14:18:56 +0000 (15:18 +0100)
scripts/git-cache-proxy

index 334f509..2f38de1 100755 (executable)
@@ -405,22 +405,24 @@ 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) {
-                   my ($file, $message) = %$err;
-                   logm 'info', "problem deleting: $file: $message";
+       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";
+                   }
+                   die "$dir: problem deleting file(s)\n";
                }
            }
-       }
-       if ($ok) {
+       };
+       if (length $@) {
+           chomp $@;
+           logm 'warning', "housekeeping: $subdir: cleanup prevented: $@";
+       } else {
            unlink $lock or hkfail "remove $lock: $!";
        }
     }