summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorScott Wittenburg <scott.wittenburg@kitware.com>2020-10-19 15:24:41 -0600
committerGitHub <noreply@github.com>2020-10-19 15:24:41 -0600
commitf561d3845b353cfe89c7873ee461028b511195d7 (patch)
treed18b3f06981cb1ffea14c92aada3487c7f54798d /lib
parent449604bfe8885d520e3ebb7c6a5ffb2bc6168734 (diff)
downloadspack-f561d3845b353cfe89c7873ee461028b511195d7.tar.gz
spack-f561d3845b353cfe89c7873ee461028b511195d7.tar.bz2
spack-f561d3845b353cfe89c7873ee461028b511195d7.tar.xz
spack-f561d3845b353cfe89c7873ee461028b511195d7.zip
Fix "buildcache update-index --keys ..." when mirror is S3 (#19141)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/binary_distribution.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index fcf436a5bc..8452cdbb97 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -350,10 +350,15 @@ def generate_key_index(key_prefix, tmpdir=None):
for entry in web_util.list_url(key_prefix, recursive=False)
if entry.endswith('.pub'))
+ remove_tmpdir = False
+
keys_local = url_util.local_file_path(key_prefix)
if keys_local:
target = os.path.join(keys_local, 'index.json')
else:
+ if not tmpdir:
+ tmpdir = tempfile.mkdtemp()
+ remove_tmpdir = True
target = os.path.join(tmpdir, 'index.json')
index = {
@@ -365,11 +370,15 @@ def generate_key_index(key_prefix, tmpdir=None):
sjson.dump(index, f)
if not keys_local:
- web_util.push_to_url(
- target,
- url_util.join(key_prefix, 'index.json'),
- keep_original=False,
- extra_args={'ContentType': 'application/json'})
+ try:
+ web_util.push_to_url(
+ target,
+ url_util.join(key_prefix, 'index.json'),
+ keep_original=False,
+ extra_args={'ContentType': 'application/json'})
+ finally:
+ if remove_tmpdir:
+ shutil.rmtree(tmpdir)
def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,