diff options
author | alalazo <massimiliano.culpo@googlemail.com> | 2016-06-14 16:11:27 +0200 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2016-10-11 01:55:32 -0700 |
commit | f22929088074ca2b5c52862184b447eb98a17f4d (patch) | |
tree | 7742addba6098174386b4268ef8ef9442fc01bb6 | |
parent | f47dcdc47a33c754fec65f81ad353bdfa18f8f66 (diff) | |
download | spack-f22929088074ca2b5c52862184b447eb98a17f4d.tar.gz spack-f22929088074ca2b5c52862184b447eb98a17f4d.tar.bz2 spack-f22929088074ca2b5c52862184b447eb98a17f4d.tar.xz spack-f22929088074ca2b5c52862184b447eb98a17f4d.zip |
stage : try to remove dead links only of folder that you actually care about
A use case where the previous approach was failing is :
- more than one spack process running on compute nodes
- stage directory is a link to fast LOCAL storage
In this case the processes may try to unlink something that is "dead" for them, but actually used by other processes on storage they cannot see.
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 55 | ||||
-rw-r--r-- | lib/spack/spack/stage.py | 3 |
2 files changed, 44 insertions, 14 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index c3ecfde4f4..e522fdda6d 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -39,15 +39,34 @@ from contextlib import contextmanager import llnl.util.tty as tty from llnl.util.lang import dedupe -__all__ = ['set_install_permissions', 'install', 'install_tree', - 'traverse_tree', - 'expand_user', 'working_dir', 'touch', 'touchp', 'mkdirp', - 'force_remove', 'join_path', 'ancestor', 'can_access', - 'filter_file', - 'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink', - 'set_executable', 'copy_mode', 'unset_executable_mode', - 'remove_dead_links', 'remove_linked_tree', - 'fix_darwin_install_name', 'find_libraries', 'LibraryList'] +__all__ = [ + 'FileFilter', + 'LibraryList', + 'ancestor', + 'can_access', + 'change_sed_delimiter', + 'copy_mode', + 'expand_user', + 'filter_file', + 'find_libraries', + 'fix_darwin_install_name', + 'force_remove', + 'force_symlink', + 'install', + 'install_tree', + 'is_exe', + 'join_path', + 'mkdirp', + 'remove_dead_links', + 'remove_if_dead_link', + 'remove_linked_tree', + 'set_executable', + 'set_install_permissions', + 'touch', + 'touchp', + 'traverse_tree', + 'unset_executable_mode', + 'working_dir'] def filter_file(regex, repl, *filenames, **kwargs): @@ -388,10 +407,20 @@ def remove_dead_links(root): """ for file in os.listdir(root): path = join_path(root, file) - if os.path.islink(path): - real_path = os.path.realpath(path) - if not os.path.exists(real_path): - os.unlink(path) + remove_if_dead_link(path) + + +def remove_if_dead_link(path): + """ + Removes the argument if it is a dead link, does nothing otherwise + + Args: + path: the potential dead link + """ + if os.path.islink(path): + real_path = os.path.realpath(path) + if not os.path.exists(real_path): + os.unlink(path) def remove_linked_tree(path): diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 9a0d5fdf3f..8fcac222a0 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -434,7 +434,8 @@ class Stage(object): """ # Create the top-level stage directory mkdirp(spack.stage_path) - remove_dead_links(spack.stage_path) + remove_if_dead_link(self.path) + # If a tmp_root exists then create a directory there and then link it # in the stage area, otherwise create the stage directory in self.path if self._need_to_create_path(): |