Created
September 10, 2012 22:24
-
-
Save RandalK/3694424 to your computer and use it in GitHub Desktop.
Patch from http://wiki.dirvish.org/ChmodOnExpire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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