Detect inter-package conflicts between files and directories

Detect a conflict between a file/symlink in one package and a directory
in another when both are being installed at once.

A side effect is the creation of conflicts between a directory symlink
and a real directory (e.g lib -> usr/lib in pkg1 and /lib in pkg2).
Given we can not guarantee pkg1 is installed before pkg2, this is a
genuine conflict.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2012-07-18 12:25:37 +10:00
parent 6860e2f703
commit c1abfeae1e
3 changed files with 38 additions and 17 deletions

View file

@ -82,27 +82,52 @@ alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
size_t ctrA = 0, ctrB = 0; size_t ctrA = 0, ctrB = 0;
while(ctrA < filesA->count && ctrB < filesB->count) { while(ctrA < filesA->count && ctrB < filesB->count) {
int cmp, isdirA, isdirB;
char *strA, *strB;
alpm_file_t *fileA = filesA->files + ctrA; alpm_file_t *fileA = filesA->files + ctrA;
alpm_file_t *fileB = filesB->files + ctrB; alpm_file_t *fileB = filesB->files + ctrB;
const char *strA = fileA->name;
const char *strB = fileB->name; isdirA = 0;
/* skip directories, we don't care about them */ strA = fileA->name;
if(strA[strlen(strA)-1] == '/') { if(strA[strlen(strA)-1] == '/') {
isdirA = 1;
strA = strndup(fileA->name, strlen(strA)-1);
}
isdirB = 0;
strB = fileB->name;
if(strB[strlen(strB)-1] == '/') {
isdirB = 1;
strB = strndup(fileB->name, strlen(strB)-1);
}
cmp = strcmp(strA, strB);
if(cmp < 0) {
ctrA++; ctrA++;
} else if(strB[strlen(strB)-1] == '/') { } else if(cmp > 0) {
ctrB++; ctrB++;
} else { } else {
int cmp = strcmp(strA, strB); /* TODO: this creates conflicts between a symlink to a directory in
if(cmp < 0) { * one package and a real directory in the other. For example,
ctrA++; * lib -> /usr/lib in pkg1 and /lib in pkg2. This would be allowed
} else if(cmp > 0) { * when installing one package at a time _provided_ pkg1 is installed
ctrB++; * first. This will need adjusted if the order of package install can
} else { * be guaranteed to install the symlink first */
/* item in both, qualifies as an intersect */
/* when not directories, item in both qualifies as an intersect */
if(! (isdirA && isdirB)) {
ret = alpm_list_add(ret, fileA); ret = alpm_list_add(ret, fileA);
ctrA++;
ctrB++;
} }
ctrA++;
ctrB++;
}
if(isdirA) {
free(strA);
}
if(isdirB) {
free(strB);
} }
} }

View file

@ -19,5 +19,3 @@ self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg1")
self.addrule("!PKG_EXIST=pkg2") self.addrule("!PKG_EXIST=pkg2")
self.addrule("!FILE_EXIST=dir/realdir/file") self.addrule("!FILE_EXIST=dir/realdir/file")
self.expectfailure = True

View file

@ -13,5 +13,3 @@ self.args = "-S pkg1 pkg2"
self.addrule("PACMAN_RETCODE=1") self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg1")
self.addrule("!PKG_EXIST=pkg2") self.addrule("!PKG_EXIST=pkg2")
self.expectfailure = True