summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcleanoldmeta18
1 files changed, 13 insertions, 5 deletions
diff --git a/cleanoldmeta b/cleanoldmeta
index 70c3710..18e32df 100755
--- a/cleanoldmeta
+++ b/cleanoldmeta
@@ -20,13 +20,21 @@ function clean ($path) {
$tab[$n][$file->getMtime()] = $file->getFilename();
}
}
+
+ $lim = time() - (26*60*60); // Keep younger than 1d + 2h
+
foreach ($tab as $n => $files) {
if (count($tab[$n]) > KEEP) {
- krsort($tab[$n]);
- while (count($tab[$n]) > KEEP) {
- $f = array_pop($tab[$n]);
- if (unlink("$path/$f")) {
- echo " $f\n";
+ ksort($tab[$n]);
+ foreach($tab[$n] as $t => $f) {
+ if (count($tab[$n]) <= KEEP) {
+ break; // Honours number limit
+ }
+ if ($t < $lim && unlink("$path/$f")) {
+ $x = array_shift($tab[$n]);
+ echo " clean $x\n";
+ } else {
+ break; // Honours time limit
}
}
}