# HG changeset patch # User Franz Glasner # Date 1725479623 -7200 # Node ID c3db1ec91f023b05e921c8ff0d52c43415bbd5a4 # Parent 703e9f3573392de2311b5ccac9d71028075e0a46 common.subr: _get_mounts_at_directory() and _get_zfs_dataset_for_mountpoint() now also work for path and/or datasets with spaces in their names/values. For this to work textproc/jq must be installed. diff -r 703e9f357339 -r c3db1ec91f02 share/local-bsdtools/common.subr --- a/share/local-bsdtools/common.subr Wed Sep 04 20:52:57 2024 +0200 +++ b/share/local-bsdtools/common.subr Wed Sep 04 21:53:43 2024 +0200 @@ -220,16 +220,30 @@ _mountpoint="$1" - /sbin/mount -t zfs -p \ - | { - while IFS=' '$'\t' read -r _ds _mount _rest ; do - if [ "$_mount" = "$_mountpoint" ]; then - echo "${_ds}" - return 0 - fi - done - return 1 - } + if [ -x "${JQ}" ]; then + /sbin/mount -t zfs -p --libxo=json,no-locale \ + | LC_ALL=C "${JQ}" -r $'.mount.fstab.[] | [.device, .mntpoint, .fstype, .opts, .dump, .pass] | @tsv ' \ + | { + while IFS=$'\t' read -r _ds _mount _rest ; do + if [ "$_mount" = "$_mountpoint" ]; then + echo "${_ds}" + return 0 + fi + done + return 1 + } + else + /sbin/mount -t zfs -p \ + | { + while IFS=' '$'\t' read -r _ds _mount _rest ; do + if [ "$_mount" = "$_mountpoint" ]; then + echo "${_ds}" + return 0 + fi + done + return 1 + } + fi } @@ -351,8 +365,16 @@ exit 1; ;; esac - _fstab="$(/sbin/mount -p | awk -v pa1="^${_directory}\$" -v pa2="^${_directory}/" '($2 ~ pa1) || ($2 ~ pa2 ) { print; }' | sort -k3)" - echo "${_fstab}" + if [ -x "${JQ}" ]; then + /sbin/mount -p --libxo=json,no-locale \ + | LC_ALL=C "${JQ}" -r $'.mount.fstab.[] | [.device, .mntpoint, .fstype, .opts, .dump, .pass] | @tsv ' \ + | LC_ALL=C /usr/bin/awk -F $'\\t+' -v OFS=$'\t' -v ds1="${_directory}" -v ds2="${_directory}/" $'{ if (($2 == ds1) || (index($2, ds2) == 1)) { print; } }' \ + | LC_ALL=C /usr/bin/sort -t $'\t' -k1 + else + + _fstab="$(/sbin/mount -p | awk -v pa1="^${_directory}\$" -v pa2="^${_directory}/" '($2 ~ pa1) || ($2 ~ pa2 ) { print; }' | sort -k3)" + echo "${_fstab}" + fi }