Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Issue #410: handle the case where left-over records are present in the files table with no corresponding entry in the pkg table.
Matthew Seaman committed 13 years ago
commit 8cc031118d98ff253ae21b8ff486f9b2832ec15b
parent 4542c3a
1 file changed +21 -1
modified libpkg/pkgdb.c
@@ -1678,6 +1678,7 @@ typedef enum _sql_prstmt_index {
	DEPS_UPDATE,
	DEPS,
	FILES,
+
	FILES_REPLACE,
	DIRS1,
	DIRS2,
	CATEGORY1,
@@ -1728,6 +1729,12 @@ static sql_prstmt sql_prepared_statements[PRSTMT_LAST] = {
		"VALUES (?1, ?2, ?3)",
		"TTI",
	},
+
	[FILES_REPLACE] = {
+
		NULL,
+
		"INSERT OR REPLACE INTO files (path, sha256, package_id) "
+
		"VALUES (?1, ?2, ?3)",
+
		"TTI",
+
	},
	[DIRS1] = {
		NULL,
		"INSERT OR IGNORE INTO directories(path) VALUES(?1)",
@@ -2016,7 +2023,20 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete)
		}
		pkg2 = NULL;
		ret = pkgdb_it_next(it, &pkg2, PKG_LOAD_BASIC);
-
		if (ret != EPKG_OK) {
+
		if (ret == EPKG_END) {
+
			/* Stray entry in the files table not related to
+
			   any known package: overwrite this */
+
			ret = run_prstmt(FILES_REPLACE, pkg_path, pkg_sum,
+
					 package_id);
+
			pkgdb_it_free(it);
+
			if (ret == SQLITE_DONE)
+
				continue;
+
			else {
+
				ERROR_SQLITE(s);
+
				goto cleanup;
+
			}
+
		}
+
		if (ret != EPKG_OK && ret != EPKG_END) {
			pkgdb_it_free(it);
			ERROR_SQLITE(s);
			goto cleanup;