d "svp=$svp # subvolume path"
fi
- # Assumes we are in the 21st century.
- ls -1dvrq $root_dir/btrbk/$subvol_dir.20* >$tmpf
- mapfile -t snaps <$tmpf
- if [[ ! ${snaps[*]} ]]; then
+ # note: relying on null glob
+ ls_args=($root_dir/btrbk/$subvol_dir.20*)
+ if (( ${#ls_args[@]} )); then
+ # Assumes we are in the 21st century.
+ ls -1dvrq $root_dir/btrbk/$subvol_dir.20* >$tmpf
+ mapfile -t snaps <$tmpf
+ else
# no snapshots yet
# TODO: make this an error and override with a cli flag
echo "$0: warning: no snapshots found at $root_dir/btrbk/$subvol_dir.20*. this is expected for a brand new volume"
# last_snap by date.
last_snap="${snaps[0]}"
+
+ case $last_snap in
+ $root_dir/btrbk/$subvol_dir.20*) : ;;
+ *)
+ echo "$0: error: unexpected last_snap:$last_snap"
+ exit 1
+ ;;
+ esac
+
+ d last_snap=$last_snap
## alternate slower alternative which would not rely on ls sorting:
# last_snap=$(
# for s in ${snaps[@]}; do
# echo "$0: error: could not find latest snapshot for $svp among ${snaps[*]}" >&2
# exit 1
# fi
- d last_snap=$last_snap
if [[ ! -e $svp ]]; then
echo "$0: warning: subvol does not exist: $svp"
if [[ $cgen -gt $last_received_cgen ]]; then
last_received_cgen=$cgen
last_received=$f
- elif [[ $last_received ]]; then
+ elif [[ $last_received ]]; then
# optimization: we are looking in reverse order by date, so if
# we find one that has a lesser cgen, assume the rest will all
# be lesser.