| @@ -1,23 +1,23 @@ | | | @@ -1,23 +1,23 @@ |
1 | /* $NetBSD: pkgdb.c,v 1.35 2009/09/11 18:00:13 joerg Exp $ */ | | 1 | /* $NetBSD: pkgdb.c,v 1.36 2009/10/22 22:51:29 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 | __RCSID("$NetBSD: pkgdb.c,v 1.35 2009/09/11 18:00:13 joerg Exp $"); | | 10 | __RCSID("$NetBSD: pkgdb.c,v 1.36 2009/10/22 22:51:29 joerg Exp $"); |
11 | | | 11 | |
12 | /*- | | 12 | /*- |
13 | * Copyright (c) 1999-2008 The NetBSD Foundation, Inc. | | 13 | * Copyright (c) 1999-2008 The NetBSD Foundation, Inc. |
14 | * All rights reserved. | | 14 | * All rights reserved. |
15 | * | | 15 | * |
16 | * This code is derived from software contributed to The NetBSD Foundation | | 16 | * This code is derived from software contributed to The NetBSD Foundation |
17 | * by Hubert Feyrer <hubert@feyrer.de>. | | 17 | * by Hubert Feyrer <hubert@feyrer.de>. |
18 | * | | 18 | * |
19 | * Redistribution and use in source and binary forms, with or without | | 19 | * Redistribution and use in source and binary forms, with or without |
20 | * modification, are permitted provided that the following conditions | | 20 | * modification, are permitted provided that the following conditions |
21 | * are met: | | 21 | * are met: |
22 | * 1. Redistributions of source code must retain the above copyright | | 22 | * 1. Redistributions of source code must retain the above copyright |
23 | * notice, this list of conditions and the following disclaimer. | | 23 | * notice, this list of conditions and the following disclaimer. |
| @@ -68,27 +68,26 @@ __RCSID("$NetBSD: pkgdb.c,v 1.35 2009/09 | | | @@ -68,27 +68,26 @@ __RCSID("$NetBSD: pkgdb.c,v 1.35 2009/09 |
68 | | | 68 | |
69 | /* | | 69 | /* |
70 | * Where we put logging information by default if PKG_DBDIR is unset. | | 70 | * Where we put logging information by default if PKG_DBDIR is unset. |
71 | */ | | 71 | */ |
72 | #ifndef DEF_LOG_DIR | | 72 | #ifndef DEF_LOG_DIR |
73 | #define DEF_LOG_DIR "/var/db/pkg" | | 73 | #define DEF_LOG_DIR "/var/db/pkg" |
74 | #endif | | 74 | #endif |
75 | | | 75 | |
76 | /* just in case we change the environment variable name */ | | 76 | /* just in case we change the environment variable name */ |
77 | #define PKG_DBDIR "PKG_DBDIR" | | 77 | #define PKG_DBDIR "PKG_DBDIR" |
78 | | | 78 | |
79 | static DB *pkgdbp; | | 79 | static DB *pkgdbp; |
80 | static char *pkgdb_dir = NULL; | | 80 | static char *pkgdb_dir = NULL; |
81 | static char pkgdb_cache[MaxPathSize]; | | | |
82 | | | 81 | |
83 | /* | | 82 | /* |
84 | * Open the pkg-database | | 83 | * Open the pkg-database |
85 | * Return value: | | 84 | * Return value: |
86 | * 1: everything ok | | 85 | * 1: everything ok |
87 | * 0: error | | 86 | * 0: error |
88 | */ | | 87 | */ |
89 | int | | 88 | int |
90 | pkgdb_open(int mode) | | 89 | pkgdb_open(int mode) |
91 | { | | 90 | { |
92 | BTREEINFO info; | | 91 | BTREEINFO info; |
93 | char cachename[MaxPathSize]; | | 92 | char cachename[MaxPathSize]; |
94 | | | 93 | |
| @@ -300,22 +299,27 @@ _pkgdb_getPKGDB_DIR(void) | | | @@ -300,22 +299,27 @@ _pkgdb_getPKGDB_DIR(void) |
300 | else | | 299 | else |
301 | _pkgdb_setPKGDB_DIR(DEF_LOG_DIR); | | 300 | _pkgdb_setPKGDB_DIR(DEF_LOG_DIR); |
302 | } | | 301 | } |
303 | | | 302 | |
304 | return pkgdb_dir; | | 303 | return pkgdb_dir; |
305 | } | | 304 | } |
306 | | | 305 | |
307 | /* | | 306 | /* |
308 | * Set the first place we look for where pkgdb is stored. | | 307 | * Set the first place we look for where pkgdb is stored. |
309 | */ | | 308 | */ |
310 | void | | 309 | void |
311 | _pkgdb_setPKGDB_DIR(const char *dir) | | 310 | _pkgdb_setPKGDB_DIR(const char *dir) |
312 | { | | 311 | { |
313 | (void) snprintf(pkgdb_cache, sizeof(pkgdb_cache), "%s", dir); | | 312 | char *new_dir; |
314 | pkgdb_dir = pkgdb_cache; | | 313 | |
| | | 314 | if (dir == pkgdb_dir) |
| | | 315 | return; |
| | | 316 | new_dir = xstrdup(dir); |
| | | 317 | free(pkgdb_dir); |
| | | 318 | pkgdb_dir = new_dir; |
315 | } | | 319 | } |
316 | | | 320 | |
317 | char * | | 321 | char * |
318 | pkgdb_pkg_file(const char *pkg, const char *file) | | 322 | pkgdb_pkg_file(const char *pkg, const char *file) |
319 | { | | 323 | { |
320 | return xasprintf("%s/%s/%s", _pkgdb_getPKGDB_DIR(), pkg, file); | | 324 | return xasprintf("%s/%s/%s", _pkgdb_getPKGDB_DIR(), pkg, file); |
321 | } | | 325 | } |