changeset 539:f6dc405ddd58

fzfs: switch to farray.sh
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 09 Sep 2024 15:16:01 +0200
parents 9f8f3e9b3d84
children bd1038de65cc
files sbin/fzfs
diffstat 1 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/sbin/fzfs	Mon Sep 09 14:39:16 2024 +0200
+++ b/sbin/fzfs	Mon Sep 09 15:16:01 2024 +0200
@@ -45,7 +45,7 @@
 
 _p_datadir="$(dirname "$0")"/../share/local-bsdtools
 . "${_p_datadir}/common.subr"
-. "${_p_datadir}/array.sh"
+. "${_p_datadir}/farray.sh"
 
 
 #
@@ -59,6 +59,7 @@
     local _opt_mount_children_only _opt_keep
 
     local _name _mp _canmount _mounted _rootds_mountpoint _rootds_mountpoint_prefix _relative_mp _real_mp
+    local _mounted_datasets
 
     _opt_dry_run=""
     _opt_keep=""
@@ -136,7 +137,7 @@
         # mounted by this routine and should be unmounted on errors
         # -- if possible.
         #
-        array_create _mounted_datasets
+        farray_create _mounted_datasets
 
         while IFS=$'\t' read -r _name _mp _canmount _mounted ; do
             # Skip filesystems that are already mounted
@@ -210,7 +211,7 @@
                             { echo "ERROR: cannot create mountpoint ${_real_mp}" >&2; _umount_datasets _mounted_datasets || true; return 1; }
                         echo "Mounting ${_name} on ${_real_mp}"
                         if /sbin/mount -t zfs "${_name}" "${_real_mp}"; then
-                            array_append _mounted_datasets "${_name}"
+                            farray_append _mounted_datasets "${_name}"
                         else
                             if ! checkyes _opt_keep; then
                                 _umount_datasets _mounted_datasets || true
@@ -226,7 +227,7 @@
                         else
                             echo "Mounting ${_name} on configured ZFS dataset mountpoint ${_mp}"
                             if zfs mount "${_name}"; then
-                                array_append _mounted_datasets "${_name}"
+                                farray_append _mounted_datasets "${_name}"
                             else
                                 if ! checkyes _opt_keep; then
                                     _umount_datasets _mounted_datasets || true
@@ -240,7 +241,7 @@
                     ;;
             esac
         done
-        array_destroy _mounted_datasets
+        farray_destroy _mounted_datasets
         return 0
     }
 }
@@ -259,7 +260,7 @@
 #: Unmounting is done in the reverse order.
 #:
 _umount_datasets() {
-    array_reversed_for_each "$1" _umount_datasets_umount
+    farray_reversed_for_each "$1" _umount_datasets_umount
 }
 
 
@@ -489,6 +490,7 @@
     local _ds_canmount _ds_mountpoint
     local _clone_props _arg_canmount _arg_other_clone_props
     local _opt _idx _idx_lp _prop _propval
+    local _ds_tree _cloned_datasets _local_props
 
     _opt_dry_run=""
     _opt_keep=""
@@ -532,17 +534,17 @@
         return 1
     fi
 
-    array_create _ds_tree
+    farray_create _ds_tree
 
     while IFS=$'\n' read -r _ds; do
-        array_append _ds_tree "${_ds}"
+        farray_append _ds_tree "${_ds}"
     done <<EOF_9ef07253679011efa78174d435fd3892
 $(zfs list -H -r -t filesystem -o name -s name "${_ds_source_base}")
 EOF_9ef07253679011efa78174d435fd3892
 
     # Check the existence of all intermediate datasets and their shapshots
     _idx=1
-    while array_tryget _ds _ds_tree ${_idx}; do
+    while farray_tryget _ds _ds_tree ${_idx}; do
         if  ! zfs get -H name "${_ds}@${_snapshot_name}" >/dev/null 2>&1; then
             err "child dataset (snapshot) does not exist: ${_ds}@${_snapshot_name}" 1>&2
             return 1
@@ -550,24 +552,24 @@
         _idx=$((${_idx} + 1))
     done
 
-    array_create _cloned_datasets
-    alist_create _local_props
+    farray_create _cloned_datasets
+    falist_create _local_props
 
     #
     # 1. Clone with "safe" canmount settings
     #
 
     _idx=1
-    while array_tryget _ds _ds_tree ${_idx}; do
+    while farray_tryget _ds _ds_tree ${_idx}; do
         # Determine the relative name of the dataset
         _ds_relname="${_ds#${_ds_source_base}}"
 
         # Need to determine in *every* case (local, default, received, ...)
         _ds_canmount="$(zfs get -H -o value canmount "${_ds}")"
 
-        alist_clear _local_props
+        falist_clear _local_props
         while IFS=$'\t' read -r _prop _propval ; do
-            alist_set _local_props "${_prop}" "${_propval}"
+            falist_set _local_props "${_prop}" "${_propval}"
         done <<EOF_ce8c76187f33471f8e8c1607ed09c42e
 $(zfs get -H -o property,value -s local,received all "${_ds}")
 EOF_ce8c76187f33471f8e8c1607ed09c42e
@@ -587,7 +589,7 @@
         # Copy all local props with the exception of canmount and mountpoint
         _arg_other_clone_props=""
         _idx_lp=1
-        while alist_tryget_key_at_index _prop _local_props ${_idx_lp}; do
+        while falist_tryget_key_at_index _prop _local_props ${_idx_lp}; do
             if [ "${_prop}" = "mountpoint" ]; then
                 _idx_lp=$((${_idx_lp} + 1))
                 continue
@@ -596,7 +598,7 @@
                 _idx_lp=$((${_idx_lp} + 1))
                 continue
             fi
-            alist_tryget_value_at_index _propvalue _local_props ${_idx_lp}
+            falist_tryget_value_at_index _propvalue _local_props ${_idx_lp}
             _arg_other_clone_props="${_arg_other_clone_props} -o ${_prop}=${_propvalue}"
             _idx_lp=$((${_idx_lp} + 1))
         done
@@ -604,7 +606,7 @@
         if ! checkyes _opt_dry_run; then
             echo "Cloning ${_ds}@${_snapshot_name} into ${_ds_dest}${_ds_relname} with ${_arg_canmount} ${_arg_other_clone_props}"
             if zfs clone ${_arg_canmount} ${_arg_other_clone_props} "${_ds}@${_snapshot_name}" "${_ds_dest}${_ds_relname}"; then
-                array_append _cloned_datasets "${_ds_dest}${_ds_relname}"
+                farray_append _cloned_datasets "${_ds_dest}${_ds_relname}"
             else
                 if ! checkyes _opt_keep; then
                     _destroy_datasets _cloned_datasets || true
@@ -622,7 +624,7 @@
     #    also handle canmount.
     #
     _idx=1
-    while array_tryget _ds _ds_tree ${_idx}; do
+    while farray_tryget _ds _ds_tree ${_idx}; do
         # Determine the relative name of the dataset
         _ds_relname="${_ds#${_ds_source_base}}"
 
@@ -662,7 +664,7 @@
         fi
         _idx=$((${_idx} + 1))
     done
-    array_destroy _cloned_datasets
+    farray_destroy _cloned_datasets
     return 0
 }
 
@@ -801,7 +803,7 @@
 #: Destruction is done in the reverse order.
 #:
 _destroy_datasets() {
-    array_reversed_for_each "$1" _destroy_datasets_destroy
+    farray_reversed_for_each "$1" _destroy_datasets_destroy
 }