+ done
+ d last_received_cgen=$last_received_cgen
+ d last_received=$last_received
+
+ # Get last_snap by date.
+ # when a btrbk bugfix makes it into the distro,
+ # we might replace this with btrbk list latest /mnt/root/$vol | ...
+ last_snap=$(
+ for s in ${snaps[@]}; do
+ f=${s##*/}
+ unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
+ printf "%s %s\n" $unix_time $s
+ done | sort -r | head -n 1 | awk '{print $2}'
+ )
+ if [[ ! $last_snap ]]; then
+ # should not happen.
+ 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"
+ echo "$0 assuming this host was just for receiving and latest snap is freshest"
+ freshest_snap=$last_snap
+ stale=true
+ stale-file
+ continue
+ fi