Skip to content

Commit 9ce9220

Browse files
committed
fixed as suggestions
1 parent 59d3cd2 commit 9ce9220

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
@@ -1386,22 +1386,18 @@ def _copy_from_file(self, source, preserve_metadata=False):
13861386
_copy_from_file_fallback = _copy_from_file
13871387
def _copy_from_file(self, source, preserve_metadata=False):
13881388
try:
1389-
source_fspath = os.fspath(source)
1389+
source_path = os.fspath(source)
13901390
except TypeError:
1391-
pass
1392-
else:
1393-
try:
1394-
copyfile2(source_fspath, str(self))
1395-
except OSError as exc:
1396-
winerror = getattr(exc, 'winerror', None)
1397-
if (_winapi is not None and
1398-
winerror in (_winapi.ERROR_PRIVILEGE_NOT_HELD,
1399-
_winapi.ERROR_ACCESS_DENIED)):
1400-
self._copy_from_file_fallback(source, preserve_metadata)
1401-
return
1402-
raise
1391+
self._copy_from_file_fallback(source, preserve_metadata)
14031392
return
1404-
self._copy_from_file_fallback(source, preserve_metadata)
1393+
try:
1394+
copyfile2(source_path, str(self))
1395+
except OSError as exc:
1396+
if hasattr(exc, "winerror") and exc.winerror in (5, 1314):
1397+
# ERROR_ACCESS_DENIED (5) or ERROR_PRIVILEGE_NOT_HELD (1314)
1398+
self._copy_from_file_fallback(source, preserve_metadata)
1399+
return
1400+
raise
14051401

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

0 commit comments

Comments
 (0)