mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
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.
This commit is contained in:
parent
089835469d
commit
f09d184821
6 changed files with 40 additions and 29 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue