last_received_cgen=0
for f in ${snaps[@]}; do
show="$(btrfs sub show $f)"
if echo "$show" | grep -E "Received UUID:\s+[[:alnum:]]" &>/dev/null; then
last_received_cgen=0
for f in ${snaps[@]}; do
show="$(btrfs sub show $f)"
if echo "$show" | grep -E "Received UUID:\s+[[:alnum:]]" &>/dev/null; then
cgen=$(echo "$show" | sed -rn 's,^\s*Gen at creation:\s+([0-9]+).*,\1,p')
if [[ $cgen -gt $last_received_cgen ]]; then
last_received_cgen=$cgen
cgen=$(echo "$show" | sed -rn 's,^\s*Gen at creation:\s+([0-9]+).*,\1,p')
if [[ $cgen -gt $last_received_cgen ]]; then
last_received_cgen=$cgen
stale=true
# fresh if $svp has $last_snap as a snapshot,
if btrfs sub show $svp 2>/dev/null | sed '0,/^\s*Snapshot(s):/d;s/^\s*//' | \
stale=true
# fresh if $svp has $last_snap as a snapshot,
if btrfs sub show $svp 2>/dev/null | sed '0,/^\s*Snapshot(s):/d;s/^\s*//' | \
stale=false
else # or else $svp is a snapshot of $last_snap. we use a uuid
# comparison, which if I remember from the docs, is a bit more
stale=false
else # or else $svp is a snapshot of $last_snap. we use a uuid
# comparison, which if I remember from the docs, is a bit more