Fix stat for BSD part 2

This commit is contained in:
Colin Hebert 2025-03-23 12:28:58 +11:00
parent 5c8aa9320d
commit 1f9ae6269f
No known key found for this signature in database
2 changed files with 16 additions and 2 deletions

View File

@ -57,6 +57,20 @@ function get_time() {
echo "$date"
}
function get_inode() {
case "$OSTYPE" in
darwin*)
inode=$(stat -f "%i" "$1")
;;
*)
inode=$(stat -c "%i" "$1")
;;
esac
echo "$inode"
}
function assertions() {
# check error log is empty
if grep -q '[^[:space:]]' $log_error_file; then
@ -67,7 +81,7 @@ function assertions() {
}
function assert_matching_file_hardlinked() {
if ! [ "$(stat -c "%i" "$1")" -eq "$(stat -c "%i" "$2")" ]; then
if ! [ "$(get_inode "$1")" -eq "$(get_inode "$2")" ]; then
echo "File '$1' was not hardlinked to '$2' when it should have been!"
exit 1
fi

View File

@ -282,7 +282,7 @@ if [[ "${OSName}" == "linux-gnu"* ]]; then
find "$root_path" -type f -not -path '*/.zfs/*' -exec stat --printf '%d:%i|%n\n' {} \; > files_list.txt
elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then
# Mac OS and FreeBSD
find "$root_path" -type f -not -path '*/.zfs/*' -exec sh -c 'stat -f "%d:%i|%N" "$0"' {} \; > files_list.txt
find "$root_path" -type f -not -path '*/.zfs/*' -exec stat -f "%d:%i|%N" {} \; > files_list.txt
else
echo "Unsupported OS type: $OSTYPE"
exit 1