From 98dd63bf117e9ae0bc5207b7053efb62a6722a40 Mon Sep 17 00:00:00 2001 From: Sertonix Date: Thu, 11 Apr 2024 14:22:44 +0200 Subject: [PATCH] abuild: improve amove - fix multiple trailing and leading / - continue moving after error --- abuild.in | 34 +++++++++++++++++----------------- tests/abuild_test | 22 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/abuild.in b/abuild.in index 61c6e79..7286dd7 100644 --- a/abuild.in +++ b/abuild.in @@ -74,28 +74,28 @@ error() { amove() { [ -n "$subpkgdir" ] || return 1 - # store directory - d="$(pwd -L)" - + local olddir="$(pwd -L)" cd "$pkgdir" - local pattern f IFS="" + + local ret=0 IFS="" pattern f d for pattern; do - for f in ${pattern#/}; do # let shell expand the pattern - # strip trailing / - f=${f%/} - if [ "${f%/*}" != "$f" ]; then - mkdir -p "$subpkgdir/${f%/*}" - mv -v "$pkgdir/$f" "$subpkgdir/${f%/*}" - else - mkdir -p "$subpkgdir" - mv -v "$pkgdir/$f" "$subpkgdir/" - fi - # cleanup - rmdir -p "$f" 2>/dev/null || rmdir -p "${f%/*}" 2>/dev/null || true + for f in ${pattern#"${pattern%%[!/]*}"}; do # let shell expand the pattern + [ -L "$f" ] || [ -e "$f" ] || { + ret=1 + continue + } + # strip all trailing / + f=${f%"${f##*[!/]}"} + d=${f%/*} + [ "$d" = "$f" ] && d=. + mkdir -p "$subpkgdir/$d" + mv -v "$f" "$subpkgdir/$d" + rmdir -p "$d" 2>/dev/null || : done done - cd "$d" + cd "$olddir" + return $ret } cross_creating() { diff --git a/tests/abuild_test b/tests/abuild_test index 7d26fba..d7c3250 100755 --- a/tests/abuild_test +++ b/tests/abuild_test @@ -688,6 +688,7 @@ abuild_amove_body() { \$pkgname-etc:_etc \$pkgname-bin:_bin \$pkgname-sbin:_sbin + \$pkgname-root:_root \$pkgname-var:_var \$pkgname-usr:_usr \$pkgname-space:_space" @@ -702,26 +703,35 @@ abuild_amove_body() { "\$pkgdir"/etc/\$pkgname.conf \ "\$pkgdir"/bin/hello \ "\$pkgdir"/sbin/shello \ + "\$pkgdir"/root \ "\$pkgdir"/sbin/space' ' \ "\$pkgdir"/var/lib/\$pkgname/testfile \ "\$pkgdir"/usr/share/a \ "\$pkgdir"/usr/share/b + ln -s dangling "\$pkgdir"/symlink } _file() { amove etc/file } _etc() { # leading and trailing / - amove /etc/ + amove ///etc/ } _bin() { # trailing / - amove bin/ + amove bin/// } _sbin() { - # no / + # no leading and trailing / amove sbin/shello } + _root() { + # no / + amove root + + # symlink without existing target + amove symlink + } _var() { # leading / amove /var/lib @@ -729,6 +739,8 @@ abuild_amove_body() { _usr() { # glob * amove usr/share/* + amove no-glob-match/* && return 1 + return 0 } _space() { # with space @@ -742,12 +754,14 @@ abuild_amove_body() { test-amove-etc/etc/test-amove.conf \ test-amove-bin/bin/hello \ test-amove-sbin/sbin/shello \ + test-amove-root/root \ + test-amove-root/symlink \ test-amove-var/var/lib/test-amove/testfile \ test-amove-usr/usr/share/a \ test-amove-usr/usr/share/b \ test-amove-space/sbin/space' ' \ ; do \ - test -f pkg/"$i" || atf_fail "$i failed" + [ -L pkg/"$i" ] || [ -e pkg/"$i" ] || atf_fail "$i failed" done }