35#include <archive_entry.h>
37#include "xbps_api_impl.h"
48 struct fetchIO *fetch;
53fetch_archive_open(
struct archive *a UNUSED,
void *client_data)
55 struct fetch_archive *f = client_data;
57 f->fetch = fetchGet(f->url, NULL);
66fetch_archive_read(
struct archive *a UNUSED,
void *client_data,
const void **buf)
68 struct fetch_archive *f = client_data;
71 return fetchIO_read(f->fetch, f->buffer,
sizeof(f->buffer));
75fetch_archive_close(
struct archive *a UNUSED,
void *client_data)
77 struct fetch_archive *f = client_data;
80 fetchIO_close(f->fetch);
86static struct archive *
87open_archive_by_url(
struct url *url)
89 struct fetch_archive *f;
92 f = malloc(
sizeof(
struct fetch_archive));
98 if ((a = archive_read_new()) == NULL) {
102 archive_read_support_filter_gzip(a);
103 archive_read_support_filter_bzip2(a);
104 archive_read_support_filter_xz(a);
105 archive_read_support_filter_lz4(a);
106 archive_read_support_filter_zstd(a);
107 archive_read_support_format_tar(a);
109 if (archive_read_open(a, f, fetch_archive_open, fetch_archive_read,
110 fetch_archive_close) != ARCHIVE_OK) {
111 archive_read_free(a);
118static struct archive *
119open_archive(
const char *url)
125 if ((a = archive_read_new()) == NULL)
128 archive_read_support_filter_gzip(a);
129 archive_read_support_filter_bzip2(a);
130 archive_read_support_filter_xz(a);
131 archive_read_support_filter_lz4(a);
132 archive_read_support_filter_zstd(a);
133 archive_read_support_format_tar(a);
136 if (archive_read_open_filename(a, url, 32768) != ARCHIVE_OK) {
137 archive_read_free(a);
143 if ((u = fetchParseURL(url)) == NULL)
146 a = open_archive_by_url(u);
156 struct archive_entry *entry;
162 if ((a = open_archive(url)) == NULL)
165 while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) {
168 bfile = archive_entry_pathname(entry);
172 if (strcmp(bfile, fname) == 0) {
173 buf = xbps_archive_get_file(a, entry);
176 archive_read_data_skip(a);
178 archive_read_free(a);
187 struct archive_entry *entry;
193 if ((a = open_archive(url)) == NULL)
196 while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) {
200 bfile = archive_entry_pathname(entry);
204 if (strcmp(bfile, XBPS_REPOIDX_META) == 0) {
205 buf = xbps_archive_get_file(a, entry);
206 repo->
idxmeta = xbps_dictionary_internalize(buf);
209 }
else if (strcmp(bfile, XBPS_REPOIDX) == 0) {
210 buf = xbps_archive_get_file(a, entry);
211 repo->
idx = xbps_dictionary_internalize(buf);
215 archive_read_data_skip(a);
220 archive_read_free(a);
222 if (xbps_object_type(repo->
idxmeta) == XBPS_TYPE_DICTIONARY)
225 if (xbps_object_type(repo->
idx) == XBPS_TYPE_DICTIONARY)
235 struct archive_entry *entry;
242 if ((a = open_archive(url)) == NULL)
247 rv = archive_read_next_header(a, &entry);
248 if (rv == ARCHIVE_EOF) {
252 if (rv == ARCHIVE_FATAL) {
253 const char *error = archive_error_string(a);
256 "Reading archive entry from: %s: %s\n",
260 "Reading archive entry from: %s: %s\n",
261 url, strerror(archive_errno(a)));
263 rv = archive_errno(a);
266 bfile = archive_entry_pathname(entry);
270 if (strcmp(bfile, fname) == 0) {
271 rv = archive_read_data_into_fd(a, fd);
272 if (rv != ARCHIVE_OK)
273 rv = archive_errno(a);
276 archive_read_data_skip(a);
278 archive_read_free(a);
292 d = xbps_dictionary_internalize(buf);
char * xbps_archive_fetch_file(const char *url, const char *fname)
xbps_dictionary_t xbps_archive_fetch_plist(const char *url, const char *plistf)
int xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd)
bool xbps_repo_fetch_remote(struct xbps_repo *repo, const char *url)
xbps_dictionary_t idxmeta
bool xbps_repository_is_remote(const char *uri)