summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2022-07-15 18:43:14 +0200
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2022-07-20 08:10:41 +0200
commit67f2d64a3f57e81564549042bcf2111baa0416ed (patch)
treeb9a8a1377f4a88e778761758e6ecf31bb1de2abe
parent7405d18e988efb24543ed921a44213f02940770f (diff)
downloadspack-67f2d64a3f57e81564549042bcf2111baa0416ed.tar.gz
spack-67f2d64a3f57e81564549042bcf2111baa0416ed.tar.bz2
spack-67f2d64a3f57e81564549042bcf2111baa0416ed.tar.xz
spack-67f2d64a3f57e81564549042bcf2111baa0416ed.zip
Use lexists instead of exists during fetch (#31509)
-rw-r--r--lib/spack/spack/fetch_strategy.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 378209308f..339d805712 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -327,9 +327,7 @@ class URLFetchStrategy(FetchStrategy):
continue
try:
- partial_file, save_file = self._fetch_from_url(url)
- if save_file and (partial_file is not None):
- llnl.util.filesystem.rename(partial_file, save_file)
+ self._fetch_from_url(url)
break
except FailedDownloadError as e:
errors.append(str(e))
@@ -379,9 +377,7 @@ class URLFetchStrategy(FetchStrategy):
@_needs_stage
def _fetch_urllib(self, url):
- save_file = None
- if self.stage.save_filename:
- save_file = self.stage.save_filename
+ save_file = self.stage.save_filename
tty.msg('Fetching {0}'.format(url))
# Run urllib but grab the mime type from the http headers
@@ -391,16 +387,18 @@ class URLFetchStrategy(FetchStrategy):
# clean up archive on failure.
if self.archive_file:
os.remove(self.archive_file)
- if save_file and os.path.exists(save_file):
+ if os.path.lexists(save_file):
os.remove(save_file)
msg = 'urllib failed to fetch with error {0}'.format(e)
raise FailedDownloadError(url, msg)
+ if os.path.lexists(save_file):
+ os.remove(save_file)
+
with open(save_file, 'wb') as _open_file:
shutil.copyfileobj(response, _open_file)
self._check_headers(str(headers))
- return None, save_file
@_needs_stage
def _fetch_curl(self, url):
@@ -461,7 +459,7 @@ class URLFetchStrategy(FetchStrategy):
if self.archive_file:
os.remove(self.archive_file)
- if partial_file and os.path.exists(partial_file):
+ if partial_file and os.path.lexists(partial_file):
os.remove(partial_file)
if curl.returncode == 22:
@@ -488,7 +486,9 @@ class URLFetchStrategy(FetchStrategy):
"Curl failed with error %d" % curl.returncode)
self._check_headers(headers)
- return partial_file, save_file
+
+ if save_file and (partial_file is not None):
+ fs.rename(partial_file, save_file)
@property # type: ignore # decorated properties unsupported in mypy
@_needs_stage
@@ -642,7 +642,7 @@ class CacheURLFetchStrategy(URLFetchStrategy):
# remove old symlink if one is there.
filename = self.stage.save_filename
- if os.path.exists(filename):
+ if os.path.lexists(filename):
os.remove(filename)
# Symlink to local cached archive.