Add ability to use a --dryrun parameter to test deletions
This commit is contained in:
parent
7aecf00971
commit
b55e3c1d92
|
|
@ -4,12 +4,14 @@ $projectRoot = dirname(dirname(__FILE__));
|
||||||
|
|
||||||
require "{$projectRoot}/header.php";
|
require "{$projectRoot}/header.php";
|
||||||
|
|
||||||
if ( $argc != 2 ) {
|
if ( $argc == 1 ) {
|
||||||
$daysToKeep = 10;
|
$daysToKeep = 10;
|
||||||
} else {
|
} else {
|
||||||
$daysToKeep = intval($argv[1]);
|
$daysToKeep = intval($argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dryrun = (in_array("--dryrun", $argv)) ? true : false;
|
||||||
|
|
||||||
$ed = $projectRoot . "/" . EXTRACTSDIR;
|
$ed = $projectRoot . "/" . EXTRACTSDIR;
|
||||||
$now = time();
|
$now = time();
|
||||||
$maxAge = $now - (86400*$daysToKeep);
|
$maxAge = $now - (86400*$daysToKeep);
|
||||||
|
|
@ -21,7 +23,7 @@ foreach ( $files as $file ) {
|
||||||
if ( $file->isDir() && in_array($file->getExtension(), $validExtensions) ) {
|
if ( $file->isDir() && in_array($file->getExtension(), $validExtensions) ) {
|
||||||
if ( filemtime($file->getRealPath()) <= $maxAge ) {
|
if ( filemtime($file->getRealPath()) <= $maxAge ) {
|
||||||
echo "Found aged extracted comic: {$file->getFilename()}\n";
|
echo "Found aged extracted comic: {$file->getFilename()}\n";
|
||||||
exec("rm -rf \"{$file->getRealPath()}\"", $output, $retval);
|
if ( !$dryrun ) exec("rm -rf \"{$file->getRealPath()}\"", $output, $retval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user