Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkgdb: enable WAL journal mode for local databases
Vsevolod Stakhov committed 3 months ago
commit a7ccf3c03e92b6f2942171ab4af9b25f122dce86
parent 9c4d787
1 file changed +22 -18
modified libpkg/pkgdb.c
@@ -959,6 +959,22 @@ _dbdir_getcwd(char *path, size_t sz)
	return 0;
}

+
static bool
+
pkgdb_is_local_fs(int fd) {
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+
	if (fstatvfs(fd, &stfs) == 0) {
+
		return (stfs.f_flag & ST_LOCAL);
+
	}
+
#elif defined(HAVE_FSTATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+
	if (fstatfs(fd, &stfs) == 0) {
+
		return (stfs.f_flags & MNT_LOCAL);
+
	}
+
#endif
+
	return (true);
+
}
+

void
pkgdb_syscall_overload(void)
{
@@ -985,28 +1001,12 @@ pkgdb_nfs_corruption(sqlite3 *db)
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */

-
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
	int dbdirfd = pkg_get_dbdirfd();
-
	struct statvfs stfs;
-

-
	if (fstatvfs(dbdirfd, &stfs) == 0) {
-
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
-
			pkg_emit_error("You are running on a remote filesystem,"
+
	if (!pkgdb_is_local_fs(dbdirfd)) {
+
		pkg_emit_error("You are running on a remote filesystem,"
			    " please make sure, the locking mechanism is "
			    " properly setup\n");
	}
-
#elif defined(HAVE_FSTATFS) && defined(MNT_LOCAL)
-
	int dbdirfd = pkg_get_dbdirfd();
-
	struct statfs stfs;
-

-
	if (fstatfs(dbdirfd, &stfs) == 0) {
-
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
-
			pkg_emit_error("You are running on a remote filesystem,"
-
			    " please make sure, the locking mechanism is "
-
			    " properly setup\n");
-
	}
-
#endif
-

}

int
@@ -1091,6 +1091,10 @@ retry:
			return (EPKG_FATAL);
		}

+
		if (pkgdb_is_local_fs(dbdirfd)) {
+
			sql_exec(db->sqlite, "PRAGMA journal_mode = WAL;");
+
		}
+

		/* Create our functions */
		pkgdb_sqlcmd_init(db->sqlite, NULL, NULL);