|
1 | 1 | __author__ = "desultory" |
2 | | -__version__ = "6.4.0" |
| 2 | +__version__ = "6.5.0" |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from typing import Union |
@@ -55,7 +55,7 @@ def _resolve_dev(self, device_path) -> str: |
55 | 55 |
|
56 | 56 |
|
57 | 57 | def _find_mountpoint(self, path: str) -> str: |
58 | | - """ Finds the mountpoint of a file or directory, |
| 58 | + """Finds the mountpoint of a file or directory, |
59 | 59 | Checks if the parent dir is a mountpoint, if not, recursively checks the parent dir.""" |
60 | 60 | check_path = Path(path).resolve() |
61 | 61 | parent = check_path.parent if not check_path.is_dir() else check_path |
@@ -341,32 +341,34 @@ def get_blkid_info(self, device=None) -> dict: |
341 | 341 |
|
342 | 342 |
|
343 | 343 | @contains("init_target", "init_target must be set", raise_exception=True) |
344 | | -@contains( |
345 | | - "autodetect_init_mount", "Skipping init mount autodetection, autodetect_init_mount is disabled.", log_level=30 |
346 | | -) |
| 344 | +@contains("autodetect_init_mount", "Init mount autodetection disabled, skipping.", log_level=30) |
347 | 345 | @contains("hostonly", "Skipping init mount autodetection, hostonly mode is disabled.", log_level=30) |
348 | | -def autodetect_init_mount(self, parent=None) -> None: |
| 346 | +def autodetect_init_mount(self) -> None: |
349 | 347 | """Checks the parent directories of init_target, if the path is a mountpoint, add it to late_mounts.""" |
350 | | - if not parent: |
351 | | - parent = self["init_target"].parent |
352 | | - if parent == Path("/"): |
| 348 | + init_mount = _find_mountpoint(self, self["init_target"]) |
| 349 | + if init_mount == "/": |
353 | 350 | return |
354 | | - if str(parent) in self["_mounts"]: |
355 | | - self.logger.info("Detected init mount: %s" % colorize(parent, "cyan")) |
356 | | - mount_name = str(parent).removeprefix("/") |
357 | | - mount_dest = str(parent) |
358 | | - mount_device = self["_mounts"][str(parent)]["device"] |
359 | | - mount_type = self["_mounts"][str(parent)]["fstype"] |
360 | | - mount_options = self["_mounts"][str(parent)]["options"] |
361 | | - blkid_info = self["_blkid_info"][mount_device] |
362 | | - mount_source_type, mount_source = _get_mount_source_type(self, blkid_info, with_val=True) |
363 | | - self["late_mounts"][mount_name] = { |
364 | | - "destination": mount_dest, |
365 | | - mount_source_type: mount_source, |
366 | | - "type": mount_type, |
367 | | - "options": mount_options, |
368 | | - } |
369 | | - autodetect_init_mount(self, parent.parent) |
| 351 | + |
| 352 | + if init_mount in self["late_mounts"]: |
| 353 | + return self.logger.debug("Init mount already detected: %s" % init_mount) |
| 354 | + |
| 355 | + if init_mount not in self["_mounts"]: |
| 356 | + raise AutodetectError("Init mount not found in host mounts: %s" % init_mount) |
| 357 | + |
| 358 | + self.logger.info("Detected init mount: %s" % colorize(init_mount, "cyan")) |
| 359 | + mount_name = init_mount.removeprefix("/") |
| 360 | + mount_dest = init_mount |
| 361 | + mount_device = self["_mounts"][init_mount]["device"] |
| 362 | + mount_type = self["_mounts"][init_mount]["fstype"] |
| 363 | + mount_options = self["_mounts"][init_mount]["options"] |
| 364 | + blkid_info = self["_blkid_info"][mount_device] |
| 365 | + mount_source_type, mount_source = _get_mount_source_type(self, blkid_info, with_val=True) |
| 366 | + self["late_mounts"][mount_name] = { |
| 367 | + "destination": mount_dest, |
| 368 | + mount_source_type: mount_source, |
| 369 | + "type": mount_type, |
| 370 | + "options": mount_options, |
| 371 | + } |
370 | 372 |
|
371 | 373 |
|
372 | 374 | @contains("hostonly", "Skipping virtual block device enumeration, hostonly mode is disabled.", log_level=30) |
|
0 commit comments