Skip to content

Commit 50a4a96

Browse files
committed
lib: add xbps_archive_errno to correctly handle archive_errno returning -1
1 parent 0f85171 commit 50a4a96

7 files changed

Lines changed: 25 additions & 18 deletions

File tree

include/xbps_api_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const char HIDDEN *vpkg_user_conf(struct xbps_handle *, const char *);
120120
struct archive HIDDEN *xbps_archive_read_new(void);
121121
int HIDDEN xbps_archive_read_open(struct archive *ar, const char *path);
122122
int HIDDEN xbps_archive_read_open_remote(struct archive *ar, const char *url);
123+
int HIDDEN xbps_archive_errno(struct archive *ar);
123124

124125
xbps_array_t HIDDEN xbps_get_pkg_fulldeptree(struct xbps_handle *,
125126
const char *, bool);

lib/archive.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
#include "fetch.h"
3636
#include "xbps_api_impl.h"
3737

38+
int HIDDEN
39+
xbps_archive_errno(struct archive *ar)
40+
{
41+
int err = archive_errno(ar);
42+
return err == -1 ? EINVAL : err;
43+
}
44+
3845
char HIDDEN *
3946
xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
4047
{
@@ -58,7 +65,7 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
5865
for (;;) {
5966
ssize_t rd = archive_read_data(ar, buf + used, len - used);
6067
if (rd == ARCHIVE_FATAL || rd == ARCHIVE_WARN) {
61-
r = -archive_errno(ar);
68+
r = -xbps_archive_errno(ar);
6269
xbps_error_printf(
6370
"failed to read archive entry: %s: %s\n",
6471
archive_entry_pathname(entry),
@@ -117,7 +124,7 @@ xbps_archive_append_buf(struct archive *ar, const void *buf, const size_t buflen
117124

118125
entry = archive_entry_new();
119126
if (!entry)
120-
return -archive_errno(ar);
127+
return -xbps_archive_errno(ar);
121128

122129
archive_entry_set_filetype(entry, AE_IFREG);
123130
archive_entry_set_perm(entry, mode);
@@ -128,15 +135,15 @@ xbps_archive_append_buf(struct archive *ar, const void *buf, const size_t buflen
128135

129136
if (archive_write_header(ar, entry) != ARCHIVE_OK) {
130137
archive_entry_free(entry);
131-
return -archive_errno(ar);
138+
return -xbps_archive_errno(ar);
132139
}
133140
if (archive_write_data(ar, buf, buflen) != ARCHIVE_OK) {
134141
archive_entry_free(entry);
135-
return -archive_errno(ar);
142+
return -xbps_archive_errno(ar);
136143
}
137144
if (archive_write_finish_entry(ar) != ARCHIVE_OK) {
138145
archive_entry_free(entry);
139-
return -archive_errno(ar);
146+
return -xbps_archive_errno(ar);
140147
}
141148
archive_entry_free(entry);
142149

@@ -222,7 +229,7 @@ xbps_archive_read_open(struct archive *ar, const char *filename)
222229
{
223230
int r = archive_read_open_filename(ar, filename, 4096);
224231
if (r == ARCHIVE_FATAL)
225-
return -archive_errno(ar);
232+
return -xbps_archive_errno(ar);
226233
return 0;
227234
}
228235

@@ -248,8 +255,7 @@ xbps_archive_read_open_remote(struct archive *ar, const char *url)
248255
r = archive_read_open(ar, f, fetch_archive_open, fetch_archive_read,
249256
fetch_archive_close);
250257
if (r == ARCHIVE_FATAL) {
251-
r = -archive_errno(ar);
252-
return r;
258+
return -xbps_archive_errno(ar);
253259
}
254260

255261
return 0;

lib/package_unpack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ unpack_archive(struct xbps_handle *xhp,
418418
* Extract entry from archive.
419419
*/
420420
if (archive_read_extract(ar, entry, flags) != 0) {
421-
error = archive_errno(ar);
421+
error = xbps_archive_errno(ar);
422422
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
423423
error, pkgver,
424424
"%s: [unpack] failed to extract file `%s': %s",
@@ -534,7 +534,7 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
534534
goto out;
535535
}
536536
if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
537-
rv = archive_errno(ar);
537+
rv = xbps_archive_errno(ar);
538538
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
539539
rv, pkgver,
540540
"%s: [unpack] failed to read binary package `%s': %s",

lib/plist_fetch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd)
133133
} else {
134134
xbps_error_printf(
135135
"Reading archive entry from: %s: %s\n",
136-
url, strerror(archive_errno(a)));
136+
url, strerror(xbps_archive_errno(a)));
137137
}
138-
rv = archive_errno(a);
138+
rv = xbps_archive_errno(a);
139139
break;
140140
}
141141
bfile = archive_entry_pathname(entry);
@@ -145,7 +145,7 @@ xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd)
145145
if (strcmp(bfile, fname) == 0) {
146146
rv = archive_read_data_into_fd(a, fd);
147147
if (rv != ARCHIVE_OK)
148-
rv = archive_errno(a);
148+
rv = xbps_archive_errno(a);
149149
break;
150150
}
151151
archive_read_data_skip(a);

lib/repo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ repo_read_next(struct xbps_repo *repo, struct archive *ar, struct archive_entry
106106
if (r == ARCHIVE_FATAL) {
107107
xbps_error_printf("failed to read repository: %s: %s\n",
108108
repo->uri, archive_error_string(ar));
109-
return -archive_errno(ar);
109+
return -xbps_archive_errno(ar);
110110
} else if (r == ARCHIVE_WARN) {
111111
xbps_warn_printf("reading repository: %s: %s\n",
112112
repo->uri, archive_error_string(ar));
@@ -141,7 +141,7 @@ repo_read_index(struct xbps_repo *repo, struct archive *ar)
141141
if (r == ARCHIVE_FATAL) {
142142
xbps_error_printf("failed to read repository: %s: archive error: %s\n",
143143
repo->uri, archive_error_string(ar));
144-
return -archive_errno(ar);
144+
return -xbps_archive_errno(ar);
145145
}
146146
repo->index = xbps_dictionary_create();
147147
return 0;
@@ -193,7 +193,7 @@ repo_read_meta(struct xbps_repo *repo, struct archive *ar)
193193
if (r == ARCHIVE_FATAL) {
194194
xbps_error_printf("failed to read repository: %s: archive error: %s\n",
195195
repo->uri, archive_error_string(ar));
196-
return -archive_errno(ar);
196+
return -xbps_archive_errno(ar);
197197
}
198198
repo->idxmeta = NULL;
199199
return 0;

lib/transaction_files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ collect_binpkg_files(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod,
713713
goto out;
714714
}
715715
if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
716-
rv = archive_errno(ar);
716+
rv = xbps_archive_errno(ar);
717717
xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL,
718718
rv, pkgver,
719719
"%s: failed to read binary package `%s': %s",

lib/transaction_internalize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ internalize_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
123123
goto out;
124124
}
125125
if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
126-
rv = archive_errno(ar);
126+
rv = xbps_archive_errno(ar);
127127
xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL,
128128
-rv, pkgver,
129129
"%s: failed to read binary package `%s': %s",

0 commit comments

Comments
 (0)