[pacman-dev] [PATCH] conflict: skip dir children when replacing a file
When replacing a file with a directory, any files under that directory do not need to be checked for conflicts. This prevents possible false-positive conflicts where the file being replaced is a symlink. We were already skipping the directory children when the file was owned by the previous version of a package being upgraded. This extends that to other packages being removed. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/conflict.c | 16 +++++++++++++++- test/pacman/tests/TESTS | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index b9e30870..48bc88b6 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -503,6 +503,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, struct stat lsbuf; char path[PATH_MAX]; size_t pathlen; + int pfile_isdir; pathlen = snprintf(path, PATH_MAX, "%s%s", handle->root, filestr); relative_path = path + rootlen; @@ -514,7 +515,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, _alpm_log(handle, ALPM_LOG_DEBUG, "checking possible conflict: %s\n", path); - if(path[pathlen - 1] == '/') { + pfile_isdir = path[pathlen - 1] == '/'; + if(pfile_isdir) { if(S_ISDIR(lsbuf.st_mode)) { _alpm_log(handle, ALPM_LOG_DEBUG, "file is a directory, not a conflict\n"); continue; @@ -551,6 +553,18 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, _alpm_log(handle, ALPM_LOG_DEBUG, "local file will be removed, not a conflict\n"); resolved_conflict = 1; + if(pfile_isdir) { + /* go ahead and skip any files inside filestr as they will + * necessarily be resolved by replacing the file with a dir + * NOTE: afterward, j will point to the last file inside filestr */ + size_t fslen = strlen(filestr); + for( ; j->next; j = j->next) { + const char *filestr2 = j->next->data; + if(strncmp(filestr, filestr2, fslen) != 0) { + break; + } + } + } } } diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS index 2d877962..44007f63 100644 --- a/test/pacman/tests/TESTS +++ b/test/pacman/tests/TESTS @@ -149,6 +149,7 @@ TESTS += test/pacman/tests/smoke001.py TESTS += test/pacman/tests/smoke002.py TESTS += test/pacman/tests/smoke003.py TESTS += test/pacman/tests/smoke004.py +TESTS += test/pacman/tests/symlink-replace-with-dir.py TESTS += test/pacman/tests/symlink001.py TESTS += test/pacman/tests/symlink002.py TESTS += test/pacman/tests/symlink010.py -- 2.11.0
On 18/12/16 00:57, Andrew Gregory wrote:
When replacing a file with a directory, any files under that directory do not need to be checked for conflicts. This prevents possible false-positive conflicts where the file being replaced is a symlink.
We were already skipping the directory children when the file was owned by the previous version of a package being upgraded. This extends that to other packages being removed.
OK
On 03/01/17 15:37, Allan McRae wrote:
On 18/12/16 00:57, Andrew Gregory wrote:
When replacing a file with a directory, any files under that directory do not need to be checked for conflicts. This prevents possible false-positive conflicts where the file being replaced is a symlink.
We were already skipping the directory children when the file was owned by the previous version of a package being upgraded. This extends that to other packages being removed.
OK
NOT OK... You missed including the test file: lib/libalpm/conflict.c | 16 +++++++++++++++- test/pacman/tests/TESTS | 1 + 2 files changed, 16 insertions(+), 1 deletion(-)
When replacing a file with a directory, any files under that directory do not need to be checked for conflicts. This prevents possible false-positive conflicts where the file being replaced is a symlink. We were already skipping the directory children when the file was owned by the previous version of a package being upgraded. This extends that to other packages being removed. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- v2: include the test file lib/libalpm/conflict.c | 16 +++++++++++++++- test/pacman/tests/TESTS | 1 + test/pacman/tests/symlink-replace-with-dir.py | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/pacman/tests/symlink-replace-with-dir.py diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index b9e30870..48bc88b6 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -503,6 +503,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, struct stat lsbuf; char path[PATH_MAX]; size_t pathlen; + int pfile_isdir; pathlen = snprintf(path, PATH_MAX, "%s%s", handle->root, filestr); relative_path = path + rootlen; @@ -514,7 +515,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, _alpm_log(handle, ALPM_LOG_DEBUG, "checking possible conflict: %s\n", path); - if(path[pathlen - 1] == '/') { + pfile_isdir = path[pathlen - 1] == '/'; + if(pfile_isdir) { if(S_ISDIR(lsbuf.st_mode)) { _alpm_log(handle, ALPM_LOG_DEBUG, "file is a directory, not a conflict\n"); continue; @@ -551,6 +553,18 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, _alpm_log(handle, ALPM_LOG_DEBUG, "local file will be removed, not a conflict\n"); resolved_conflict = 1; + if(pfile_isdir) { + /* go ahead and skip any files inside filestr as they will + * necessarily be resolved by replacing the file with a dir + * NOTE: afterward, j will point to the last file inside filestr */ + size_t fslen = strlen(filestr); + for( ; j->next; j = j->next) { + const char *filestr2 = j->next->data; + if(strncmp(filestr, filestr2, fslen) != 0) { + break; + } + } + } } } diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS index 2d877962..44007f63 100644 --- a/test/pacman/tests/TESTS +++ b/test/pacman/tests/TESTS @@ -149,6 +149,7 @@ TESTS += test/pacman/tests/smoke001.py TESTS += test/pacman/tests/smoke002.py TESTS += test/pacman/tests/smoke003.py TESTS += test/pacman/tests/smoke004.py +TESTS += test/pacman/tests/symlink-replace-with-dir.py TESTS += test/pacman/tests/symlink001.py TESTS += test/pacman/tests/symlink002.py TESTS += test/pacman/tests/symlink010.py diff --git a/test/pacman/tests/symlink-replace-with-dir.py b/test/pacman/tests/symlink-replace-with-dir.py new file mode 100644 index 00000000..511d751b --- /dev/null +++ b/test/pacman/tests/symlink-replace-with-dir.py @@ -0,0 +1,18 @@ +self.description = "incoming package replaces symlink with directory" + +lp = pmpkg("pkg1") +lp.files = ["usr/lib/foo", + "lib -> usr/lib"] +self.addpkg2db("local", lp) + +p1 = pmpkg("pkg2") +p1.files = ["lib/foo"] +p1.conflicts = ["pkg1"] +self.addpkg2db("sync", p1) + +self.args = "-S pkg2 --ask=4" + +self.addrule("PACMAN_RETCODE=0") +self.addrule("!PKG_EXIST=pkg1") +self.addrule("PKG_EXIST=pkg2") +self.addrule("FILE_TYPE=lib|dir") -- 2.11.0
participants (2)
-
Allan McRae
-
Andrew Gregory