Skip to content

Commit bbd3417

Browse files
committed
fixed as suggestions
1 parent 9d80882 commit bbd3417

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Lib/pathlib/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
import grp
2626
except ImportError:
2727
grp = None
28-
try:
29-
import _winapi
30-
except ImportError:
31-
_winapi = None
3228

3329
from pathlib._os import (
3430
PathInfo, DirEntryInfo,
@@ -1151,7 +1147,8 @@ def _copy_from_file(self, source, preserve_metadata=False):
11511147
try:
11521148
copyfile2(source_path, str(self))
11531149
except OSError as exc:
1154-
if hasattr(exc, "winerror") and exc.winerror in (5, 1314):
1150+
# On Windows, OSError from file operations is guaranteed to have winerror attribute
1151+
if exc.winerror in (5, 1314):
11551152
# ERROR_ACCESS_DENIED (5) or ERROR_PRIVILEGE_NOT_HELD (1314)
11561153
self._copy_from_file_fallback(source, preserve_metadata)
11571154
return
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix ``pathlib.Path.copy()`` failing on Windows when copying files that require elevated privileges (e.g., hidden or system files) by adding a fallback mechanism when ``copyfile2`` encounters privilege-related errors.
1+
Fix :meth:`pathlib.Path.copy` failing on Windows when copying files that require elevated privileges (e.g., hidden or system files) by adding a fallback mechanism when ``CopyFile2()`` encounters privilege-related errors.

0 commit comments

Comments
 (0)