Tue Aug 5 19:09:35 2008 UTC ()
Use a predictable name for the +VIEWS temporary file.


(joerg)
diff -r1.23.2.4 -r1.23.2.5 pkgsrc/pkgtools/pkg_install/files/delete/perform.c
diff -r1.42.2.11 -r1.42.2.12 pkgsrc/pkgtools/pkg_install/files/lib/lib.h

cvs diff -r1.23.2.4 -r1.23.2.5 pkgsrc/pkgtools/pkg_install/files/delete/Attic/perform.c (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_install/files/delete/Attic/perform.c 2008/08/05 19:01:27 1.23.2.4
+++ pkgsrc/pkgtools/pkg_install/files/delete/Attic/perform.c 2008/08/05 19:09:35 1.23.2.5
@@ -1,27 +1,27 @@ @@ -1,27 +1,27 @@
1/* $NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $ */ 1/* $NetBSD: perform.c,v 1.23.2.5 2008/08/05 19:09:35 joerg Exp $ */
2 2
3#if HAVE_CONFIG_H 3#if HAVE_CONFIG_H
4#include "config.h" 4#include "config.h"
5#endif 5#endif
6#include <nbcompat.h> 6#include <nbcompat.h>
7#if HAVE_SYS_CDEFS_H 7#if HAVE_SYS_CDEFS_H
8#include <sys/cdefs.h> 8#include <sys/cdefs.h>
9#endif 9#endif
10#ifndef lint 10#ifndef lint
11#if 0 11#if 0
12static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; 12static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
13#else 13#else
14__RCSID("$NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $"); 14__RCSID("$NetBSD: perform.c,v 1.23.2.5 2008/08/05 19:09:35 joerg Exp $");
15#endif 15#endif
16#endif 16#endif
17 17
18/* 18/*
19 * FreeBSD install - a package for the installation and maintainance 19 * FreeBSD install - a package for the installation and maintainance
20 * of non-core utilities. 20 * of non-core utilities.
21 * 21 *
22 * Redistribution and use in source and binary forms, with or without 22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions 23 * modification, are permitted provided that the following conditions
24 * are met: 24 * are met:
25 * 1. Redistributions of source code must retain the above copyright 25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer. 26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright 27 * 2. Redistributions in binary form must reproduce the above copyright
@@ -161,103 +161,99 @@ undepend(const char *deppkgname, void *v @@ -161,103 +161,99 @@ undepend(const char *deppkgname, void *v
161 free(fname); 161 free(fname);
162 free(fname_tmp); 162 free(fname_tmp);
163 163
164 return 0; 164 return 0;
165} 165}
166 166
167/* 167/*
168 * Remove the current view's package dbdir from the +VIEWS file of the 168 * Remove the current view's package dbdir from the +VIEWS file of the
169 * depoted package named by pkgname. 169 * depoted package named by pkgname.
170 */ 170 */
171static int 171static int
172unview(const char *pkgname) 172unview(const char *pkgname)
173{ 173{
174 char fname[MaxPathSize], ftmp[MaxPathSize]; 174 const char *dbdir;
 175 char *fname, *fname_tmp;
175 char fbuf[MaxPathSize]; 176 char fbuf[MaxPathSize];
176 char dbdir[MaxPathSize]; 
177 FILE *fp, *fpwr; 177 FILE *fp, *fpwr;
178 int s; 178 int rv;
179 int cc; 179 int cc;
180 180
181 (void) snprintf(dbdir, sizeof(dbdir), "%s", _pkgdb_getPKGDB_DIR()); 181 dbdir = _pkgdb_getPKGDB_DIR();
182 182
183 /* Get the depot directory. */ 183 fname = pkgdb_pkg_file(pkgname, DEPOT_FNAME);
184 (void) snprintf(fname, sizeof(fname), "%s/%s/%s", 
185 dbdir, pkgname, DEPOT_FNAME); 
186 if ((fp = fopen(fname, "r")) == NULL) { 184 if ((fp = fopen(fname, "r")) == NULL) {
187 warnx("unable to open `%s' file", fname); 185 warnx("unable to open `%s' file", fname);
188 return -1; 186 return -1;
189 } 187 }
190 if (fgets(fbuf, sizeof(fbuf), fp) == NULL) { 188 if (fgets(fbuf, sizeof(fbuf), fp) == NULL) {
191 (void) fclose(fp); 189 (void) fclose(fp);
192 warnx("empty depot file `%s'", fname); 190 warnx("empty depot file `%s'", fname);
 191 free(fname);
193 return -1; 192 return -1;
194 } 193 }
195 if (fbuf[cc = strlen(fbuf) - 1] == '\n') { 194 if (fbuf[cc = strlen(fbuf) - 1] == '\n') {
196 fbuf[cc] = 0; 195 fbuf[cc] = 0;
197 } 196 }
198 fclose(fp); 197 fclose(fp);
 198 free(fname);
199 199
200 /* 200 /*
201 * Copy the contents of the +VIEWS file into a temp file, but 201 * Copy the contents of the +VIEWS file into a temp file, but
202 * skip copying the name of the current view's package dbdir. 202 * skip copying the name of the current view's package dbdir.
203 */ 203 */
204 (void) snprintf(fname, sizeof(fname), "%s/%s", fbuf, VIEWS_FNAME); 204 fname = pkgdb_pkg_file(pkgname, VIEWS_FNAME);
 205 fname_tmp = pkgdb_pkg_file(pkgname, VIEWS_FNAME_TMP);
205 if ((fp = fopen(fname, "r")) == NULL) { 206 if ((fp = fopen(fname, "r")) == NULL) {
206 warnx("unable to open `%s' file", fname); 207 warnx("unable to open `%s' file", fname);
 208 free(fname);
 209 free(fname_tmp);
207 return -1; 210 return -1;
208 } 211 }
209 (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXX", fname); 212 if ((fpwr = fopen(fname_tmp, "w")) == NULL) {
210 if ((s = mkstemp(ftmp)) == -1) { 
211 (void) fclose(fp); 
212 warnx("unable to open `%s' temp file", ftmp); 
213 return -1; 
214 } 
215 if ((fpwr = fdopen(s, "w")) == NULL) { 
216 (void) close(s); 
217 (void) remove(ftmp); 
218 (void) fclose(fp); 213 (void) fclose(fp);
219 warnx("unable to fdopen `%s' temp file", ftmp); 214 warnx("unable to fopen `%s' temporary file", fname_tmp);
 215 free(fname);
 216 free(fname_tmp);
220 return -1; 217 return -1;
221 } 218 }
222 while (fgets(fbuf, sizeof(fbuf), fp) != NULL) { 219 while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
223 if (fbuf[cc = strlen(fbuf) - 1] == '\n') { 220 if (fbuf[cc = strlen(fbuf) - 1] == '\n') {
224 fbuf[cc] = 0; 221 fbuf[cc] = 0;
225 } 222 }
226 if (strcmp(fbuf, dbdir) != 0) { 223 if (strcmp(fbuf, dbdir) != 0) {
227 (void) fputs(fbuf, fpwr); 224 (void) fputs(fbuf, fpwr);
228 (void) putc('\n', fpwr); 225 (void) putc('\n', fpwr);
229 } 226 }
230 } 227 }
231 (void) fclose(fp); 228 (void) fclose(fp);
232 if (fchmod(s, 0644) == FAIL) { 229
233 (void) fclose(fpwr); 
234 (void) remove(ftmp); 
235 warnx("unable to change permissions of `%s' temp file", ftmp); 
236 return -1; 
237 } 
238 if (fclose(fpwr) == EOF) { 230 if (fclose(fpwr) == EOF) {
239 (void) remove(ftmp); 231 remove(fname_tmp);
240 warnx("unable to close `%s' temp file", ftmp); 232 warnx("unable to close `%s' temp file", fname_tmp);
 233 free(fname);
 234 free(fname_tmp);
241 return -1; 235 return -1;
242 } 236 }
243 237
244 /* Rename the temp file to the +VIEWS file */ 238 /* Rename the temp file to the +VIEWS file */
245 if (rename(ftmp, fname) == -1) { 239 if ((rv = rename(fname_tmp, fname)) == -1)
246 (void) remove(ftmp); 240 warnx("unable to rename `%s' to `%s'", fname_tmp, fname);
247 warnx("unable to rename `%s' to `%s'", ftmp, fname); 241
248 return -1; 242 remove(fname_tmp);
249 } 243 free(fname);
250 return 0; 244 free(fname_tmp);
 245
 246 return rv;
251} 247}
252 248
253/* 249/*
254 * Delete from directory 'home' all packages on lpkg_list.  250 * Delete from directory 'home' all packages on lpkg_list.
255 * If tryall is set, ignore errors from pkg_delete(1). 251 * If tryall is set, ignore errors from pkg_delete(1).
256 */ 252 */
257static int 253static int
258require_delete(int tryall) 254require_delete(int tryall)
259{ 255{
260 char *best_installed; 256 char *best_installed;
261 lpkg_t *lpp; 257 lpkg_t *lpp;
262 int rv, fail; 258 int rv, fail;
263 259

cvs diff -r1.42.2.11 -r1.42.2.12 pkgsrc/pkgtools/pkg_install/files/lib/lib.h (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_install/files/lib/lib.h 2008/08/05 19:01:27 1.42.2.11
+++ pkgsrc/pkgtools/pkg_install/files/lib/lib.h 2008/08/05 19:09:35 1.42.2.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lib.h,v 1.42.2.11 2008/08/05 19:01:27 joerg Exp $ */ 1/* $NetBSD: lib.h,v 1.42.2.12 2008/08/05 19:09:35 joerg Exp $ */
2 2
3/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ 3/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
4 4
5/* 5/*
6 * FreeBSD install - a package for the installation and maintainance 6 * FreeBSD install - a package for the installation and maintainance
7 * of non-core utilities. 7 * of non-core utilities.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -112,26 +112,27 @@ enum { @@ -112,26 +112,27 @@ enum {
112#define INSTALL_FNAME "+INSTALL" 112#define INSTALL_FNAME "+INSTALL"
113#define DEINSTALL_FNAME "+DEINSTALL" 113#define DEINSTALL_FNAME "+DEINSTALL"
114#define REQUIRED_BY_FNAME "+REQUIRED_BY" 114#define REQUIRED_BY_FNAME "+REQUIRED_BY"
115#define REQUIRED_BY_FNAME_TMP "+REQUIRED_BY.tmp" 115#define REQUIRED_BY_FNAME_TMP "+REQUIRED_BY.tmp"
116#define DISPLAY_FNAME "+DISPLAY" 116#define DISPLAY_FNAME "+DISPLAY"
117#define MTREE_FNAME "+MTREE_DIRS" 117#define MTREE_FNAME "+MTREE_DIRS"
118#define BUILD_VERSION_FNAME "+BUILD_VERSION" 118#define BUILD_VERSION_FNAME "+BUILD_VERSION"
119#define BUILD_INFO_FNAME "+BUILD_INFO" 119#define BUILD_INFO_FNAME "+BUILD_INFO"
120#define INSTALLED_INFO_FNAME "+INSTALLED_INFO" 120#define INSTALLED_INFO_FNAME "+INSTALLED_INFO"
121#define SIZE_PKG_FNAME "+SIZE_PKG" 121#define SIZE_PKG_FNAME "+SIZE_PKG"
122#define SIZE_ALL_FNAME "+SIZE_ALL" 122#define SIZE_ALL_FNAME "+SIZE_ALL"
123#define PRESERVE_FNAME "+PRESERVE" 123#define PRESERVE_FNAME "+PRESERVE"
124#define VIEWS_FNAME "+VIEWS" 124#define VIEWS_FNAME "+VIEWS"
 125#define VIEWS_FNAME_TMP "+VIEWS.tmp"
125#define DEPOT_FNAME "+DEPOT" 126#define DEPOT_FNAME "+DEPOT"
126 127
127/* The names of special variables */ 128/* The names of special variables */
128#define AUTOMATIC_VARNAME "automatic" 129#define AUTOMATIC_VARNAME "automatic"
129 130
130/* Prefix for extended PLIST cmd */ 131/* Prefix for extended PLIST cmd */
131#define CMD_CHAR '@'  132#define CMD_CHAR '@'
132 133
133/* The name of the "prefix" environment variable given to scripts */ 134/* The name of the "prefix" environment variable given to scripts */
134#define PKG_PREFIX_VNAME "PKG_PREFIX" 135#define PKG_PREFIX_VNAME "PKG_PREFIX"
135 136
136/* The name of the "destdir" environment variable given to scripts */ 137/* The name of the "destdir" environment variable given to scripts */
137#define PKG_DESTDIR_VNAME "PKG_DESTDIR" 138#define PKG_DESTDIR_VNAME "PKG_DESTDIR"