[projects/pld-ftp-admin] pfa-rmpkg, pfa-checktree, pfa-from-incoming, clean-dups: unlock whatever stops them

arekm arekm at pld-linux.org
Thu Oct 29 09:17:30 CET 2026


commit 58e21bd65a4b760589b4094db7ba3f6d46032a8e
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Wed Oct 28 23:03:49 2026 +0100

    pfa-rmpkg, pfa-checktree, pfa-from-incoming, clean-dups: unlock whatever stops them
    
    They unlocked their trees only on a clean run, or on a SomeError.
    Any other error or a Ctrl-C left the trees locked, since ftpiod keeps
    a lock until someone unlocks it: pfa-from-incoming then could not lock
    the default tree on its next runs, and nothing came in from incoming.
    
    In pfa-from-incoming most of the diff is the indentation of the moving
    loops, now inside try.

 bin/pfa-checktree     |  34 +++++------
 bin/pfa-from-incoming | 160 +++++++++++++++++++++++++-------------------------
 bin/pfa-rmpkg         |   7 +--
 wwwbin/clean-dups.py  |   7 +--
 4 files changed, 104 insertions(+), 104 deletions(-)
---
diff --git a/bin/pfa-checktree b/bin/pfa-checktree
index ffe5b51..df7bdfc 100755
--- a/bin/pfa-checktree
+++ b/bin/pfa-checktree
@@ -31,23 +31,23 @@ checkdir(dstname)
 
 ftpio.connect('check-tree')
 
-if not ftpio.lock(srcname, True):
-    print(f"ERR: {srcname} tree already locked")
-    sys.exit(1)
-
-if not ftpio.lock(dstname, True):
-    ftpio.unlock(srcname)
-    print(f"ERR: {dstname} tree already locked")
-    sys.exit(1)
-
-srctree=ftptree.FtpTree(srcname, loadall=True)
-dsttree=ftptree.FtpTree(dstname)
-
-srctree.checktree(dsttree)
-
-# We've loaded all interesting info, so we can continue without locks
-ftpio.unlock(srcname)
-ftpio.unlock(dstname)
+locked = []
+try:
+    for name in (srcname, dstname):
+        if not ftpio.lock(name, True):
+            print(f"ERR: {name} tree already locked")
+            sys.exit(1)
+        locked.append(name)
+
+    srctree=ftptree.FtpTree(srcname, loadall=True)
+    dsttree=ftptree.FtpTree(dstname)
+
+    srctree.checktree(dsttree)
+finally:
+    # all is loaded, the rest needs no locks; ftpiod keeps a lock until
+    # someone unlocks it, so on any exit
+    for name in locked:
+        ftpio.unlock(name)
 
 names=sorted({pkg.name for pkg in srctree.values()})
 
diff --git a/bin/pfa-from-incoming b/bin/pfa-from-incoming
index 5673459..58e8418 100755
--- a/bin/pfa-from-incoming
+++ b/bin/pfa-from-incoming
@@ -167,101 +167,103 @@ if not ftpio.lock(cval['default_to']):
 
 moved_anything = False
 
-for uploadinfo in findfiles(incoming_dir + 'SRPMS'):
-    content = getcontent(incoming_dir + 'SRPMS/' + uploadinfo)
-    if not content:
-        continue # Uploading not finished
-
-    pkg = BasePkg(uploadinfo[:-19], content = content)
-    srpm = pkg.files['SRPMS'][0]
-
-    if not os.path.exists(incoming_dir + 'SRPMS/' + srpm):
-        ftpio.log(f"{srpm} file missing; skipping move until next round")
-        continue
-
-    if ftptree.has_key(repr(pkg)):
-        ftpio.log(f"{srpm} already present in {ftptree}; removing older files")
-        rm(default_to + 'SRPMS/RPMS/' + srpm)
-        bid = next(iter(pkg.build))
-        build = pkg.build[bid]
-        with open(default_to + 'SRPMS/.metadata/' + srpm+'.info', 'a') as f:
-            f.write(f"info:build:{bid}:requester:{build.requester}\ninfo:build:{bid}:requester_email:{build.requester_email}\n")
-    else:
-        with open(default_to + 'SRPMS/.metadata/' + srpm + '.info', 'w') as f:
-            f.write(content)
-
-    mv(incoming_dir + 'SRPMS/' + srpm, default_to + 'SRPMS/RPMS')
-    rm(incoming_dir + 'SRPMS/' + uploadinfo)
-
-for arch in ftp_archs:
-    for uploadinfo in findfiles(incoming_dir + arch):
-        content = getcontent(incoming_dir + arch + '/' + uploadinfo)
+try:
+    for uploadinfo in findfiles(incoming_dir + 'SRPMS'):
+        content = getcontent(incoming_dir + 'SRPMS/' + uploadinfo)
         if not content:
-            ftpio.log(f"{uploadinfo} not finished uploading")
             continue # Uploading not finished
 
-        srcpkg = BasePkg(uploadinfo[:-19], content = content)
-        srpm = srcpkg.files['SRPMS'][0]
-
-        if not ftptree.has_key(repr(srcpkg)):
-            continue # We require the src.rpm to be present
+        pkg = BasePkg(uploadinfo[:-19], content = content)
+        srpm = pkg.files['SRPMS'][0]
 
-        renvr = re.compile(r'(.*)-(.*)-(.*)\.[^.]*\.rpm')
-        srcnvr = renvr.match(srpm).groups()
-
-        rpmfile_missing = [f for f in srcpkg.files['ARCH'] if not os.path.exists(incoming_dir + arch + '/'+f)]
-        if len(rpmfile_missing):
-            for filem in rpmfile_missing:
-                ftpio.log(f"{filem} file missing; skipping move until next round")
+        if not os.path.exists(incoming_dir + 'SRPMS/' + srpm):
+            ftpio.log(f"{srpm} file missing; skipping move until next round")
             continue
 
-        dstpkg = BasePkg(repr(srcpkg), ftptree)
-
-        if arch in dstpkg.files:
-            ftpio.log(f"files from {srcpkg!r} for arch {arch} already present in {ftptree}; removing older files")
-            for rpmfile in dstpkg.files[arch]:
-                if is_debuginfo(rpmfile):
-                    dstfile = default_to + arch + '/debuginfo'
-                else:
-                    dstfile = default_to + arch + '/RPMS'
-                try:
-                    rm(dstfile + '/' + rpmfile)
-                except OSError as e:
-                    l = f"Removing {dstfile}/{rpmfile} problem: {e}"
-                    ftpio.log(l)
-                    print(l)
-
-        with open(default_to + 'SRPMS/.metadata/' + srpm + '.info', 'a') as f:
-            for rpmfile in srcpkg.files['ARCH']:
-                moved_anything = True
-
-# Too much noise, too little use
-#            archnvr = renvr.match(rpmfile).groups()
-#            if srcnvr[1] != archnvr[1] or srcnvr[2] != archnvr[2]:
-#                send_vr_msg(srcnvr, archnvr, dstpkg, arch)
-
-                if rpmfile[-11:] == '.noarch.rpm' and config.separate_noarch:
-                    move_noarch(f, arch, rpmfile, dstpkg)
-                else:
-                    if arch not in dstpkg.files:
-                        f.write(f"file:{arch}:{rpmfile}\n")
-                    srcfile = incoming_dir + arch + '/' + rpmfile
-
+        if ftptree.has_key(repr(pkg)):
+            ftpio.log(f"{srpm} already present in {ftptree}; removing older files")
+            rm(default_to + 'SRPMS/RPMS/' + srpm)
+            bid = next(iter(pkg.build))
+            build = pkg.build[bid]
+            with open(default_to + 'SRPMS/.metadata/' + srpm+'.info', 'a') as f:
+                f.write(f"info:build:{bid}:requester:{build.requester}\ninfo:build:{bid}:requester_email:{build.requester_email}\n")
+        else:
+            with open(default_to + 'SRPMS/.metadata/' + srpm + '.info', 'w') as f:
+                f.write(content)
+
+        mv(incoming_dir + 'SRPMS/' + srpm, default_to + 'SRPMS/RPMS')
+        rm(incoming_dir + 'SRPMS/' + uploadinfo)
+
+    for arch in ftp_archs:
+        for uploadinfo in findfiles(incoming_dir + arch):
+            content = getcontent(incoming_dir + arch + '/' + uploadinfo)
+            if not content:
+                ftpio.log(f"{uploadinfo} not finished uploading")
+                continue # Uploading not finished
+
+            srcpkg = BasePkg(uploadinfo[:-19], content = content)
+            srpm = srcpkg.files['SRPMS'][0]
+
+            if not ftptree.has_key(repr(srcpkg)):
+                continue # We require the src.rpm to be present
+
+            renvr = re.compile(r'(.*)-(.*)-(.*)\.[^.]*\.rpm')
+            srcnvr = renvr.match(srpm).groups()
+
+            rpmfile_missing = [f for f in srcpkg.files['ARCH'] if not os.path.exists(incoming_dir + arch + '/'+f)]
+            if len(rpmfile_missing):
+                for filem in rpmfile_missing:
+                    ftpio.log(f"{filem} file missing; skipping move until next round")
+                continue
+
+            dstpkg = BasePkg(repr(srcpkg), ftptree)
+
+            if arch in dstpkg.files:
+                ftpio.log(f"files from {srcpkg!r} for arch {arch} already present in {ftptree}; removing older files")
+                for rpmfile in dstpkg.files[arch]:
                     if is_debuginfo(rpmfile):
                         dstfile = default_to + arch + '/debuginfo'
                     else:
                         dstfile = default_to + arch + '/RPMS'
-
                     try:
-                        mv(srcfile, dstfile)
+                        rm(dstfile + '/' + rpmfile)
                     except OSError as e:
-                        l = f"Moving {srcfile} to {dstfile} problem: {e}"
+                        l = f"Removing {dstfile}/{rpmfile} problem: {e}"
                         ftpio.log(l)
                         print(l)
 
-        rm(incoming_dir + arch + '/' + uploadinfo)
+            with open(default_to + 'SRPMS/.metadata/' + srpm + '.info', 'a') as f:
+                for rpmfile in srcpkg.files['ARCH']:
+                    moved_anything = True
 
-ftpio.unlock(cval['default_to'])
+    # Too much noise, too little use
+    #            archnvr = renvr.match(rpmfile).groups()
+    #            if srcnvr[1] != archnvr[1] or srcnvr[2] != archnvr[2]:
+    #                send_vr_msg(srcnvr, archnvr, dstpkg, arch)
+
+                    if rpmfile[-11:] == '.noarch.rpm' and config.separate_noarch:
+                        move_noarch(f, arch, rpmfile, dstpkg)
+                    else:
+                        if arch not in dstpkg.files:
+                            f.write(f"file:{arch}:{rpmfile}\n")
+                        srcfile = incoming_dir + arch + '/' + rpmfile
+
+                        if is_debuginfo(rpmfile):
+                            dstfile = default_to + arch + '/debuginfo'
+                        else:
+                            dstfile = default_to + arch + '/RPMS'
+
+                        try:
+                            mv(srcfile, dstfile)
+                        except OSError as e:
+                            l = f"Moving {srcfile} to {dstfile} problem: {e}"
+                            ftpio.log(l)
+                            print(l)
+
+            rm(incoming_dir + arch + '/' + uploadinfo)
+finally:
+    # ftpiod keeps a lock until someone unlocks it, so on any exit
+    ftpio.unlock(cval['default_to'])
 
 if moved_anything:
     os.system(f"{os.getenv('HOME')}/pld-ftp-admin/bin/pfa-genindex --quiet {cval['default_to']} > /dev/null")
diff --git a/bin/pfa-rmpkg b/bin/pfa-rmpkg
index 5618fef..a793e7b 100755
--- a/bin/pfa-rmpkg
+++ b/bin/pfa-rmpkg
@@ -34,9 +34,8 @@ try:
     tree.mark4removal(pkgs)
     tree.removepkgs()
 except ftptree.SomeError:
-    # In case of problems we need to unlock the tree before exiting
-    ftpio.unlock(treename)
     sys.exit(1)
-
-ftpio.unlock(treename)
+finally:
+    # ftpiod keeps a lock until someone unlocks it, so on any exit
+    ftpio.unlock(treename)
 
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index 3a832f1..a8b7513 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -168,8 +168,7 @@ try:
     tree.mark4removal(pkgs)
     tree.removepkgs()
 except ftptree.SomeError:
-    # In case of problems we need to unlock the tree before exiting
-    ftpio.unlock(ftp_tree)
     sys.exit(1)
-
-ftpio.unlock(ftp_tree)
+finally:
+    # ftpiod keeps a lock until someone unlocks it, so on any exit
+    ftpio.unlock(ftp_tree)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/16c6c5f2d4269aef64813afc632c36b5ce242afa



More information about the pld-cvs-commit mailing list