diff options
-rw-r--r-- | lib/spack/spack/database.py | 13 | ||||
-rw-r--r-- | lib/spack/spack/test/database.py | 15 |
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) |