36 #include "xbps_api_impl.h"
60 check_binpkgs_hash(
struct xbps_handle *xhp, prop_object_iterator_t iter)
63 const char *pkgver, *repoloc, *filen, *sha256, *trans;
64 const char *pkgname, *version;
68 while ((obj = prop_object_iterator_next(iter)) != NULL) {
69 prop_dictionary_get_cstring_nocopy(obj,
"transaction", &trans);
70 if ((strcmp(trans,
"remove") == 0) ||
71 (strcmp(trans,
"configure") == 0))
74 prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
75 prop_dictionary_get_cstring_nocopy(obj,
"version", &version);
76 prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc);
77 prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
78 prop_dictionary_get_cstring_nocopy(obj,
"filename", &filen);
79 prop_dictionary_get_cstring_nocopy(obj,
80 "filename-sha256", &sha256);
82 binfile = xbps_repository_pkg_path(xhp, obj);
83 if (binfile == NULL) {
87 xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver, filen,
88 "Verifying `%s' package integrity...", filen, repoloc);
92 xbps_set_cb_state(xhp, XBPS_STATE_VERIFY_FAIL,
94 "Failed to verify `%s' package integrity: %s",
100 prop_object_iterator_reset(iter);
106 download_binpkgs(
struct xbps_handle *xhp, prop_object_iterator_t iter)
109 const char *pkgver, *repoloc, *filen, *trans;
110 const char *pkgname, *version, *fetchstr;
113 bool state_dload =
false;
115 while ((obj = prop_object_iterator_next(iter)) != NULL) {
116 prop_dictionary_get_cstring_nocopy(obj,
"transaction", &trans);
117 if ((strcmp(trans,
"remove") == 0) ||
118 (strcmp(trans,
"configure") == 0))
121 prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
122 prop_dictionary_get_cstring_nocopy(obj,
"version", &version);
123 prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc);
124 prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
125 prop_dictionary_get_cstring_nocopy(obj,
"filename", &filen);
127 binfile = xbps_repository_pkg_path(xhp, obj);
128 if (binfile == NULL) {
135 if (access(binfile, R_OK) == 0) {
142 if (access(xhp->
cachedir, R_OK|X_OK|W_OK) == -1) {
144 xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
145 errno, pkgname, version,
146 "%s: [trans] cannot create cachedir `%s':"
154 if (state_dload ==
false) {
155 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD,
156 0, NULL, NULL, NULL);
159 xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
161 "Downloading binary package `%s' (from `%s')...",
167 xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
168 errno, pkgname, version,
169 "%s: [trans] failed to change dir to cachedir"
180 xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
181 fetchLastErrCode != 0 ? fetchLastErrCode : errno,
183 "%s: [trans] failed to download binary package "
184 "`%s' from `%s': %s", pkgver, filen, repoloc,
185 fetchstr ? fetchstr : strerror(errno));
192 prop_object_iterator_reset(iter);
201 prop_object_iterator_t iter;
202 const char *pkgname, *version, *pkgver, *tract;
204 bool update, install, sr;
206 assert(prop_object_type(xhp->
transd) == PROP_TYPE_DICTIONARY);
208 update = install =
false;
215 if ((rv = download_binpkgs(xhp, iter)) != 0)
220 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
221 if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
227 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
229 while ((obj = prop_object_iterator_next(iter)) != NULL) {
231 prop_dictionary_get_cstring_nocopy(obj,
"transaction", &tract);
232 prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
233 prop_dictionary_get_cstring_nocopy(obj,
"version", &version);
234 prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
236 if (strcmp(tract,
"remove") == 0) {
242 prop_dictionary_get_bool(obj,
"remove-and-update",
244 prop_dictionary_get_bool(obj,
"softreplace", &sr);
247 xbps_dbg_printf(xhp,
"[trans] failed to "
248 "remove %s-%s\n", pkgname, version);
251 }
else if (strcmp(tract,
"configure") == 0) {
262 if (strcmp(tract,
"update") == 0)
272 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0,
273 pkgname, version, NULL);
276 xbps_set_cb_state(xhp,
277 XBPS_STATE_UPDATE_FAIL,
278 rv, pkgname, version,
279 "%s: [trans] failed to update "
280 "package to `%s': %s", pkgver,
281 version, strerror(rv));
286 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL,
287 0, pkgname, version, NULL);
292 if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0)
301 prop_object_iterator_reset(iter);
304 if (!update && !install)
310 xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
312 while ((obj = prop_object_iterator_next(iter)) != NULL) {
313 prop_dictionary_get_cstring_nocopy(obj,
"transaction", &tract);
314 if ((strcmp(tract,
"remove") == 0) ||
315 (strcmp(tract,
"configure") == 0))
318 prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
319 prop_dictionary_get_cstring_nocopy(obj,
"version", &version);
321 if (strcmp(tract,
"update") == 0)
326 xbps_dbg_printf(xhp,
"%s: configure failed for "
327 "%s-%s: %s\n", pkgname, version, strerror(rv));
335 xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
336 pkgname, version, NULL);
338 xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
339 pkgname, version, NULL);
344 prop_object_iterator_release(iter);