scripts/dl_cleanup: add support for subdirectories
authorMichael Pratt <mcpratt@pm.me>
Mon, 19 Sep 2022 20:39:34 +0000 (16:39 -0400)
committerMichael Pratt <mcpratt@pm.me>
Thu, 22 Sep 2022 20:48:36 +0000 (16:48 -0400)
Allow comparing subdirectories exactly like files.

Handle a corner case where the new subdirectory
has the same tarball inside of it
as the one that was downloaded
before a subdirectory for that package was established.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
scripts/dl_cleanup.py

index f7232b78c9f6aed4f1cff5316c1f0296831d2fa1..b15a9bb1a704b1f7f3776a33760793ceeba3f362 100755 (executable)
@@ -149,15 +149,18 @@ class Entry:
         self.fileext = ""
         self.filenoext = ""
 
-        for ext in extensions:
-            if filename.endswith(ext):
-                filename = filename[0 : 0 - len(ext)]
-                self.filenoext = filename
-                self.fileext = ext
-                break
+        if os.path.isdir(self.getPath()):
+            self.filenoext = filename
         else:
-            print(self.filename, "has an unknown file-extension")
-            raise EntryParseError("ext")
+            for ext in extensions:
+                if filename.endswith(ext):
+                    filename = filename[0 : 0 - len(ext)]
+                    self.filenoext = filename
+                    self.fileext = ext
+                    break
+            else:
+                print(self.filename, "has an unknown file-extension")
+                raise EntryParseError("ext")
         for (regex, parseVersion) in versionRegex:
             match = regex.match(filename)
             if match:
@@ -184,7 +187,10 @@ class Entry:
         path = self.getPath()
         print("Deleting", path)
         if not opt_dryrun:
-            os.unlink(path)
+            if os.path.isdir(path):
+                shutil.rmtree(path)
+            else:
+                os.unlink(path)
 
     def deleteBuildDir(self):
         paths = self.getBuildPaths()
@@ -301,6 +307,9 @@ def main(argv):
         lastVersion = None
         versions = progmap[prog]
         for version in versions:
+            if lastVersion:
+                if os.path.isdir(lastVersion.getPath()) and not os.path.isdir(version.getPath()):
+                    continue
             if lastVersion is None or version >= lastVersion:
                 lastVersion = version
         if lastVersion: