From d4c9918cf5b63b03771bc131c67327f4ad980ddf Mon Sep 17 00:00:00 2001 From: twojstaryzdomu Date: Sat, 3 Jul 2021 23:15:47 +0200 Subject: [PATCH] Fixed stat and grep parameters for FreeBSD --- testsuite/update-links.test | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/testsuite/update-links.test b/testsuite/update-links.test index c6b89a134..f43dbbfd9 100644 --- a/testsuite/update-links.test +++ b/testsuite/update-links.test @@ -7,6 +7,17 @@ DSELF="$(dirname "$LSRC")" . "${testsuite:-${DSELF}}/rsync.fns" +set_os_opts(){ + case $(uname -s) in + Linux) + stat_opt=c + ;; + FreeBSD) + stat_opt=f + ;; + esac +} + log(){ echo "${SELF}: $@" } @@ -20,15 +31,15 @@ error(){ } get_ctime(){ - stat -c "%Y" "$1" || test_fail "Unable to get ctime of $1" + stat -${stat_opt} "%Y" "$1" || test_fail "Unable to get ctime of $1" } get_mtime(){ - stat -c "%Y" "$1" || test_fail "Unable to get mtime of $1" + stat -${stat_opt} "%Y" "$1" || test_fail "Unable to get mtime of $1" } get_size(){ - stat -c "%s" "$1" || test_fail "Unable to get size of $1" + stat -${stat_opt} "%s" "$1" || test_fail "Unable to get size of $1" } get_referent(){ @@ -157,7 +168,7 @@ shift_mtime(){ offset=$1 shift for f in $@; do - epoch=$(stat -c%Y "$f") + epoch=$(stat -${stat_opt} %Y "$f") rc=$? debug "shift_mtime: $f; offset = $offset; rc = $rc; touch -hd @$((epoch${offset})) $f" [ $rc -eq 0 ] && touch -hd @$((epoch${offset})) "$f" || error "Unable to stat $f" @@ -173,7 +184,7 @@ take_a_second(){ } show_files(){ - stat -c "%Y %Z %N" $@ 1>&2 || test_fail "Unable to stat $@" + stat -${stat_opt} "%Y %Z %N" $@ 1>&2 || test_fail "Unable to stat $@" } count_words(){ @@ -257,7 +268,7 @@ list_contains(){ $@ _EOT_ debug "list_contains: opt = $opt; opts = $opts" - echo "$opts" | grep -qPo -- "${opt}(?=$|\s)" 1>/dev/null + echo "$opts" | egrep -q -- " ${opt} |^${opt} | ${opt}$" 1>/dev/null } # Various scenarios that modify either side before re-running rsync & performing a check