Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add an annotation for relocated packages delete files/dirs from the relocated place
Baptiste Daroussin committed 12 years ago
commit 1698afd899320067058663e6987e147cdbd31714
parent ed81404
3 files changed +26 -8
modified libpkg/pkg_add.c
@@ -291,6 +291,9 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags,
		}
	}

+
	if (location != NULL)
+
		pkg_addannotation(pkg, "relocated", location);
+

	/* register the package before installing it in case there are
	 * problems that could be caught here. */
	retcode = pkgdb_register_pkg(db, pkg, flags & PKG_ADD_UPGRADE, flags & PKG_FLAG_FORCE);
modified libpkg/pkg_delete.c
@@ -59,7 +59,6 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
	 */
	if ((ret = pkgdb_load_rdeps(db, pkg)) != EPKG_OK)
		return (ret);
-

	if ((ret = pkgdb_load_files(db, pkg)) != EPKG_OK)
		return (ret);
	if ((ret = pkgdb_load_dirs(db, pkg)) != EPKG_OK)
@@ -68,6 +67,8 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
		return (ret);
	if ((ret = pkgdb_load_mtree(db, pkg)) != EPKG_OK)
		return (ret);
+
	if ((ret = pkgdb_load_annotations(db, pkg)) != EPKG_OK)
+
		return (ret);

	if ((flags & PKG_DELETE_UPGRADE) == 0)
		pkg_emit_deinstall_begin(pkg);
@@ -139,19 +140,24 @@ pkg_delete_files(struct pkg *pkg, unsigned force)
	struct pkg_file	*file = NULL;
	char		 sha256[SHA256_DIGEST_LENGTH * 2 + 1];
	const char	*path;
+
	char		fpath[MAXPATHLEN];

	while (pkg_files(pkg, &file) == EPKG_OK) {
		const char *sum = pkg_file_cksum(file);
+
		ucl_object_t *obj;

		if (file->keep == 1)
			continue;

		path = pkg_file_path(file);
+
		obj = pkg_annotation_lookup(pkg, "relocated");
+
		snprintf(fpath, sizeof(fpath), "%s%s",
+
		    obj ? pkg_object_string(obj) : "" , path );

		/* Regular files and links */
		/* check sha256 */
		if (!force && sum[0] != '\0') {
-
			if (sha256_file(path, sha256) != EPKG_OK)
+
			if (sha256_file(fpath, sha256) != EPKG_OK)
				continue;
			if (strcmp(sha256, sum)) {
				pkg_emit_error("%s fails original SHA256 "
@@ -160,9 +166,9 @@ pkg_delete_files(struct pkg *pkg, unsigned force)
			}
		}

-
		if (unlink(path) == -1) {
+
		if (unlink(fpath) == -1) {
			if (force < 2)
-
				pkg_emit_errno("unlink", path);
+
				pkg_emit_errno("unlink", fpath);
			continue;
		}
	}
@@ -174,18 +180,24 @@ int
pkg_delete_dirs(__unused struct pkgdb *db, struct pkg *pkg, bool force)
{
	struct pkg_dir	*dir = NULL;
+
	ucl_object_t *obj;
+
	char		fpath[MAXPATHLEN];

	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
		if (dir->keep == 1)
			continue;

+
		obj = pkg_annotation_lookup(pkg, "relocated");
+
		snprintf(fpath, sizeof(fpath), "%s%s",
+
		    obj ? pkg_object_string(obj) : "" , pkg_dir_path(dir) );
+

		if (pkg_dir_try(dir)) {
-
			if (rmdir(pkg_dir_path(dir)) == -1 &&
+
			if (rmdir(fpath) == -1 &&
			    errno != ENOTEMPTY && errno != EBUSY && !force)
-
				pkg_emit_errno("rmdir", pkg_dir_path(dir));
+
				pkg_emit_errno("rmdir", fpath);
		} else {
-
			if (rmdir(pkg_dir_path(dir)) == -1 && !force)
-
				pkg_emit_errno("rmdir", pkg_dir_path(dir));
+
			if (rmdir(fpath) == -1 && !force)
+
				pkg_emit_errno("rmdir", fpath);
		}
	}

modified src/register.c
@@ -332,6 +332,9 @@ exec_register(int argc, char **argv)

	if (!testing_mode && input_path != NULL)
		pkg_copy_tree(pkg, input_path, location ? location : "/");
+
	
+
	if (location != NULL)
+
		pkg_addannotation(pkg, "relocated", location);

	if (old) {
		if (pkg_register_old(pkg) != EPKG_OK)