From 41ef02ee1009a86d040314433a3823ca3dd13a02 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 19 Dec 2018 14:08:39 +0100 Subject: stage: fix resources being deleted from local cache (#10152) Non-expanded resources were being deleted from the cache on account of two behaviors: * ResourceStage was moving files rather than copying them, and uses "os.path.realpath" to resolve symlinks * CacheFetchStrategy creates a symlink to a cached resource rather than copying it This alters the first behavior: ResourceStage now copies the file rather than moving it. --- lib/spack/spack/stage.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 2e02abd9b4..b337ae5617 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -8,7 +8,6 @@ import stat import sys import errno import hashlib -import shutil import tempfile import getpass from six import string_types @@ -16,7 +15,7 @@ from six import iteritems from six.moves.urllib.parse import urljoin import llnl.util.tty as tty -from llnl.util.filesystem import mkdirp, can_access +from llnl.util.filesystem import mkdirp, can_access, copy, copy_tree from llnl.util.filesystem import remove_if_dead_link, remove_linked_tree import spack.paths @@ -406,7 +405,7 @@ class Stage(object): self.fetcher = fetcher self.fetcher.fetch() break - except spack.fetch_strategy.NoCacheError as e: + except spack.fetch_strategy.NoCacheError: # Don't bother reporting when something is not cached. continue except spack.error.SpackError as e: @@ -545,7 +544,13 @@ class ResourceStage(Stage): '{stage}\n\tdestination : {destination}'.format( stage=source_path, destination=destination_path )) - shutil.move(os.path.realpath(source_path), destination_path) + + src = os.path.realpath(source_path) + + if os.path.isdir(src): + copy_tree(src, destination_path) + else: + copy(src, destination_path) @pattern.composite(method_list=[ -- cgit v1.2.3-70-g09d2