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:
parent
4349108b68
commit
937272e967
6 changed files with 43 additions and 7 deletions
|
@ -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=
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue