Skip to content

Instantly share code, notes, and snippets.

@RandalK
Created September 10, 2012 22:24
Show Gist options
  • Save RandalK/3694424 to your computer and use it in GitHub Desktop.
Save RandalK/3694424 to your computer and use it in GitHub Desktop.
diff --git a/dirvish-expire.pl b/dirvish-expire.pl
index 1259d3d..35c8c61 100644
--- a/dirvish-expire.pl
+++ b/dirvish-expire.pl
@@ -166,14 +166,53 @@ for $expire (sort(imsort @expires))
$$Options{'no-run'} and next;
- system("rm -rf $$expire{path}/tree");
+ $exit = system("chmod u+rwX $$expire{path}/tree && find $$expire{path}/tree -type d -exec chmod u+rwX \\{\\} \\;");
+ check_exitcode("Failed to chmod $$expire{path}/tree and subdirectories", "chmod/find", $exit);
+
+ $exit = system("rm -rf $$expire{path}/tree");
+ check_exitcode("Failed to delete $$expire{path}/tree", "rm", $exit);
+
$$Options{tree} and next;
- system("rm -rf $$expire{path}");
+ $exit = system("chmod u+rwX $$expire{path} && find $$expire{path} -type d -exec chmod u+rwX \\{\\} \\;");
+ check_exitcode("Failed to chmod $$expire{path} and subdirectories", "chmod/find", $exit);
+
+ $exit = system("rm -rf $$expire{path}");
+ check_exitcode("Failed to delete $$expire{path}", "rm", $exit);
}
exit 0;
+sub check_exitcode
+{
+ my ($action, $command, $exit) = @_;
+ my $msg = "WARNING: $action. $command ";
+
+ # Code based on the documentation for the system() call in Programming Perl,2nd ed.
+ $exit &= 0xffff;
+
+ if ($exit == 0) {
+ return 1;
+ } elsif ($exit == 0xff00) {
+ $msg .= " failed: $!";
+ } elsif ($exit > 0x80) {
+ $exit >>= 8;
+ $msg .= "exited with status $exit.";
+ } else {
+ $msg .= "failed with ";
+ if ($exit & 0x80) {
+ $exit &= ~0x80;
+ $msg .= "coredump from ";
+ }
+ $msg .= "signal $exit.";
+ }
+
+ print STDERR "$msg\n";
+
+ return 0;
+}
+
sub check_expire
{
my ($summary, $expire_time) = @_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment