nanonyme commented on code in PR #1793:
URL: https://github.com/apache/buildstream/pull/1793#discussion_r1060044253
##########
src/buildstream/utils.py:
##########
@@ -357,6 +358,21 @@ def sha256sum(filename: str) -> str:
return h.hexdigest()
+def copy_file_range(src, dest):
+ if not _USE_CP_FILE_RANGE:
+ return False
+ with open(src, "rb") as src_file, open(dest, "wb") as dest_file:
+ num_bytes = os.fstat(src_file.fileno()).st_size
+ while num_bytes > 0:
+ try:
+ num_bytes -= os.copy_file_range(src_file.fileno(),
dest_file.fileno(), num_bytes)
+ except OSError as error:
+ if error.errno in (errno.ENOSYS, errno.EXDEV):
+ return False
+ raise error from None
+ return True
Review Comment:
Essentially how this works here is:
1. Return True implies there was a success and copy_file_range was supported
2. Return False implies copy_file_range was not supported and there should
be a fallback
3. Any other exception implies failure and does not result in fallbacks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]