mirror of https://github.com/digint/btrbk
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
parent
fb3d4d96ff
commit
8ffd7ac1e9
9
btrbk
9
btrbk
|
@ -1917,18 +1917,15 @@ sub btrfs_mountpoint
|
||||||
$mountinfo_cache{$vol->{MACHINE_ID}} = $mountinfo;
|
$mountinfo_cache{$vol->{MACHINE_ID}} = $mountinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
# find longest match
|
# find mount point (last mountinfo entry matching realpath)
|
||||||
$realpath .= '/' unless($realpath =~ /\/$/); # correctly handle root path="/"
|
$realpath .= '/' unless($realpath =~ /\/$/); # correctly handle root path="/"
|
||||||
my $mountpoint;
|
my $mountpoint;
|
||||||
foreach(@$mountinfo) {
|
foreach(reverse @$mountinfo) {
|
||||||
my $mnt_path = $_->{mount_point};
|
my $mnt_path = $_->{mount_point};
|
||||||
$mnt_path .= '/' unless($mnt_path =~ /\/$/); # correctly handle root path="/"
|
$mnt_path .= '/' unless($mnt_path =~ /\/$/); # correctly handle root path="/"
|
||||||
if($realpath =~ /^\Q$mnt_path\E/) {
|
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) {
|
unless($mountpoint) {
|
||||||
|
|
Loading…
Reference in New Issue