xbps-src: abstract away non-portable stat(1)

This implements semi-portable abstractions for both GNU and BSD
flavors of stat.
This commit is contained in:
q66 2023-09-11 04:30:55 +02:00 committed by Đoàn Trần Công Danh
parent 4349108b68
commit 937272e967
6 changed files with 43 additions and 7 deletions

View File

@ -15,7 +15,7 @@ elif [ -z "${SOURCE_DATE_EPOCH}" ]; then
fi
# check if the template is under version control:
if [ -n "$basepkg" -a -z "$($XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} ls-files template)" ]; then
export SOURCE_DATE_EPOCH="$(stat -c %Y ${XBPS_SRCPKGDIR}/${basepkg}/template)"
export SOURCE_DATE_EPOCH="$(stat_mtime ${XBPS_SRCPKGDIR}/${basepkg}/template)"
else
export SOURCE_DATE_EPOCH=$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} cat-file commit HEAD |
sed -n '/^committer /{s/.*> \([0-9][0-9]*\) [-+][0-9].*/\1/p;q;}')

View File

@ -253,7 +253,7 @@ hook() {
if [[ $cksum = $filesum ]]; then
dfgood=$((dfgood + 1))
else
inode=$(stat "$distfile" --printf "%i")
inode=$(stat_inode "$distfile")
msg_warn "$pkgver: wrong checksum found for ${curfile} - purging\n"
find ${XBPS_SRCDISTDIR} -inum ${inode} -delete -print
fi

View File

@ -1,5 +1,41 @@
# vim: set ts=4 sw=4 et:
# A portable abstraction for stat(1)
#
# The stat(1) command has different syntaxes between GNU flavor
# and BSD flavor; implementations generally follow one or the other
#
if ! stat -c "%s" / > /dev/null 2>&1; then
# BSD stat
stat_size() {
stat -f %z "$1"
}
stat_inode() {
stat -f %i "$1"
}
stat_mtime() {
stat -f %m "$1"
}
else
# GNU stat
stat_size() {
stat -c %s "$1"
}
stat_inode() {
stat -c %i "$1"
}
stat_mtime() {
stat -c %Y "$1"
}
fi
run_func() {
local func="$1" desc="$2" funcname="$3" restoretrap= logpipe= logfile= teepid=

View File

@ -16,7 +16,7 @@ remove_pkg_cross_deps() {
$XBPS_REMOVE_XCMD -Ryo > $tmplogf 2>&1
rval=$?
while [ $rval -eq 0 ]; do
local curs=$(stat -c %s $tmplogf)
local curs=$(stat_size $tmplogf)
if [ $curs -eq $prevs ]; then
break
fi

View File

@ -65,11 +65,11 @@ remove_pkg_autodeps() {
remove_pkg_cross_deps
$XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
prevs=$(stat -c %s $tmplogf)
prevs=$(stat_size $tmplogf)
echo yes | $XBPS_REMOVE_CMD -Ryod 2>> $errlogf 1>> $tmplogf
rval=$?
while [ $rval -eq 0 ]; do
local curs=$(stat -c %s $tmplogf)
local curs=$(stat_size $tmplogf)
if [ $curs -eq $prevs ]; then
break
fi

View File

@ -57,7 +57,7 @@ purge_distfiles() {
cur=0
percent=-1
for distfile in ${distfiles[@]}; do
inode=$(stat "$distfile" --printf "%i")
inode=$(stat_inode "$distfile")
if [ -z "${inodes[$inode]}" ]; then
inodes[$inode]="$distfile"
else
@ -77,7 +77,7 @@ purge_distfiles() {
hash_distfile=${file##*/}
hash=${hash_distfile:0:$HASHLEN}
[ -n "${my_hashes[$hash]}" ] && continue
inode=$(stat "$file" --printf "%i")
inode=$(stat_inode "$file")
echo "Obsolete $hash (inode: $inode)"
( IFS="|"; for f in ${inodes[$inode]}; do rm -vf "$f"; rmdir "${f%/*}" 2>/dev/null; done )
done