From d9dbc432c35ea3e8a199b0048681db521492ca0a Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sun, 26 Jun 2022 14:53:05 +0200 Subject: [PATCH] btrbk: add get_btrbk_snapshot_siblings replacement for: vinfo_subvol_list(..., btrbk_direct_leaf => ) --- btrbk | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/btrbk b/btrbk index 6515555..307d74f 100755 --- a/btrbk +++ b/btrbk @@ -3607,6 +3607,41 @@ sub _related_nodes($;@) } +sub get_btrbk_snapshot_siblings($;@) +{ + my $sroot = shift || die; + my %opts = @_; + my $readonly = $opts{readonly}; + my $tag; + my $subtree; + if(my $rvol = $opts{refvol}) { + $tag = $rvol->{node}{BTRBK_TAG}; + $subtree = $rvol->{node}{TOP_LEVEL}{SUBTREE}; + TRACE "Creating snapshot siblings list for: $rvol->{PRINT}" if($do_trace); + } elsif($opts{name}) { + my $family = $opts{family} // "btrbk"; + $tag = join(":", $opts{name}, $family, ($sroot->{NODE_SUBDIR} // "")); + $subtree = $sroot->{node}{SUBTREE}; + TRACE "Creating snapshot siblings list for: $sroot->{PRINT}/$opts{name}.*" if($do_trace); + } else { + die; + } + return [] unless defined($tag); + my @ret = map { vinfo_resolved($_, $sroot) // die _fs_path($_) . " is not in $sroot->{PRINT}" + } grep { + defined($_->{BTRBK_TAG}) && ($_->{BTRBK_TAG} eq $tag) && + (!$readonly || $_->{readonly}) + } @$subtree; + TRACE "Found " . scalar(@ret) . " btrbk snapshot siblings for tag: $tag" if($do_trace); + if($opts{sort} && ($opts{sort} eq "desc")) { + @ret = sort { cmp_date($b->{node}{BTRBK_DATE}, $a->{node}{BTRBK_DATE}) } @ret; + } elsif($opts{sort}) { + @ret = sort { cmp_date($a->{node}{BTRBK_DATE}, $b->{node}{BTRBK_DATE}) } @ret; + } + return \@ret; +} + + # returns parent, along with clone sources sub get_best_parent($$;@) {