address review: refactor for clarity
This commit is contained in:
parent
4bc30a40a3
commit
fec8a6dace
@ -631,16 +631,13 @@ def valid_update_method_exchange(self, force):
|
|||||||
if not spack.util.atomic_update.renameat2():
|
if not spack.util.atomic_update.renameat2():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# This is all to ensure we don't swap symlink -> exchange if we have
|
# Ensure we don't swap symlink -> exchange if we have a symlink and symlink is an
|
||||||
# symlink as an acceptable method. This is to avoid problems switching
|
# acceptable method. This is to avoid problems switching between OSs.
|
||||||
# between OSs
|
if os.path.islink(self.root):
|
||||||
if os.path.exists(self.root):
|
if force:
|
||||||
if os.path.islink(self.root):
|
os.unlink(self.root)
|
||||||
if force:
|
elif "symlink" in self.update_method:
|
||||||
os.unlink(self.root)
|
return False
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return "symlink" not in self.update_method
|
|
||||||
|
|
||||||
return True
|
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)
|
tty.debug("View at %s does not need regeneration." % self.root)
|
||||||
return
|
return
|
||||||
|
|
||||||
if update_method == "exchange":
|
if update_method == "exchange" and os.path.isdir(new_root):
|
||||||
if os.path.isdir(new_root):
|
# If new_root is the newest thing in its directory, no need to update
|
||||||
# If new_root is the newest thing in its directory, no need to update
|
parent = os.path.dirname(new_root)
|
||||||
parent = os.path.dirname(new_root)
|
siblings = [os.path.join(parent, s) for s in os.listdir(parent)]
|
||||||
siblings = [os.path.join(parent, s) for s in os.listdir(parent)]
|
siblings.sort(reverse=True, key=lambda p: os.stat(p).st_mtime)
|
||||||
siblings.sort(reverse=True, key=lambda p: os.stat(p).st_mtime)
|
if siblings[0] == new_root:
|
||||||
if siblings[0] == new_root:
|
tty.debug("View at %s does not need regenration." % self.root)
|
||||||
tty.debug("View at %s does not need regenration." % self.root)
|
return
|
||||||
return
|
shutil.rmtree(new_root)
|
||||||
shutil.rmtree(new_root)
|
|
||||||
|
|
||||||
_error_on_nonempty_view_dir(new_root)
|
_error_on_nonempty_view_dir(new_root)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user