diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-02 20:37:37 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-02 20:51:23 +0900 |
commit | a3f1a8ef83a0996eafeb7b433e60cc3243374991 (patch) | |
tree | f193f25e64adddfc86d8b735b25ca838c8baf22a /buildstream/sandbox | |
parent | 859125628d6976ae70afed82323f2600a8b6572a (diff) | |
download | buildstream-a3f1a8ef83a0996eafeb7b433e60cc3243374991.tar.gz |
_sandboxbwrap.py: Force cleanup when in interactive mode
When running a sandbox in interactive mode (implies `bst shell` was launched
or an interactive shell for debugging), dont bail out when cleaning up
directories which are not empty.
We treat this as a bug, if any of the base sandbox directories (/dev,
/tmp or /proc) are not empty when tearing down the sandbox, because
it would indicate something is wrong with bwrap.
When in interactive mode however, the user/project may have mounted
additional directories inside these base directories; for which we
need to create intermediate directories for the mount.
Instead of keeping track of every intermediate directory, just force
remove in interactive mode, as this is safe.
Ideally, we should fix upstream bwrap to cleanup the debris it creates
when exiting.
Diffstat (limited to 'buildstream/sandbox')
-rw-r--r-- | buildstream/sandbox/_sandboxbwrap.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py index c40565814..fc47be31e 100644 --- a/buildstream/sandbox/_sandboxbwrap.py +++ b/buildstream/sandbox/_sandboxbwrap.py @@ -24,6 +24,7 @@ import time import errno import signal import subprocess +import shutil from contextlib import ExitStack import psutil @@ -208,14 +209,30 @@ class SandboxBwrap(Sandbox): continue base_directory = os.path.join(root_mount_source, basedir) - try: - os.rmdir(base_directory) - except FileNotFoundError: - # ignore this, if bwrap cleaned up properly then it's not a problem. + + if flags & SandboxFlags.INTERACTIVE: + # Be more lenient in interactive mode here. + # + # In interactive mode; it's possible that the project shell + # configuration has mounted some things below the base + # directories, such as /dev/dri, and in this case it's less + # important to consider cleanup, as we wont be collecting + # this build result and creating an artifact. + # + # Note: Ideally; we should instead fix upstream bubblewrap to + # cleanup any debris it creates at startup time, and do + # the same ourselves for any directories we explicitly create. # - # If the directory was not empty on the other hand, then this is clearly - # a bug, bwrap mounted a tempfs here and when it exits, that better be empty. - pass + shutil.rmtree(base_directory, ignore_errors=True) + else: + try: + os.rmdir(base_directory) + except FileNotFoundError: + # ignore this, if bwrap cleaned up properly then it's not a problem. + # + # If the directory was not empty on the other hand, then this is clearly + # a bug, bwrap mounted a tempfs here and when it exits, that better be empty. + pass return exit_code |