Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
When extracting files and they already exists on the local filesystem but aren't part of any local package, save the current file as .pkgsave
Emmanuel Vadot committed 6 years ago
commit 344fc3c32556af7bb9dc5899edcc857f7c0fce0f
parent 8004f58
4 files changed +38 -3
modified libpkg/pkg_add.c
@@ -127,7 +127,7 @@ attempt_to_merge(int rootfd, struct pkg_config_file *rcf, struct pkg *local,
	if (local == NULL) {
		pkg_debug(3, "No local package");
		if (fstatat(rootfd, RELATIVE_PATH(rcf->path), &st, 0) == 0) {
-
			rcf->status = MERGE_FAILED;
+
			rcf->status = MERGE_NOT_LOCAL;
		}
		return;
	}
@@ -738,6 +738,16 @@ pkg_extract_finalize(struct pkg *pkg)
			snprintf(path, sizeof(path), "%s.pkgnew", f->path);
			fto = path;
		}
+

+
		if (f->config && f->config->status == MERGE_NOT_LOCAL) {
+
			snprintf(path, sizeof(path), "%s.pkgsave", f->path);
+
			if (renameat(pkg->rootfd, RELATIVE_PATH(fto),
+
			    pkg->rootfd, RELATIVE_PATH(path)) == -1) {
+
				pkg_fatal_errno("Fail to rename %s -> %s",
+
				  fto, path);
+
			}
+
		}
+

		/*
		 * enforce an unlink of the file to workaround a bug that
		 * results in renameat returning 0 of the from file is hardlink
@@ -751,7 +761,9 @@ pkg_extract_finalize(struct pkg *pkg)
				    AT_SYMLINK_NOFOLLOW);
			}
#endif
-
			unlinkat(pkg->rootfd, RELATIVE_PATH(fto), 0);
+
			snprintf(path, sizeof(path), "%s.pkgsave", f->path);
+
			renameat(pkg->rootfd, RELATIVE_PATH(fto),
+
			    pkg->rootfd, RELATIVE_PATH(path));
		}
		if (renameat(pkg->rootfd, RELATIVE_PATH(f->temppath),
		    pkg->rootfd, RELATIVE_PATH(fto)) == -1) {
modified libpkg/private/pkg.h
@@ -377,6 +377,7 @@ typedef enum {
	MERGE_NOTNEEDED = 0,
	MERGE_FAILED,
	MERGE_SUCCESS,
+
	MERGE_NOT_LOCAL,
} merge_status;

struct pkg_config_file {
modified tests/frontend/configmerge.sh
@@ -151,7 +151,7 @@ config_fileexist_notinpkg_body()
	atf_check \
		pkg -o REPOS_DIR=${TMPDIR} -r ${TMPDIR}/target install -qy test

-
	test -f ${TMPDIR}/target/${TMPDIR}/a.pkgnew || atf_fail "file overwritten when it should not have"
+
	test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave || atf_fail "file overwritten when it should not have"
}

config_morecomplicated_body()
modified tests/frontend/conflicts.sh
@@ -4,6 +4,7 @@

tests_init \
	complex_conflicts \
+
	fileexists_notinpkg \
	find_conflicts

# install foo
@@ -170,6 +171,27 @@ Number of packages to be upgraded: 1
		pkg info
}

+
fileexists_notinpkg_body()
+
{
+
	mkdir -p ${TMPDIR}/target/${TMPDIR}
+
	echo "entry" > ${TMPDIR}/target/${TMPDIR}/a
+
	unset PKG_DBDIR
+

+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
+
	echo "entry 2" > a
+
	echo "${TMPDIR}/a" > plist
+

+
	atf_check \
+
		pkg create -M test.ucl -p plist
+

+
	pkg repo .
+
	echo "local: { url: file://${TMPDIR} }" > local.conf
+
	atf_check \
+
		pkg -o REPOS_DIR=${TMPDIR} -r ${TMPDIR}/target install -qy test
+

+
	test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave || atf_fail "file not saved when it should not have"
+
}
+

find_conflicts_body() {
	touch a
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_manifest test 1 /