MCPcopy Create free account
hub / github.com/RustPython/RustPython / _get_copy_blocksize

Function _get_copy_blocksize

Lib/pathlib/_os.py:24–40  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

_copy_file_rangeFunction · 0.85
_sendfileFunction · 0.85

Calls 2

maxFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected