Skip to content

Commit

Permalink
Use % builtin instead of awk for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
adiov authored Jan 6, 2025
1 parent b0a0fa3 commit 2ecbce0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions zfs-inplace-rebalancing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function rebalance() {
# file permissions, owner, group, size, modification time
original_checksum="${original_checksum} $(stat -c "%A %U %G %s %Y" "${file_path}")"
# file content
original_checksum="${original_checksum} $(cksum "${file_path}" | awk '{ print $1 }')"
original_checksum="${original_checksum} $(cksum "${file_path}")"


# file attributes
Expand All @@ -153,7 +153,9 @@ function rebalance() {
# file permissions, owner, group, size, modification time
copy_checksum="${copy_checksum} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
# file content
copy_checksum="${copy_checksum} $(cksum "${file_path}" | awk '{ print $1 }')"
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_checksum=${copy_checksum%"${tmp_extension}"}
elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then
# Mac OS
# FreeBSD
Expand All @@ -163,12 +165,14 @@ function rebalance() {
# file permissions, owner, group size, modification time
original_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"
# file content
original_checksum="${original_checksum} $(cksum "${file_path}" | awk '{ print $1 }')"
original_checksum="${original_checksum} $(cksum "${file_path}")"

# file permissions, owner, group size, modification time
copy_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
# file content
copy_checksum="${copy_checksum} $(cksum "${file_path}" | awk '{ print $1 }')"
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_checksum=${copy_checksum%"${tmp_extension}"}
else
echo "Unsupported OS type: $OSTYPE"
exit 1
Expand Down

0 comments on commit 2ecbce0

Please sign in to comment.