btrbk: cleanup: add config_subsection

pull/411/head
Axel Burri 2021-07-24 20:11:32 +02:00
parent 247cb37acf
commit c1610c754d
1 changed files with 18 additions and 27 deletions

45
btrbk
View File

@ -3364,6 +3364,14 @@ sub vinfo_snapshot_root($)
} }
sub config_subsection($$;$)
{
my $config = shift || die;
my $context = shift || die;
die if grep($_->{CONTEXT} ne $context, @{$config->{SUBSECTION}});
return @{$config->{SUBSECTION}};
}
sub vinfo_subsection($$;$) sub vinfo_subsection($$;$)
{ {
# if config: must have SUBSECTION key # if config: must have SUBSECTION key
@ -3371,32 +3379,20 @@ sub vinfo_subsection($$;$)
my $config_or_vinfo = shift || die; my $config_or_vinfo = shift || die;
my $context = shift || die; my $context = shift || die;
my $include_aborted = shift; my $include_aborted = shift;
my $config_list; my @config_list;
my $vinfo_check; my $vinfo_check;
if(exists($config_or_vinfo->{SUBSECTION})) { if(exists($config_or_vinfo->{SUBSECTION})) {
# config @config_list = config_subsection($config_or_vinfo, $context);
$config_list = $config_or_vinfo->{SUBSECTION};
} }
else { else {
# vinfo @config_list = config_subsection($config_or_vinfo->{CONFIG}, $context);
$config_list = $config_or_vinfo->{CONFIG}->{SUBSECTION};
die unless($config_or_vinfo->{CONFIG}->{VINFO} == $config_or_vinfo); # check back reference die unless($config_or_vinfo->{CONFIG}->{VINFO} == $config_or_vinfo); # check back reference
} }
# for now be paranoid and check all contexts return map {
my @ret;
foreach (@$config_list) {
die unless($_->{CONTEXT} eq $context);
next if((not $include_aborted) && $_->{ABORTED});
die unless($_->{VINFO});
die unless($_->{VINFO}->{CONFIG});
die unless($_->{VINFO} == $_->{VINFO}->{CONFIG}->{VINFO}); # check all back references die unless($_->{VINFO} == $_->{VINFO}->{CONFIG}->{VINFO}); # check all back references
push @ret, $_->{VINFO}; ($include_aborted || !$_->{ABORTED}) ? $_->{VINFO} : ()
} } @config_list;
return @ret;
# much simpler implementation, without checks
#return map { $_->{ABORTED} ? () : $_->{VINFO} } @$config_list;
} }
@ -6264,15 +6260,12 @@ MAIN:
# #
# expand subvolume globs (wildcards) # expand subvolume globs (wildcards)
# #
foreach my $config_vol (@{$config->{SUBSECTION}}) { foreach my $config_vol (config_subsection($config, "volume")) {
die unless($config_vol->{CONTEXT} eq "volume");
# read-in subvolume list (and expand globs) only if needed # read-in subvolume list (and expand globs) only if needed
next unless(grep defined($_->{GLOB_CONTEXT}), @{$config_vol->{SUBSECTION}}); next unless(grep defined($_->{GLOB_CONTEXT}), @{$config_vol->{SUBSECTION}});
my $sroot_glob; # read-in late my $sroot_glob; # read-in late
my @vol_subsection_expanded; my @vol_subsection_expanded;
foreach my $config_subvol (@{$config_vol->{SUBSECTION}}) { foreach my $config_subvol (config_subsection($config_vol, "subvolume")) {
die unless($config_subvol->{CONTEXT} eq "subvolume");
if($config_subvol->{GLOB_CONTEXT}) { if($config_subvol->{GLOB_CONTEXT}) {
my $globs = $config_subvol->{rel_path}; my $globs = $config_subvol->{rel_path};
@ -6335,12 +6328,10 @@ MAIN:
# #
# create vinfo nodes (no readin yet) # create vinfo nodes (no readin yet)
# #
foreach my $config_vol (@{$config->{SUBSECTION}}) { foreach my $config_vol (config_subsection($config, "volume")) {
die unless($config_vol->{CONTEXT} eq "volume");
my $sroot = vinfo($config_vol->{url}, $config_vol); my $sroot = vinfo($config_vol->{url}, $config_vol);
vinfo_assign_config($sroot); vinfo_assign_config($sroot);
foreach my $config_subvol (@{$config_vol->{SUBSECTION}}) { foreach my $config_subvol (config_subsection($config_vol, "subvolume")) {
die unless($config_subvol->{CONTEXT} eq "subvolume");
my $svol = vinfo_child($sroot, $config_subvol->{rel_path}, $config_subvol); my $svol = vinfo_child($sroot, $config_subvol->{rel_path}, $config_subvol);
# TODO: add config option "snapshot_path", reuse snaproot with same URL # TODO: add config option "snapshot_path", reuse snaproot with same URL
my $snapshot_dir = config_key($svol, "snapshot_dir", prefix => '/') // ""; my $snapshot_dir = config_key($svol, "snapshot_dir", prefix => '/') // "";