summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-02 16:55:57 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-02 16:55:57 +0100
commit4d63544fe918393de9265f8879bb0199a542cc3b (patch)
tree73022f2b992bd5b46eb59d291b84f6ba78784945 /lib
parent901e4851b993f73c4bdd92b85b2469d6673b7617 (diff)
downloadspack-4d63544fe918393de9265f8879bb0199a542cc3b.tar.gz
spack-4d63544fe918393de9265f8879bb0199a542cc3b.tar.bz2
spack-4d63544fe918393de9265f8879bb0199a542cc3b.tar.xz
spack-4d63544fe918393de9265f8879bb0199a542cc3b.zip
remove_link_tree : moved to llnl.util.filesystem
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py20
-rw-r--r--lib/spack/spack/stage.py21
2 files changed, 21 insertions, 20 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 4a708b639a..015eeb9aa1 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', 'remove_dead_links']
+ 'FileFilter', 'change_sed_delimiter', 'is_exe', 'force_symlink', 'remove_dead_links', 'remove_linked_tree']
import os
import sys
@@ -353,4 +353,20 @@ def remove_dead_links(root):
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
+ os.unlink(path)
+
+def remove_linked_tree(path):
+ """
+ Removes a directory and its contents. If the directory is a symlink, follows the link and removes the real
+ directory before removing the link.
+
+ Args:
+ path: directory to be removed
+
+ """
+ if os.path.exists(path):
+ if os.path.islink(path):
+ shutil.rmtree(os.path.realpath(path), True)
+ os.unlink(path)
+ else:
+ shutil.rmtree(path, True)
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index e910643192..e87b822a8f 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -114,15 +114,13 @@ class Stage(object):
# Create the top-level stage directory
mkdirp(spack.stage_path)
remove_dead_links(spack.stage_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.tmp_root:
- if self._need_to_create_path():
+ if self._need_to_create_path():
+ if self.tmp_root:
tmp_dir = tempfile.mkdtemp('', STAGE_PREFIX, self.tmp_root)
os.symlink(tmp_dir, self.path)
- else:
- if self._need_to_create_path():
+ else:
mkdirp(self.path)
# Make sure we can actually do something with the stage we made.
ensure_access(self.path)
@@ -436,19 +434,6 @@ def ensure_access(file=spack.stage_path):
tty.die("Insufficient permissions for %s" % file)
-def remove_linked_tree(path):
- """Removes a directory and its contents. If the directory is a symlink,
- follows the link and reamoves the real directory before removing the
- link.
- """
- if os.path.exists(path):
- if os.path.islink(path):
- shutil.rmtree(os.path.realpath(path), True)
- os.unlink(path)
- else:
- shutil.rmtree(path, True)
-
-
def purge():
"""Remove all build directories in the top-level stage path."""
if os.path.isdir(spack.stage_path):