From: Michael Schroeder Date: Mon, 8 Apr 2013 09:36:43 +0000 (+0200) Subject: fix bugs in fileconflicts code and prepare for aliased dirs X-Git-Tag: BASE-SuSE-Code-12_3-Branch~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb9ff59dde27663a23fa798419f4bd6ab91d1be;p=thirdparty%2Flibsolv.git fix bugs in fileconflicts code and prepare for aliased dirs Breaks API but that should not be a problem as noone seems to use the function yet. --- diff --git a/examples/solv.c b/examples/solv.c index eea621da..37456d86 100644 --- a/examples/solv.c +++ b/examples/solv.c @@ -3141,8 +3141,8 @@ rerunsolver: if (conflicts.count) { printf("\n"); - for (i = 0; i < conflicts.count; i += 5) - printf("file %s of package %s conflicts with package %s\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_solvid2str(pool, conflicts.elements[i + 3])); + for (i = 0; i < conflicts.count; i += 6) + printf("file %s of package %s conflicts with package %s\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_solvid2str(pool, conflicts.elements[i + 4])); printf("\n"); if (yesno("Re-run solver (y/n/q)? ")) { diff --git a/ext/pool_fileconflicts.c b/ext/pool_fileconflicts.c index 5bf96670..5f56e602 100644 --- a/ext/pool_fileconflicts.c +++ b/ext/pool_fileconflicts.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012, Novell Inc. + * Copyright (c) 2009-2013, Novell Inc. * * This program is licensed under the BSD license, read LICENSE.BSD * for further information @@ -240,30 +240,30 @@ findfileconflicts2_cb(void *cbdatav, const char *fn, int fmode, const char *md5) addfilesspace(cbdata, (unsigned char *)fn, strlen(fn) + 1); } -static int lookat_sort(const void *ap, const void *bp, void *dp) +static int +lookat_cmp(const void *ap, const void *bp, void *dp) { const Id *a = ap; const Id *b = bp; unsigned int ahx = (unsigned int)a[0]; /* a[0] can be < 0 */ unsigned int bhx = (unsigned int)b[0]; - if (ahx < bhx) - return -1; - if (ahx > bhx) - return 1; - return a[1] - b[1]; + return ahx < bhx ? -1 : ahx > bhx ? 1 : a[1] - b[1]; } -static int conflicts_cmp(const void *ap, const void *bp, void *dp) +static int +conflicts_cmp(const void *ap, const void *bp, void *dp) { Pool *pool = dp; const Id *a = ap; const Id *b = bp; - if (a[0] != b[0]) /* filename */ + if (a[0] != b[0]) /* filename1 */ return strcmp(pool_id2str(pool, a[0]), pool_id2str(pool, b[0])); - if (a[1] != b[1]) /* idx1 */ + if (a[3] != b[3]) /* filename2 */ + return strcmp(pool_id2str(pool, a[3]), pool_id2str(pool, b[3])); + if (a[1] != b[1]) /* pkgid1 */ return a[1] - b[1]; - if (a[3] != b[3]) /* idx2 */ - return a[3] - b[3]; + if (a[4] != b[4]) /* pkgid2 */ + return a[4] - b[4]; return 0; } @@ -362,7 +362,7 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo queue_free(&cbdata.lookat_dir); /* sort and unify */ - solv_sort(cbdata.lookat.elements, cbdata.lookat.count / 2, sizeof(Id) * 2, &lookat_sort, pool); + solv_sort(cbdata.lookat.elements, cbdata.lookat.count / 2, sizeof(Id) * 2, &lookat_cmp, pool); for (i = j = 0; i < cbdata.lookat.count; i += 2) { Id hx = cbdata.lookat.elements[i]; @@ -401,7 +401,7 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo rpm_iterate_filelist(handle, iterflags, findfileconflicts2_cb, &cbdata); pend = cbdata.files.count; - for (j = i + 2; j < cbdata.lookat.count && cbdata.lookat.elements[j] == hx; j++) + for (j = i + 2; j < cbdata.lookat.count && cbdata.lookat.elements[j] == hx; j += 2) { Id qidx = cbdata.lookat.elements[j + 1]; Id q = pkgs->elements[qidx]; @@ -423,12 +423,14 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo continue; /* md5 sum matches */ if (obsoleteusescolors && fsi[33] && fsj[33] && (fsi[33] & fsj[33]) == 0) continue; /* colors do not conflict */ - queue_push(conflicts, pool_str2id(pool, (char *)cbdata.filesspace + cbdata.files.elements[ii] + 34, 1)); + queue_push(conflicts, pool_str2id(pool, fsi + 34, 1)); queue_push(conflicts, p); - queue_push(conflicts, pool_str2id(pool, (char *)cbdata.filesspace + cbdata.files.elements[ii], 1)); + queue_push(conflicts, pool_str2id(pool, fsi, 1)); + queue_push(conflicts, pool_str2id(pool, fsj + 34, 1)); queue_push(conflicts, q); - queue_push(conflicts, pool_str2id(pool, (char *)cbdata.filesspace + cbdata.files.elements[jj], 1)); + queue_push(conflicts, pool_str2id(pool, fsj, 1)); } + queue_truncate(&cbdata.files, pend); } } cbdata.filesspace = solv_free(cbdata.filesspace); @@ -436,10 +438,10 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo queue_free(&cbdata.lookat); queue_free(&cbdata.files); POOL_DEBUG(SOLV_DEBUG_STATS, "candidate check took %d ms\n", solv_timems(now)); - if (conflicts->count > 5) - solv_sort(conflicts->elements, conflicts->count / 5, 5 * sizeof(Id), conflicts_cmp, pool); + if (conflicts->count > 6) + solv_sort(conflicts->elements, conflicts->count / 6, 6 * sizeof(Id), conflicts_cmp, pool); (*handle_cb)(pool, 0, handle_cbdata); - POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file conflicts\n", conflicts->count / 5); + POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file conflicts\n", conflicts->count / 6); POOL_DEBUG(SOLV_DEBUG_STATS, "file conflict detection took %d ms\n", solv_timems(start)); return conflicts->count; } diff --git a/src/pool.c b/src/pool.c index 21b28609..2bcb71cc 100644 --- a/src/pool.c +++ b/src/pool.c @@ -2142,12 +2142,12 @@ pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts) if (!conflicts->count) return; - for (i = 0; i < conflicts->count; i += 5) + for (i = 0; i < conflicts->count; i += 6) { fn = conflicts->elements[i]; p = conflicts->elements[i + 1]; md5 = conflicts->elements[i + 2]; - q = conflicts->elements[i + 3]; + q = conflicts->elements[i + 4]; id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1); s = pool->solvables + p; if (!s->repo) diff --git a/tools/findfileconflicts.c b/tools/findfileconflicts.c index 1ef55927..ff49e422 100644 --- a/tools/findfileconflicts.c +++ b/tools/findfileconflicts.c @@ -56,8 +56,8 @@ int main(int argc, char **argv) queue_push(&todo, p); pool_findfileconflicts(pool, &todo, 0, &conflicts, &iterate_handle, (void *)&state); queue_free(&todo); - for (i = 0; i < conflicts.count; i += 5) - printf("%s: %s[%s] %s[%s]\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_id2str(pool, conflicts.elements[i + 2]), pool_solvid2str(pool, conflicts.elements[i + 3]), pool_id2str(pool, conflicts.elements[i + 4])); + for (i = 0; i < conflicts.count; i += 6) + printf("%s: %s[%s] %s[%s]\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_id2str(pool, conflicts.elements[i + 2]), pool_solvid2str(pool, conflicts.elements[i + 4]), pool_id2str(pool, conflicts.elements[i + 5])); if (conflicts.count) { Queue job;