Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Reduce code duplication
Baptiste Daroussin committed 9 years ago
commit 55b980e0806463d3fa586a0ce797a0dd8b0253c8
parent d9e4922
3 files changed +30 -45
modified libpkg/pkgdb.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * Copyright (c) 2011-2016 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011 Will Andrews <will@FreeBSD.org>
 * Copyright (c) 2011 Philippe Pepiot <phil@philpep.org>
@@ -1014,6 +1014,32 @@ pkgdb_syscall_overload(void)
	vfs->xSetSystemCall(vfs, "mkdir", (sqlite3_syscall_ptr)_dbdir_mkdir);
}

+
void
+
pkgdb_setup_lock(void)
+
{
+
	const char *dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));
+

+
	/*
+
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
+
	 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+

+
	if (statvfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+

+
	if (statfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#endif
+

+
}
+

int
pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
{
@@ -1073,24 +1099,7 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)

		sqlite3_initialize();

-
		/*
-
		 * Fall back on unix-dotfile locking strategy if on a network filesystem
-
		 */
-
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
-
		struct statvfs stfs;
-

-
		if (statvfs(dbdir, &stfs) == 0) {
-
			if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
-
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
-
		}
-
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
-
		struct statfs stfs;
-

-
		if (statfs(dbdir, &stfs) == 0) {
-
			if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
-
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
-
		}
-
#endif
+
		pkgdb_setup_lock();
		pkgdb_syscall_overload();

		if (sqlite3_open(localpath, &db->sqlite) != SQLITE_OK) {
modified libpkg/private/pkgdb.h
@@ -186,5 +186,6 @@ void pkgdb_myarch(sqlite3_context *ctx, int argc, sqlite3_value **argv);
int pkgdb_sqlcmd_init(sqlite3 *db, const char **err, const void *noused);
int pkgdb_update_config_file_content(struct pkg *pkg, sqlite3 *s);
void pkgdb_syscall_overload(void);
+
void pkgdb_setup_lock(void);

#endif
modified libpkg/repo/binary/init.c
@@ -39,12 +39,6 @@

#include <bsd_compat.h>

-
#ifdef HAVE_SYS_STATFS_H
-
#include <sys/statfs.h>
-
#elif defined(HAVE_SYS_STATVFS_H)
-
#include <sys/statvfs.h>
-
#endif
-

#include "pkg.h"
#include "private/event.h"
#include "private/pkg.h"
@@ -311,27 +305,8 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	struct pkg *pkg = NULL;

	sqlite3_initialize();
-
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));
-

-
	/*
-
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
-
	 */
-
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
-
	struct statvfs stfs;
-

-
	if (statvfs(dbdir, &stfs) == 0) {
-
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
-
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
-
	}
-
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
-
	struct statfs stfs;
-

-
	if (statfs(dbdir, &stfs) == 0) {
-
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
-
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
-
	}
-
#endif

+
	pkgdb_setup_lock();
	pkgdb_syscall_overload();

	snprintf(filepath, sizeof(filepath), "%s/%s.meta",