abuild: improve amove

- fix multiple trailing and leading /
- continue moving after error
This commit is contained in:
Sertonix 2024-04-11 14:22:44 +02:00 committed by Natanael Copa
parent f12f4dde1a
commit 98dd63bf11
2 changed files with 35 additions and 21 deletions

View File

@ -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() {

View File

@ -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
}