summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-10-09 00:35:23 +0200
committerGitHub <noreply@github.com>2021-10-08 22:35:23 +0000
commit2386630e10780b5ef94713e8ee24083b50b24b77 (patch)
tree5c705ea21981fe3b58ab963159e82cd217c958d0 /lib
parent21ce23816e959a123397463b665cbe16149a7b53 (diff)
downloadspack-2386630e10780b5ef94713e8ee24083b50b24b77.tar.gz
spack-2386630e10780b5ef94713e8ee24083b50b24b77.tar.bz2
spack-2386630e10780b5ef94713e8ee24083b50b24b77.tar.xz
spack-2386630e10780b5ef94713e8ee24083b50b24b77.zip
Remove DB reindex during a read operation (#26601)
The DB should be what is trusted for certain operations. If it is not present when read we should assume the corresponding store is empty, rather than trying a write operation during a read. * Add a unit test * Document what needs to be there in tests
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/database.py13
-rw-r--r--lib/spack/spack/test/database.py15
2 files changed, 16 insertions, 12 deletions
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index 2dbcd51950..b7294f3ecb 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -1024,12 +1024,7 @@ class Database(object):
raise
def _read(self):
- """Re-read Database from the data in the set location.
-
- This does no locking, with one exception: it will automatically
- try to regenerate a missing DB if local. This requires taking a
- write lock.
- """
+ """Re-read Database from the data in the set location. This does no locking."""
if os.path.isfile(self._index_path):
current_verifier = ''
if _use_uuid:
@@ -1049,12 +1044,6 @@ class Database(object):
"No database index file is present, and upstream"
" databases cannot generate an index file")
- # The file doesn't exist, try to traverse the directory.
- # reindex() takes its own write lock, so no lock here.
- with lk.WriteTransaction(self.lock):
- self._write(None, None, None)
- self.reindex(spack.store.layout)
-
def _add(
self,
spec,
diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py
index 37d19d6794..57a03a5db9 100644
--- a/lib/spack/spack/test/database.py
+++ b/lib/spack/spack/test/database.py
@@ -894,3 +894,18 @@ def test_prefix_write_lock_error(mutable_database, monkeypatch):
with pytest.raises(Exception):
with spack.store.db.prefix_write_lock(s):
assert False
+
+
+@pytest.mark.regression('26600')
+def test_database_works_with_empty_dir(tmpdir):
+ # Create the lockfile and failures directory otherwise
+ # we'll get a permission error on Database creation
+ db_dir = tmpdir.ensure_dir('.spack-db')
+ db_dir.ensure('lock')
+ db_dir.ensure_dir('failures')
+ tmpdir.chmod(mode=0o555, rec=1)
+ db = spack.database.Database(str(tmpdir))
+ with db.read_transaction():
+ db.query()
+ # Check that reading an empty directory didn't create a new index.json
+ assert not os.path.exists(db._index_path)