From 3c34c300d1827f011803b24e9ab5058c81ec3564 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 18 Feb 2015 14:55:54 +0100 Subject: [PATCH] xbps-create(8): record target file or relative symlinks correctly. --- NEWS | 2 ++ bin/xbps-create/main.c | 3 ++- tests/xbps/xbps-create/basic_test.sh | 31 +++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e7b8b7f8..f6e7d2a4 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ xbps-0.44 (???): + * xbps-create(8): properly detect target of relative symlinks in some cases. + * libxbps: make sure that symlinks with relative target are detected and removed properly. Fix #78: https://github.com/voidlinux/xbps/issues/78 diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index 9e655990..f09a114f 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -303,7 +303,8 @@ ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf _u free(p2); free(p); } - } else if (strchr(buf, '/') == NULL) { + } else if (buf[0] != '/') { + /* relative path */ p = strdup(filep); assert(p); dname = dirname(p); diff --git a/tests/xbps/xbps-create/basic_test.sh b/tests/xbps/xbps-create/basic_test.sh index 67690476..d7124030 100644 --- a/tests/xbps/xbps-create/basic_test.sh +++ b/tests/xbps/xbps-create/basic_test.sh @@ -19,7 +19,7 @@ hardlinks_size_body() { cd .. xbps-rindex -d -a repo/*.xbps atf_check_equal $? 0 - result="$(xbps-query -r root -C empty.conf --repository=$PWD/repo -p installed_size foo)" + result="$(xbps-query -r root --repository=repo -p installed_size foo)" expected="10B" rv=0 if [ "$result" != "$expected" ]; then @@ -30,6 +30,35 @@ hardlinks_size_body() { atf_check_equal $rv 0 } +atf_test_case symlink_relative_target + +symlink_relative_target_head() { + atf_set "descr" "xbps-create(8): relative symlinks in destdir must be absolute" +} + +symlink_relative_target_body() { + mkdir -p repo pkg_A/usr/include/gsm + touch -f pkg_A/usr/include/gsm/gsm.h + cd pkg_A/usr/include + ln -s gsm/gsm.h gsm.h + cd ../../../repo + xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + cd .. + xbps-rindex -d -a repo/*.xbps + atf_check_equal $? 0 + result="$(xbps-query -r root --repository=repo -f foo|tr -d '\n')" + expected="/usr/include/gsm/gsm.h/usr/include/gsm.h -> /usr/include/gsm/gsm.h" + rv=0 + if [ "$result" != "$expected" ]; then + echo "result: $result" + echo "expected: $expected" + rv=1 + fi + atf_check_equal $rv 0 +} + atf_init_test_cases() { atf_add_test_case hardlinks_size + atf_add_test_case symlink_relative_target }