mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 09:51:50 -05:00
pactest: make more resiliant to missing files
Add a bunch of guards around function calls like open() and stat() to ensure we are not going to get ourselves a python error. This made implementing and testing the new upgrade045 pactest much easier, as its whole purpose was to create a dead symlink and debug a segfault of pacman (which caused no DB entries to be written) to support the previously checked in fix for FS#9235 (commit 0c2206f542ce6df2606586d43f190cd5a423fb13). Both of these cases are now non-fatal in pactest. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
0c2206f542
commit
11fe18479e
@ -119,7 +119,10 @@ class pmdb:
|
||||
|
||||
# desc
|
||||
filename = os.path.join(path, "desc")
|
||||
fd = file(filename, "r")
|
||||
if not os.path.isfile(filename):
|
||||
print "invalid db entry found (desc missing) for pkg", pkgname
|
||||
return None
|
||||
fd = open(filename, "r")
|
||||
while 1:
|
||||
line = fd.readline()
|
||||
if not line:
|
||||
@ -158,7 +161,10 @@ class pmdb:
|
||||
|
||||
# files
|
||||
filename = os.path.join(path, "files")
|
||||
fd = file(filename, "r")
|
||||
if not os.path.isfile(filename):
|
||||
print "invalid db entry found (files missing) for pkg", pkgname
|
||||
return None
|
||||
fd = open(filename, "r")
|
||||
while 1:
|
||||
line = fd.readline()
|
||||
if not line:
|
||||
@ -177,6 +183,9 @@ class pmdb:
|
||||
|
||||
# depends
|
||||
filename = os.path.join(path, "depends")
|
||||
if not os.path.isfile(filename):
|
||||
print "invalid db entry found (depends missing) for pkg", pkgname
|
||||
return None
|
||||
fd = file(filename, "r")
|
||||
while 1:
|
||||
line = fd.readline()
|
||||
|
16
pactest/tests/upgrade045.py
Normal file
16
pactest/tests/upgrade045.py
Normal file
@ -0,0 +1,16 @@
|
||||
self.description = "FS#9235"
|
||||
|
||||
lp = pmpkg("foo")
|
||||
lp.files = ["etc/foo.cfg -> etc/foo.cfg"]
|
||||
lp.backup = ["etc/foo.cfg"]
|
||||
self.addpkg2db("local", lp)
|
||||
|
||||
p1 = pmpkg("foo", "1.0-2")
|
||||
p1.files = ["etc/foo.cfg*"]
|
||||
p1.backup = ["etc/foo.cfg"]
|
||||
self.addpkg(p1)
|
||||
|
||||
self.args = "-U %s" % p1.filename()
|
||||
|
||||
self.addrule("PKG_VERSION=foo|1.0-2")
|
||||
self.addrule("FILE_EXIST=etc/foo.cfg")
|
@ -196,6 +196,9 @@ def mkcfgfile(filename, root, option, db):
|
||||
def getmd5sum(filename):
|
||||
"""
|
||||
"""
|
||||
if not os.path.isfile(filename):
|
||||
print "file %s does not exist!" % filename
|
||||
return ""
|
||||
fd = open(filename, "rb")
|
||||
checksum = md5.new()
|
||||
while 1:
|
||||
@ -223,6 +226,9 @@ def mkmd5sum(data):
|
||||
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 st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user