Temp file handling tweaks
- rename rpmMkTemp() (back) to rpmMkTempFile() - rpmMkTemp() is now a lower level thin wrapper around mkstemp()
This commit is contained in:
parent
87ea239ffc
commit
0ee67fede8
|
@ -126,7 +126,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb,
|
|||
goto exit;
|
||||
}
|
||||
|
||||
fd = rpmMkTemp(rootDir, &scriptName);
|
||||
fd = rpmMkTempFile(rootDir, &scriptName);
|
||||
if (fd == NULL || Ferror(fd)) {
|
||||
rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n"));
|
||||
rc = RPMRC_FAIL;
|
||||
|
|
|
@ -417,7 +417,7 @@ rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileName,
|
|||
* Write the header+archive into a temp file so that the size of
|
||||
* archive (after compression) can be added to the header.
|
||||
*/
|
||||
fd = rpmMkTemp(NULL, &sigtarget);
|
||||
fd = rpmMkTempFile(NULL, &sigtarget);
|
||||
if (fd == NULL || Ferror(fd)) {
|
||||
rc = RPMRC_FAIL;
|
||||
rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n"));
|
||||
|
|
|
@ -761,7 +761,7 @@ static rpmRC runScript(rpmpsm psm, Header h, rpmTag stag, ARGV_t * argvp,
|
|||
const char * rootDir = rpmtsRootDir(ts);
|
||||
FD_t fd;
|
||||
|
||||
fd = rpmMkTemp((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn);
|
||||
fd = rpmMkTempFile((!rpmtsChrootDone(ts) ? rootDir : "/"), &fn);
|
||||
if (fd == NULL || Ferror(fd)) {
|
||||
rc = RPMRC_FAIL;
|
||||
goto exit;
|
||||
|
|
|
@ -197,7 +197,7 @@ static int rpmReSign(rpmts ts, QVA_t qva, ARGV_const_t argv)
|
|||
msg = _free(msg);
|
||||
|
||||
/* ASSERT: ofd == NULL && sigtarget == NULL */
|
||||
ofd = rpmMkTemp(NULL, &sigtarget);
|
||||
ofd = rpmMkTempFile(NULL, &sigtarget);
|
||||
if (ofd == NULL || Ferror(ofd)) {
|
||||
rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n"));
|
||||
goto exit;
|
||||
|
@ -325,7 +325,7 @@ static int rpmReSign(rpmts ts, QVA_t qva, ARGV_const_t argv)
|
|||
if (sigh == NULL) /* XXX can't happen */
|
||||
goto exit;
|
||||
|
||||
ofd = rpmMkTemp(NULL, &trpm);
|
||||
ofd = rpmMkTempFile(NULL, &trpm);
|
||||
if (ofd == NULL || Ferror(ofd)) {
|
||||
rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n"));
|
||||
goto exit;
|
||||
|
|
|
@ -304,7 +304,7 @@ restart:
|
|||
if (rpmIsVerbose())
|
||||
fprintf(stdout, _("Retrieving %s\n"), fileURL);
|
||||
|
||||
tfd = rpmMkTemp(rpmtsRootDir(ts), &tfn);
|
||||
tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn);
|
||||
if (tfd && tfn) {
|
||||
Fclose(tfd);
|
||||
rc = urlGetFile(fileURL, tfn);
|
||||
|
|
|
@ -686,7 +686,7 @@ static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTag,
|
|||
if (h == NULL)
|
||||
goto exit;
|
||||
(void) Fclose(fd);
|
||||
fd = rpmMkTemp(NULL, &fn);
|
||||
fd = rpmMkTempFile(NULL, &fn);
|
||||
if (fd == NULL || Ferror(fd))
|
||||
goto exit;
|
||||
if (headerWrite(fd, h, HEADER_MAGIC_YES))
|
||||
|
@ -705,7 +705,7 @@ static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTag,
|
|||
if (h == NULL)
|
||||
goto exit;
|
||||
(void) Fclose(fd);
|
||||
fd = rpmMkTemp(NULL, &fn);
|
||||
fd = rpmMkTempFile(NULL, &fn);
|
||||
if (fd == NULL || Ferror(fd))
|
||||
goto exit;
|
||||
if (headerWrite(fd, h, HEADER_MAGIC_YES))
|
||||
|
|
|
@ -225,11 +225,27 @@ exit:
|
|||
return rc;
|
||||
}
|
||||
|
||||
FD_t rpmMkTemp(const char * prefix, char **fn)
|
||||
FD_t rpmMkTemp(char *template)
|
||||
{
|
||||
int sfd;
|
||||
FD_t tfd = NULL;
|
||||
|
||||
sfd = mkstemp(template);
|
||||
if (sfd < 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
tfd = fdDup(sfd);
|
||||
close(sfd);
|
||||
|
||||
exit:
|
||||
return tfd;
|
||||
}
|
||||
|
||||
FD_t rpmMkTempFile(const char * prefix, char **fn)
|
||||
{
|
||||
const char *tpmacro = "%{_tmppath}"; /* always set from rpmrc */
|
||||
char *tempfn;
|
||||
int sfd;
|
||||
static int _initialized = 0;
|
||||
FD_t tfd = NULL;
|
||||
|
||||
|
@ -245,16 +261,10 @@ FD_t rpmMkTemp(const char * prefix, char **fn)
|
|||
}
|
||||
|
||||
tempfn = rpmGetPath(prefix, tpmacro, "/rpm-tmp.XXXXXX", NULL);
|
||||
sfd = mkstemp(tempfn);
|
||||
if (sfd < 0) {
|
||||
rpmlog(RPMLOG_ERR, _("error creating temporary file: %m\n"));
|
||||
goto exit;
|
||||
}
|
||||
tfd = rpmMkTemp(tempfn);
|
||||
|
||||
tfd = fdDup(sfd);
|
||||
close(sfd);
|
||||
if (tfd == NULL || Ferror(tfd)) {
|
||||
rpmlog(RPMLOG_ERR, _("error opening temporary file %s: %m\n"), tempfn);
|
||||
rpmlog(RPMLOG_ERR, _("error creating temporary file %s: %m\n"), tempfn);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,13 @@ typedef enum rpmCompressedMagic_e {
|
|||
int rpmDoDigest(pgpHashAlgo algo, const char * fn,int asAscii,
|
||||
unsigned char * digest, rpm_off_t * fsizep);
|
||||
|
||||
/** \ingroup rpmfileutil
|
||||
* Thin wrapper for mkstemp(3).
|
||||
* @param template template for temporary filename
|
||||
* @return file handle or NULL on error
|
||||
*/
|
||||
FD_t rpmMkTemp(char *template);
|
||||
|
||||
/** \ingroup rpmfileutil
|
||||
* Return file handle for a temporaray file.
|
||||
* A unique temporaray file path will be created in
|
||||
|
@ -43,7 +50,7 @@ int rpmDoDigest(pgpHashAlgo algo, const char * fn,int asAscii,
|
|||
* @retval fn temp file name (or NULL)
|
||||
* @return fdptr open file handle or NULL on error
|
||||
*/
|
||||
FD_t rpmMkTemp(const char * prefix, char **fn);
|
||||
FD_t rpmMkTempFile(const char * prefix, char **fn);
|
||||
|
||||
/** \ingroup rpmfileutil
|
||||
* Insure that directories in path exist, creating as needed.
|
||||
|
|
|
@ -782,7 +782,7 @@ static FD_t urlOpen(const char * url, int flags, mode_t mode)
|
|||
char *dest = NULL;
|
||||
int rc = 1; /* assume failure */
|
||||
|
||||
fd = rpmMkTemp(NULL, &dest);
|
||||
fd = rpmMkTempFile(NULL, &dest);
|
||||
if (fd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue