[pacman-dev] [PATCH 1/2] Add pactests for not detecting directory conflicts with upgrades
From: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org> --- test/pacman/tests/fileconflict020.py | 20 ++++++++++++++++++++ test/pacman/tests/fileconflict021.py | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/pacman/tests/fileconflict020.py create mode 100644 test/pacman/tests/fileconflict021.py diff --git a/test/pacman/tests/fileconflict020.py b/test/pacman/tests/fileconflict020.py new file mode 100644 index 0000000..306aca2 --- /dev/null +++ b/test/pacman/tests/fileconflict020.py @@ -0,0 +1,20 @@ +self.description = "upgrade introduces new directory that conflicts with a package file" + +lp1 = pmpkg("pkg1") +lp1.files = ["usr/bin/foo"] +self.addpkg2db("local", lp1) + +lp2 = pmpkg("pkg2") +self.addpkg2db("local", lp2) + +p = pmpkg("pkg2", "1.0-2") +p.files = ["usr/bin/foo/"] +self.addpkg2db("sync", p) + +self.args = "-S pkg2" + +self.addrule("PACMAN_RETCODE=1") +self.addrule("PKG_VERSION=pkg2|1.0-1") +self.addrule("!DIR_EXIST=usr/bin/foo/") + +self.expectfailure = True diff --git a/test/pacman/tests/fileconflict021.py b/test/pacman/tests/fileconflict021.py new file mode 100644 index 0000000..ccb70f2 --- /dev/null +++ b/test/pacman/tests/fileconflict021.py @@ -0,0 +1,18 @@ +self.description = "upgrade package overwriting existing unowned file with directory" + +lp1 = pmpkg("pkg1") +self.addpkg2db("local", lp1) + +self.filesystem = ["file"] + +p = pmpkg("pkg1", "1.0-2") +p.files = ["file/"] +self.addpkg2db("sync", p) + +self.args = "-S pkg1" + +self.addrule("PACMAN_RETCODE=1") +self.addrule("PKG_VERSION=pkg1|1.0-1") +self.addrule("!DIR_EXIST=file/") + +self.expectfailure = True -- 1.8.0.1
This is a bug that has been around since at least 2007. On a package upgrade (either by -S or -U) a new directory could overwrite any file. This is caused by the filelist difference calculation ignoring all directories and thus no new directories were checked for conflicting files on the filesystem. Signed-off-by: Allan McRae <allan@archlinux.org> --- This version also cares about directories at the end of filelists... lib/libalpm/filelist.c | 28 +++++++++------------------- test/pacman/tests/fileconflict020.py | 2 -- test/pacman/tests/fileconflict021.py | 2 -- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c index bf7645b..f884e6a 100644 --- a/lib/libalpm/filelist.c +++ b/lib/libalpm/filelist.c @@ -228,34 +228,24 @@ alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA, alpm_file_t *fileA = filesA->files + ctrA; const char *strA = filesA->resolved_path[ctrA]; const char *strB = filesB->resolved_path[ctrB]; - /* skip directories, we don't care about them */ - if(strA[strlen(strA)-1] == '/') { + + int cmp = strcmp(strA, strB); + if(cmp < 0) { + /* item only in filesA, qualifies as a difference */ + ret = alpm_list_add(ret, fileA); ctrA++; - } else if(strB[strlen(strB)-1] == '/') { + } else if(cmp > 0) { ctrB++; } else { - int cmp = strcmp(strA, strB); - if(cmp < 0) { - /* item only in filesA, qualifies as a difference */ - ret = alpm_list_add(ret, fileA); - ctrA++; - } else if(cmp > 0) { - ctrB++; - } else { - ctrA++; - ctrB++; - } + ctrA++; + ctrB++; } } /* ensure we have completely emptied pA */ while(ctrA < filesA->count) { alpm_file_t *fileA = filesA->files + ctrA; - const char *strA = fileA->name; - /* skip directories */ - if(strA[strlen(strA)-1] != '/') { - ret = alpm_list_add(ret, fileA); - } + ret = alpm_list_add(ret, fileA); ctrA++; } diff --git a/test/pacman/tests/fileconflict020.py b/test/pacman/tests/fileconflict020.py index 306aca2..db59e47 100644 --- a/test/pacman/tests/fileconflict020.py +++ b/test/pacman/tests/fileconflict020.py @@ -16,5 +16,3 @@ self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg2|1.0-1") self.addrule("!DIR_EXIST=usr/bin/foo/") - -self.expectfailure = True diff --git a/test/pacman/tests/fileconflict021.py b/test/pacman/tests/fileconflict021.py index ccb70f2..f695aef 100644 --- a/test/pacman/tests/fileconflict021.py +++ b/test/pacman/tests/fileconflict021.py @@ -14,5 +14,3 @@ self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") self.addrule("!DIR_EXIST=file/") - -self.expectfailure = True -- 1.8.0.1
On 11.12.2012 15:38, Allan McRae wrote:
From: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Florian Pritz <bluewind@xinu.at> -- Florian Pritz
participants (2)
-
Allan McRae
-
Florian Pritz