diff --git a/NEWS b/NEWS index 576f8d22..8fe9fa44 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ xbps-0.27 (???): + * Fixed issue #20: https://github.com/xtraeme/xbps/issues/20 + * Fixed issue #19: https://github.com/xtraeme/xbps/issues/19 * Fixed issue #18: https://github.com/xtraeme/xbps/issues/18 diff --git a/lib/package_unpack.c b/lib/package_unpack.c index e9b28b33..d3907072 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -368,6 +368,12 @@ unpack_archive(struct xbps_handle *xhp, conf_file = skip_extract = file_exists = false; if (lstat(entry_pname, &st) == 0) file_exists = true; + /* + * If file to be extracted does not match the file type of + * file currently stored on disk, remove file on disk. + */ + if (file_exists && (entry_type != (int)st.st_mode)) + remove(entry_pname); if (!force && (entry_type == AE_IFREG)) { buf = strchr(entry_pname, '.') + 1; diff --git a/tests/xbps/libxbps/Makefile b/tests/xbps/libxbps/Makefile index 8d032749..51ecad12 100644 --- a/tests/xbps/libxbps/Makefile +++ b/tests/xbps/libxbps/Makefile @@ -11,5 +11,6 @@ SUBDIRS += find_pkg_obsoletes SUBDIRS += find_pkg_orphans SUBDIRS += pkgdb SUBDIRS += issue18 +SUBDIRS += issue20 include ../../../mk/subdir.mk diff --git a/tests/xbps/libxbps/common/Kyuafile b/tests/xbps/libxbps/common/Kyuafile index 59fd8160..11f3dfa8 100644 --- a/tests/xbps/libxbps/common/Kyuafile +++ b/tests/xbps/libxbps/common/Kyuafile @@ -9,5 +9,6 @@ atf_test_program{name="plist_match_test"} atf_test_program{name="plist_match_virtual_test"} atf_test_program{name="find_pkg_obsoletes_test"} atf_test_program{name="issue18_test"} +atf_test_program{name="issue20_test"} include('find_pkg_orphans/Kyuafile') include('pkgdb/Kyuafile') diff --git a/tests/xbps/libxbps/issue20/Makefile b/tests/xbps/libxbps/issue20/Makefile new file mode 100644 index 00000000..0cde5cc4 --- /dev/null +++ b/tests/xbps/libxbps/issue20/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../../.. +-include $(TOPDIR)/config.mk + +TEST = issue20_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test-shell.mk diff --git a/tests/xbps/libxbps/issue20/issue20_test.sh b/tests/xbps/libxbps/issue20/issue20_test.sh new file mode 100644 index 00000000..7cd7b4e4 --- /dev/null +++ b/tests/xbps/libxbps/issue20/issue20_test.sh @@ -0,0 +1,57 @@ +#! /usr/bin/env atf-sh + +# xbps issue #20. +# How to reproduce it: +# Create pkg a-0.1_1 containing 1 file and 1 symlink: +# +# /foo +# /blah -> foo +# +# Create pkg a-0.2_1 containing 1 file and 1 symlink (inverted): +# +# /foo -> blah +# /blah +# +# Upgrade pkg a to 0.2. + +atf_test_case issue20 + +issue20_head() { + atf_set "descr" "xbps issue #20 (https://github.com/xtraeme/xbps/issues/18)" +} + +issue20_body() { + mkdir repo + cd repo + mkdir pkg_a + touch pkg_a/foo + ln -sr pkg_a/foo pkg_a/blah + xbps-create -A noarch -n a-0.1_1 -s "pkg a" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -a *.xbps + atf_check_equal $? 0 + xbps-install -r rootdir --repository=$PWD -y a + atf_check_equal $? 0 + + mkdir pkg_a + touch pkg_a/blah + ln -sr pkg_a/blah pkg_a/foo + xbps-create -A noarch -n a-0.2_1 -s "pkg a" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -a *.xbps + atf_check_equal $? 0 + xbps-install -r rootdir --repository=$PWD -yu + atf_check_equal $? 0 + tgt=$(readlink rootdir/foo) + rval=1 + if [ -f rootdir/blah -a "$tgt" = "blah" ]; then + rval=0 + fi + atf_check_equal $rval 0 +} + +atf_init_test_cases() { + atf_add_test_case issue20 +}