Determine blocksize for fastcopying on Linux. Hopefully the whole file will be copied in a single call. The copying itself should be performed in a loop 'till EOF is reached (0 return) so a blocksize smaller or bigger than the actual file size should not make any difference, also in
(infd)
| 21 | |
| 22 | |
| 23 | def _get_copy_blocksize(infd): |
| 24 | """Determine blocksize for fastcopying on Linux. |
| 25 | Hopefully the whole file will be copied in a single call. |
| 26 | The copying itself should be performed in a loop 'till EOF is |
| 27 | reached (0 return) so a blocksize smaller or bigger than the actual |
| 28 | file size should not make any difference, also in case the file |
| 29 | content changes while being copied. |
| 30 | """ |
| 31 | try: |
| 32 | blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8 MiB |
| 33 | except OSError: |
| 34 | blocksize = 2 ** 27 # 128 MiB |
| 35 | # On 32-bit architectures truncate to 1 GiB to avoid OverflowError, |
| 36 | # see gh-82500. |
| 37 | if sys.maxsize < 2 ** 32: |
| 38 | blocksize = min(blocksize, 2 ** 30) |
| 39 | return blocksize |
| 40 | |
| 41 | |
| 42 | if fcntl and hasattr(fcntl, 'FICLONE'): |
no outgoing calls
no test coverage detected
searching dependent graphs…