Split _alpm_filelist_operation function
To improve conflict checking, we will need to make these functions diverge to an extent where having two separate functions will be preferable. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
72d3713cc7
commit
d46bb6b27b
3 changed files with 57 additions and 30 deletions
|
@ -367,8 +367,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
||||||
for(j = i->next; j; j = j->next) {
|
for(j = i->next; j; j = j->next) {
|
||||||
alpm_list_t *common_files;
|
alpm_list_t *common_files;
|
||||||
alpm_pkg_t *p2 = j->data;
|
alpm_pkg_t *p2 = j->data;
|
||||||
common_files = _alpm_filelist_operation(alpm_pkg_get_files(p1),
|
common_files = _alpm_filelist_intersection(alpm_pkg_get_files(p1),
|
||||||
alpm_pkg_get_files(p2), INTERSECT);
|
alpm_pkg_get_files(p2));
|
||||||
|
|
||||||
if(common_files) {
|
if(common_files) {
|
||||||
alpm_list_t *k;
|
alpm_list_t *k;
|
||||||
|
@ -400,8 +400,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
||||||
if(dbpkg) {
|
if(dbpkg) {
|
||||||
alpm_list_t *difference;
|
alpm_list_t *difference;
|
||||||
/* older ver of package currently installed */
|
/* older ver of package currently installed */
|
||||||
difference = _alpm_filelist_operation(alpm_pkg_get_files(p1),
|
difference = _alpm_filelist_difference(alpm_pkg_get_files(p1),
|
||||||
alpm_pkg_get_files(dbpkg), DIFFERENCE);
|
alpm_pkg_get_files(dbpkg));
|
||||||
tmpfiles.count = alpm_list_count(difference);
|
tmpfiles.count = alpm_list_count(difference);
|
||||||
tmpfiles.files = alpm_list_to_array(difference, tmpfiles.count,
|
tmpfiles.files = alpm_list_to_array(difference, tmpfiles.count,
|
||||||
sizeof(alpm_file_t));
|
sizeof(alpm_file_t));
|
||||||
|
@ -533,7 +533,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
||||||
if(handle->pm_errno == ALPM_ERR_MEMORY) {
|
if(handle->pm_errno == ALPM_ERR_MEMORY) {
|
||||||
FREELIST(conflicts);
|
FREELIST(conflicts);
|
||||||
if(dbpkg) {
|
if(dbpkg) {
|
||||||
/* only freed if it was generated from filelist_operation() */
|
/* only freed if it was generated from _alpm_filelist_difference() */
|
||||||
free(tmpfiles.files);
|
free(tmpfiles.files);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -541,7 +541,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dbpkg) {
|
if(dbpkg) {
|
||||||
/* only freed if it was generated from filelist_operation() */
|
/* only freed if it was generated from _alpm_filelist_difference() */
|
||||||
free(tmpfiles.files);
|
free(tmpfiles.files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,12 @@
|
||||||
/* libalpm */
|
/* libalpm */
|
||||||
#include "filelist.h"
|
#include "filelist.h"
|
||||||
|
|
||||||
/* Returns a set operation on the provided two lists of files.
|
/* Returns the difference of the provided two lists of files.
|
||||||
* Pre-condition: both lists are sorted!
|
* Pre-condition: both lists are sorted!
|
||||||
* When done, free the list but NOT the contained data.
|
* When done, free the list but NOT the contained data.
|
||||||
*
|
|
||||||
* Operations:
|
|
||||||
* DIFFERENCE - a difference operation is performed. filesA - filesB.
|
|
||||||
* INTERSECT - an intersection operation is performed. filesA & filesB.
|
|
||||||
*/
|
*/
|
||||||
alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA,
|
alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA,
|
||||||
alpm_filelist_t *filesB, enum filelist_op operation)
|
alpm_filelist_t *filesB)
|
||||||
{
|
{
|
||||||
alpm_list_t *ret = NULL;
|
alpm_list_t *ret = NULL;
|
||||||
size_t ctrA = 0, ctrB = 0;
|
size_t ctrA = 0, ctrB = 0;
|
||||||
|
@ -49,26 +45,20 @@ alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA,
|
||||||
} else {
|
} else {
|
||||||
int cmp = strcmp(strA, strB);
|
int cmp = strcmp(strA, strB);
|
||||||
if(cmp < 0) {
|
if(cmp < 0) {
|
||||||
if(operation == DIFFERENCE) {
|
/* item only in filesA, qualifies as a difference */
|
||||||
/* item only in filesA, qualifies as a difference */
|
ret = alpm_list_add(ret, fileA);
|
||||||
ret = alpm_list_add(ret, fileA);
|
|
||||||
}
|
|
||||||
ctrA++;
|
ctrA++;
|
||||||
} else if(cmp > 0) {
|
} else if(cmp > 0) {
|
||||||
ctrB++;
|
ctrB++;
|
||||||
} else {
|
} else {
|
||||||
if(operation == INTERSECT) {
|
|
||||||
/* item in both, qualifies as an intersect */
|
|
||||||
ret = alpm_list_add(ret, fileA);
|
|
||||||
}
|
|
||||||
ctrA++;
|
ctrA++;
|
||||||
ctrB++;
|
ctrB++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if doing a difference, ensure we have completely emptied pA */
|
/* ensure we have completely emptied pA */
|
||||||
while(operation == DIFFERENCE && ctrA < filesA->count) {
|
while(ctrA < filesA->count) {
|
||||||
alpm_file_t *fileA = filesA->files + ctrA;
|
alpm_file_t *fileA = filesA->files + ctrA;
|
||||||
const char *strA = fileA->name;
|
const char *strA = fileA->name;
|
||||||
/* skip directories */
|
/* skip directories */
|
||||||
|
@ -81,6 +71,44 @@ alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the intersection of the provided two lists of files.
|
||||||
|
* Pre-condition: both lists are sorted!
|
||||||
|
* When done, free the list but NOT the contained data.
|
||||||
|
*/
|
||||||
|
alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
|
||||||
|
alpm_filelist_t *filesB)
|
||||||
|
{
|
||||||
|
alpm_list_t *ret = NULL;
|
||||||
|
size_t ctrA = 0, ctrB = 0;
|
||||||
|
|
||||||
|
while(ctrA < filesA->count && ctrB < filesB->count) {
|
||||||
|
alpm_file_t *fileA = filesA->files + ctrA;
|
||||||
|
alpm_file_t *fileB = filesB->files + ctrB;
|
||||||
|
const char *strA = fileA->name;
|
||||||
|
const char *strB = fileB->name;
|
||||||
|
/* skip directories, we don't care about them */
|
||||||
|
if(strA[strlen(strA)-1] == '/') {
|
||||||
|
ctrA++;
|
||||||
|
} else if(strB[strlen(strB)-1] == '/') {
|
||||||
|
ctrB++;
|
||||||
|
} else {
|
||||||
|
int cmp = strcmp(strA, strB);
|
||||||
|
if(cmp < 0) {
|
||||||
|
ctrA++;
|
||||||
|
} else if(cmp > 0) {
|
||||||
|
ctrB++;
|
||||||
|
} else {
|
||||||
|
/* item in both, qualifies as an intersect */
|
||||||
|
ret = alpm_list_add(ret, fileA);
|
||||||
|
ctrA++;
|
||||||
|
ctrB++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Helper function for comparing files list entries
|
/* Helper function for comparing files list entries
|
||||||
*/
|
*/
|
||||||
int _alpm_files_cmp(const void *f1, const void *f2)
|
int _alpm_files_cmp(const void *f1, const void *f2)
|
||||||
|
|
|
@ -21,13 +21,12 @@
|
||||||
|
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
enum filelist_op {
|
|
||||||
DIFFERENCE = 0,
|
|
||||||
INTERSECT = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA,
|
alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA,
|
||||||
alpm_filelist_t *filesB, enum filelist_op operation);
|
alpm_filelist_t *filesB);
|
||||||
|
|
||||||
|
alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
|
||||||
|
alpm_filelist_t *filesB);
|
||||||
|
|
||||||
int _alpm_files_cmp(const void *f1, const void *f2);
|
int _alpm_files_cmp(const void *f1, const void *f2);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue