Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
repos: only allocate once per repos the file path
Baptiste Daroussin committed 2 years ago
commit 45968329b08a40e9f3bb2028c1426c8176f5b648
parent b9896cc
5 files changed +10 -10
modified libpkg/private/pkg.h
@@ -557,6 +557,7 @@ struct pkg_repo {
	ip_version_t ip;
	kvlist_t env;
	int dfd;
+
	char *dbpath;

	/* Opaque repository data */
	void *priv;
modified libpkg/repo/binary/binary_private.h
@@ -671,6 +671,6 @@ void pkg_repo_binary_finalize_prstatements(void);
/*
 * Warning: returns a pointer to static array
 */
-
const char * pkg_repo_binary_get_filename(const char *name);
+
const char * pkg_repo_binary_get_filename(struct pkg_repo *);

#endif /* INIT_PRIVATE_H_ */
modified libpkg/repo/binary/common.c
@@ -231,14 +231,13 @@ pkg_repo_binary_run_prstatement(sql_prstmt_index s, ...)
}

const char *
-
pkg_repo_binary_get_filename(const char *name)
+
pkg_repo_binary_get_filename(struct pkg_repo *repo)
{
-
	static char reponame[MAXPATHLEN];
+
	if (repo->dbpath == NULL)
+
		xasprintf(&repo->dbpath, "%s/repos/%s/db", ctx.dbdir,
+
		    repo->name);

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

-
	return (reponame);
+
	return (repo->dbpath);
}

void
modified libpkg/repo/binary/init.c
@@ -303,7 +303,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
		close(fd);
	}

-
	filepath = pkg_repo_binary_get_filename(repo->name);
+
	filepath = pkg_repo_binary_get_filename(repo);

	/* Always want read mode here */
	if (faccessat(dbdirfd, filepath, R_OK | mode, 0) != 0) {
@@ -507,7 +507,7 @@ pkg_repo_binary_access(struct pkg_repo *repo, unsigned mode)
	int			 ret = EPKG_OK;

	ret = pkgdb_check_access(mode,
-
		pkg_repo_binary_get_filename(pkg_repo_name(repo)));
+
		pkg_repo_binary_get_filename(repo));

	return (ret);
}
modified libpkg/repo/binary/update.c
@@ -701,7 +701,7 @@ 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->name);
+
	filename = 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)