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()
|
libdwarf = spack.spec.Spec("libdwarf").concretized()
|
||||||
install("libdwarf")
|
install("libdwarf")
|
||||||
|
|
||||||
# Ensure multiple previous views around
|
# Create a "previous" view
|
||||||
view.regenerate([libelf])
|
view.regenerate([libelf])
|
||||||
view.regenerate([libelf, libdwarf])
|
|
||||||
|
|
||||||
# monkeypatch so that any attempt to actually regenerate the view fails
|
# monkeypatch so that any attempt to actually regenerate the view fails
|
||||||
def raises(*args, **kwargs):
|
def raises(*args, **kwargs):
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
old_view = view.view
|
||||||
monkeypatch.setattr(view, "view", raises)
|
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])
|
view.regenerate([libelf, libdwarf])
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
view.regenerate([libelf])
|
view.regenerate([libelf])
|
||||||
|
@ -49,14 +49,12 @@ def atomic_update_renameat2(src, dest):
|
|||||||
|
|
||||||
dest_exists = os.path.lexists(dest)
|
dest_exists = os.path.lexists(dest)
|
||||||
if not dest_exists:
|
if not dest_exists:
|
||||||
fs.touch(dest)
|
fs.mkdirp(dest)
|
||||||
try:
|
try:
|
||||||
rc = renameat2()(AT_FDCWD, src.encode(), AT_FDCWD, dest.encode(), RENAME_EXCHANGE)
|
rc = renameat2()(AT_FDCWD, src.encode(), AT_FDCWD, dest.encode(), RENAME_EXCHANGE)
|
||||||
if rc:
|
if rc:
|
||||||
raise OSError(f"renameat2 failed to exchange {src} and {dest}")
|
raise OSError(f"renameat2 failed to exchange {src} and {dest}")
|
||||||
if not dest_exists:
|
except OSError:
|
||||||
os.unlink(src)
|
|
||||||
except (OSError, IOError):
|
|
||||||
if not dest_exists:
|
if not dest_exists:
|
||||||
os.unlink(dest)
|
os.unlink(dest)
|
||||||
raise
|
raise
|
||||||
|
Loading…
Reference in New Issue
Block a user