diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-04-16 00:12:56 +0200 |
---|---|---|
committer | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-04-17 01:41:35 +0200 |
commit | 6d1dcf7937ba3739d17eda614591d1f59ac0bf3a (patch) | |
tree | caa2ccc7815cc1c0dc95b36c20a0d4287f74a3ac | |
parent | 16b91f798faf6413f9b043543c5c0c3467b6fdbf (diff) | |
download | pacman-6d1dcf7937ba3739d17eda614591d1f59ac0bf3a.tar.gz pacman-6d1dcf7937ba3739d17eda614591d1f59ac0bf3a.tar.xz |
conflict: include owner for filesystem conflicts
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
-rw-r--r-- | lib/libalpm/conflict.c | 25 | ||||
-rw-r--r-- | src/pacman/sync.c | 9 | ||||
-rw-r--r-- | test/pacman/tests/TESTS | 1 | ||||
-rw-r--r-- | test/pacman/tests/file-conflict-with-installed-pkg.py | 17 |
4 files changed, 45 insertions, 7 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 0e37419f..d52f8942 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -278,12 +278,15 @@ static alpm_list_t *add_fileconflict(alpm_handle_t *handle, STRDUP(conflict->target, pkg1->name, goto error); STRDUP(conflict->file, filestr, goto error); - if(pkg2) { - conflict->type = ALPM_FILECONFLICT_TARGET; - STRDUP(conflict->ctarget, pkg2->name, goto error); - } else { + if(!pkg2) { conflict->type = ALPM_FILECONFLICT_FILESYSTEM; STRDUP(conflict->ctarget, "", goto error); + } else if(pkg2->origin == ALPM_PKG_FROM_LOCALDB) { + conflict->type = ALPM_FILECONFLICT_FILESYSTEM; + STRDUP(conflict->ctarget, pkg2->name, goto error); + } else { + conflict->type = ALPM_FILECONFLICT_TARGET; + STRDUP(conflict->ctarget, pkg2->name, goto error); } conflicts = alpm_list_add(conflicts, conflict); @@ -385,6 +388,17 @@ static alpm_list_t *alpm_db_find_file_owners(alpm_db_t* db, const char *path) return owners; } +static alpm_pkg_t *_alpm_find_file_owner(alpm_handle_t *handle, const char *path) +{ + alpm_list_t *i; + for(i = alpm_db_get_pkgcache(handle->db_local); i; i = i->next) { + if(alpm_filelist_contains(alpm_pkg_get_files(i->data), path)) { + return i->data; + } + } + return NULL; +} + static int _alpm_can_overwrite_file(alpm_handle_t *handle, const char *path) { return handle->trans->flags & ALPM_TRANS_FLAG_FORCE @@ -668,7 +682,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, } if(!resolved_conflict) { - conflicts = add_fileconflict(handle, conflicts, path, p1, NULL); + conflicts = add_fileconflict(handle, conflicts, path, p1, + _alpm_find_file_owner(handle, relative_path)); if(handle->pm_errno == ALPM_ERR_MEMORY) { alpm_list_free_inner(conflicts, (alpm_list_fn_free) alpm_conflict_free); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index e37b91c7..680d7b3e 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -823,8 +823,13 @@ int sync_prepare_execute(void) conflict->file, conflict->target, conflict->ctarget); break; case ALPM_FILECONFLICT_FILESYSTEM: - printf(_("%s: %s exists in filesystem\n"), - conflict->target, conflict->file); + if(conflict->ctarget[0]) { + printf(_("%s: %s exists in filesystem (owned by %s)\n"), + conflict->target, conflict->file, conflict->ctarget); + } else { + printf(_("%s: %s exists in filesystem\n"), + conflict->target, conflict->file); + } break; } alpm_fileconflict_free(conflict); diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS index 4dfa3bdb..309eb17e 100644 --- a/test/pacman/tests/TESTS +++ b/test/pacman/tests/TESTS @@ -28,6 +28,7 @@ TESTS += test/pacman/tests/epoch005.py TESTS += test/pacman/tests/epoch010.py TESTS += test/pacman/tests/epoch011.py TESTS += test/pacman/tests/epoch012.py +TESTS += test/pacman/tests/file-conflict-with-installed-pkg.py TESTS += test/pacman/tests/fileconflict001.py TESTS += test/pacman/tests/fileconflict002.py TESTS += test/pacman/tests/fileconflict003.py diff --git a/test/pacman/tests/file-conflict-with-installed-pkg.py b/test/pacman/tests/file-conflict-with-installed-pkg.py new file mode 100644 index 00000000..cf88e8a9 --- /dev/null +++ b/test/pacman/tests/file-conflict-with-installed-pkg.py @@ -0,0 +1,17 @@ +self.description = "File conflict with an installed package" + +lp = pmpkg("foobar") +lp.files = ["conflicting-file"] +self.addpkg2db("local", lp) + +p1 = pmpkg("pkg1") +p1.files = ["conflicting-file"] +self.addpkg(p1) + +self.args = "-U %s" % (p1.filename()) + +self.addrule("!PACMAN_RETCODE=0") +self.addrule("PKG_EXIST=foobar") +self.addrule("!PKG_EXIST=pkg1") +self.addrule("FILE_EXIST=conflicting-file") +self.addrule("PACMAN_OUTPUT=foobar") |