summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2011-05-18 15:53:54 +0300
committerPanu Matilainen <pmatilai@redhat.com>2011-05-18 16:01:47 +0300
commit63ee1e735aac4b8cc6e5c1e80c616215cd241bf3 (patch)
tree8f2a564c24d2232c8c006d7c8576d2f35bcd077f
parentab3337e4f6a3e0f1c5587890520d0e5bb4ad9569 (diff)
downloadlibrpm-tizen-63ee1e735aac4b8cc6e5c1e80c616215cd241bf3.tar.gz
librpm-tizen-63ee1e735aac4b8cc6e5c1e80c616215cd241bf3.tar.bz2
librpm-tizen-63ee1e735aac4b8cc6e5c1e80c616215cd241bf3.zip
Fix error handling in payload copying
- Lift the payload copy into a separate helper function to clean things up a bit - The code to handle read errors was unreachable before this, causing any read error (rare as they might be) to be silently ignored and package generation considered successful. - This could/should perhaps use ufdCopy() instead but that ha its own set of problems (not clean wrt large files, error reporting...)
-rw-r--r--build/pack.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/build/pack.c b/build/pack.c
index 5a263ca71..9d4f4044e 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -211,17 +211,39 @@ exit:
return rc;
}
+static rpmRC copyPayload(FD_t ifd, const char *ifn, FD_t ofd, const char *ofn)
+{
+ char buf[BUFSIZ];
+ size_t nb;
+ rpmRC rc = RPMRC_OK;
+
+ while ((nb = Fread(buf, 1, sizeof(buf), ifd)) > 0) {
+ if (Fwrite(buf, sizeof(buf[0]), nb, ofd) != nb) {
+ rpmlog(RPMLOG_ERR, _("Unable to write payload to %s: %s\n"),
+ ofn, Fstrerror(ofd));
+ rc = RPMRC_FAIL;
+ break;
+ }
+ }
+
+ if (nb < 0) {
+ rpmlog(RPMLOG_ERR, _("Unable to read payload from %s: %s\n"),
+ ifn, Fstrerror(ifd));
+ rc = RPMRC_FAIL;
+ }
+
+ return rc;
+}
+
static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileName,
CSA_t csa, char **cookie)
{
FD_t fd = NULL;
FD_t ifd = NULL;
- ssize_t count;
char * sigtarget = NULL;;
char * rpmio_flags = NULL;
char * SHA1 = NULL;
const char *s;
- char *buf = NULL;
Header h;
Header sig = NULL;
int xx;
@@ -250,6 +272,7 @@ static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileNam
}
s = strchr(rpmio_flags, '.');
if (s) {
+ char *buf = NULL;
const char *compr = NULL;
headerPutString(h, RPMTAG_PAYLOADFORMAT, "cpio");
@@ -458,25 +481,7 @@ static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileNam
}
/* Write the payload into the package. */
- buf = xmalloc(BUFSIZ);
- while ((count = Fread(buf, 1, BUFSIZ, ifd)) > 0) {
- if (count == -1) {
- free(buf);
- rc = RPMRC_FAIL;
- rpmlog(RPMLOG_ERR, _("Unable to read payload from %s: %s\n"),
- sigtarget, Fstrerror(ifd));
- goto exit;
- }
- if (Fwrite(buf, sizeof(buf[0]), count, fd) != count) {
- free(buf);
- rc = RPMRC_FAIL;
- rpmlog(RPMLOG_ERR, _("Unable to write payload to %s: %s\n"),
- fileName, Fstrerror(fd));
- goto exit;
- }
- }
- free(buf);
- rc = RPMRC_OK;
+ rc = copyPayload(ifd, fileName, fd, sigtarget);
exit:
rpmio_flags = _free(rpmio_flags);