From ae3a5f38487742e2c54d8eb7615251d9ba3141be Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 29 Mar 2023 12:23:31 -0700 Subject: [PATCH] additional testing --- lib/spack/spack/test/cmd/env.py | 25 +++++++++++++++++++++++++ lib/spack/spack/util/atomic_update.py | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index cc1e4fa2e3e..84e0f5609ed 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -3320,3 +3320,28 @@ def test_view_update_mismatch(update_method, tmpdir, install_mockery, mock_fetch with pytest.raises(RuntimeError, match=checker): view.regenerate([spec]) + + +@pytest.mark.parametrize("update_method", ["symlink", "exchange"]) +def test_view_update_fails(update_method, tmpdir, install_mockery, mock_fetch, monkeypatch): + root = str(tmpdir.join("root")) + view = ev.environment.ViewDescriptor( + base_path=str(tmpdir), root=root, update_method=update_method + ) + + spec = spack.spec.Spec("libelf").concretized() + install("libelf") + + def raises(*args, **kwargs): + raise OSError + + monkeypatch.setattr(fs, "rename", raises) + monkeypatch.setattr(spack.util.atomic_update, "_renameat2", raises) + + with pytest.raises(OSError): + view.regenerate([spec]) + + assert not os.path.exists(view.root) + if update_method == "symlink": + link = os.path.join(str(tmpdir), "._root", "._tmp_symlink") + assert not os.path.lexists(link) diff --git a/lib/spack/spack/util/atomic_update.py b/lib/spack/spack/util/atomic_update.py index fd205ed7a64..abc3ed67131 100644 --- a/lib/spack/spack/util/atomic_update.py +++ b/lib/spack/spack/util/atomic_update.py @@ -59,6 +59,7 @@ def atomic_update_renameat2(src, dest): except (OSError, IOError): if not dest_exists: os.unlink(dest) + raise def atomic_update_symlink(src, dest): @@ -71,6 +72,6 @@ def atomic_update_symlink(src, dest): # atomically mv the symlink to destpath (still points to srcpath) try: fs.rename(tmp_symlink_name, dest) - except Exception: + except OSError: os.unlink(tmp_symlink_name) raise