btrbk: fix mount point resolving

Searching for longest match in mountinfo is plain wrong, as it is
possible (while very uncommon) to have a later mount point shadowing a
longer mount.
pull/293/head
Axel Burri 2019-07-18 15:28:21 +02:00
parent fb3d4d96ff
commit 8ffd7ac1e9
1 changed files with 4 additions and 7 deletions

11
btrbk
View File

@ -1917,18 +1917,15 @@ sub btrfs_mountpoint
$mountinfo_cache{$vol->{MACHINE_ID}} = $mountinfo;
}
# find longest match
# find mount point (last mountinfo entry matching realpath)
$realpath .= '/' unless($realpath =~ /\/$/); # correctly handle root path="/"
my $mountpoint;
foreach(@$mountinfo) {
foreach(reverse @$mountinfo) {
my $mnt_path = $_->{mount_point};
$mnt_path .= '/' unless($mnt_path =~ /\/$/); # correctly handle root path="/"
if($realpath =~ /^\Q$mnt_path\E/) {
if((not $mountpoint) || (length($_->{mount_point}) >= length($mountpoint->{mount_point}))) {
# pick longest match (last if same size).
# NOTE: on duplicate match (mounted multiple times, e.g. autofs), use the latest in list.
$mountpoint = $_;
}
$mountpoint = $_;
last;
}
}
unless($mountpoint) {