address review: refactor for clarity

This commit is contained in:
Gregory Becker 2023-04-03 11:54:09 -07:00
parent 4bc30a40a3
commit fec8a6dace

View File

@ -631,16 +631,13 @@ def valid_update_method_exchange(self, force):
if not spack.util.atomic_update.renameat2():
return False
# This is all to ensure we don't swap symlink -> exchange if we have
# symlink as an acceptable method. This is to avoid problems switching
# between OSs
if os.path.exists(self.root):
if os.path.islink(self.root):
if force:
os.unlink(self.root)
return True
else:
return "symlink" not in self.update_method
# Ensure we don't swap symlink -> exchange if we have a symlink and symlink is an
# acceptable method. This is to avoid problems switching between OSs.
if os.path.islink(self.root):
if force:
os.unlink(self.root)
elif "symlink" in self.update_method:
return False
return True
@ -690,16 +687,15 @@ def regenerate(self, concretized_root_specs, force=False):
tty.debug("View at %s does not need regeneration." % self.root)
return
if update_method == "exchange":
if os.path.isdir(new_root):
# If new_root is the newest thing in its directory, no need to update
parent = os.path.dirname(new_root)
siblings = [os.path.join(parent, s) for s in os.listdir(parent)]
siblings.sort(reverse=True, key=lambda p: os.stat(p).st_mtime)
if siblings[0] == new_root:
tty.debug("View at %s does not need regenration." % self.root)
return
shutil.rmtree(new_root)
if update_method == "exchange" and os.path.isdir(new_root):
# If new_root is the newest thing in its directory, no need to update
parent = os.path.dirname(new_root)
siblings = [os.path.join(parent, s) for s in os.listdir(parent)]
siblings.sort(reverse=True, key=lambda p: os.stat(p).st_mtime)
if siblings[0] == new_root:
tty.debug("View at %s does not need regenration." % self.root)
return
shutil.rmtree(new_root)
_error_on_nonempty_view_dir(new_root)