Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
repos: fix database path handling when PKG_DBDIR is overridden
Mark Johnston committed 2 years ago
commit 481c87b02d698b20af0daaad6ec1f7ae6f6517a4
parent 9b56ce7
3 files changed +10 -8
modified libpkg/repo/binary/common.c
@@ -230,13 +230,14 @@ pkg_repo_binary_run_prstatement(sql_prstmt_index s, ...)
	return (retcode);
}

+
/*
+
 * Returns a path relative to the dbdir.
+
 */
const char *
pkg_repo_binary_get_filename(struct pkg_repo *repo)
{
	if (repo->dbpath == NULL)
-
		xasprintf(&repo->dbpath, "%s/repos/%s/db", ctx.dbdir,
-
		    repo->name);
-

+
		xasprintf(&repo->dbpath, "repos/%s/db", repo->name);
	return (repo->dbpath);
}

modified libpkg/repo/binary/init.c
@@ -219,7 +219,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
			repo->name);
		sqlite3_close(sqlite);
		if (mode & W_OK)
-
			unlink(filepath);
+
			(void)unlinkat(dbdirfd, filepath, 0);
		return (EPKG_REPOSCHEMA);
	}

@@ -249,14 +249,14 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
int
pkg_repo_binary_create(struct pkg_repo *repo)
{
-
	char filepath[MAXPATHLEN];
+
	const char *filepath;
	sqlite3 *sqlite = NULL;
	int retcode, dbdirfd;

	sqlite3_initialize();

	dbdirfd = pkg_get_dbdirfd();
-
	snprintf(filepath, sizeof(filepath), "repos/%s/db", repo->name);
+
	filepath = pkg_repo_binary_get_filename(repo);
	/* Should never ever happen */
	if (faccessat(dbdirfd, filepath, R_OK, 0) == 0)
		return (EPKG_CONFLICT);
modified libpkg/repo/binary/update.c
@@ -685,7 +685,7 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)
	char *lockpath = NULL;
	const char update_finish_sql[] = ""
		"DROP TABLE repo_update;";
-
	const char *filename;
+
	char filename[PATH_MAX];
	sqlite3 *sqlite;

	struct stat st;
@@ -701,7 +701,8 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)

	pkg_debug(1, "PkgRepo: verifying update for %s", repo->name);

-
	filename = pkg_repo_binary_get_filename(repo);
+
	(void)snprintf(filename, sizeof(filename), "%s/%s",
+
	    ctx.dbdir, pkg_repo_binary_get_filename(repo));

	/* First of all, try to open and init repo and check whether it is fine */
	if (repo->dfd == -1 && pkg_repo_open(repo) == EPKG_FATAL)