Skip to content

Commit 943bf4d

Browse files
committed
lib: add new transaction type "replaced", for packages that would be...
installed, but were not due to something like matching "replaces" fixes: #667
1 parent 2900717 commit 943bf4d

File tree

6 files changed

+66
-19
lines changed

6 files changed

+66
-19
lines changed

include/xbps.h.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ int xbps_transaction_commit(struct xbps_handle *xhp);
13861386
* - XBPS_TRANS_REMOVE: pkg will be removed
13871387
* - XBPS_TRANS_HOLD: pkg won't be updated (on hold mode)
13881388
* - XBPS_TRANS_DOWNLOAD: pkg will be downloaded
1389+
* - XBPS_TRANS_REPLACED: pkg was to be installed, now replaced by another
13891390
*/
13901391
typedef enum xbps_trans_type {
13911392
XBPS_TRANS_UNKNOWN = 0,
@@ -1395,7 +1396,8 @@ typedef enum xbps_trans_type {
13951396
XBPS_TRANS_CONFIGURE,
13961397
XBPS_TRANS_REMOVE,
13971398
XBPS_TRANS_HOLD,
1398-
XBPS_TRANS_DOWNLOAD
1399+
XBPS_TRANS_DOWNLOAD,
1400+
XBPS_TRANS_REPLACED,
13991401
} xbps_trans_type_t;
14001402

14011403
/**

lib/transaction_check_replaces.c

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <unistd.h>
3232
#include <libgen.h>
3333

34+
#include "xbps.h"
3435
#include "xbps_api_impl.h"
3536

3637
/*
@@ -56,13 +57,17 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
5657

5758
obj = xbps_array_get(pkgs, i);
5859
replaces = xbps_dictionary_get(obj, "replaces");
59-
if (replaces == NULL || xbps_array_count(replaces) == 0)
60+
if (replaces == NULL || xbps_array_count(replaces) == 0) {
61+
xbps_dbg_printf("[replaces] 1\n");
6062
continue;
63+
}
6164

6265
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) {
66+
xbps_dbg_printf("[replaces] 2\n");
6367
return false;
6468
}
6569
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
70+
xbps_dbg_printf("[replaces] 3\n");
6671
return false;
6772
}
6873

@@ -72,29 +77,40 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
7277
for (unsigned int j = 0; j < xbps_array_count(replaces); j++) {
7378
const char *curpkgver = NULL, *pattern = NULL;
7479
char curpkgname[XBPS_NAME_SIZE] = {0};
75-
bool instd_auto = false, hold = false;
80+
bool instd_auto = false, hold = false, in_trans_install = false;
7681
xbps_trans_type_t ttype;
7782

7883
if(!xbps_array_get_cstring_nocopy(replaces, j, &pattern))
7984
abort();
8085

8186
/*
8287
* Find the installed package that matches the pattern
83-
* to be replaced.
88+
* to be replaced. Also check if the package would be
89+
* installed in the transaction.
8490
*/
8591
if (((instd = xbps_pkgdb_get_pkg(xhp, pattern)) == NULL) &&
86-
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL))
87-
continue;
92+
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL)) {
93+
if ((instd = xbps_find_pkg_in_array(pkgs, pattern, XBPS_TRANS_INSTALL)) == NULL) {
94+
xbps_dbg_printf("[replaces] 4\n");
95+
continue;
96+
}
97+
in_trans_install = true;
98+
xbps_dbg_printf("[replaces] 4.5\n");
99+
}
88100

89101
if (!xbps_dictionary_get_cstring_nocopy(instd, "pkgver", &curpkgver)) {
102+
xbps_dbg_printf("[replaces] 5\n");
90103
xbps_object_iterator_release(iter);
91104
return false;
92105
}
93106
/* ignore pkgs on hold mode */
94-
if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold)
107+
if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold) {
108+
xbps_dbg_printf("[replaces] 6\n");
95109
continue;
110+
}
96111

97112
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
113+
xbps_dbg_printf("[replaces] 7\n");
98114
xbps_object_iterator_release(iter);
99115
return false;
100116
}
@@ -103,6 +119,7 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
103119
* due to virtual packages.
104120
*/
105121
if (strcmp(pkgname, curpkgname) == 0) {
122+
xbps_dbg_printf("[replaces] 8\n");
106123
continue;
107124
}
108125
/*
@@ -111,41 +128,52 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
111128
xbps_dictionary_get_bool(instd, "automatic-install", &instd_auto);
112129
reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, 0);
113130
if (reppkgd) {
131+
xbps_dbg_printf("[replaces] 9\n");
114132
ttype = xbps_transaction_pkg_type(reppkgd);
115-
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD)
133+
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
134+
xbps_dbg_printf("[replaces] 10\n");
116135
continue;
136+
}
117137
if (!xbps_dictionary_get_cstring_nocopy(reppkgd,
118138
"pkgver", &curpkgver)) {
139+
xbps_dbg_printf("[replaces] 11\n");
119140
xbps_object_iterator_release(iter);
120141
return false;
121142
}
122143
if (!xbps_match_virtual_pkg_in_dict(reppkgd, pattern) &&
123-
!xbps_pkgpattern_match(curpkgver, pattern))
144+
!xbps_pkgpattern_match(curpkgver, pattern)) {
145+
xbps_dbg_printf("[replaces] 12\n");
124146
continue;
147+
}
125148
/*
126149
* Package contains replaces="pkgpattern", but the
127150
* package that should be replaced is also in the
128151
* transaction and it's going to be updated.
129152
*/
130153
if (!instd_auto) {
154+
xbps_dbg_printf("[replaces] 13\n");
131155
xbps_dictionary_remove(obj, "automatic-install");
132156
}
133157
if (!xbps_dictionary_set_bool(reppkgd, "replaced", true)) {
158+
xbps_dbg_printf("[replaces] 14\n");
134159
xbps_object_iterator_release(iter);
135160
return false;
136161
}
137-
if (!xbps_transaction_pkg_type_set(reppkgd, XBPS_TRANS_REMOVE)) {
162+
if (!xbps_transaction_pkg_type_set(reppkgd, in_trans_install ? XBPS_TRANS_REPLACED : XBPS_TRANS_REMOVE)) {
163+
xbps_dbg_printf("[replaces] 15\n");
138164
xbps_object_iterator_release(iter);
139165
return false;
140166
}
141167
if (xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname) != 0) {
168+
xbps_dbg_printf("[replaces] 16\n");
142169
xbps_object_iterator_release(iter);
143170
return false;
144171
}
145172
xbps_dbg_printf(
146173
"Package `%s' in transaction will be "
147174
"replaced by `%s', matched with `%s'\n",
148175
curpkgver, pkgver, pattern);
176+
xbps_dbg_printf("[replaces] 17\n");
149177
continue;
150178
}
151179
/*
@@ -154,29 +182,35 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs)
154182
* the automatic-install object.
155183
*/
156184
if (xbps_match_virtual_pkg_in_dict(obj, pattern)) {
185+
xbps_dbg_printf("[replaces] 18\n");
157186
if (!instd_auto) {
187+
xbps_dbg_printf("[replaces] 19\n");
158188
xbps_dictionary_remove(obj, "automatic-install");
159189
}
160190
}
161191
/*
162192
* Add package dictionary into the transaction and mark
163193
* it as to be "removed".
164194
*/
165-
if (!xbps_transaction_pkg_type_set(instd, XBPS_TRANS_REMOVE)) {
195+
if (!xbps_transaction_pkg_type_set(instd, in_trans_install ? XBPS_TRANS_REPLACED : XBPS_TRANS_REMOVE)) {
196+
xbps_dbg_printf("[replaces] 20\n");
166197
xbps_object_iterator_release(iter);
167198
return false;
168199
}
169200
if (!xbps_dictionary_set_bool(instd, "replaced", true)) {
201+
xbps_dbg_printf("[replaces] 21\n");
170202
xbps_object_iterator_release(iter);
171203
return false;
172204
}
173205
if (!xbps_array_add_first(pkgs, instd)) {
206+
xbps_dbg_printf("[replaces] 22\n");
174207
xbps_object_iterator_release(iter);
175208
return false;
176209
}
177210
xbps_dbg_printf(
178211
"Package `%s' will be replaced by `%s', "
179212
"matched with `%s'\n", curpkgver, pkgver, pattern);
213+
xbps_dbg_printf("[replaces] 23\n");
180214
}
181215
xbps_object_iterator_release(iter);
182216
}

lib/transaction_commit.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
225225
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
226226

227227
ttype = xbps_transaction_pkg_type(obj);
228-
if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
228+
if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE || ttype == XBPS_TRANS_REPLACED) {
229229
xbps_dbg_printf("%s: skipping pre-remove script for "
230230
"%s: %d\n", __func__, pkgver, ttype);
231231
continue;
@@ -284,7 +284,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
284284
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
285285
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
286286
ttype = xbps_transaction_pkg_type(obj);
287-
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
287+
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_REPLACED) {
288288
xbps_dbg_printf("%s: skipping pre-install script for "
289289
"%s: %d\n", __func__, pkgver, ttype);
290290
continue;
@@ -344,6 +344,11 @@ xbps_transaction_commit(struct xbps_handle *xhp)
344344
* Package is on hold mode, ignore it.
345345
*/
346346
continue;
347+
} else if (ttype == XBPS_TRANS_REPLACED) {
348+
/*
349+
* Package was replaced, ignore it.
350+
*/
351+
continue;
347352
} else {
348353
/* Install or reinstall package */
349354
xbps_set_cb_state(xhp, XBPS_STATE_INSTALL, 0,
@@ -401,7 +406,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
401406
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
402407
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
403408
ttype = xbps_transaction_pkg_type(obj);
404-
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
409+
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_REPLACED) {
405410
xbps_dbg_printf("%s: skipping configuration for "
406411
"%s: %d\n", __func__, pkgver, ttype);
407412
continue;

lib/transaction_files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
823823

824824
/* ignore pkgs in hold mode or in unpacked state */
825825
ttype = xbps_transaction_pkg_type(obj);
826-
if (ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE) {
826+
if (ttype == XBPS_TRANS_HOLD || ttype == XBPS_TRANS_CONFIGURE || ttype == XBPS_TRANS_REPLACED) {
827827
continue;
828828
}
829829

lib/transaction_ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t tty
589589
case XBPS_TRANS_REINSTALL:
590590
case XBPS_TRANS_HOLD:
591591
case XBPS_TRANS_DOWNLOAD:
592+
case XBPS_TRANS_REPLACED:
592593
break;
593594
default:
594595
return false;

lib/transaction_prepare.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ compute_transaction_stats(struct xbps_handle *xhp)
6262
struct statvfs svfs;
6363
uint64_t rootdir_free_size, tsize, dlsize, instsize, rmsize;
6464
uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt, dl_pkgcnt;
65-
uint32_t hold_pkgcnt;
65+
uint32_t hold_pkgcnt, repl_pkgcnt;
6666

6767
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
68-
hold_pkgcnt = dl_pkgcnt = 0;
68+
hold_pkgcnt = dl_pkgcnt = repl_pkgcnt = 0;
6969
tsize = dlsize = instsize = rmsize = 0;
7070

7171
iter = xbps_array_iter_from_dict(xhp->transd, "packages");
@@ -96,10 +96,12 @@ compute_transaction_stats(struct xbps_handle *xhp)
9696
up_pkgcnt++;
9797
} else if (ttype == XBPS_TRANS_HOLD) {
9898
hold_pkgcnt++;
99+
} else if (ttype == XBPS_TRANS_REPLACED) {
100+
repl_pkgcnt++;
99101
}
100102

101103
if ((ttype != XBPS_TRANS_CONFIGURE) && (ttype != XBPS_TRANS_REMOVE) &&
102-
(ttype != XBPS_TRANS_HOLD) &&
104+
(ttype != XBPS_TRANS_HOLD) && (ttype != XBPS_TRANS_REPLACED) &&
103105
xbps_repository_is_remote(repo) && !xbps_binpkg_exists(xhp, obj)) {
104106
xbps_dictionary_get_uint64(obj, "filename-size", &tsize);
105107
tsize += 512;
@@ -112,7 +114,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
112114
}
113115
/* installed_size from repo */
114116
if (ttype != XBPS_TRANS_REMOVE && ttype != XBPS_TRANS_HOLD &&
115-
ttype != XBPS_TRANS_CONFIGURE) {
117+
ttype != XBPS_TRANS_CONFIGURE && ttype != XBPS_TRANS_REPLACED) {
116118
xbps_dictionary_get_uint64(obj, "installed_size", &tsize);
117119
instsize += tsize;
118120
}
@@ -160,6 +162,9 @@ compute_transaction_stats(struct xbps_handle *xhp)
160162
if (!xbps_dictionary_set_uint32(xhp->transd,
161163
"total-hold-pkgs", hold_pkgcnt))
162164
return EINVAL;
165+
if (!xbps_dictionary_set_uint32(xhp->transd,
166+
"total-replaced-pkgs", repl_pkgcnt))
167+
return EINVAL;
163168
if (!xbps_dictionary_set_uint64(xhp->transd,
164169
"total-installed-size", instsize))
165170
return EINVAL;

0 commit comments

Comments
 (0)