diff options
author | Stefan Berger <stefanb@linux.vnet.ibm.com> | 2017-10-26 20:14:01 -0400 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-03-28 14:09:16 +0300 |
commit | 1c6a151c3b5f42cec8c083ad915b7eeca61a1f25 (patch) | |
tree | 2201e98683ee86efae312426b7c92ef50b11a0be | |
parent | 91252a6116e11ab1177b941828948e9f38a5624d (diff) | |
download | rpm-1c6a151c3b5f42cec8c083ad915b7eeca61a1f25.tar.gz |
Create first hard link file and keep open, write it at end
This avoids having to reopen the file later on, which was problematic
in various ways: it was fundamentally incompatible with IMA (#333) and
also required validating the file wasn't changed in the meanwhile so
it simplifies things too.
(cherry picked from commit ef3ff412c33a71be6b3543a50c244377dff3d9e7)
-rw-r--r-- | lib/fsm.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -276,7 +276,7 @@ exit: static int fsmMkfile(rpmfi fi, const char *dest, rpmfiles files, rpmpsm psm, int nodigest, int *setmeta, - int * firsthardlink) + int * firsthardlink, FD_t *firstlinkfile) { int rc = 0; int numHardlinks = rpmfiFNlink(fi); @@ -285,7 +285,7 @@ static int fsmMkfile(rpmfi fi, const char *dest, rpmfiles files, /* Create first hardlinked file empty */ if (*firsthardlink < 0) { *firsthardlink = rpmfiFX(fi); - rc = expandRegular(fi, dest, psm, 1, nodigest, 1); + rc = wfd_open(firstlinkfile, dest, 1); } else { /* Create hard links for others */ char *fn = rpmfilesFN(files, *firsthardlink); @@ -303,7 +303,8 @@ static int fsmMkfile(rpmfi fi, const char *dest, rpmfiles files, rc = expandRegular(fi, dest, psm, 1, nodigest, 0); } else if (rpmfiArchiveHasContent(fi)) { if (!rc) - rc = expandRegular(fi, dest, psm, 0, nodigest, 0); + rc = rpmfiArchiveReadToFilePsm(fi, *firstlinkfile, nodigest, psm); + wfd_close(firstlinkfile); *firsthardlink = -1; } else { *setmeta = 0; @@ -863,6 +864,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, int rc = 0; int nodigest = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOFILEDIGEST) ? 1 : 0; int firsthardlink = -1; + FD_t firstlinkfile = NULL; int skip; rpmFileAction action; char *tid = NULL; @@ -930,7 +932,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, if (S_ISREG(sb.st_mode)) { if (rc == RPMERR_ENOENT) { rc = fsmMkfile(fi, fpath, files, psm, nodigest, - &setmeta, &firsthardlink); + &setmeta, &firsthardlink, &firstlinkfile); } } else if (S_ISDIR(sb.st_mode)) { if (rc == RPMERR_ENOENT) { @@ -968,7 +970,8 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files, /* we skip the hard linked file containing the content */ /* write the content to the first used instead */ char *fn = rpmfilesFN(files, firsthardlink); - rc = expandRegular(fi, fn, psm, 0, nodigest, 0); + rc = rpmfiArchiveReadToFilePsm(fi, firstlinkfile, nodigest, psm); + wfd_close(&firstlinkfile); firsthardlink = -1; free(fn); } |