btrbk: action ls: allow multiple path arguments; soft fail on errors

pull/334/head
Axel Burri 2019-12-23 13:44:44 +01:00
parent 73c24e0495
commit c5b3ebb808
1 changed files with 61 additions and 50 deletions

25
btrbk
View File

@ -5038,7 +5038,7 @@ MAIN:
elsif ($command eq "ls") { elsif ($command eq "ls") {
$action_ls = 1; $action_ls = 1;
$fallback_default_config = 1; $fallback_default_config = 1;
$args_expected_min = $args_expected_max = 1; $args_expected_min = 1;
@dir_args = @ARGV; @dir_args = @ARGV;
} }
elsif ($command eq "diff") { elsif ($command eq "diff") {
@ -5290,22 +5290,31 @@ MAIN:
# #
# print accessible subvolumes for local path # print accessible subvolumes for local path
# #
my $path = $dir_args[0] || die; my $exit_status = 0;
my @data;
foreach my $path (@dir_args) {
my $root_vol = vinfo($path, $config); my $root_vol = vinfo($path, $config);
# map url to real path (we need to match against mount points below) # map url to real path (we need to match against mount points below)
my $root_path = system_realpath($root_vol); my $root_path = system_realpath($root_vol);
unless($root_path) { unless($root_path) {
ERROR "Cannot find real path for: $root_vol->{PATH}", @stderr; ERROR "Cannot find real path for: $root_vol->{PATH}", @stderr;
exit 1; $exit_status = 1;
next;
} }
$root_vol = vinfo($root_path, $config); $root_vol = vinfo($root_path, $config);
$root_path .= '/' unless($root_path =~ /\/$/); # append trailing slash $root_path .= '/' unless($root_path =~ /\/$/); # append trailing slash
my $mountinfo = system_list_mountinfo($root_vol) || die; my $mountinfo = $mountinfo_cache{$root_vol->{MACHINE_ID}};
unless($mountinfo) {
$mountinfo = system_list_mountinfo($root_vol);
unless($mountinfo) {
$exit_status = 1;
next;
}
$mountinfo_cache{$root_vol->{MACHINE_ID}} = $mountinfo; $mountinfo_cache{$root_vol->{MACHINE_ID}} = $mountinfo;
}
my @data;
my @path_hidden; my @path_hidden;
foreach my $mnt (reverse @$mountinfo) { foreach my $mnt (reverse @$mountinfo) {
my $mnt_path = $mnt->{mount_point}; my $mnt_path = $mnt->{mount_point};
@ -5318,7 +5327,8 @@ MAIN:
my $vol = vinfo($mnt->{mount_point}, $config); my $vol = vinfo($mnt->{mount_point}, $config);
unless(vinfo_init_root($vol)) { unless(vinfo_init_root($vol)) {
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr; ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr;
exit 1; $exit_status = 1;
next;
} }
my $subvol_list = vinfo_subvol_list($vol); my $subvol_list = vinfo_subvol_list($vol);
@ -5349,6 +5359,7 @@ MAIN:
last if($root_path =~ /^\Q$mnt_path\E/); last if($root_path =~ /^\Q$mnt_path\E/);
push @path_hidden, ($mnt->{mount_point} . '/'); push @path_hidden, ($mnt->{mount_point} . '/');
} }
}
my @sorted = sort { $a->{path} cmp $b->{path} } @data; my @sorted = sort { $a->{path} cmp $b->{path} } @data;
if($output_format) { if($output_format) {
@ -5356,7 +5367,7 @@ MAIN:
} else { } else {
print join("\n", map { $_->{path} } @sorted) . "\n"; print join("\n", map { $_->{path} } @sorted) . "\n";
} }
exit 0; exit $exit_status;
} }