mirror of https://github.com/digint/btrbk
btrbk: action ls: allow multiple path arguments; soft fail on errors
parent
73c24e0495
commit
c5b3ebb808
111
btrbk
111
btrbk
|
@ -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,64 +5290,75 @@ MAIN:
|
||||||
#
|
#
|
||||||
# print accessible subvolumes for local path
|
# print accessible subvolumes for local path
|
||||||
#
|
#
|
||||||
my $path = $dir_args[0] || die;
|
my $exit_status = 0;
|
||||||
my $root_vol = vinfo($path, $config);
|
|
||||||
|
|
||||||
# map url to real path (we need to match against mount points below)
|
|
||||||
my $root_path = system_realpath($root_vol);
|
|
||||||
unless($root_path) {
|
|
||||||
ERROR "Cannot find real path for: $root_vol->{PATH}", @stderr;
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
$root_vol = vinfo($root_path, $config);
|
|
||||||
$root_path .= '/' unless($root_path =~ /\/$/); # append trailing slash
|
|
||||||
|
|
||||||
my $mountinfo = system_list_mountinfo($root_vol) || die;
|
|
||||||
$mountinfo_cache{$root_vol->{MACHINE_ID}} = $mountinfo;
|
|
||||||
|
|
||||||
my @data;
|
my @data;
|
||||||
my @path_hidden;
|
foreach my $path (@dir_args) {
|
||||||
foreach my $mnt (reverse @$mountinfo) {
|
my $root_vol = vinfo($path, $config);
|
||||||
my $mnt_path = $mnt->{mount_point};
|
|
||||||
$mnt_path .= '/' unless($mnt_path =~ /\/$/); # append trailing slash
|
|
||||||
|
|
||||||
if(($mnt->{fs_type} eq "btrfs") &&
|
# map url to real path (we need to match against mount points below)
|
||||||
(($root_path =~ /^\Q$mnt_path\E/) || ($mnt_path =~ /^\Q$root_path\E/)))
|
my $root_path = system_realpath($root_vol);
|
||||||
{
|
unless($root_path) {
|
||||||
$realpath_cache{$mnt->{mount_point}} = $mnt->{mount_point}; # we know those are real paths, prevents calling readlink in btrfs_mountpoint
|
ERROR "Cannot find real path for: $root_vol->{PATH}", @stderr;
|
||||||
my $vol = vinfo($mnt->{mount_point}, $config);
|
$exit_status = 1;
|
||||||
unless(vinfo_init_root($vol)) {
|
next;
|
||||||
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr;
|
}
|
||||||
exit 1;
|
$root_vol = vinfo($root_path, $config);
|
||||||
|
$root_path .= '/' unless($root_path =~ /\/$/); # append trailing slash
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
my $subvol_list = vinfo_subvol_list($vol);
|
my @path_hidden;
|
||||||
foreach my $svol ($vol, @$subvol_list) {
|
foreach my $mnt (reverse @$mountinfo) {
|
||||||
my $svol_path = $svol->{PATH};
|
my $mnt_path = $mnt->{mount_point};
|
||||||
$svol_path .= '/' unless($svol_path =~ /\/$/); # append trailing slash
|
$mnt_path .= '/' unless($mnt_path =~ /\/$/); # append trailing slash
|
||||||
|
|
||||||
next unless($svol_path =~ /^\Q$root_path\E/);
|
if(($mnt->{fs_type} eq "btrfs") &&
|
||||||
|
(($root_path =~ /^\Q$mnt_path\E/) || ($mnt_path =~ /^\Q$root_path\E/)))
|
||||||
if(grep { $svol_path =~ /^\Q$_\E/ } @path_hidden) {
|
{
|
||||||
DEBUG "subvolume is hidden by another mount point: $svol->{PRINT}";
|
$realpath_cache{$mnt->{mount_point}} = $mnt->{mount_point}; # we know those are real paths, prevents calling readlink in btrfs_mountpoint
|
||||||
|
my $vol = vinfo($mnt->{mount_point}, $config);
|
||||||
|
unless(vinfo_init_root($vol)) {
|
||||||
|
ERROR "Failed to fetch subvolume detail for: $vol->{PRINT}", @stderr;
|
||||||
|
$exit_status = 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
push @data, {
|
my $subvol_list = vinfo_subvol_list($vol);
|
||||||
%{$svol->{node}}, # copy node
|
foreach my $svol ($vol, @$subvol_list) {
|
||||||
mount_point => $svol->{VINFO_MOUNTPOINT}{PATH},
|
my $svol_path = $svol->{PATH};
|
||||||
mount_source => $svol->{node}{TREE_ROOT}{host_mount_source},
|
$svol_path .= '/' unless($svol_path =~ /\/$/); # append trailing slash
|
||||||
mount_subvolid => $mnt->{MNTOPS}{subvolid},
|
|
||||||
mount_subvolume => $mnt->{MNTOPS}{subvol},
|
next unless($svol_path =~ /^\Q$root_path\E/);
|
||||||
subvolume_path => $svol->{node}{path},
|
|
||||||
subvolume_rel_path => $svol->{node}{REL_PATH},
|
if(grep { $svol_path =~ /^\Q$_\E/ } @path_hidden) {
|
||||||
path => $svol->{PATH},
|
DEBUG "subvolume is hidden by another mount point: $svol->{PRINT}";
|
||||||
flags => ($svol->{node}{readonly} ? "readonly" : undef),
|
next;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
push @data, {
|
||||||
|
%{$svol->{node}}, # copy node
|
||||||
|
mount_point => $svol->{VINFO_MOUNTPOINT}{PATH},
|
||||||
|
mount_source => $svol->{node}{TREE_ROOT}{host_mount_source},
|
||||||
|
mount_subvolid => $mnt->{MNTOPS}{subvolid},
|
||||||
|
mount_subvolume => $mnt->{MNTOPS}{subvol},
|
||||||
|
subvolume_path => $svol->{node}{path},
|
||||||
|
subvolume_rel_path => $svol->{node}{REL_PATH},
|
||||||
|
path => $svol->{PATH},
|
||||||
|
flags => ($svol->{node}{readonly} ? "readonly" : undef),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
last if($root_path =~ /^\Q$mnt_path\E/);
|
||||||
|
push @path_hidden, ($mnt->{mount_point} . '/');
|
||||||
}
|
}
|
||||||
last if($root_path =~ /^\Q$mnt_path\E/);
|
|
||||||
push @path_hidden, ($mnt->{mount_point} . '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my @sorted = sort { $a->{path} cmp $b->{path} } @data;
|
my @sorted = sort { $a->{path} cmp $b->{path} } @data;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue