summaryrefslogtreecommitdiffstats
path: root/cleanoldmeta
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2018-11-13 10:21:23 +0100
committerRemi Collet <remi@remirepo.net>2018-11-13 10:21:23 +0100
commit5d8da9e8dfaa4d88f128934461d639687da26d57 (patch)
treea50c6e842c01638d4de607b8fbb45273cdf68879 /cleanoldmeta
parent76ba248da60a2c4857952d92a5d97cebbefde16a (diff)
add helper to clean old metadata in repository
Diffstat (limited to 'cleanoldmeta')
-rwxr-xr-xcleanoldmeta43
1 files changed, 43 insertions, 0 deletions
diff --git a/cleanoldmeta b/cleanoldmeta
new file mode 100755
index 0000000..21714a9
--- /dev/null
+++ b/cleanoldmeta
@@ -0,0 +1,43 @@
+#!/usr/bin/php
+<?php
+define('KEEP', 8);
+
+function clean ($path) {
+ if (!is_dir($path) || !is_file("$path/repomd.xml")) {
+ echo "** $path is not a repodata directory\n";
+ return;
+ }
+ $path = realpath($path);
+ echo "+ Clean old metadata in $path\n";
+ $dir = new DirectoryIterator($path);
+ $tab = [];
+ foreach ($dir as $file) {
+ if (!$file->isFile()) {
+ continue;
+ }
+ if (preg_match("/^[^-]*-(.*)$/", $file->getFilename(), $reg)) {
+ $n = $reg[1];
+ $tab[$n][$file->getMtime()] = $file->getFilename();
+ }
+ }
+ foreach ($tab as $n => $files) {
+ if (count($tab[$n]) > KEEP) {
+ echo " $n\n";
+ krsort($tab[$n]);
+ while (count($tab[$n]) > KEEP) {
+ $f = array_pop($tab[$n]);
+ if (unlink("$path/$f")) {
+ echo " $f\n";
+ }
+ }
+ }
+ }
+}
+
+if ($_SERVER['argc'] < 2) {
+ die("\nusage {$_SERVER['argv'][0]} path/to/repodata\n");
+}
+
+for ($i=1 ; $i<$_SERVER['argc'] ; $i++) {
+ clean($_SERVER['argv'][$i]);
+}