bin/xbps-rindex: better error handling for writing repodata archives

This fixes issues when writes fail (as example if the disk is full),
where xbps would create empty repodata or stagedata archives.
This commit is contained in:
Duncan Overbruck
2019-10-25 23:00:35 +02:00
committed by Juan RP
parent 04d5554ed2
commit 7b4a925302
2 changed files with 34 additions and 22 deletions

View File

@ -83,7 +83,8 @@ xbps_archive_append_buf(struct archive *ar, const void *buf, const size_t buflen
assert(gname);
entry = archive_entry_new();
assert(entry);
if (entry == NULL)
return archive_errno(ar);
archive_entry_set_filetype(entry, AE_IFREG);
archive_entry_set_perm(entry, mode);
@ -100,7 +101,10 @@ xbps_archive_append_buf(struct archive *ar, const void *buf, const size_t buflen
archive_entry_free(entry);
return archive_errno(ar);
}
archive_write_finish_entry(ar);
if (archive_write_finish_entry(ar) != ARCHIVE_OK) {
archive_entry_free(entry);
return archive_errno(ar);
}
archive_entry_free(entry);
return 0;