Skip to content

Commit f09c103

Browse files
committed
fixed as suggestions
1 parent 9ce9220 commit f09c103

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
@@ -27,10 +27,6 @@
2727
import grp
2828
except ImportError:
2929
grp = None
30-
try:
31-
import _winapi
32-
except ImportError:
33-
_winapi = None
3430

3531
from pathlib._os import (
3632
vfsopen, vfspath,
@@ -1393,7 +1389,8 @@ def _copy_from_file(self, source, preserve_metadata=False):
13931389
try:
13941390
copyfile2(source_path, str(self))
13951391
except OSError as exc:
1396-
if hasattr(exc, "winerror") and exc.winerror in (5, 1314):
1392+
# On Windows, OSError from file operations is guaranteed to have winerror attribute
1393+
if exc.winerror in (5, 1314):
13971394
# ERROR_ACCESS_DENIED (5) or ERROR_PRIVILEGE_NOT_HELD (1314)
13981395
self._copy_from_file_fallback(source, preserve_metadata)
13991396
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)