Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
When checking if a package is being used to not self count
Baptiste Daroussin committed 11 years ago
commit 1e3e5b1c92d6428a8fbf43b89f8899a7799c8caf
parent 8463aa9
3 files changed +13 -4
modified libpkg/pkg_delete.c
@@ -163,7 +163,7 @@ rmdir_p(struct pkgdb *db, struct pkg *pkg, char *dir, const char *prefix_r)
	char fullpath[MAXPATHLEN];

	snprintf(fullpath, sizeof(fullpath), "/%s", dir);
-
	if (pkgdb_is_dir_used(db, fullpath, &cnt) != EPKG_OK)
+
	if (pkgdb_is_dir_used(db, pkg, fullpath, &cnt) != EPKG_OK)
		return;

	pkg_debug(1, "Number of packages owning the directory '%s': %d",
modified libpkg/pkgdb.c
@@ -3203,20 +3203,29 @@ pkgdb_end_solver(struct pkgdb *db)
}

int
-
pkgdb_is_dir_used(struct pkgdb *db, const char *dir, int64_t *res)
+
pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res)
{
	sqlite3_stmt *stmt;
	int ret;
+
	const char *name;
+
	const char *origin;
+

	const char sql[] = ""
		"SELECT count(package_id) FROM pkg_directories, directories "
-
		"WHERE directory_id = directories.id AND directories.path = ?1;";
+
		"WHERE directory_id = directories.id AND directories.path = ?1 "
+
		"AND package_id != (SELECT id from PACKAGES where name=?2 and "
+
		"origin=?3);";

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
		ERROR_SQLITE(db->sqlite, sql);
		return (EPKG_FATAL);
	}

+
	pkg_get(p, PKG_NAME, &name, PKG_ORIGIN, &origin);
+

	sqlite3_bind_text(stmt, 1, dir, -1, SQLITE_TRANSIENT);
+
	sqlite3_bind_text(stmt, 2, name, -1, SQLITE_TRANSIENT);
+
	sqlite3_bind_text(stmt, 3, origin, -1, SQLITE_TRANSIENT);

	ret = sqlite3_step(stmt);

modified libpkg/private/pkg.h
@@ -548,7 +548,7 @@ int pkgdb_update_provides(struct pkg *pkg, int64_t package_id, sqlite3 *s);
int pkgdb_insert_annotations(struct pkg *pkg, int64_t package_id, sqlite3 *s);
int pkgdb_register_finale(struct pkgdb *db, int retcode);
int pkgdb_set_pkg_digest(struct pkgdb *db, struct pkg *pkg);
-
int pkgdb_is_dir_used(struct pkgdb *db, const char *dir, int64_t *res);
+
int pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res);

int pkg_emit_manifest_sbuf(struct pkg*, struct sbuf *, short, char **);
int pkg_emit_filelist(struct pkg *, FILE *);