diff --git a/install3/misc.c b/install3/misc.c index e3d238e..1e7a927 100644 --- a/install3/misc.c +++ b/install3/misc.c @@ -16,11 +16,12 @@ #include "ictx.h" -int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc) +int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc) { tn_array *dbpkgs = NULL; - int n; - + int n = 0, arch = 0, freshen = 0, upgrade = -1; + freshen = ts->getop(ts, POLDEK_OP_FRESHEN); + n = pkgdb_search(ts->db, &dbpkgs, PMTAG_NAME, pkg->name, NULL, PKG_LDNEVR); n_assert(n >= 0); @@ -30,17 +31,28 @@ int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc) } if (poldek_conf_MULTILIB) { /* filter out different architectures */ - int i; tn_array *arr = n_array_clone(dbpkgs); //DBGF("pkg = %s\n", pkg_id(pkg)); //pkgs_array_dump(dbpkgs, "before_multilib"); - for (i=0; i < n_array_size(dbpkgs); i++) { + for (unsigned int i=0; i < n_array_size(dbpkgs); i++) { struct pkg *dbpkg = n_array_nth(dbpkgs, i); - if (pkg_is_kind_of(dbpkg, pkg)) - n_array_push(arr, pkg_link(dbpkg)); + + // if freshen (upgrade) preffer same arch but + // change from/to noarch depends on which pkg is noarch + // add package if pkg_is_kind_of (have same name and color) + if (freshen) + { + arch = pkg_cmp_arch(dbpkg, pkg); + upgrade = ( 0 == arch + || (0 > arch && pkg_is_noarch(pkg)) + || (0 < arch && pkg_is_noarch(dbpkg))); + } + + if ( upgrade && (0 != pkg_is_kind_of(dbpkg, pkg))) + n_array_push(arr, pkg_link(dbpkg)); } - + n_array_cfree(&dbpkgs); dbpkgs = arr; n = n_array_size(arr); diff --git a/pkg.h b/pkg.h index 8a1d0b2..77acf0a 100644 --- a/pkg.h +++ b/pkg.h @@ -43,6 +43,8 @@ struct pkgdir; /* defined in pkgdir/pkgdir.h */ ((pkg)->flags & color) #endif /* POLDEK_PKG_DAG_COLOURS */ +#define pkg_is_noarch(pkg) (0 == strcmp(pkg_arch((pkg)), "noarch")) + #define pkg_set_prereqed(pkg) ((pkg)->flags |= PKG_ORDER_PREREQ) #define pkg_clr_prereqed(pkg) ((pkg)->flags &= ~PKG_ORDER_PREREQ) #define pkg_is_prereqed(pkg) ((pkg)->flags & PKG_ORDER_PREREQ)