archives: Add output for out of space errors

Libarchive's archive_error_string() method returns a textual
error message suitable for display.
However, this method returns only "Write Failed" if libarchive
runs out of hard disk space.

Check specifically for ENOSPC and print a correct
warning message to the user.

Signed-off-by: Brian J Lovin <brian.j.lovin@intel.com>
This commit is contained in:
Brian J Lovin
2018-11-07 13:41:08 -08:00
committed by Otavio Pontes
parent fce640d14d
commit ffead6e434
+9
View File
@@ -23,6 +23,7 @@
#include <archive.h>
#include <archive_entry.h>
#include <stdlib.h>
#include <sys/errno.h>
#include "swupd.h"
@@ -32,6 +33,7 @@
static int _archive_check_err(struct archive *ar, int ret)
{
int is_fatal = 0;
int error_num = 0;
if (ret < ARCHIVE_WARN || ret == ARCHIVE_RETRY) {
/* error was worse than a warning or error was ARCHIVE_RETRY (greater
@@ -42,6 +44,13 @@ static int _archive_check_err(struct archive *ar, int ret)
} else if (ret < ARCHIVE_OK) {
/* operation succeeded, warning encountered */
fprintf(stderr, "Warning: %s\n", archive_error_string(ar));
error_num = archive_errno(ar);
/* archive_error_string is "Write Failed" on ENOSPC */
/* check if the error is ENOSPC and report to user */
if (error_num == ENOSPC) {
fprintf(stderr, "Warning: %s\n", strerror(error_num));
}
is_fatal = 0;
}