Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Avoid SQLite3 database corruption.
John Hood committed 3 years ago
commit d94168d172bd9ca3984627ef209e54e7a88995b3
parent 187d1b7
3 files changed +11 -7
modified libpkg/pkgdb.c
@@ -336,6 +336,8 @@ static int
pkgdb_init(sqlite3 *sdb)
{
	const char	sql[] = ""
+
	"PRAGMA journal_mode = TRUNCATE;"
+
	"PRAGMA synchronous = FULL;"
	"BEGIN;"
	"CREATE TABLE packages ("
		"id INTEGER PRIMARY KEY,"
@@ -2925,8 +2927,6 @@ int
pkgdb_begin_solver(struct pkgdb *db)
{
	const char solver_sql[] = ""
-
		"PRAGMA synchronous = OFF;"
-
		"PRAGMA journal_mode = MEMORY;"
		"BEGIN TRANSACTION;";
	const char update_digests_sql[] = ""
		"DROP INDEX IF EXISTS pkg_digest_id;"
@@ -2992,9 +2992,7 @@ int
pkgdb_end_solver(struct pkgdb *db)
{
	const char solver_sql[] = ""
-
		"END TRANSACTION;"
-
		"PRAGMA synchronous = NORMAL;"
-
		"PRAGMA journal_mode = DELETE;";
+
		"END TRANSACTION;";

	return (sql_exec(db->sqlite, solver_sql));
}
modified libpkg/repo/binary/init.c
@@ -482,7 +482,12 @@ pkg_repo_binary_init(struct pkg_repo *repo)

	sqlite3_create_function(sqlite, "file_exists", 2, SQLITE_ANY, NULL,
		    sqlite_file_exists, NULL, NULL);
-
	retcode = sql_exec(sqlite, "PRAGMA synchronous=default");
+

+
	retcode = sql_exec(sqlite, "PRAGMA journal_mode=TRUNCATE;");
+
	if (retcode != EPKG_OK)
+
		return (retcode);
+

+
	retcode = sql_exec(sqlite, "PRAGMA synchronous=FULL");
	if (retcode != EPKG_OK)
		return (retcode);

modified libpkg/repo/binary/update.c
@@ -519,7 +519,8 @@ pkg_repo_binary_update_proceed(const char *name, struct pkg_repo *repo,
	sql_exec(sqlite, "PRAGMA mmap_size = 209715200;");
	sql_exec(sqlite, "PRAGMA page_size = %d;", getpagesize());
	sql_exec(sqlite, "PRAGMA foreign_keys = OFF;");
-
	sql_exec(sqlite, "PRAGMA synchronous = OFF;");
+
	sql_exec(sqlite, "PRAGMA journal_mode = TRUNCATE;");
+
	sql_exec(sqlite, "PRAGMA synchronous = FULL;");

	rc = pkgdb_transaction_begin_sqlite(sqlite, "REPO");
	if (rc != EPKG_OK)