From ae3a2e440005fd04a88ce49d405a37326fba45bc Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 4 Sep 2023 17:12:07 +0900 Subject: [PATCH] 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. --- src/_port | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/_port b/src/_port index 5deec68..0e94574 100644 --- a/src/_port +++ b/src/_port @@ -253,15 +253,10 @@ _port_select() { 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() { local reg_time comp_time check_file + + zmodload -F zsh/stat b:zstat 2> /dev/null case "${1##*/}" in PORT_INSTALLED_PACKAGES) check_file=$port_prefix/var/macports/registry/registry.db @@ -270,9 +265,17 @@ _port_caching_policy() { check_file=${$(port dir MacPorts)%/*/*}/PortIndex ;; esac - reg_time=$($stat_cmd $check_file) - comp_time=$($stat_cmd $1) + reg_time=$(zstat +mtime $check_file) + comp_time=$(zstat +mtime $1) return $(( reg_time < comp_time )) } _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