From: Panu Matilainen Date: Thu, 21 Apr 2011 08:09:28 +0000 (+0300) Subject: Handle errors from moving target file into place in rpmSign() X-Git-Tag: tznext/4.11.0.1.tizen20130304~1174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eada0e3e47b80da2dec8c11fefb5ad16e4d6faaa;p=tools%2Flibrpm-tizen.git Handle errors from moving target file into place in rpmSign() - Signing isn't successful unless we manage to replace the original file with the signed one, take the stat() etc returns into count. --- diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c index 3285212..e858e21 100644 --- a/sign/rpmgensig.c +++ b/sign/rpmgensig.c @@ -435,7 +435,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) Header sigh = NULL; char * msg; int res = -1; /* assume failure */ - int xx; rpmRC rc; struct rpmtd_s utd; @@ -476,7 +475,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) } msg = _free(msg); - /* ASSERT: ofd == NULL && sigtarget == NULL */ ofd = rpmMkTempFile(NULL, &sigtarget); if (ofd == NULL || Ferror(ofd)) { rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n")); @@ -486,7 +484,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) if (copyFile(&fd, rpm, &ofd, sigtarget)) goto exit; /* Both fd and ofd are now closed. sigtarget contains tempfile name. */ - /* ASSERT: fd == NULL && ofd == NULL */ /* Dump the immutable region (if present). */ if (headerGet(sigh, RPMTAG_HEADERSIGNATURES, &utd, HEADERGET_DEFAULT)) { @@ -569,22 +566,14 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) } /* Append the header and archive from the temp file */ - /* ASSERT: fd == NULL && ofd != NULL */ - if (copyFile(&fd, sigtarget, &ofd, trpm)) - goto exit; - /* Both fd and ofd are now closed. */ - /* ASSERT: fd == NULL && ofd == NULL */ - - /* Move final target into place, restore file permissions. */ - { + if (copyFile(&fd, sigtarget, &ofd, trpm) == 0) { struct stat st; - xx = stat(rpm, &st); - xx = unlink(rpm); - xx = rename(trpm, rpm); - xx = chmod(rpm, st.st_mode); - } - res = 0; + /* Move final target into place, restore file permissions. */ + if (stat(rpm, &st) == 0 && unlink(rpm) == 0 && + rename(trpm, rpm) == 0 && chmod(rpm, st.st_mode) == 0) + res = 0; + } exit: if (fd) (void) closeFile(&fd); @@ -594,7 +583,7 @@ exit: /* Clean up intermediate target */ if (sigtarget) { - xx = unlink(sigtarget); + unlink(sigtarget); sigtarget = _free(sigtarget); } if (trpm) {