1 diff --git a/install3/misc.c b/install3/misc.c
2 index e3d238e..ded4de0 100644
9 -int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
10 +int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
12 tn_array *dbpkgs = NULL;
15 + int n = 0, freshen = 0;
16 + freshen = ts->getop(ts, POLDEK_OP_FRESHEN)
17 + || poldek_ts_issetf(ts, POLDEK_TS_UPGRADE)
18 + || poldek_ts_issetf(ts, POLDEK_TS_DOWNGRADE)
19 + || poldek_ts_issetf(ts, POLDEK_TS_UPGRADEDIST);
21 n = pkgdb_search(ts->db, &dbpkgs, PMTAG_NAME, pkg->name, NULL, PKG_LDNEVR);
24 @@ -30,17 +34,25 @@ int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
27 if (poldek_conf_MULTILIB) { /* filter out different architectures */
29 tn_array *arr = n_array_clone(dbpkgs);
31 //DBGF("pkg = %s\n", pkg_id(pkg));
32 //pkgs_array_dump(dbpkgs, "before_multilib");
33 - for (i=0; i < n_array_size(dbpkgs); i++) {
34 + for (unsigned int i=0; i < n_array_size(dbpkgs); i++) {
35 struct pkg *dbpkg = n_array_nth(dbpkgs, i);
36 - if (pkg_is_kind_of(dbpkg, pkg))
37 - n_array_push(arr, pkg_link(dbpkg));
39 + msgn(4, "from pkg %s.%s => to pkg %s-%s-%s.%s freshen:%d kind:%d up_arch:%d",
40 + pkg_snprintf_s(dbpkg), pkg_arch(dbpkg), pkg->name, pkg->ver, pkg->rel, pkg_arch(pkg),
41 + freshen, pkg_is_kind_of(dbpkg, pkg), pkg_is_arch_compat(dbpkg, pkg));
43 + // if freshen (upgrade) preffer same arch but
44 + // change from/to noarch depends on which pkg is noarch
45 + // add package if pkg_is_kind_of (have same name and color)
46 + if (pkg_is_kind_of(dbpkg, pkg)
47 + && !(freshen && !pkg_is_arch_compat(dbpkg, pkg)))
48 + n_array_push(arr, pkg_link(dbpkg));
52 n_array_cfree(&dbpkgs);
54 n = n_array_size(arr);
55 diff --git a/libpoldek.sym b/libpoldek.sym
56 index 6c2a356..26e05d5 100644
59 @@ -71,6 +71,7 @@ pkg_id_snprintf
67 diff --git a/pkg.h b/pkg.h
68 index 8a1d0b2..77acf0a 100644
71 @@ -43,6 +43,8 @@ struct pkgdir; /* defined in pkgdir/pkgdir.h */
72 ((pkg)->flags & color)
73 #endif /* POLDEK_PKG_DAG_COLOURS */
75 +#define pkg_is_noarch(pkg) (0 == strcmp(pkg_arch((pkg)), "noarch"))
77 #define pkg_set_prereqed(pkg) ((pkg)->flags |= PKG_ORDER_PREREQ)
78 #define pkg_clr_prereqed(pkg) ((pkg)->flags &= ~PKG_ORDER_PREREQ)
79 #define pkg_is_prereqed(pkg) ((pkg)->flags & PKG_ORDER_PREREQ)
80 diff --git a/pkgcmp.c b/pkgcmp.c
81 index f123e03..7bf34d4 100644
84 @@ -88,7 +88,19 @@ int pkg_is_colored_like(const struct pkg *candidate, const struct pkg *pkg)
88 -int pkg_eq_capreq(const struct pkg *pkg, const struct capreq *cr)
89 +/* ret : 1 if pkg is cappable to upgrade arch<=>arch, arch<=>noarch */
90 +int pkg_is_arch_compat(const struct pkg *candidate, const struct pkg *pkg)
92 + // if upgrade preffer same arch but
93 + // change from/to noarch depends on which pkg is noarch
95 + int cmp_arch = pkg_cmp_arch(candidate, pkg);
96 + return ( cmp_arch == 0
97 + || (cmp_arch > 0 && pkg_is_noarch(candidate))
98 + || (cmp_arch < 0 && pkg_is_noarch(pkg)));
101 +int pkg_eq_capreq(const struct pkg *pkg, const struct capreq *cr)
103 return strcmp(pkg->name, capreq_name(cr)) == 0 &&
104 strcmp(pkg->ver, capreq_ver(cr)) == 0 &&
105 diff --git a/pkgcmp.h b/pkgcmp.h
106 index 6b1b75a..980f675 100644
109 @@ -17,6 +17,9 @@ int pkg_is_colored_like(const struct pkg *candidate, const struct pkg *pkg);
110 /* same name && arch */
111 int pkg_is_kind_of(const struct pkg *candidate, const struct pkg *pkg);
113 +/* ret : 0 if pkg is cappable to upgrade arch<=>arch, arch<=>noarch */
114 +int pkg_is_arch_compat(const struct pkg *candidate, const struct pkg *pkg);
116 /* strncmp(p1->name, p2->name, strlen(p2->name)) */
117 extern__inline int pkg_ncmp_name(const struct pkg *p1, const struct pkg *p2);
119 @@ -27,7 +30,7 @@ int pkg_cmp_name(const struct pkg *p1, const struct pkg *p2);
120 extern__inline int pkg_cmp_id(const struct pkg *p1, const struct pkg *p2);
124 +/* versions only (+epoch) */
125 int pkg_cmp_ver(const struct pkg *p1, const struct pkg *p2);
127 int pkg_cmp_evr(const struct pkg *p1, const struct pkg *p2);
128 diff --git a/upgrade-dist.c b/upgrade-dist.c
129 index 458b764..00f34fc 100644
132 @@ -64,8 +64,18 @@ int process_pkg(const struct pkg *dbpkg, struct poldek_ts *ts,
134 if (!ts->getop(ts, POLDEK_OP_MULTILIB))
137 - if (pkg_is_kind_of(pkg, dbpkg))
139 + if (0 != strcmp(dbpkg->name, pkg->name))
145 + msgn(4, "UPGRADE-DIST from pkg %s.%s => to pkg %s-%s-%s.%s kind:%d up_arch:%d",
146 + pkg_snprintf_s(dbpkg), pkg_arch(dbpkg), pkg->name, pkg->ver, pkg->rel, pkg_arch(pkg),
147 + pkg_is_kind_of(dbpkg, pkg), pkg_is_arch_compat(dbpkg, pkg));
149 + if (pkg_cmp_evr(pkg, dbpkg) > 0 && pkg_is_kind_of(pkg, dbpkg) && pkg_is_arch_compat(pkg, dbpkg))