Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
repos: move repos database under /var/db/pkg/repos/<name>/db
Baptiste Daroussin committed 2 years ago
commit 8ecdfa0e28e70024e6214d60636f061cae6eac88
parent c7cdede
4 files changed +14 -23
modified libpkg/pkgdb.c
@@ -846,7 +846,7 @@ pkgdb_open_repos(struct pkgdb *db, const char *reponame)
}

static const char*
-
_dbdir_trim_path(const char *path)
+
_dbdir_trim_path(const char*path)
{
	static size_t l = 0;
	const char *p;
@@ -860,11 +860,9 @@ _dbdir_trim_path(const char *path)
			p++;
		return (p);
	}
-
	p = strrchr(path, '/');
-

-
	if(p == NULL)
-
		return (path);
-
	return (p + 1);
+
	if (*path == '/')
+
		return (path + 1);
+
	return (path);
}

static int
modified libpkg/repo/binary/common.c
@@ -247,8 +247,8 @@ pkg_repo_binary_get_filename(const char *name)
{
	static char reponame[MAXPATHLEN];

-
	snprintf(reponame, sizeof(reponame), REPO_NAME_PREFIX "%s.sqlite",
-
			name);
+
	snprintf(reponame, sizeof(reponame), "%s/repos/%s/db",
+
	    ctx.dbdir, name);

	return (reponame);
}
modified libpkg/repo/binary/init.c
@@ -272,7 +272,7 @@ pkg_repo_binary_check_version(struct pkg_repo *repo, sqlite3 *sqlite)
int
pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
{
-
	char filepath[MAXPATHLEN];
+
	const char *filepath;
	sqlite3 *sqlite = NULL;
	int flags, dbdirfd, fd, reposfd, thisrepofd;
	int64_t res;
@@ -303,8 +303,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
		close(fd);
	}

-
	snprintf(filepath, sizeof(filepath), "%s",
-
		pkg_repo_binary_get_filename(pkg_repo_name(repo)));
+
	filepath = pkg_repo_binary_get_filename(repo->name);

	/* Always want read mode here */
	if (faccessat(dbdirfd, filepath, R_OK | mode, 0) != 0) {
@@ -393,8 +392,7 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	sqlite3_initialize();

	dbdirfd = pkg_get_dbdirfd();
-
	snprintf(filepath, sizeof(filepath), "%s",
-
		pkg_repo_binary_get_filename(pkg_repo_name(repo)));
+
	snprintf(filepath, sizeof(filepath), "repos/%s/db", repo->name);
	/* Should never ever happen */
	if (faccessat(dbdirfd, filepath, R_OK, 0) == 0)
		return (EPKG_CONFLICT);
modified libpkg/repo/binary/update.c
@@ -49,7 +49,7 @@
#include "binary_private.h"

static int
-
pkg_repo_binary_init_update(struct pkg_repo *repo, const char *name)
+
pkg_repo_binary_init_update(struct pkg_repo *repo)
{
	sqlite3 *sqlite;
	const char update_check_sql[] = ""
@@ -584,7 +584,7 @@ pkg_repo_binary_update_proceed(const char *name, struct pkg_repo *repo,
	xasprintf(&path, "%s-pkgtemp", name);
	rename(name, path);
	pkg_register_cleanup_callback(rollback_repo, (void *)name);
-
	rc = pkg_repo_binary_init_update(repo, name);
+
	rc = pkg_repo_binary_init_update(repo);
	if (rc != EPKG_OK) {
		rc = EPKG_FATAL;
		goto cleanup;
@@ -682,7 +682,6 @@ cleanup:
int
pkg_repo_binary_update(struct pkg_repo *repo, bool force)
{
-
	char filepath[MAXPATHLEN];
	char *lockpath = NULL;
	const char update_finish_sql[] = ""
		"DROP TABLE repo_update;";
@@ -712,8 +711,6 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)
		pkg_debug(1, "PkgRepo: need forced update of %s", repo->name);
		t = 0;
		force = true;
-
		snprintf(filepath, sizeof(filepath), "%s/%s", ctx.dbdir,
-
		    filename);
	}
	else {
		repo->ops->close(repo, false);
@@ -722,9 +719,7 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)
			got_meta = true;
		}

-
		snprintf(filepath, sizeof(filepath), "%s/%s", ctx.dbdir,
-
			filename);
-
		if (got_meta && stat(filepath, &st) != -1) {
+
		if (got_meta && stat(filename, &st) != -1) {
			if (!force)
				t = st.st_mtime;
		}
@@ -745,7 +740,7 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)
		goto cleanup;
	}

-
	res = pkg_repo_binary_update_proceed(filepath, repo, &t, force);
+
	res = pkg_repo_binary_update_proceed(filename, repo, &t, force);
	if (res != EPKG_OK && res != EPKG_UPTODATE) {
		pkg_emit_notice("Unable to update repository %s", repo->name);
		goto cleanup;
@@ -779,7 +774,7 @@ cleanup:
			}
		};

-
		utimes(filepath, ftimes);
+
		utimes(filename, ftimes);
		if (got_meta)
			futimesat(repo->dfd, "meta", ftimes);
	}