summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-08-08 14:19:48 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-08-09 13:22:19 +0000
commitc38b5ddeb6359f6f848553bcfdde52365c807ab4 (patch)
tree383bb813af8e3dcb0527fd4436ed2884b8561b79
parentdfb54752494a7260f9e707cb572df2f1acf306b6 (diff)
downloaddefinitions-c38b5ddeb6359f6f848553bcfdde52365c807ab4.tar.gz
deploy plugin: Clean up deployments' tempdirs
We can't assume an extension cleans up after itself, as they can be arbitrary shell scripts, and the best shell has to offer for cleanup is `trap`, which is difficult to use. So now, anything created with `mktemp` will get automatically cleaned up by morph.
-rw-r--r--morphlib/plugins/deploy_plugin.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 4e588eaa..ef607ffe 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -283,8 +283,9 @@ class DeployPlugin(cliapp.Plugin):
# Unpack the artifact (tarball) to a temporary directory.
self.app.status(msg='Unpacking system for configuration')
- system_tree = tempfile.mkdtemp(
+ deploy_tempdir = tempfile.mkdtemp(
dir=os.path.join(self.app.settings['tempdir'], 'deployments'))
+ system_tree = tempfile.mkdtemp(dir=deploy_tempdir)
if build_command.lac.has(artifact):
f = build_command.lac.get(artifact)
@@ -310,11 +311,10 @@ class DeployPlugin(cliapp.Plugin):
'%s is already set in the enviroment' % name)
env[name] = value
- if 'TMPDIR' not in env:
- # morphlib.app already took care of ensuring the tempdir setting
- # is good, so use it if we don't have one already set.
- env['TMPDIR'] = os.path.join(self.app.settings['tempdir'],
- 'deployments')
+ # Extensions get a private tempdir so we can more easily clean
+ # up any files an extension left behind
+ deploy_private_tempdir = tempfile.mkdtemp(dir=deploy_tempdir)
+ env['TMPDIR'] = deploy_private_tempdir
# Run configuration extensions.
self.app.status(msg='Configure system')
@@ -340,7 +340,7 @@ class DeployPlugin(cliapp.Plugin):
# Cleanup.
self.app.status(msg='Cleaning up')
- shutil.rmtree(system_tree)
+ shutil.rmtree(deploy_tempdir)
self.app.status(msg='Finished deployment')