summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoerg <joerg>2008-08-05 19:09:35 +0000
committerjoerg <joerg>2008-08-05 19:09:35 +0000
commit364e05c70527702d9266f9e615da65ac4daa7676 (patch)
tree231db1f143110a901cbedb43ceb33fa363d30db8
parentc31a27c772f9289ca786e2a6879d8548ec80055d (diff)
downloadpkgsrc-364e05c70527702d9266f9e615da65ac4daa7676.tar.gz
Use a predictable name for the +VIEWS temporary file.
-rw-r--r--pkgtools/pkg_install/files/delete/perform.c64
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h3
2 files changed, 32 insertions, 35 deletions
diff --git a/pkgtools/pkg_install/files/delete/perform.c b/pkgtools/pkg_install/files/delete/perform.c
index 28c074782ac..a7fb582f9a5 100644
--- a/pkgtools/pkg_install/files/delete/perform.c
+++ b/pkgtools/pkg_install/files/delete/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.23.2.5 2008/08/05 19:09:35 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.23.2.5 2008/08/05 19:09:35 joerg Exp $");
#endif
#endif
@@ -171,18 +171,16 @@ undepend(const char *deppkgname, void *vp)
static int
unview(const char *pkgname)
{
- char fname[MaxPathSize], ftmp[MaxPathSize];
+ const char *dbdir;
+ char *fname, *fname_tmp;
char fbuf[MaxPathSize];
- char dbdir[MaxPathSize];
FILE *fp, *fpwr;
- int s;
+ int rv;
int cc;
- (void) snprintf(dbdir, sizeof(dbdir), "%s", _pkgdb_getPKGDB_DIR());
+ dbdir = _pkgdb_getPKGDB_DIR();
- /* Get the depot directory. */
- (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
- dbdir, pkgname, DEPOT_FNAME);
+ fname = pkgdb_pkg_file(pkgname, DEPOT_FNAME);
if ((fp = fopen(fname, "r")) == NULL) {
warnx("unable to open `%s' file", fname);
return -1;
@@ -190,33 +188,32 @@ unview(const char *pkgname)
if (fgets(fbuf, sizeof(fbuf), fp) == NULL) {
(void) fclose(fp);
warnx("empty depot file `%s'", fname);
+ free(fname);
return -1;
}
if (fbuf[cc = strlen(fbuf) - 1] == '\n') {
fbuf[cc] = 0;
}
fclose(fp);
+ free(fname);
/*
* Copy the contents of the +VIEWS file into a temp file, but
* skip copying the name of the current view's package dbdir.
*/
- (void) snprintf(fname, sizeof(fname), "%s/%s", fbuf, VIEWS_FNAME);
+ fname = pkgdb_pkg_file(pkgname, VIEWS_FNAME);
+ fname_tmp = pkgdb_pkg_file(pkgname, VIEWS_FNAME_TMP);
if ((fp = fopen(fname, "r")) == NULL) {
warnx("unable to open `%s' file", fname);
+ free(fname);
+ free(fname_tmp);
return -1;
}
- (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXX", fname);
- if ((s = mkstemp(ftmp)) == -1) {
- (void) fclose(fp);
- warnx("unable to open `%s' temp file", ftmp);
- return -1;
- }
- if ((fpwr = fdopen(s, "w")) == NULL) {
- (void) close(s);
- (void) remove(ftmp);
+ if ((fpwr = fopen(fname_tmp, "w")) == NULL) {
(void) fclose(fp);
- warnx("unable to fdopen `%s' temp file", ftmp);
+ warnx("unable to fopen `%s' temporary file", fname_tmp);
+ free(fname);
+ free(fname_tmp);
return -1;
}
while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
@@ -229,25 +226,24 @@ unview(const char *pkgname)
}
}
(void) fclose(fp);
- if (fchmod(s, 0644) == FAIL) {
- (void) fclose(fpwr);
- (void) remove(ftmp);
- warnx("unable to change permissions of `%s' temp file", ftmp);
- return -1;
- }
+
if (fclose(fpwr) == EOF) {
- (void) remove(ftmp);
- warnx("unable to close `%s' temp file", ftmp);
+ remove(fname_tmp);
+ warnx("unable to close `%s' temp file", fname_tmp);
+ free(fname);
+ free(fname_tmp);
return -1;
}
/* Rename the temp file to the +VIEWS file */
- if (rename(ftmp, fname) == -1) {
- (void) remove(ftmp);
- warnx("unable to rename `%s' to `%s'", ftmp, fname);
- return -1;
- }
- return 0;
+ if ((rv = rename(fname_tmp, fname)) == -1)
+ warnx("unable to rename `%s' to `%s'", fname_tmp, fname);
+
+ remove(fname_tmp);
+ free(fname);
+ free(fname_tmp);
+
+ return rv;
}
/*
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 52d43bbe30a..35916d9d169 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.42.2.11 2008/08/05 19:01:27 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.42.2.12 2008/08/05 19:09:35 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -122,6 +122,7 @@ enum {
#define SIZE_ALL_FNAME "+SIZE_ALL"
#define PRESERVE_FNAME "+PRESERVE"
#define VIEWS_FNAME "+VIEWS"
+#define VIEWS_FNAME_TMP "+VIEWS.tmp"
#define DEPOT_FNAME "+DEPOT"
/* The names of special variables */