From 20851a6e6c62093231a6874f177bf534143ec389 Mon Sep 17 00:00:00 2001 From: Carson Woods Date: Thu, 18 Jul 2019 10:53:01 -0600 Subject: [PATCH] Fix .spack-db/index.json not being created in global upstream if previously uninitialized --- lib/spack/spack/database.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index 9c824dd6d38..a2e5c72e386 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -178,7 +178,6 @@ def __init__(self, root, db_dir=None, upstream_dbs=None, """ self.root = root - if db_dir is None: # If the db_dir is not provided, default to within the db root. self._db_dir = os.path.join(self.root, _db_dirname) @@ -200,7 +199,28 @@ def __init__(self, root, db_dir=None, upstream_dbs=None, self.is_upstream = is_upstream + # Create global + index_path = self._index_path + global_install_tree = spack.config.get( + 'upstreams')['global']['install_tree'] + global_install_tree = global_install_tree.replace( + '$spack', spack.paths.prefix) if self.is_upstream: + if global_install_tree in self._db_dir: + if not os.path.isfile(index_path): + f = open(self._index_path, "w+") + database = { + 'database': { + 'installs': {}, + 'version': str(_db_version) + } + } + try: + sjson.dump(database, f) + except YAMLError as e: + raise syaml.SpackYAMLError( + "error writing YAML database:", str(e)) + self.lock = ForbiddenLock() else: self.lock = Lock(self._lock_path)