diff options
author | Allan McRae <allan@archlinux.org> | 2012-07-18 04:09:24 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-08-02 16:40:44 +0200 |
commit | d46bb6b27b05579acf5665368c111b4cc41eedcb (patch) | |
tree | 5e5f6e4b3d2d51fa7fdbea892f570f7f0ce800f4 /lib/libalpm/filelist.c | |
parent | 72d3713cc7865af5f4d91410ad56ed4287be6109 (diff) | |
download | pacman-d46bb6b27b05579acf5665368c111b4cc41eedcb.tar.gz pacman-d46bb6b27b05579acf5665368c111b4cc41eedcb.tar.xz |
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>
Diffstat (limited to 'lib/libalpm/filelist.c')
-rw-r--r-- | lib/libalpm/filelist.c | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c index 04075a52..f6c0ed45 100644 --- a/lib/libalpm/filelist.c +++ b/lib/libalpm/filelist.c @@ -22,16 +22,12 @@ /* libalpm */ #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! * 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_filelist_t *filesB, enum filelist_op operation) +alpm_list_t *_alpm_filelist_difference(alpm_filelist_t *filesA, + alpm_filelist_t *filesB) { alpm_list_t *ret = NULL; size_t ctrA = 0, ctrB = 0; @@ -49,26 +45,20 @@ alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA, } else { int cmp = strcmp(strA, strB); if(cmp < 0) { - if(operation == DIFFERENCE) { - /* item only in filesA, qualifies as a difference */ - ret = alpm_list_add(ret, fileA); - } + /* item only in filesA, qualifies as a difference */ + ret = alpm_list_add(ret, fileA); ctrA++; } else if(cmp > 0) { ctrB++; } else { - if(operation == INTERSECT) { - /* item in both, qualifies as an intersect */ - ret = alpm_list_add(ret, fileA); - } ctrA++; ctrB++; } - } + } } - /* if doing a difference, ensure we have completely emptied pA */ - while(operation == DIFFERENCE && ctrA < filesA->count) { + /* ensure we have completely emptied pA */ + while(ctrA < filesA->count) { alpm_file_t *fileA = filesA->files + ctrA; const char *strA = fileA->name; /* skip directories */ @@ -81,6 +71,44 @@ alpm_list_t *_alpm_filelist_operation(alpm_filelist_t *filesA, 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 */ int _alpm_files_cmp(const void *f1, const void *f2) |