summaryrefslogtreecommitdiff
path: root/kbas/__main__.py
diff options
context:
space:
mode:
authorPaul Sherwood <paul.sherwood@codethink.co.uk>2015-10-30 18:32:47 +0000
committerPaul Sherwood <paul.sherwood@codethink.co.uk>2015-10-30 18:32:47 +0000
commit23a5d4df073c6b9c0d0251ca280acfe6703e10ad (patch)
treeb4b9b4f87f82b1881e0760e4cf6858d6c1db79da /kbas/__main__.py
parentb525d72901b34b827198062c0667294b51e5478a (diff)
downloadybd-23a5d4df073c6b9c0d0251ca280acfe6703e10ad.tar.gz
Check uploaded artifact can be unpacked
Diffstat (limited to 'kbas/__main__.py')
-rwxr-xr-xkbas/__main__.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/kbas/__main__.py b/kbas/__main__.py
index 926068d..6a7e1fb 100755
--- a/kbas/__main__.py
+++ b/kbas/__main__.py
@@ -117,14 +117,20 @@ class KeyedBinaryArtifactServer(object):
tmpdir = tempfile.mkdtemp()
try:
upload = request.files.get('file')
- upload.save(os.path.join(tmpdir, cache_id))
+ artifact = os.path.join(tmpdir, cache_id)
+ upload.save(artifact)
+ unpackdir = artifact + '.unpacked'
+ if call(['tar', 'xf', artifact, '--directory', unpackdir]):
+ app.log(this, 'ERROR: Problem unpacking', artifact)
+ raise
+ shutil.rmtree(unpackdir)
os.rename(tmpdir, os.path.join(app.config['artifact-dir'], cache_id))
response.status = 201 # success!
return
except:
- # this was a race, remove the tmpdir
+ # something went wrong, clean up
shutil.rmtree(tmpdir)
- response.status = 999 # method not allowed, this artifact exists
+ response.status = 999
return