X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/e620e51bbb86b3fc2776e4d041df928391f944ab..0841a74bf82f59e316d8fbcfdff415bb003bc84e:/tools/helpers/mount.py diff --git a/tools/helpers/mount.py b/tools/helpers/mount.py index 1d61037..236ff5b 100644 --- a/tools/helpers/mount.py +++ b/tools/helpers/mount.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os import tools.helpers.run +from tools.helpers.version import versiontuple, kernel_version def ismount(folder): @@ -109,17 +110,20 @@ def umount_all(args, folder): if ismount(mountpoint): raise RuntimeError("Failed to umount: " + mountpoint) -def mount(args, source, destination, create_folders=True, umount=False, readonly=True, mount_type=None, options=None): +def mount(args, source, destination, create_folders=True, umount=False, + readonly=True, mount_type=None, options=None, force=True): """ Mount and create necessary directory structure. :param umount: when destination is already a mount point, umount it first. + :param force: attempt mounting even if the mount point already exists. """ # Check/umount destination if ismount(destination): if umount: umount_all(args, destination) else: - return + if not force: + return # Check/create folders if not os.path.exists(destination): @@ -146,3 +150,31 @@ def mount(args, source, destination, create_folders=True, umount=False, readonly # Verify, that it has worked if not ismount(destination): raise RuntimeError("Mount failed: " + source + " -> " + destination) + +def mount_overlay(args, lower_dirs, destination, upper_dir=None, work_dir=None, + create_folders=True, readonly=True): + """ + Mount an overlay. + """ + dirs = [*lower_dirs] + options = ["lowerdir=" + (":".join(lower_dirs))] + + if upper_dir: + dirs.append(upper_dir) + dirs.append(work_dir) + options.append("upperdir=" + upper_dir) + options.append("workdir=" + work_dir) + + if kernel_version() >= versiontuple("4.17"): + options.append("xino=off") + + for dir_path in dirs: + if not os.path.exists(dir_path): + if create_folders: + tools.helpers.run.user(args, ["mkdir", "-p", dir_path]) + else: + raise RuntimeError("Mount failed, folder does not exist: " + + dir_path) + + mount(args, "overlay", destination, mount_type="overlay", options=options, + readonly=readonly, create_folders=create_folders, force=True)