diff options
author | Stefan Berger <stefanb@linux.vnet.ibm.com> | 2017-10-26 20:00:59 -0400 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-03-28 14:09:16 +0300 |
commit | 91252a6116e11ab1177b941828948e9f38a5624d (patch) | |
tree | 0bb021fed188aee45968e875843039ba13475204 | |
parent | 5d26889a48c7532f9dbf2aca82e84524e913b02f (diff) | |
download | rpm-91252a6116e11ab1177b941828948e9f38a5624d.tar.gz |
Split off function wfd_open() to open a file
(cherry picked from commit 0afe0c3c6cba64d8b7adcdec6ed70f8d32961b58)
-rw-r--r-- | lib/fsm.c | 36 |
1 files changed, 25 insertions, 11 deletions
@@ -227,36 +227,50 @@ static void wfd_close(FD_t *wfdp) } } -/** \ingroup payload - * Create file from payload stream. - * @return 0 on success - */ -static int expandRegular(rpmfi fi, const char *dest, rpmpsm psm, int exclusive, int nodigest, int nocontent) +static int wfd_open(FD_t *wfdp, const char *dest, int exclusive) { - FD_t wfd = NULL; int rc = 0; - /* Create the file with 0200 permissions (write by owner). */ { mode_t old_umask = umask(0577); - wfd = Fopen(dest, exclusive ? "wx.ufdio" : "a.ufdio"); + *wfdp = Fopen(dest, exclusive ? "wx.ufdio" : "a.ufdio"); umask(old_umask); /* If reopening, make sure the file is what we expect */ - if (!exclusive && wfd != NULL && !linkSane(wfd, dest)) { + if (!exclusive && *wfdp != NULL && !linkSane(*wfdp, dest)) { rc = RPMERR_OPEN_FAILED; goto exit; } } - if (Ferror(wfd)) { + if (Ferror(*wfdp)) { rc = RPMERR_OPEN_FAILED; goto exit; } + return 0; + +exit: + wfd_close(wfdp); + return rc; +} + +/** \ingroup payload + * Create file from payload stream. + * @return 0 on success + */ +static int expandRegular(rpmfi fi, const char *dest, rpmpsm psm, int exclusive, int nodigest, int nocontent) +{ + FD_t wfd = NULL; + int rc; + + rc = wfd_open(&wfd, dest, exclusive); + if (rc != 0) + goto exit; + if (!nocontent) rc = rpmfiArchiveReadToFilePsm(fi, wfd, nodigest, psm); -exit: wfd_close(&wfd); +exit: return rc; } |