Fix port's cache policy function

The option of stat on macOS/BSD is wrong. So cache is always purged and
cache is always recreated so it is really slow.

Use 'zstat' module instead stat command for portability.
This commit is contained in:
Shohei YOSHIDA 2023-09-04 17:12:07 +09:00
parent ab99231c26
commit ae3a2e4400
1 changed files with 12 additions and 9 deletions

View File

@ -253,15 +253,10 @@ _port_select() {
fi fi
} }
stat -f%m . > /dev/null 2>&1
if [ "$?" = 0 ]; then
stat_cmd=(stat -f%Z)
else
stat_cmd=(stat --format=%Z)
fi
_port_caching_policy() { _port_caching_policy() {
local reg_time comp_time check_file local reg_time comp_time check_file
zmodload -F zsh/stat b:zstat 2> /dev/null
case "${1##*/}" in case "${1##*/}" in
PORT_INSTALLED_PACKAGES) PORT_INSTALLED_PACKAGES)
check_file=$port_prefix/var/macports/registry/registry.db check_file=$port_prefix/var/macports/registry/registry.db
@ -270,9 +265,17 @@ _port_caching_policy() {
check_file=${$(port dir MacPorts)%/*/*}/PortIndex check_file=${$(port dir MacPorts)%/*/*}/PortIndex
;; ;;
esac esac
reg_time=$($stat_cmd $check_file) reg_time=$(zstat +mtime $check_file)
comp_time=$($stat_cmd $1) comp_time=$(zstat +mtime $1)
return $(( reg_time < comp_time )) return $(( reg_time < comp_time ))
} }
_port "$@" _port "$@"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et