From 5104d016a178a0ad1938bd15baaa1170fede6a89 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 15 Oct 2023 07:05:54 +0200 Subject: _mountinfo: fix mountpoint_for_path() The correct mount is not the longest one but the last one, because an earlier longer match could be bind-mounted over. This is also shorter and simpler. --- lbup/_mountinfo.py | 15 +++++---------- lbup/targets.py | 2 ++ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lbup/_mountinfo.py b/lbup/_mountinfo.py index bbced58..0328131 100644 --- a/lbup/_mountinfo.py +++ b/lbup/_mountinfo.py @@ -142,15 +142,10 @@ class MountInfo: def mountpoint_for_path(self, path): """ - Find the longest mountpoint that is a parent of path. + Find the mount entry which contains path. """ - best_match = None - for e in self.mounts.values(): - if (path in e.mount_point and - (best_match is None or len(best_match) < len(e.mount_point))): - best_match = e.mount_point + for mount in reversed(self.mounts.values()): + if path in mount.mount_point: + return mount - if best_match is None: - raise LookupError('No mountpoint for', path) - - return best_match + raise LookupError('No mountpoint for', path) diff --git a/lbup/targets.py b/lbup/targets.py index bd53b1e..3f86563 100644 --- a/lbup/targets.py +++ b/lbup/targets.py @@ -49,6 +49,8 @@ def _resolve_mntdev(mntinfo, dirs): mountpoint = None fstype = None for d in dirs: + d = AbsPath(d) + mp = mntinfo.mountpoint_for_path(d) e = list(mntinfo.entries_for_mountpoint(mp)) -- cgit v1.2.3