diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 18:38:25 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 18:38:25 +0900 |
commit | f507f6f52d205293d16c1fae9de58ef641d5190a (patch) | |
tree | aea5ff08db517807441ee89f36d12f8f38524926 /buildstream/sandbox/_mount.py | |
parent | 97110ee4a93afac3230e98da56a535f45554b338 (diff) | |
download | buildstream-f507f6f52d205293d16c1fae9de58ef641d5190a.tar.gz |
sandbox/_mount.py: Renamed _mounter.py
Disambiguate with the Mount and MountMap classes, which were
accidentally added to public API.
Diffstat (limited to 'buildstream/sandbox/_mount.py')
-rw-r--r-- | buildstream/sandbox/_mount.py | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/buildstream/sandbox/_mount.py b/buildstream/sandbox/_mount.py deleted file mode 100644 index f78d3aa3d..000000000 --- a/buildstream/sandbox/_mount.py +++ /dev/null @@ -1,125 +0,0 @@ -import sys -from contextlib import contextmanager - -from .._exceptions import SandboxError -from .. import utils, _signals - - -# A class to wrap the `mount` and `umount` commands -class Mount(object): - @classmethod - def _mount(cls, dest, src=None, mount_type=None, - stdout=sys.stdout, stderr=sys.stderr, options=None, - flags=None): - - argv = [utils.get_host_tool('mount')] - if mount_type: - argv.extend(['-t', mount_type]) - if options: - argv.extend(['-o', options]) - if flags: - argv.extend(flags) - - if src is not None: - argv += [src] - argv += [dest] - - status, _ = utils._call( - argv, - terminate=True, - stdout=stdout, - stderr=stderr - ) - - if status != 0: - raise SandboxError('`{}` failed with exit code {}' - .format(' '.join(argv), status)) - - return dest - - @classmethod - def _umount(cls, path, stdout=sys.stdout, stderr=sys.stderr): - - cmd = [utils.get_host_tool('umount'), '-R', path] - status, _ = utils._call( - cmd, - terminate=True, - stdout=stdout, - stderr=stderr - ) - - if status != 0: - raise SandboxError('`{}` failed with exit code {}' - .format(' '.join(cmd), status)) - - # mount() - # - # A wrapper for the `mount` command. The device is unmounted when - # the context is left. - # - # Args: - # dest (str) - The directory to mount to - # src (str) - The directory to mount - # stdout (file) - stdout - # stderr (file) - stderr - # mount_type (str|None) - The mount type (can be omitted or None) - # kwargs - Arguments to pass to the mount command, such as `ro=True` - # - # Yields: - # (str) The path to the destination - # - @classmethod - @contextmanager - def mount(cls, dest, src=None, stdout=sys.stdout, - stderr=sys.stderr, mount_type=None, **kwargs): - - def kill_proc(): - cls._umount(dest, stdout, stderr) - - options = ','.join([key for key, val in kwargs.items() if val]) - - with _signals.terminator(kill_proc): - yield cls._mount(dest, src, mount_type, stdout=stdout, stderr=stderr, options=options) - - cls._umount(dest, stdout, stderr) - - # bind_mount() - # - # Mount a directory to a different location (a hardlink for all - # intents and purposes). The directory is unmounted when the - # context is left. - # - # Args: - # dest (str) - The directory to mount to - # src (str) - The directory to mount - # stdout (file) - stdout - # stderr (file) - stderr - # kwargs - Arguments to pass to the mount command, such as `ro=True` - # - # Yields: - # (str) The path to the destination - # - # While this is equivalent to `mount --rbind`, this option may not - # exist and can be dangerous, requiring careful cleanupIt is - # recommended to use this function over a manual mount invocation. - # - @classmethod - @contextmanager - def bind_mount(cls, dest, src=None, stdout=sys.stdout, - stderr=sys.stderr, **kwargs): - - def kill_proc(): - cls._umount(dest, stdout, stderr) - - kwargs['rbind'] = True - options = ','.join([key for key, val in kwargs.items() if val]) - - path = cls._mount(dest, src, None, stdout, stderr, options) - - with _signals.terminator(kill_proc): - # Make the rbind a slave to avoid unmounting vital devices in - # /proc - cls._mount(dest, flags=['--make-rslave']) - yield path - - cls._umount(dest, stdout, stderr) |