Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/pathlib/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def copyfileobj(source_f, target_f):
_ficlone(source_fd, target_fd)
return
except OSError as err:
if err.errno not in (EBADF, EOPNOTSUPP, ETXTBSY, EXDEV):
if err.errno not in (EACCES, EBADF, ENOTTY, EOPNOTSUPP,
EPERM, ETXTBSY, EXDEV):
raise err

# Use OS copy where available.
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,19 @@ def raiser(*args, **kwargs):
with mock.patch(patchpoint, make_raiser(errno.ENOENT)):
self.assertRaises(FileNotFoundError, source.copy, target)

@unittest.skipUnless(hasattr(fcntl, 'FICLONE'), 'requires fcntl.FICLONE')
def test_copy_ficlone_fallback(self):
base = self.cls(self.base)
source = base / 'fileA'
for err in (errno.EACCES, errno.ENOTTY, errno.EPERM):
with self.subTest(errno=err):
target = base / f'copy{err}'
error = OSError(err, os.strerror(err))
with mock.patch('fcntl.ioctl', side_effect=error) as ioctl:
source.copy(target)
ioctl.assert_called_once()
self.assertEqual(target.read_bytes(), source.read_bytes())

@unittest.skipIf(sys.platform == "win32" or sys.platform == "wasi", "directories are always readable on Windows and WASI")
@requires_non_root_user
def test_copy_dir_no_read_permission(self):
Expand Down
Loading