32#include <archive_entry.h>
34#include "xbps_api_impl.h"
37internalize_script(xbps_dictionary_t pkg_repod,
const char *script,
38 struct archive *ar,
struct archive_entry *entry)
41 xbps_data_t data = NULL;
43 int64_t entry_size = archive_entry_size(entry);
50 if ((
size_t)entry_size >
sizeof buffer) {
51 buf = malloc(entry_size);
56 if (archive_read_data(ar, buf != NULL ? buf : buffer, entry_size) != entry_size) {
61 data = xbps_data_create_data(buf != NULL ? buf : buffer, entry_size);
68 xbps_dictionary_set(pkg_repod, script, data);
69 xbps_object_release(data);
74internalize_binpkg(
struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
76 char pkgfile[PATH_MAX];
77 xbps_dictionary_t filesd = NULL, propsd = NULL;
79 struct archive *ar = NULL;
80 struct archive_entry *entry;
81 const char *pkgver, *pkgname, *binpkg_pkgver;
86 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgver", &pkgver);
88 xbps_dictionary_get_cstring_nocopy(pkg_repod,
"pkgname", &pkgname);
95 if ((ar = archive_read_new()) == NULL)
101 archive_read_support_filter_gzip(ar);
102 archive_read_support_filter_bzip2(ar);
103 archive_read_support_filter_xz(ar);
104 archive_read_support_filter_lz4(ar);
105 archive_read_support_filter_zstd(ar);
106 archive_read_support_format_tar(ar);
108 pkg_fd = open(pkgfile, O_RDONLY|O_CLOEXEC);
111 xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL,
113 "%s: failed to open binary package `%s': %s",
114 pkgver, pkgfile, strerror(rv));
117 if (fstat(pkg_fd, &st) == -1) {
119 xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL,
121 "%s: failed to fstat binary package `%s': %s",
122 pkgver, pkgfile, strerror(rv));
125 if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
126 rv = archive_errno(ar);
127 xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL,
129 "%s: failed to read binary package `%s': %s",
130 pkgver, pkgfile, strerror(rv));
134 for (uint8_t i = 0; i < 4; i++) {
135 const char *entry_pname;
136 int ar_rv = archive_read_next_header(ar, &entry);
137 if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL)
139 else if (ar_rv == ARCHIVE_RETRY)
142 entry_pname = archive_entry_pathname(entry);
144 if (strcmp(
"./INSTALL", entry_pname) == 0) {
145 rv = internalize_script(pkg_repod,
"install-script", ar, entry);
148 }
else if (strcmp(
"./REMOVE", entry_pname) == 0) {
149 rv = internalize_script(pkg_repod,
"remove-script", ar, entry);
152 }
else if ((strcmp(
"./files.plist", entry_pname)) == 0) {
153 filesd = xbps_archive_get_dictionary(ar, entry);
154 if (filesd == NULL) {
158 }
else if (strcmp(
"./props.plist", entry_pname) == 0) {
159 propsd = xbps_archive_get_dictionary(ar, entry);
160 if (propsd == NULL) {
172 if (propsd == NULL || filesd == NULL) {
174 xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL, -rv, pkgver,
175 "%s: [files] invalid binary package `%s'.", pkgver, pkgfile);
183 xbps_dictionary_get_cstring_nocopy(propsd,
"pkgver", &binpkg_pkgver);
184 if (strcmp(pkgver, binpkg_pkgver) != 0) {
186 xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL, -rv, pkgver,
187 "%s: [files] pkgver mismatch repodata: `%s' binpkg: `%s'.",
188 pkgfile, pkgver, binpkg_pkgver);
193 xbps_object_release(propsd);
194 xbps_object_release(filesd);
198 archive_read_free(ar);
203xbps_transaction_internalize(
struct xbps_handle *xhp, xbps_object_iterator_t iter)
210 while ((obj = xbps_object_iterator_next(iter)) != NULL) {
215 if (ttype != XBPS_TRANS_INSTALL && ttype != XBPS_TRANS_UPDATE)
218 rv = internalize_binpkg(xhp, obj);
222 xbps_object_iterator_reset(iter);
Generic XBPS structure handler for initialization.
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
ssize_t xbps_pkg_path(struct xbps_handle *xhp, char *dst, size_t dstsz, xbps_dictionary_t pkgd)