Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
When dealing with configuration files, never overwrites a previous files if not tracked as a configuration itself
Baptiste Daroussin committed 9 years ago
commit 1fcafeacb4386fd7ab1f03c1ccd6cd826f101161
parent b20b10c
2 files changed +64 -1
modified libpkg/pkg_add.c
@@ -109,6 +109,7 @@ attempt_to_merge(int rootfd, struct pkg_config_file *rcf, struct pkg *local,
    bool merge)
{
	const struct pkg_file *lf = NULL;
+
	struct stat st;
	UT_string *newconf;
	struct pkg_config_file *lcf = NULL;

@@ -123,11 +124,15 @@ 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;
+
		}
		return;
	}

	if (!pkg_is_config_file(local, rcf->path, &lf, &lcf)) {
		pkg_debug(3, "No local package");
+
		rcf->status = MERGE_FAILED;
		return;
	}

modified tests/frontend/configmerge.sh
@@ -2,7 +2,9 @@

. $(atf_get_srcdir)/test_environment.sh
tests_init \
-
	config
+
	config \
+
	config_fileexist \
+
	config_fileexist_notinpkg

config_body()
{
@@ -43,3 +45,59 @@ config_body()
		-o inline:"entry 2\naddition\n" \
		cat ${TMPDIR}/target/${TMPDIR}/a
}
+

+
config_fileexist_body()
+
{
+
	new_pkg "test" "test" "1"
+
	echo "${TMPDIR}/a" > plist
+

+
	echo "entry" > a
+

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

+
	mkdir ${TMPDIR}/target
+
	unset PKG_DBDIR
+
	atf_check \
+
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qy ${TMPDIR}/test-1.txz
+
	test -f ${TMPDIR}/target/${TMPDIR}/a || atf_fail "file absent"
+
	echo "addition" >> ${TMPDIR}/target/${TMPDIR}/a
+
	atf_check \
+
		-o inline:"entry\naddition\n" \
+
		cat ${TMPDIR}/target/${TMPDIR}/a
+

+
	new_pkg "test" "test" "2"
+
	echo "entry 2" > a
+
	echo "@config ${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 upgrade -qy test
+

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

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

+
	new_pkg "test" "test" "2"
+
	echo "entry 2" > a
+
	echo "@config ${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.pkgnew || atf_fail "file overwritten when it should not have"
+
}