34 #include "xbps_api_impl.h"
42 struct fetch_archive {
44 struct fetchIO *fetch;
49 fetch_archive_open(
struct archive *a,
void *client_data)
51 struct fetch_archive *f = client_data;
55 f->fetch = fetchGet(f->url, NULL);
63 fetch_archive_read(
struct archive *a,
void *client_data,
const void **buf)
65 struct fetch_archive *f = client_data;
70 return fetchIO_read(f->fetch, f->buffer,
sizeof(f->buffer));
74 fetch_archive_close(
struct archive *a,
void *client_data)
76 struct fetch_archive *f = client_data;
81 fetchIO_close(f->fetch);
87 static struct archive *
88 open_archive_by_url(
struct url *url)
90 struct fetch_archive *f;
93 f = malloc(
sizeof(
struct fetch_archive));
98 if ((a = archive_read_new()) == NULL) {
102 archive_read_support_compression_gzip(a);
103 archive_read_support_compression_bzip2(a);
104 archive_read_support_compression_xz(a);
105 archive_read_support_format_tar(a);
107 if (archive_read_open(a, f, fetch_archive_open, fetch_archive_read,
108 fetch_archive_close)) {
109 archive_read_finish(a);
116 static struct archive *
117 open_archive(
const char *url)
123 if ((a = archive_read_new()) == NULL)
126 archive_read_support_compression_gzip(a);
127 archive_read_support_compression_bzip2(a);
128 archive_read_support_compression_xz(a);
129 archive_read_support_format_tar(a);
131 if (archive_read_open_filename(a, url,
132 ARCHIVE_READ_BLOCKSIZE)) {
133 archive_read_close(a);
139 if ((u = fetchParseURL(url)) == NULL)
142 a = open_archive_by_url(u);
151 prop_dictionary_t plistd = NULL;
153 struct archive_entry *entry;
154 const char *curpath, *comptype;
157 assert(fname != NULL);
158 assert(plistf != NULL);
160 if ((a = open_archive(fname)) == NULL)
166 comptype = archive_compression_name(a);
168 while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) {
169 curpath = archive_entry_pathname(entry);
170 if (strcmp(curpath, plistf)) {
171 archive_read_data_skip(a);
183 plistd = xbps_dictionary_from_archive_entry(a, entry);
184 if (plistd == NULL) {
188 prop_dictionary_set_cstring_nocopy(plistd,
189 "archive-compression-type", comptype);
193 archive_read_close(a);
194 archive_read_free(a);