[pacman-dev] [PATCH 1/3] pactest: treat symlinks with more respect

Dan McGee dan at archlinux.org
Mon May 16 12:51:44 EDT 2011


Don't call os.stat() when we should be using os.lstat(); this allows us
to actually test dead symlinks that don't have a corresponding file. Add
a new LINK_EXIST rule that complements FILE_EXIST for a similar purpose.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
These are for maint.

 test/pacman/pmpkg.py  |    2 +-
 test/pacman/pmrule.py |    8 ++++++++
 test/pacman/util.py   |    6 ++----
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 73156ab..be177f3 100755
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -102,7 +102,7 @@ def makepkg(self, path):
         # Generate package file system
         for f in self.files:
             util.mkfile(f, f)
-            self.size += os.stat(util.getfilename(f))[stat.ST_SIZE]
+            self.size += os.lstat(util.getfilename(f))[stat.ST_SIZE]
 
         # .PKGINFO
         data = ["pkgname = %s" % self.name]
diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py
index c68d085..0f6ae60 100755
--- a/test/pacman/pmrule.py
+++ b/test/pacman/pmrule.py
@@ -146,6 +146,14 @@ def check(self, test):
             else:
                 print "FILE rule '%s' not found" % case
                 success = -1
+        elif kind == "LINK":
+            filename = os.path.join(test.root, key)
+            if case == "EXIST":
+                if not os.path.islink(filename):
+                    success = 0
+            else:
+                print "LINK rule '%s' not found" % case
+                success = -1
         elif kind == "CACHE":
             cachedir = os.path.join(test.root, util.PM_CACHEDIR)
             if case == "EXISTS":
diff --git a/test/pacman/util.py b/test/pacman/util.py
index b771a34..47fde31 100755
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -149,7 +149,6 @@ def getmd5sum(filename):
     """
     """
     if not os.path.isfile(filename):
-        print "file %s does not exist!" % filename
         return ""
     fd = open(filename, "rb")
     checksum = hashlib.md5()
@@ -177,9 +176,8 @@ def getmtime(filename):
     """
     """
     if not os.path.exists(filename):
-        print "path %s does not exist!" % filename
-        return 0, 0, 0
-    st = os.stat(filename)
+        return None, None, None
+    st = os.lstat(filename)
     return st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME]
 
 #
-- 
1.7.5.1



More information about the pacman-dev mailing list