mirror of
https://github.com/markusressel/zfs-inplace-rebalancing
synced 2026-02-04 21:14:09 +00:00
freebsd and macos fixes (#44)
freebsd and macos share stat and sed history with some differences from gnu tested on freebsd and linux, mac just verified with man pages and stack overflow Co-authored-by: mosshope <moss@lararium.houseofdusk.online>
This commit is contained in:
parent
9cea80a9c7
commit
4a6fb83c3d
@ -60,7 +60,27 @@ function rebalance () {
|
||||
# this shouldn't be needed in the typical case of `find` only finding files with links == 1
|
||||
# but this can run for a long time, so it's good to double check if something changed
|
||||
if [[ "${skip_hardlinks_flag,,}" == "true"* ]]; then
|
||||
if [[ "${OSTYPE,,}" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
#
|
||||
# -c --format=FORMAT
|
||||
# use the specified FORMAT instead of the default; output a
|
||||
# newline after each use of FORMAT
|
||||
# %h number of hard links
|
||||
|
||||
hardlink_count=$(stat -c "%h" "${file_path}")
|
||||
elif [[ "${OSTYPE,,}" == "darwin"* ]] || [[ "${OSTYPE,,}" == "freebsd"* ]]; then
|
||||
# Mac OS
|
||||
# FreeBSD
|
||||
# -f format
|
||||
# Display information using the specified format
|
||||
# l Number of hard links to file (st_nlink)
|
||||
|
||||
hardlink_count=$(stat -f %l "${file_path}")
|
||||
else
|
||||
echo "Unsupported OS type: $OSTYPE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${hardlink_count}" -ge 2 ]; then
|
||||
echo "Skipping hard-linked file: ${file_path}"
|
||||
@ -180,7 +200,7 @@ function rebalance () {
|
||||
else
|
||||
rebalance_count_line_nr="$((line_nr + 1))"
|
||||
rebalance_count="$((rebalance_count + 1))"
|
||||
sed -i "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}"
|
||||
sed -i '' "${rebalance_count_line_nr}s/.*/${rebalance_count}/" "./${rebalance_db_file_name}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user