diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-10-15 07:05:54 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-10-15 07:08:05 +0200 |
commit | 5104d016a178a0ad1938bd15baaa1170fede6a89 (patch) | |
tree | 1de1e1bbf9a93e8b73b5aa15084c907f1f9b18fb | |
parent | 617ceee6766bd9459b9d938508ed8d52ca9674fd (diff) |
_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.
-rw-r--r-- | lbup/_mountinfo.py | 15 | ||||
-rw-r--r-- | 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)) |