Do not treat libarchive warnings as errors (#293)

This commit is contained in:
Yichao Yu 2021-10-05 04:49:03 +08:00 committed by GitHub
parent e5a1af0818
commit 3bd4a3c757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 15 deletions

View File

@ -300,14 +300,22 @@ Archive *new_archive(TALLOC_CTX *context, const Tracee* tracee,
}
status = archive_write_disk_set_options(archive->handle, flags);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "set archive options: %s",
archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't set archive options: %s",
archive_error_string(archive->handle));
return NULL;
}
status = archive_write_disk_set_standard_lookup(archive->handle);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "set archive lookup: %s",
archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't set archive lookup: %s",
archive_error_string(archive->handle));
return NULL;
@ -329,7 +337,11 @@ Archive *new_archive(TALLOC_CTX *context, const Tracee* tracee,
assert(format.set_format != NULL);
status = format.set_format(archive->handle);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "set archive format: %s",
archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't set archive format: %s",
archive_error_string(archive->handle));
return NULL;
@ -344,7 +356,11 @@ Archive *new_archive(TALLOC_CTX *context, const Tracee* tracee,
if (format.add_filter != NULL) {
status = format.add_filter(archive->handle);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "add archive filter: %s",
archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't add archive filter: %s",
archive_error_string(archive->handle));
return NULL;
@ -353,7 +369,11 @@ Archive *new_archive(TALLOC_CTX *context, const Tracee* tracee,
if (format.options != NULL) {
status = archive_write_set_options(archive->handle, format.options);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "set archive options: %s",
archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't set archive options: %s",
archive_error_string(archive->handle));
return NULL;
@ -396,7 +416,11 @@ Archive *new_archive(TALLOC_CTX *context, const Tracee* tracee,
status = archive_write_open_filename(archive->handle, output);
break;
}
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "open archive '%s': %s",
output, archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't open archive '%s': %s",
output, archive_error_string(archive->handle));
return NULL;
@ -420,11 +444,11 @@ int finalize_archive(Archive *archive)
archive_entry_linkresolver_free(archive->hardlink_resolver);
status = archive_write_close(archive->handle);
if (status != ARCHIVE_OK)
if (status != ARCHIVE_OK && status != ARCHIVE_WARN)
return -1;
status = archive_write_free(archive->handle);
if (status != ARCHIVE_OK)
if (status != ARCHIVE_OK && status != ARCHIVE_WARN)
return -1;
return 0;
@ -487,8 +511,12 @@ int archive(const Tracee* tracee, Archive *archive,
}
status = archive_write_header(archive->handle, entry);
if (status != ARCHIVE_OK) {
note(tracee, WARNING, INTERNAL, "can't write header for '%s': %s",
if (status == ARCHIVE_WARN) {
note(tracee, WARNING, INTERNAL, "write header for '%s': %s",
path, archive_error_string(archive->handle));
}
else if (status != ARCHIVE_OK) {
note(tracee, ERROR, INTERNAL, "can't write header for '%s': %s",
path, archive_error_string(archive->handle));
status = -1;
goto end;

View File

@ -63,6 +63,11 @@ static int extract_archive(struct archive *archive)
while (archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
status = archive_read_extract(archive, entry, flags);
switch (status) {
case ARCHIVE_WARN:
note(NULL, WARNING, INTERNAL, "%s: %s",
archive_error_string(archive),
strerror(archive_errno(archive)));
/* FALLTHROUGH */
case ARCHIVE_OK:
note(NULL, INFO, USER, "extracted: %s", archive_entry_pathname(entry));
break;
@ -235,7 +240,11 @@ int extract_archive_from_file(const char *path)
}
status = archive_read_support_format_cpio(archive);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(NULL, WARNING, INTERNAL, "set archive format: %s",
archive_error_string(archive));
}
else if (status != ARCHIVE_OK) {
note(NULL, ERROR, INTERNAL, "can't set archive format: %s",
archive_error_string(archive));
status = -1;
@ -243,7 +252,11 @@ int extract_archive_from_file(const char *path)
}
status = archive_read_support_format_gnutar(archive);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(NULL, WARNING, INTERNAL, "set archive format: %s",
archive_error_string(archive));
}
else if (status != ARCHIVE_OK) {
note(NULL, ERROR, INTERNAL, "can't set archive format: %s",
archive_error_string(archive));
status = -1;
@ -251,7 +264,11 @@ int extract_archive_from_file(const char *path)
}
status = archive_read_support_filter_gzip(archive);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(NULL, WARNING, INTERNAL, "add archive filter: %s",
archive_error_string(archive));
}
else if (status != ARCHIVE_OK) {
note(NULL, ERROR, INTERNAL, "can't add archive filter: %s",
archive_error_string(archive));
status = -1;
@ -259,7 +276,11 @@ int extract_archive_from_file(const char *path)
}
status = archive_read_support_filter_lzop(archive);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
note(NULL, WARNING, INTERNAL, "add archive filter: %s",
archive_error_string(archive));
}
else if (status != ARCHIVE_OK) {
note(NULL, ERROR, INTERNAL, "can't add archive filter: %s",
archive_error_string(archive));
status = -1;
@ -283,7 +304,12 @@ int extract_archive_from_file(const char *path)
}
status = archive_read_open(archive, data, open_callback, read_callback, close_callback);
if (status != ARCHIVE_OK) {
if (status == ARCHIVE_WARN) {
if (archive_error_string(archive) != NULL)
note(NULL, WARNING, INTERNAL, "read archive: %s",
archive_error_string(archive));
}
else if (status != ARCHIVE_OK) {
/* Don't complain if no error message were registered,
* ie. when testing for a self-extracting archive. */
if (archive_error_string(archive) != NULL)