[projects/pld-ftp-admin] clean-dups.py: pick the old versions under the lock, by .info files
arekm
arekm at pld-linux.org
Sat Nov 21 10:43:02 CET 2026
commit 5b29049e376bf5a4213d0afe223d5cb2c0fa3bf1
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Nov 21 01:38:15 2026 +0100
clean-dups.py: pick the old versions under the lock, by .info files
It listed the src.rpm files before locking the tree, at a path of the
production host, and one with no .info stopped the whole removal as
not found. Now it locks first and goes by the packages of the tree
in ftp_dir, as the removal itself does.
wwwbin/clean-dups.py | 60 ++++++++++++++++++----------------------------------
1 file changed, 21 insertions(+), 39 deletions(-)
---
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index 7d3eaa5..bce3531 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -24,9 +24,7 @@ sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
import ftpio
import ftptree
-re_rpm = re.compile(r'.*\.rpm$')
-re_nvr = re.compile(r'^(.*)-([^-]*)-([^-]*)\.rpm$')
-dir = '/home/pld/admins/th/ftp/test/SRPMS/RPMS'
+ftp_tree = "test"
ignore = re.compile(r'^(kernel-.*)$')
@@ -90,41 +88,13 @@ def find_dupes(dupes):
print(f"{e}; keeping {' '.join(old)}")
return pkgs
-files = {}
-dupes = {}
-
-for file in os.listdir(dir):
- if not re_rpm.match(file):
- continue
-
- if ignore.match(file):
- continue
-
- m = re_nvr.match(file)
- if not m:
- print(f"problem with: {file}")
- sys.exit(1)
-
- if args.min_age:
- try:
- if os.stat(os.path.join(dir, file)).st_mtime > cutoff:
- continue
- except FileNotFoundError:
- # moved or removed since listdir(); the tree is locked only later
- continue
-
- name = m.group(1)
-
- if name in files:
- if name in dupes:
- dupes[name].append(file)
- else:
- dupes[name] = [ files[name] ]
- dupes[name].append(file)
- else:
- files[name] = file
+def young(path):
+ """Newer than --min-age; a missing file is not, so reading its header later keeps all its versions"""
+ try:
+ return os.stat(path).st_mtime > cutoff
+ except FileNotFoundError:
+ return False
-ftp_tree = "test"
ftpio.connect('clean-dups')
if not ftpio.lock(ftp_tree, True):
@@ -132,8 +102,20 @@ if not ftpio.lock(ftp_tree, True):
sys.exit(1)
try:
- tree=ftptree.FtpTree(ftp_tree)
- pkgs = find_dupes(dupes.values())
+ tree = ftptree.FtpTree(ftp_tree)
+ dir = tree.basedir + '/SRPMS/RPMS'
+
+ # by the .info files, as the removal goes: a src.rpm with none is no package of the tree
+ byname = {}
+ for nvr in tree.pkgnames:
+ if ignore.match(nvr):
+ continue
+ file = nvr + '.src.rpm'
+ if args.min_age and young(os.path.join(dir, file)):
+ continue
+ byname.setdefault('-'.join(nvr.split('-')[:-2]), []).append(file)
+
+ pkgs = find_dupes(files for files in byname.values() if len(files) > 1)
for pkg in pkgs:
print(f"removing: {pkg}")
tree.mark4removal(pkgs)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/a049a512859eaede288d71649a2320e16c959476
More information about the pld-cvs-commit
mailing list