summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorCharles Machalow <csm10495@gmail.com>2022-11-22 17:19:34 (GMT)
committerGitHub <noreply@github.com>2022-11-22 17:19:34 (GMT)
commit1b2de89bce7eee3c63ce2286f071db57cd2cfa22 (patch)
tree34dfc872d34c8468edb2b7ef37cb89055097846e /Lib/shutil.py
parentc2102136be569e6fc8ed90181f229b46d07142f8 (diff)
downloadcpython-1b2de89bce7eee3c63ce2286f071db57cd2cfa22.zip
cpython-1b2de89bce7eee3c63ce2286f071db57cd2cfa22.tar.gz
cpython-1b2de89bce7eee3c63ce2286f071db57cd2cfa22.tar.bz2
gh-99547: Add isjunction methods for checking if a path is a junction (GH-99548)
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py25
1 files changed, 6 insertions, 19 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index f5687e3..f372406 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -565,18 +565,6 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
dirs_exist_ok=dirs_exist_ok)
if hasattr(os.stat_result, 'st_file_attributes'):
- # Special handling for directory junctions to make them behave like
- # symlinks for shutil.rmtree, since in general they do not appear as
- # regular links.
- def _rmtree_isdir(entry):
- try:
- st = entry.stat(follow_symlinks=False)
- return (stat.S_ISDIR(st.st_mode) and not
- (st.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
- and st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT))
- except OSError:
- return False
-
def _rmtree_islink(path):
try:
st = os.lstat(path)
@@ -586,12 +574,6 @@ if hasattr(os.stat_result, 'st_file_attributes'):
except OSError:
return False
else:
- def _rmtree_isdir(entry):
- try:
- return entry.is_dir(follow_symlinks=False)
- except OSError:
- return False
-
def _rmtree_islink(path):
return os.path.islink(path)
@@ -605,7 +587,12 @@ def _rmtree_unsafe(path, onerror):
entries = []
for entry in entries:
fullname = entry.path
- if _rmtree_isdir(entry):
+ try:
+ is_dir = entry.is_dir(follow_symlinks=False)
+ except OSError:
+ is_dir = False
+
+ if is_dir and not entry.is_junction():
try:
if entry.is_symlink():
# This can only happen if someone replaces