Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix sqlite on FS without proper locking mechanism
Baptiste Daroussin committed 11 years ago
commit 9dd3fd699662d9a4f91cc7770003b2a2f165de78
parent 8cb2239
1 file changed +18 -0
modified libpkg/repo/binary/init.c
@@ -294,6 +294,7 @@ int
pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
{
	char filepath[MAXPATHLEN];
+
	struct statfs stfs;
	const char *dbdir = NULL;
	sqlite3 *sqlite = NULL;
	int flags;
@@ -302,6 +303,14 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	sqlite3_initialize();
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

+
	/*
+
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
+
	 */
+
	if (statfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+

	snprintf(filepath, sizeof(filepath), "%s/%s.meta",
		dbdir, pkg_repo_name(repo));

@@ -370,6 +379,7 @@ int
pkg_repo_binary_create(struct pkg_repo *repo)
{
	char filepath[MAXPATHLEN];
+
	struct statfs stfs;
	const char *dbdir = NULL;
	sqlite3 *sqlite = NULL;
	int retcode;
@@ -383,6 +393,14 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	if (access(filepath, R_OK) == 0)
		return (EPKG_CONFLICT);

+
	/*
+
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
+
	 */
+
	if (statfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+

	/* Open for read/write/create */
	if (sqlite3_open(filepath, &sqlite) != SQLITE_OK)
		return (EPKG_FATAL);