summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib/_local.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-07-03 03:30:29 (GMT)
committerGitHub <noreply@github.com>2024-07-03 03:30:29 (GMT)
commitf09d184821efd9438d092643881e28bdf8de4de5 (patch)
tree1aa17585a9a686154135ef1f9305c0a4a5984234 /Lib/pathlib/_local.py
parent089835469d5efbea4793cd611b43cb8387f2e7e5 (diff)
downloadcpython-f09d184821efd9438d092643881e28bdf8de4de5.zip
cpython-f09d184821efd9438d092643881e28bdf8de4de5.tar.gz
cpython-f09d184821efd9438d092643881e28bdf8de4de5.tar.bz2
GH-73991: Support copying directory symlinks on older Windows (#120807)
Check for `ERROR_INVALID_PARAMETER` when calling `_winapi.CopyFile2()` and raise `UnsupportedOperation`. In `Path.copy()`, handle this exception and fall back to the `PathBase.copy()` implementation.
Diffstat (limited to 'Lib/pathlib/_local.py')
-rw-r--r--Lib/pathlib/_local.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py
index 0105ea3..acb5721 100644
--- a/Lib/pathlib/_local.py
+++ b/Lib/pathlib/_local.py
@@ -17,8 +17,8 @@ try:
except ImportError:
grp = None
-from ._abc import UnsupportedOperation, PurePathBase, PathBase
-from ._os import copyfile
+from ._os import UnsupportedOperation, copyfile
+from ._abc import PurePathBase, PathBase
__all__ = [
@@ -791,12 +791,15 @@ class Path(PathBase, PurePath):
try:
target = os.fspath(target)
except TypeError:
- if isinstance(target, PathBase):
- # Target is an instance of PathBase but not os.PathLike.
- # Use generic implementation from PathBase.
- return PathBase.copy(self, target, follow_symlinks=follow_symlinks)
- raise
- copyfile(os.fspath(self), target, follow_symlinks)
+ if not isinstance(target, PathBase):
+ raise
+ else:
+ try:
+ copyfile(os.fspath(self), target, follow_symlinks)
+ return
+ except UnsupportedOperation:
+ pass # Fall through to generic code.
+ PathBase.copy(self, target, follow_symlinks=follow_symlinks)
def chmod(self, mode, *, follow_symlinks=True):
"""