# HG changeset patch # User Franz Glasner # Date 1727196917 -7200 # Node ID ce0616aecc6c22889e4c4502a7580f86787dff61 # Parent 87d37db3ac06429ac29c528197dd3486bac078af common.subr: "_get_mounts_at_directory()" not accepts an optional "-r" option for reverse output diff -r 87d37db3ac06 -r ce0616aecc6c share/local-bsdtools/common.subr --- a/share/local-bsdtools/common.subr Tue Sep 24 18:49:56 2024 +0200 +++ b/share/local-bsdtools/common.subr Tue Sep 24 18:55:17 2024 +0200 @@ -418,6 +418,9 @@ #: Args: #: $1: the directory where to start for mounts and sub-mounts #: +#: Other Parameters: +#: -r (optional): If given the the output is sorted in reverse order. +#: #: Output (stdout): #: The sorted list (lines) of mounts in :manpage:`fstab(5)` format. #: This list may be empty. @@ -431,8 +434,23 @@ #: _get_mounts_at_directory() { local _directory + local _opt_reversed - local _fstab _mp1 _mp2 + local _opt _fstab _mp1 _mp2 + + _opt_reversed="" + while getopts "r" _opt ; do + case ${_opt} in + r) + _opt_reversed="--reverse" + ;; + \?) + fatal 2 "invalid option given" + ;; + esac + done + shift $((OPTIND-1)) + OPTIND=1 _directory=${1-} case "${_directory}" in @@ -461,13 +479,13 @@ /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 mp1="${_mp1}" -v mp2="${_mp2}" $'{ if (($2 == mp1) || (index($2, mp2) == 1)) { print; } }' \ - | LC_ALL=C /usr/bin/sort --field-separator=$'\t' --key=2 + | LC_ALL=C /usr/bin/sort --field-separator=$'\t' --key=2 ${_opt_reversed} else # Check for unexpected spaces if ! check_for_proper_fstab; then fatal 1 "Unexpected spaces in fstab. Please install \`${JQ}'." fi - _fstab="$(/sbin/mount -p | LC_ALL=C awk -v OFS=$'\t' -v mp1="${_mp1}" -v mp2="${_mp2}" $'{ if (($2 == mp1) || (index($2, mp2) == 1)) { print $1, $2, $3, $4, $5, $6; } }' | LC_ALL=C /usr/bin/sort --field-separator=$'\t' --key=2)" + _fstab="$(/sbin/mount -p | LC_ALL=C awk -v OFS=$'\t' -v mp1="${_mp1}" -v mp2="${_mp2}" $'{ if (($2 == mp1) || (index($2, mp2) == 1)) { print $1, $2, $3, $4, $5, $6; } }' | LC_ALL=C /usr/bin/sort --field-separator=$'\t' --key=2 ${_opt_reversed})" printf '%s' "${_fstab}" fi }