Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Save files that are not tracked and will be overwritten by a new package
Baptiste Daroussin committed 6 years ago
commit bbdeecdca55e538afbcea0cb1d74857e4f86df44
parent 09789ab
3 files changed +12 -6
modified libpkg/pkg_add.c
@@ -719,7 +719,7 @@ cleanup:
}

static int
-
pkg_extract_finalize(struct pkg *pkg)
+
pkg_extract_finalize(struct pkgdb *db, struct pkg *pkg)
{
	struct stat st;
	struct pkg_file *f = NULL;
@@ -761,6 +761,12 @@ pkg_extract_finalize(struct pkg *pkg)
				    AT_SYMLINK_NOFOLLOW);
			}
#endif
+
			/* if the files does not belong to any package, we do save it */
+
			if (pkgdb_file_exists(db, fto)) {
+
				snprintf(path, sizeof(path), "%s.pkgsave", f->path);
+
				renameat(pkg->rootfd, RELATIVE_PATH(fto),
+
				    pkg->rootfd, RELATIVE_PATH(path));
+
			}
			unlinkat(pkg->rootfd, RELATIVE_PATH(fto), 0);
		}
		if (renameat(pkg->rootfd, RELATIVE_PATH(f->temppath),
@@ -1139,7 +1145,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	/* Update configuration file content with db with newer versions */
	pkgdb_update_config_file_content(pkg, db->sqlite);

-
	retcode = pkg_extract_finalize(pkg);
+
	retcode = pkg_extract_finalize(db, pkg);
cleanup_reg:
	pkgdb_register_finale(db, retcode);
	/*
@@ -1252,7 +1258,7 @@ pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
}

int
-
pkg_add_fromdir(struct pkg *pkg, const char *src)
+
pkg_add_fromdir(struct pkgdb *db, struct pkg *pkg, const char *src)
{
	struct stat st;
	struct pkg_dir *d = NULL;
@@ -1422,7 +1428,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
		}
	}

-
	retcode = pkg_extract_finalize(pkg);
+
	retcode = pkg_extract_finalize(db, pkg);

cleanup:
	kh_destroy_hls(hardlinks);
modified libpkg/pkg_ports.c
@@ -1340,7 +1340,7 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,

		if (input_path != NULL) {
			pkg_register_cleanup_callback(pkg_rollback_cb, pkg);
-
			rc = pkg_add_fromdir(pkg, input_path);
+
			rc = pkg_add_fromdir(db, pkg, input_path);
			pkg_unregister_cleanup_callback(pkg_rollback_cb, pkg);
			if (rc != EPKG_OK) {
				pkg_rollback_pkg(pkg);
modified libpkg/private/pkg.h
@@ -852,7 +852,7 @@ enum pkg_metalog_type {
int pkg_set_from_fileat(int fd, struct pkg *pkg, pkg_attr attr, const char *file, bool trimcr);
void pkg_rollback_cb(void *);
void pkg_rollback_pkg(struct pkg *);
-
int pkg_add_fromdir(struct pkg *, const char *);
+
int pkg_add_fromdir(struct pkgdb *, struct pkg *, const char *);
struct pkg_dep* pkg_adddep_chain(struct pkg_dep *chain,
		struct pkg *pkg, const char *name, const char *origin, const
		char *version, bool locked);