fix bug in recreating new exchange view; test
This commit is contained in:
parent
4fbb23b89e
commit
c20a4d6ad1
@ -3367,16 +3367,31 @@ def test_view_update_unnecessary(update_method, tmpdir, install_mockery, mock_fe
|
||||
libdwarf = spack.spec.Spec("libdwarf").concretized()
|
||||
install("libdwarf")
|
||||
|
||||
# Ensure multiple previous views around
|
||||
# Create a "previous" view
|
||||
view.regenerate([libelf])
|
||||
view.regenerate([libelf, libdwarf])
|
||||
|
||||
# monkeypatch so that any attempt to actually regenerate the view fails
|
||||
def raises(*args, **kwargs):
|
||||
raise AssertionError
|
||||
|
||||
old_view = view.view
|
||||
monkeypatch.setattr(view, "view", raises)
|
||||
|
||||
# regenerating the view is a no-op, so doesn't raise
|
||||
# will raise if the view isn't identical
|
||||
view.regenerate([libelf])
|
||||
with pytest.raises(AssertionError):
|
||||
view.regenerate([libelf, libdwarf])
|
||||
|
||||
# Create another view so there are multiple old views around
|
||||
monkeypatch.setattr(view, "view", old_view)
|
||||
view.regenerate([libelf, libdwarf])
|
||||
|
||||
# Redo the monkeypatch
|
||||
monkeypatch.setattr(view, "view", raises)
|
||||
|
||||
# no raise for no-op regeneration
|
||||
# raise when it's not a no-op
|
||||
view.regenerate([libelf, libdwarf])
|
||||
with pytest.raises(AssertionError):
|
||||
view.regenerate([libelf])
|
||||
|
@ -49,14 +49,12 @@ def atomic_update_renameat2(src, dest):
|
||||
|
||||
dest_exists = os.path.lexists(dest)
|
||||
if not dest_exists:
|
||||
fs.touch(dest)
|
||||
fs.mkdirp(dest)
|
||||
try:
|
||||
rc = renameat2()(AT_FDCWD, src.encode(), AT_FDCWD, dest.encode(), RENAME_EXCHANGE)
|
||||
if rc:
|
||||
raise OSError(f"renameat2 failed to exchange {src} and {dest}")
|
||||
if not dest_exists:
|
||||
os.unlink(src)
|
||||
except (OSError, IOError):
|
||||
except OSError:
|
||||
if not dest_exists:
|
||||
os.unlink(dest)
|
||||
raise
|
||||
|
Loading…
Reference in New Issue
Block a user