Skip to content

Commit

Permalink
Split off function wfd_close() to close a file
Browse files Browse the repository at this point in the history
(cherry picked from commit e276991)
  • Loading branch information
stefanberger authored and pmatilai committed Jan 16, 2018
1 parent 718c296 commit 4afad76
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions lib/fsm.c
Expand Up @@ -218,6 +218,26 @@ static int linkSane(FD_t wfd, const char *dest)
sb.st_dev == lsb.st_dev && sb.st_ino == lsb.st_ino);
}

static void wfd_close(FD_t *wfdp)
{
if (wfdp && *wfdp) {
int myerrno = errno;
static int oneshot = 0;
static int flush_io = 0;
if (!oneshot) {
flush_io = rpmExpandNumeric("%{?_flush_io}");
oneshot = 1;
}
if (flush_io) {
int fdno = Fileno(*wfdp);
fsync(fdno);
}
Fclose(*wfdp);
*wfdp = NULL;
errno = myerrno;
}
}

/** \ingroup payload
* Create file from payload stream.
* @return 0 on success
Expand Down Expand Up @@ -247,21 +267,7 @@ static int expandRegular(rpmfi fi, const char *dest, rpmpsm psm, int exclusive,
if (!nocontent)
rc = rpmfiArchiveReadToFilePsm(fi, wfd, nodigest, psm);
exit:
if (wfd) {
int myerrno = errno;
static int oneshot = 0;
static int flush_io = 0;
if (!oneshot) {
flush_io = rpmExpandNumeric("%{?_flush_io}");
oneshot = 1;
}
if (flush_io) {
int fdno = Fileno(wfd);
fsync(fdno);
}
Fclose(wfd);
errno = myerrno;
}
wfd_close(&wfd);
return rc;
}

Expand Down

0 comments on commit 4afad76

Please sign in to comment.