xbps_unpack_binary_pkg: handle ARCHIVE_{EOF,FATAL,RETRY} and use archive_read_{close,free}.

This commit is contained in:
Juan RP 2012-06-05 16:46:50 +02:00
parent 1244d663d8
commit cc30039c60

View File

@ -164,7 +164,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
size_t nmetadata = 0, entry_idx = 0; size_t nmetadata = 0, entry_idx = 0;
const char *entry_pname, *transact, *pkgname, *version, *pkgver, *fname; const char *entry_pname, *transact, *pkgname, *version, *pkgver, *fname;
char *buf = NULL, *pkgfilesd = NULL; char *buf = NULL, *pkgfilesd = NULL;
int rv, flags; int ar_rv, rv, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes; bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace; bool softreplace;
@ -225,7 +225,13 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
/* /*
* Process the archive files. * Process the archive files.
*/ */
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) { for (;;) {
ar_rv = archive_read_next_header(ar, &entry);
if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL)
break;
else if (ar_rv == ARCHIVE_RETRY)
continue;
entry_statp = archive_entry_stat(entry); entry_statp = archive_entry_stat(entry);
entry_pname = archive_entry_pathname(entry); entry_pname = archive_entry_pathname(entry);
flags = set_extract_flags(); flags = set_extract_flags();
@ -470,8 +476,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
if ((rv = archive_errno(ar)) != 0) { if ((rv = archive_errno(ar)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] error while extracting files from `%s': %s", "%s: [unpack] failed to extract files: %s",
pkgver, fname, strerror(rv)); pkgver, fname, archive_error_string(ar));
goto out; goto out;
} }
/* /*
@ -614,8 +620,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Extract archive files. * Extract archive files.
*/ */
rv = unpack_archive(pkg_repod, ar); if ((rv = unpack_archive(pkg_repod, ar)) != 0) {
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to unpack files from archive: %s", "%s: [unpack] failed to unpack files from archive: %s",
@ -633,8 +638,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
pkgver, strerror(rv)); pkgver, strerror(rv));
} }
out: out:
if (ar) if (ar) {
archive_read_finish(ar); archive_read_close(ar);
archive_read_free(ar);
}
return rv; return rv;
} }