|
1 | 1 | __author__ = "desultory" |
2 | | -__version__ = "6.3.0" |
| 2 | +__version__ = "6.4.0" |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from typing import Union |
@@ -54,6 +54,18 @@ def _resolve_dev(self, device_path) -> str: |
54 | 54 | return device_path |
55 | 55 |
|
56 | 56 |
|
| 57 | +def _find_mountpoint(self, path: str) -> str: |
| 58 | + """ Finds the mountpoint of a file or directory, |
| 59 | + Checks if the parent dir is a mountpoint, if not, recursively checks the parent dir.""" |
| 60 | + check_path = Path(path).resolve() |
| 61 | + parent = check_path.parent if not check_path.is_dir() else check_path |
| 62 | + if str(parent) in self["_mounts"]: |
| 63 | + return str(parent) |
| 64 | + elif parent == Path("/"): # The root mount SHOULD always be found... |
| 65 | + raise AutodetectError("Mountpoint not found for: %s" % path) |
| 66 | + return _find_mountpoint(self, parent.parent) |
| 67 | + |
| 68 | + |
57 | 69 | def _resolve_device_mountpoint(self, device) -> str: |
58 | 70 | """Gets the mountpoint of a device based on the device path.""" |
59 | 71 | for mountpoint, mount_info in self["_mounts"].items(): |
@@ -82,12 +94,9 @@ def _resolve_overlay_lower_device(self, mountpoint) -> dict: |
82 | 94 |
|
83 | 95 | while self["_mounts"][mountpoint]["fstype"] == "overlay": |
84 | 96 | lowerdir = _resolve_overlay_lower_dir(self, mountpoint) |
85 | | - lower_path = Path(lowerdir) |
86 | | - while str(lower_path) not in self["_mounts"]: |
87 | | - lower_path = lower_path.parent |
88 | | - if lower_path == Path("/"): |
89 | | - raise AutodetectError("Lowerdir mount not found: %s" % lowerdir) |
90 | | - mountpoint = str(lower_path) |
| 97 | + mountpoint = _find_mountpoint(self, lowerdir) |
| 98 | + if mountpoint == "/": # The lowerdir mount should never be the root mount |
| 99 | + raise AutodetectError("Lowerdir mount not found: %s" % lowerdir) |
91 | 100 |
|
92 | 101 | return self["_mounts"][mountpoint]["device"] |
93 | 102 |
|
|
0 commit comments