Skip to content

Commit

Permalink
stage : try to remove dead links only of folder that you actually car…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
alalazo authored and tgamblin committed Aug 19, 2016
1 parent db16387 commit 537e9cc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
56 changes: 43 additions & 13 deletions lib/spack/llnl/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,35 @@

import llnl.util.tty as tty

__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', 'find_library_path',
'fix_darwin_install_name', 'to_link_flags', 'to_lib_name']
__all__ = [
'FileFilter',
'ancestor',
'can_access',
'change_sed_delimiter',
'copy_mode',
'expand_user',
'filter_file',
'find_library_path',
'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',
'to_lib_name',
'to_link_flags',
'touch',
'touchp',
'traverse_tree',
'unset_executable_mode',
'working_dir']


def filter_file(regex, repl, *filenames, **kwargs):
Expand Down Expand Up @@ -384,10 +404,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):
Expand Down
3 changes: 2 additions & 1 deletion lib/spack/spack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ def create(self):
"""
# 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():
Expand Down

0 comments on commit 537e9cc

Please sign in to comment.