| @@ -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 |
12 | static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; | | 12 | static 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 | */ |
171 | static int | | 171 | static int |
172 | unview(const char *pkgname) | | 172 | unview(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 | */ |
257 | static int | | 253 | static int |
258 | require_delete(int tryall) | | 254 | require_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 | |