From 1c39e4fbade29d570858ca6eca4958ab72cfbdd0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 16 Jul 2011 10:07:25 -0500 Subject: Handle removal of empty directories properly This addresses FS#25141. We shouldn't remove every empty directory we come across during the removal process unless it is truly not known to any other package. This will prevent removal of essential directories such as '/var/lock/'. This is accomplished by first checking the empty/non-empty status of a directory, which was previously done implicitly by calling rmdir() and ignoring errors. We do this to avoid the next (new) check in most cases, which is to look at all local packages to see if the to-be-removed directory is present in another packages' filelist. If we do not find it anywhere, then we remove it, else we keep the file around. The pactest has been updated to test more cases, as well as finding a flaw in the original expected to fail case- we need separate DIR and FILE based EXIST rules. Signed-off-by: Dan McGee --- test/pacman/pmrule.py | 8 ++++++++ test/pacman/tests/remove070.py | 24 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py index 0f6ae602..cb7ae88d 100644 --- a/test/pacman/pmrule.py +++ b/test/pacman/pmrule.py @@ -146,6 +146,14 @@ class pmrule(object): else: print "FILE rule '%s' not found" % case success = -1 + elif kind == "DIR": + filename = os.path.join(test.root, key) + if case == "EXIST": + if not os.path.isdir(filename): + success = 0 + else: + print "DIR rule '%s' not found" % case + success = -1 elif kind == "LINK": filename = os.path.join(test.root, key) if case == "EXIST": diff --git a/test/pacman/tests/remove070.py b/test/pacman/tests/remove070.py index e0587e17..898e2f50 100644 --- a/test/pacman/tests/remove070.py +++ b/test/pacman/tests/remove070.py @@ -1,21 +1,29 @@ -self.description = "Remove a package with an empty directory needed by another package" +self.description = "Remove a package with various directory overlaps" + +self.filesystem = ["lib/alsoonfs/randomfile"] p1 = pmpkg("pkg1") -p1.files = ["bin/pkg1", "opt/"] +p1.files = ["bin/pkg1", + "opt/", + "lib/onlyinp1/", + "lib/alsoonfs/"] p2 = pmpkg("pkg2") -p2.files = ["bin/pkg2", "opt/"] +p2.files = ["bin/pkg2", + "opt/", + "lib/onlyinp2/"] for p in p1, p2: - self.addpkg2db("local", p) + self.addpkg2db("local", p) self.args = "-R %s" % p1.name self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") self.addrule("PKG_EXIST=pkg2") -self.addrule("!FILE_EXIST=bin/pkg1") -self.addrule("FILE_EXIST=bin/pkg2") -self.addrule("FILE_EXIST=opt/") -self.expectfailure = True +self.addrule("DIR_EXIST=bin/") +self.addrule("DIR_EXIST=opt/") +self.addrule("!DIR_EXIST=lib/onlyinp1/") +self.addrule("DIR_EXIST=lib/onlyinp2/") +self.addrule("DIR_EXIST=lib/alsoonfs/") -- cgit v1.2.3-24-g4f1b