diff options
author | Richard Maw <richard.maw@gmail.com> | 2015-11-21 21:04:45 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2015-11-21 21:14:20 +0000 |
commit | a658ede1ed5b37700f9470b5e78cbf4f184489bb (patch) | |
tree | e53cb775a5af98e93e33c6e55e6087fc5c73b9cd | |
parent | c38fcea43111826b8ea499813fb10459ed29dae8 (diff) | |
download | sandboxlib-a658ede1ed5b37700f9470b5e78cbf4f184489bb.tar.gz |
sandboxlib.chroot: Make mount commands nicer
It's more natural to not pass -t when bind-mounting,
to not pass -o when no options are required,
and to not pass the source path when remounting.
-rw-r--r-- | sandboxlib/chroot.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py index b5d2da5..a787c93 100644 --- a/sandboxlib/chroot.py +++ b/sandboxlib/chroot.py @@ -101,8 +101,18 @@ def mount(source, path, mount_type, mount_options): # little sad. It's possible to call the libc's mount() function # directly from Python using the 'ctypes' library, and perhaps we # should do that instead. - argv = [ - 'mount', '-t', mount_type, '-o', mount_options, source, path] + def is_none(value): + return value in (None, 'none', '') + + argv = ['mount'] + if not is_none(mount_type): + argv.extend(('-t', mount_type)) + if not is_none(mount_options): + argv.extend(('-o', mount_options)) + if not is_none(source): + argv.append(source) + argv.append(path) + exit, out, err = sandboxlib._run_command( argv, stdout=sandboxlib.CAPTURE, stderr=sandboxlib.CAPTURE) |