summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2019-11-22 08:50:26 +0100
committerRemi Collet <remi@remirepo.net>2019-11-22 08:50:26 +0100
commitc98476169a66197e23f26e7e43c49cb0adaf44ca (patch)
tree46c2861fa96bca26dc473fd2c0c5011b25a8c538
parent5b4156b7cf77734a60b9954a399d306c93a6fb93 (diff)
ensure we keep all metadata, younger than 1d
-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
}
}
}