diff --git a/cron/clearextracts.php b/cron/clearextracts.php index 363f173..74cb89a 100644 --- a/cron/clearextracts.php +++ b/cron/clearextracts.php @@ -4,12 +4,14 @@ $projectRoot = dirname(dirname(__FILE__)); require "{$projectRoot}/header.php"; -if ( $argc != 2 ) { +if ( $argc == 1 ) { $daysToKeep = 10; } else { $daysToKeep = intval($argv[1]); } +$dryrun = (in_array("--dryrun", $argv)) ? true : false; + $ed = $projectRoot . "/" . EXTRACTSDIR; $now = time(); $maxAge = $now - (86400*$daysToKeep); @@ -21,7 +23,7 @@ foreach ( $files as $file ) { if ( $file->isDir() && in_array($file->getExtension(), $validExtensions) ) { if ( filemtime($file->getRealPath()) <= $maxAge ) { echo "Found aged extracted comic: {$file->getFilename()}\n"; - exec("rm -rf \"{$file->getRealPath()}\"", $output, $retval); + if ( !$dryrun ) exec("rm -rf \"{$file->getRealPath()}\"", $output, $retval); } } }