From 0c2206f542ce6df2606586d43f190cd5a423fb13 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Thu, 7 Feb 2008 14:58:23 +0100 Subject: libalpm/add.c : safety check for fixing FS#9235. Fixes FS#9235. We already had the following case in extract_single_file : /* cases 1,2,3: couldn't stat an existing file, skip all backup checks */ But we actually only did a lstat here. And if lstat worked, we did a stat without checking. When lstat works and stat fails, it means we have a broken symlink, like in FS#9235. We can actually treat this case like a non-existing file. The broken symlink will then be simply overwritten. Signed-off-by: Chantry Xavier --- lib/libalpm/add.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index ec49c2a3..eddf637e 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -361,14 +361,12 @@ static int extract_single_file(struct archive *archive, * links, etc. * 12- skip extraction, dir already exists. */ - struct stat lsbuf; - if(_alpm_lstat(filename, &lsbuf) != 0) { + + /* do both a lstat and a stat, so we can see what symlinks point to */ + struct stat lsbuf, sbuf; + if(_alpm_lstat(filename, &lsbuf) != 0 || stat(filename, &sbuf) != 0) { /* cases 1,2,3: couldn't stat an existing file, skip all backup checks */ } else { - /* do a stat as well, so we can see what symlinks point to */ - struct stat sbuf; - stat(filename, &sbuf); - if(S_ISDIR(lsbuf.st_mode) && S_ISDIR(entrymode)) { /* case 12: existing dir, ignore it */ if(lsbuf.st_mode != entrymode) { -- cgit v1.2.3-70-g09d2 From 11fe18479eeb7bb97062a2922da13ba816597007 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 7 Feb 2008 19:36:17 -0600 Subject: 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 --- pactest/pmdb.py | 13 +++++++++++-- pactest/tests/upgrade045.py | 16 ++++++++++++++++ pactest/util.py | 6 ++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 pactest/tests/upgrade045.py diff --git a/pactest/pmdb.py b/pactest/pmdb.py index cc852c2a..af392000 100755 --- a/pactest/pmdb.py +++ b/pactest/pmdb.py @@ -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() diff --git a/pactest/tests/upgrade045.py b/pactest/tests/upgrade045.py new file mode 100644 index 00000000..b2f81274 --- /dev/null +++ b/pactest/tests/upgrade045.py @@ -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") diff --git a/pactest/util.py b/pactest/util.py index b24bfdcf..2a6ff4e7 100755 --- a/pactest/util.py +++ b/pactest/util.py @@ -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] -- cgit v1.2.3-70-g09d2 From 14ee1be1ef21e09a84f01dc9623e8513218709d4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 7 Feb 2008 19:43:52 -0600 Subject: makepkg: do a quick check for the VCS binaries Fixes FS#9230. Ensure we have the VCS binaries available when doing the development version number checking. Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 68ad5978..cecda1d2 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -998,23 +998,30 @@ devel_check() { # This will only be used on the first call to makepkg; subsequent # calls to makepkg via fakeroot will explicitly pass the version # number to avoid having to determine the version number twice. + # Also do a brief check to make sure we have the VCS tool available. oldpkgver=$pkgver if [ ! -z ${_darcstrunk} ] && [ ! -z ${_darcsmod} ] ; then + [ $(type -p darcs) ] || return 0 msg "$(gettext "Determining latest darcs revision...")" newpkgver=$(date +%Y%m%d) elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then + [ $(type -p cvs) ] || return 0 msg "$(gettext "Determining latest cvs revision...")" newpkgver=$(date +%Y%m%d) elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then + [ $(type -p git) ] || return 0 msg "$(gettext "Determining latest git revision...")" newpkgver=$(date +%Y%m%d) elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then + [ $(type -p svn) ] || return 0 msg "$(gettext "Determining latest svn revision...")" newpkgver=$(svn log $_svntrunk --limit 1 -q | sed -n 's/^r\([0-9]*\) .*$/\1/p') elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then + [ $(type -p bzr) ] || return 0 msg "$(gettext "Determining latest bzr revision...")" newpkgver=$(bzr revno ${_bzrtrunk}) elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then + [ $(type -p hg) ] || return 0 msg "$(gettext "Determining latest hg revision...")" if [ -d ./src/$_hgrepo ] ; then cd ./src/$_hgrepo -- cgit v1.2.3-70-g09d2