Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Added pkgdb_get_dir()
jlaffaye committed 15 years ago
commit df1982e9ec76caf5230f4790a33382bed200e885
parent 25f6a543a903aea404e314d5195a90d592399765
4 files changed +17 -11
modified libpkg/pkg.c
@@ -123,7 +123,7 @@ pkg_create(char *pkgname, pkg_formats format, const char *outdir, const char *ro
{
	struct pkgdb db;
	struct pkg *pkg;
-
	char *pkgdb_dir;
+
	const char *pkg_dbdir;
	char pkgpath[MAXPATHLEN];
	struct archive *pkg_archive;
	char archive_path[MAXPATHLEN];
@@ -148,7 +148,7 @@ pkg_create(char *pkgname, pkg_formats format, const char *outdir, const char *ro
			break; /* NOT REACHED */
	}

-
	pkgdb_dir = getenv("PKG_DBDIR");
+
	pkg_dbdir = pkgdb_get_dir();

	pkgdb_init(&db, pkgname, MATCH_EXACT, 0);

@@ -159,7 +159,7 @@ pkg_create(char *pkgname, pkg_formats format, const char *outdir, const char *ro

	PKGDB_FOREACH(pkg, &db) {
		printf("Creating package %s/%s.%s\n", outdir, pkg->name_version, ext);
-
		snprintf(pkgpath, sizeof(pkgpath), "%s/%s/", pkgdb_dir ? pkgdb_dir : PKG_DBDIR, pkg->name_version);
+
		snprintf(pkgpath, sizeof(pkgpath), "%s/%s/", pkg_dbdir, pkg->name_version);
		snprintf(archive_path, sizeof(archive_path), "%s/%s.%s", outdir, pkg->name_version, ext);

		pkg_archive = archive_write_new();
modified libpkg/pkgdb.c
@@ -59,3 +59,14 @@ pkgdb_count(struct pkgdb *db)
	return (db->count);
}

+
const char *
+
pkgdb_get_dir()
+
{
+
	const char *pkg_dbdir;
+

+
	if ((pkg_dbdir = getenv("PKG_DBDIR")) == NULL)
+
		pkg_dbdir = PKG_DBDIR;
+

+
	return pkg_dbdir;
+
}
+

modified libpkg/pkgdb.h
@@ -15,6 +15,6 @@ typedef enum _math_t {
void pkgdb_init(struct pkgdb *db, const char *pattern, match_t match, unsigned char flags);
void pkgdb_free(struct pkgdb *db);
size_t pkgdb_count(struct pkgdb *db);
-

+
const char * pkgdb_get_dir(void);

#endif
modified libpkg/pkgdb_cache.c
@@ -225,13 +225,10 @@ pkg_get_rdeps(struct cdb *db, struct pkg *pkg, size_t count)
static int
pkgdb_open(struct cdb *db, int flags)
{
-
	char *pkgdb_dir;
	char filepath[MAXPATHLEN];

-
	pkgdb_dir = getenv("PKG_DBDIR");
+
	snprintf(filepath, sizeof(filepath), "%s/pkgdb.cache", pkgdb_get_dir());

-
	snprintf(filepath, sizeof(filepath), "%s/pkgdb.cache",
-
			(pkgdb_dir) ? pkgdb_dir : PKG_DBDIR);
	return (db_open(db, filepath, flags));
}

@@ -373,9 +370,7 @@ pkgdb_cache_update()
	struct stat dir_st, cache_st;
	uid_t uid;

-
	if ((pkg_dbdir = getenv("PKG_DBDIR")) == NULL)
-
		pkg_dbdir = PKG_DBDIR;
-

+
	pkg_dbdir = pkgdb_get_dir();
	uid = getuid();

	if (stat(pkg_dbdir, &dir_st) == -1) {