Skip to content

Commit 98d5c6d

Browse files
committed
Tidying, naming.
1 parent f19ff13 commit 98d5c6d

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

Lib/pathlib/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def copy_into(self, target_dir, **kwargs):
11281128
def _copy_from(self, source, follow_symlinks=True, preserve_metadata=False):
11291129
"""
11301130
Recursively copy the given path to this path. This a generator
1131-
function that yields (target, source, part_size) tuples as the copying
1131+
function that yields (target, source, sent) tuples as the copying
11321132
operation progresses.
11331133
"""
11341134
yield self, source, 0
@@ -1143,8 +1143,8 @@ def _copy_from(self, source, follow_symlinks=True, preserve_metadata=False):
11431143
if preserve_metadata:
11441144
copy_info(source.info, self)
11451145
else:
1146-
for part_size in self._copy_from_file(source, preserve_metadata):
1147-
yield self, source, part_size
1146+
for sent in self._copy_from_file(source, preserve_metadata):
1147+
yield self, source, sent
11481148

11491149
def _copy_from_file(self, source, preserve_metadata=False):
11501150
ensure_different_files(source, self)
@@ -1164,8 +1164,8 @@ def _copy_from_file(self, source, preserve_metadata=False):
11641164
pass
11651165
else:
11661166
copyfile2(source, str(self))
1167-
return iter([])
1168-
return self._copy_from_file_fallback(source, preserve_metadata)
1167+
return
1168+
yield from self._copy_from_file_fallback(source, preserve_metadata)
11691169

11701170
if os.name == 'nt':
11711171
# If a directory-symlink is copied *before* its target, then

Lib/pathlib/_os.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,12 @@ def _copy_file_range(source_fd, target_fd):
7272
copy.
7373
This should work on Linux >= 4.5 only.
7474
"""
75+
fn = os.copy_file_range
7576
blocksize = _get_copy_blocksize(source_fd)
7677
offset = 0
77-
while True:
78-
sent = os.copy_file_range(source_fd, target_fd, blocksize,
79-
offset_dst=offset)
80-
if sent == 0:
81-
break # EOF
82-
offset += sent
78+
while sent := fn(source_fd, target_fd, blocksize, None, offset):
8379
yield sent
80+
offset += sent
8481
else:
8582
_copy_file_range = None
8683

@@ -91,14 +88,12 @@ def _sendfile(source_fd, target_fd):
9188
high-performance sendfile(2) syscall.
9289
This should work on Linux >= 2.6.33 only.
9390
"""
91+
fn = os.sendfile
9492
blocksize = _get_copy_blocksize(source_fd)
9593
offset = 0
96-
while True:
97-
sent = os.sendfile(target_fd, source_fd, offset, blocksize)
98-
if sent == 0:
99-
break # EOF
100-
offset += sent
94+
while sent := fn(target_fd, source_fd, offset, blocksize):
10195
yield sent
96+
offset += sent
10297
else:
10398
_sendfile = None
10499

Lib/pathlib/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def write_text(self, data, encoding=None, errors=None, newline=None):
414414
def _copy_from(self, source, follow_symlinks=True):
415415
"""
416416
Recursively copy the given path to this path. This a generator
417-
function that yields (target, source, part_size) tuples as the copying
417+
function that yields (target, source, sent) tuples as the copying
418418
operation progresses.
419419
"""
420420
stack = [(self, source)]
@@ -432,8 +432,8 @@ def _copy_from(self, source, follow_symlinks=True):
432432
ensure_different_files(src, dst)
433433
with magic_open(src, 'rb') as source_f:
434434
with magic_open(dst, 'wb') as target_f:
435-
for part_size in copyfileobj(source_f, target_f):
436-
yield dst, src, part_size
435+
for sent in copyfileobj(source_f, target_f):
436+
yield dst, src, sent
437437

438438

439439
_JoinablePath.register(PurePath)

0 commit comments

Comments
 (0)