From c98476169a66197e23f26e7e43c49cb0adaf44ca Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 22 Nov 2019 08:50:26 +0100 Subject: ensure we keep all metadata, younger than 1d --- cleanoldmeta | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'cleanoldmeta') 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 } } } -- cgit