Make rpm2cpio exit code accurate for large packages and partial copy
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 14 Mar 2012 08:09:35 +0000 (10:09 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 14 Mar 2012 09:20:42 +0000 (11:20 +0200)
- 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 (RhBug:790396)

rpm2cpio.c

index ed3051e..89ebdfa 100644 (file)
@@ -18,6 +18,7 @@ int main(int argc, char *argv[])
     Header h;
     char * rpmio_flags = NULL;
     int rc;
+    off_t payload_size;
     FD_t gzdi;
     
     setprogname(argv[0]);      /* Retrofit glibc __progname */
@@ -69,9 +70,10 @@ int main(int argc, char *argv[])
        break;
     }
 
-    /* Retrieve type of payload compression. */
+    /* Retrieve payload size and compression type. */
     {  const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
        rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
+       payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
     }
 
     gzdi = Fdopen(fdi, rpmio_flags);   /* XXX gzdi == fdi */
@@ -82,8 +84,8 @@ int main(int argc, char *argv[])
        exit(EXIT_FAILURE);
     }
 
-    rc = ufdCopy(gzdi, fdo);
-    rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+    rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE;
+
     Fclose(fdo);
 
     Fclose(gzdi);      /* XXX gzdi == fdi */