Skip to content

Commit 160acfa

Browse files
committed
fix(watch): prefer GNU stat for cross-platform checksum compatibility
On Linux, `stat -f` returns filesystem info (not per-file mtime), so the checksum changed whenever any file on the filesystem changed, including non-.sh files. Reversed order to try GNU `stat -c` first and fall back to BSD `stat -f` on macOS.
1 parent f86b6bd commit 160acfa

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/main.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ function bashunit::main::watch_get_checksum() {
543543
if [ -d "$file" ]; then
544544
local found
545545
found=$(find "$file" -name '*.sh' -type f \
546-
-exec stat -f '%m %N' {} + 2>/dev/null ||
546+
-exec stat -c '%Y %n' {} + 2>/dev/null ||
547547
find "$file" -name '*.sh' -type f \
548-
-exec stat -c '%Y %n' {} + 2>/dev/null) || true
548+
-exec stat -f '%m %N' {} + 2>/dev/null) || true
549549
checksum="${checksum}${found}"
550550
elif [ -f "$file" ]; then
551551
local mtime
552-
mtime=$(stat -f '%m' "$file" 2>/dev/null ||
553-
stat -c '%Y' "$file" 2>/dev/null) || true
552+
mtime=$(stat -c '%Y' "$file" 2>/dev/null ||
553+
stat -f '%m' "$file" 2>/dev/null) || true
554554
checksum="${checksum}${mtime} ${file}"
555555
fi
556556
done

0 commit comments

Comments
 (0)