summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-06-10 08:04:52 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2020-06-10 13:26:49 +0000
commitcc093b0ea933fa8f19a953934c9981ad1ff71b63 (patch)
tree8ffb6993e914d54d92a441b634bc6f867ed9dc8b
parent57c731299c0851d34774ffdcdd5960503c1f8fec (diff)
downloadbuildstream-cc093b0ea933fa8f19a953934c9981ad1ff71b63.tar.gz
utils.py: Fix error handling in safe_copy()
Catch errors raised by `shutil.copyfile()`.
-rw-r--r--src/buildstream/utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 99c22d169..9591951e8 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -385,7 +385,11 @@ def safe_copy(src: str, dest: str, *, result: Optional[FileListResult] = None) -
if e.errno != errno.ENOENT:
raise UtilError("Failed to remove destination file '{}': {}".format(dest, e)) from e
- shutil.copyfile(src, dest)
+ try:
+ shutil.copyfile(src, dest)
+ except (OSError, shutil.Error) as e:
+ raise UtilError("Failed to copy '{} -> {}': {}".format(src, dest, e)) from e
+
try:
shutil.copystat(src, dest)
except PermissionError:
@@ -398,9 +402,6 @@ def safe_copy(src: str, dest: str, *, result: Optional[FileListResult] = None) -
if result:
result.failed_attributes.append(dest)
- except shutil.Error as e:
- raise UtilError("Failed to copy '{} -> {}': {}".format(src, dest, e)) from e
-
def safe_link(src: str, dest: str, *, result: Optional[FileListResult] = None, _unlink=False) -> None:
"""Try to create a hardlink, but resort to copying in the case of cross device links.