Skip to content

Commit

Permalink
Fixed stat and grep parameters for FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
twojstaryzdomu committed Jul 3, 2021
1 parent 1fa1836 commit d4c9918
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions testsuite/update-links.test
Original file line number Diff line number Diff line change
Expand Up @@ -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}: $@"
}
Expand All @@ -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(){
Expand Down Expand Up @@ -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"
Expand All @@ -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(){
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4c9918

Please sign in to comment.