Use lexists instead of exists during fetch (#31509)
This commit is contained in:
@@ -337,9 +337,7 @@ def fetch(self):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
partial_file, save_file = self._fetch_from_url(url)
|
self._fetch_from_url(url)
|
||||||
if save_file and (partial_file is not None):
|
|
||||||
llnl.util.filesystem.rename(partial_file, save_file)
|
|
||||||
break
|
break
|
||||||
except FailedDownloadError as e:
|
except FailedDownloadError as e:
|
||||||
errors.append(str(e))
|
errors.append(str(e))
|
||||||
@@ -389,9 +387,7 @@ def _check_headers(self, headers):
|
|||||||
|
|
||||||
@_needs_stage
|
@_needs_stage
|
||||||
def _fetch_urllib(self, url):
|
def _fetch_urllib(self, url):
|
||||||
save_file = None
|
save_file = self.stage.save_filename
|
||||||
if self.stage.save_filename:
|
|
||||||
save_file = self.stage.save_filename
|
|
||||||
tty.msg('Fetching {0}'.format(url))
|
tty.msg('Fetching {0}'.format(url))
|
||||||
|
|
||||||
# Run urllib but grab the mime type from the http headers
|
# Run urllib but grab the mime type from the http headers
|
||||||
@@ -401,16 +397,18 @@ def _fetch_urllib(self, url):
|
|||||||
# clean up archive on failure.
|
# clean up archive on failure.
|
||||||
if self.archive_file:
|
if self.archive_file:
|
||||||
os.remove(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)
|
os.remove(save_file)
|
||||||
msg = 'urllib failed to fetch with error {0}'.format(e)
|
msg = 'urllib failed to fetch with error {0}'.format(e)
|
||||||
raise FailedDownloadError(url, msg)
|
raise FailedDownloadError(url, msg)
|
||||||
|
|
||||||
|
if os.path.lexists(save_file):
|
||||||
|
os.remove(save_file)
|
||||||
|
|
||||||
with open(save_file, 'wb') as _open_file:
|
with open(save_file, 'wb') as _open_file:
|
||||||
shutil.copyfileobj(response, _open_file)
|
shutil.copyfileobj(response, _open_file)
|
||||||
|
|
||||||
self._check_headers(str(headers))
|
self._check_headers(str(headers))
|
||||||
return None, save_file
|
|
||||||
|
|
||||||
@_needs_stage
|
@_needs_stage
|
||||||
def _fetch_curl(self, url):
|
def _fetch_curl(self, url):
|
||||||
@@ -471,7 +469,7 @@ def _fetch_curl(self, url):
|
|||||||
if self.archive_file:
|
if self.archive_file:
|
||||||
os.remove(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)
|
os.remove(partial_file)
|
||||||
|
|
||||||
if curl.returncode == 22:
|
if curl.returncode == 22:
|
||||||
@@ -498,7 +496,9 @@ def _fetch_curl(self, url):
|
|||||||
"Curl failed with error %d" % curl.returncode)
|
"Curl failed with error %d" % curl.returncode)
|
||||||
|
|
||||||
self._check_headers(headers)
|
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
|
@property # type: ignore # decorated properties unsupported in mypy
|
||||||
@_needs_stage
|
@_needs_stage
|
||||||
@@ -613,7 +613,7 @@ def fetch(self):
|
|||||||
|
|
||||||
# remove old symlink if one is there.
|
# remove old symlink if one is there.
|
||||||
filename = self.stage.save_filename
|
filename = self.stage.save_filename
|
||||||
if os.path.exists(filename):
|
if os.path.lexists(filename):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
# Symlink to local cached archive.
|
# Symlink to local cached archive.
|
||||||
|
Reference in New Issue
Block a user