]> git.ipfire.org Git - pbs.git/commitdiff
Revert "Refactor deleting files"
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Oct 2017 17:53:50 +0000 (17:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 31 Oct 2017 17:53:50 +0000 (17:53 +0000)
This reverts commit 0742a8f2e48b59808743308632070324018ce848.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Conflicts:
src/buildservice/__init__.py

src/buildservice/__init__.py

index 63c50d6fb61d3c86d62c4988f015adfd89444027..a340aa329790d5bfadd5b062ac1473fd33419395 100644 (file)
@@ -6,7 +6,6 @@ import ConfigParser
 import logging
 import os
 import pakfire
-import shutil
 
 from . import arches
 from . import bugtracker
@@ -138,6 +137,9 @@ class Backend(object):
                        WHERE (not_before IS NULL OR not_before <= NOW())")
 
                for row in query:
+                       if not row.path:
+                               continue
+
                        path = row.path
 
                        if not path or not path.startswith("%s/" % PAKFIRE_DIR):
@@ -146,9 +148,26 @@ class Backend(object):
 
                        try:
                                logging.debug("Removing %s..." % path)
-                               shutil.rmtree(path)
-                       except shutil.Error as e:
+                               os.unlink(path)
+                       except OSError, e:
                                logging.error("Could not remove %s: %s" % (path, e))
-                               continue
+
+                       while True:                     
+                               path = os.path.dirname(path)
+
+                               # Stop if we are running outside of the tree.
+                               if not path.startswith(PAKFIRE_DIR):
+                                       break
+
+                               # If the directory is not empty, we cannot remove it.
+                               if os.path.exists(path) and os.listdir(path):
+                                       break
+
+                               try:
+                                       logging.debug("Removing %s..." % path)
+                                       os.rmdir(path)
+                               except OSError, e:
+                                       logging.error("Could not remove %s: %s" % (path, e))
+                                       break
 
                        self.db.execute("DELETE FROM queue_delete WHERE id = %s", row.id)