Make rpm2cpio exit code accurate for large packages

Grab the uncompressed payload size from header and compare number of
bytes copied to that for exit code.  Previously, truncated payloads could
have returned with success.  This also fixes the exit code for large
payloads.
This commit is contained in:
Gleb Fotengauer-Malinovskiy 2015-11-18 20:11:16 +03:00
parent 499405d5b4
commit 91210177c1
2 changed files with 10 additions and 3 deletions

View File

@ -10,6 +10,7 @@ int main(int argc, char **argv)
FD_t fdi, fdo;
Header h;
char * rpmio_flags;
const int * archive_size;
int rc, isSource;
FD_t gzdi;
@ -57,6 +58,10 @@ int main(int argc, char **argv)
t = stpcpy(t, ".lzdio");
if (!strcmp(payload_compressor, "xz"))
t = stpcpy(t, ".xzdio");
if (!headerGetEntry(h, RPMTAG_ARCHIVESIZE, NULL,
(void **) &archive_size, NULL))
archive_size = NULL;
}
gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
@ -66,7 +71,9 @@ int main(int argc, char **argv)
}
rc = ufdCopy(gzdi, fdo);
rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
rc = archive_size
? (*archive_size != rc ? EXIT_FAILURE : EXIT_SUCCESS)
: ((rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS);
if (Fclose(fdo) < 0)
rc = EXIT_FAILURE;

View File

@ -1285,8 +1285,8 @@ void urlSetCallback(rpmCallbackFunction notify, void *notifyData, int notifyCoun
int ufdCopy(FD_t sfd, FD_t tfd)
{
char buf[BUFSIZ];
int itemsRead;
int itemsCopied = 0;
unsigned int itemsRead;
unsigned int itemsCopied = 0;
int rc = 0;
int notifier = -1;