summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-02 16:19:32 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-02 16:19:32 +0100
commit901e4851b993f73c4bdd92b85b2469d6673b7617 (patch)
treeb79c7d86b01ab6b8c7f3f1ceb064cecfdb085224
parent9001b9ed3c01f8ccaceaca60d6a34c3551f77240 (diff)
downloadspack-901e4851b993f73c4bdd92b85b2469d6673b7617.tar.gz
spack-901e4851b993f73c4bdd92b85b2469d6673b7617.tar.bz2
spack-901e4851b993f73c4bdd92b85b2469d6673b7617.tar.xz
spack-901e4851b993f73c4bdd92b85b2469d6673b7617.zip
_cleanup_dead_links : factored method into a function and put it in llnl.filesystem
-rw-r--r--lib/spack/llnl/util/filesystem.py19
-rw-r--r--lib/spack/spack/stage.py20
2 files changed, 21 insertions, 18 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 24cfbfde71..4a708b639a 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -25,7 +25,7 @@
__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']
+ 'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink', 'remove_dead_links']
import os
import sys
@@ -235,7 +235,7 @@ def touchp(path):
def force_symlink(src, dest):
try:
os.symlink(src, dest)
- except OSError, e:
+ except OSError as e:
os.remove(dest)
os.symlink(src, dest)
@@ -339,3 +339,18 @@ def traverse_tree(source_root, dest_root, rel_path='', **kwargs):
if order == 'post':
yield (source_path, dest_path)
+
+def remove_dead_links(root):
+ """
+ Removes any dead link that is present in root
+
+ Args:
+ root: path where to search for dead links
+
+ """
+ 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) \ No newline at end of file
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index 900acd664d..e910643192 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -98,7 +98,7 @@ class Stage(object):
# Try to construct here a temporary name for the stage directory
# If this is a named stage, then construct a named path.
self.path = join_path(spack.stage_path, self.name)
-
+ # Flag to decide whether to delete the stage folder on exit or not
self.delete_on_exit = True
def __enter__(self):
@@ -113,20 +113,17 @@ class Stage(object):
"""
# Create the top-level stage directory
mkdirp(spack.stage_path)
- self._cleanup_dead_links()
+ remove_dead_links(spack.stage_path)
- # If this is a temporary stage, them make the temp directory
+ # 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.tmp_root:
if self._need_to_create_path():
tmp_dir = tempfile.mkdtemp('', STAGE_PREFIX, self.tmp_root)
os.symlink(tmp_dir, self.path)
-
- # if we're not using a tmp dir, create the stage directly in the
- # stage dir, rather than linking to it.
else:
if self._need_to_create_path():
mkdirp(self.path)
-
# Make sure we can actually do something with the stage we made.
ensure_access(self.path)
@@ -151,15 +148,6 @@ class Stage(object):
if self.delete_on_exit:
self.destroy()
- def _cleanup_dead_links(self):
- """Remove any dead links in the stage directory."""
- for file in os.listdir(spack.stage_path):
- path = join_path(spack.stage_path, file)
- if os.path.islink(path):
- real_path = os.path.realpath(path)
- if not os.path.exists(real_path):
- os.unlink(path)
-
def _need_to_create_path(self):
"""Makes sure nothing weird has happened since the last time we
looked at path. Returns True if path already exists and is ok.