Skip to content

Commit 5ec9c09

Browse files
committed
fixed as suggestions
1 parent 85637e2 commit 5ec9c09

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Lib/pathlib/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,22 +1144,18 @@ def _copy_from_file(self, source, preserve_metadata=False):
11441144
_copy_from_file_fallback = _copy_from_file
11451145
def _copy_from_file(self, source, preserve_metadata=False):
11461146
try:
1147-
source_fspath = os.fspath(source)
1147+
source_path = os.fspath(source)
11481148
except TypeError:
1149-
pass
1150-
else:
1151-
try:
1152-
copyfile2(source_fspath, str(self))
1153-
except OSError as exc:
1154-
winerror = getattr(exc, 'winerror', None)
1155-
if (_winapi is not None and
1156-
winerror in (_winapi.ERROR_PRIVILEGE_NOT_HELD,
1157-
_winapi.ERROR_ACCESS_DENIED)):
1158-
self._copy_from_file_fallback(source, preserve_metadata)
1159-
return
1160-
raise
1149+
self._copy_from_file_fallback(source, preserve_metadata)
11611150
return
1162-
self._copy_from_file_fallback(source, preserve_metadata)
1151+
try:
1152+
copyfile2(source_path, str(self))
1153+
except OSError as exc:
1154+
if hasattr(exc, "winerror") and exc.winerror in (5, 1314):
1155+
# ERROR_ACCESS_DENIED (5) or ERROR_PRIVILEGE_NOT_HELD (1314)
1156+
self._copy_from_file_fallback(source, preserve_metadata)
1157+
return
1158+
raise
11631159

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

0 commit comments

Comments
 (0)