aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorCharles Machalow <csm10495@gmail.com>2022-11-22 09:19:34 -0800
committerGitHub <noreply@github.com>2022-11-22 17:19:34 +0000
commit1b2de89bce7eee3c63ce2286f071db57cd2cfa22 (patch)
tree34dfc872d34c8468edb2b7ef37cb89055097846e /Lib/ntpath.py
parentc2102136be569e6fc8ed90181f229b46d07142f8 (diff)
downloadcpython-1b2de89bce7eee3c63ce2286f071db57cd2cfa22.tar.gz
cpython-1b2de89bce7eee3c63ce2286f071db57cd2cfa22.zip
gh-99547: Add isjunction methods for checking if a path is a junction (GH-99548)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index d9582f40874..873c884c3bd 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -30,7 +30,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"ismount", "expanduser","expandvars","normpath","abspath",
"curdir","pardir","sep","pathsep","defpath","altsep",
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
- "samefile", "sameopenfile", "samestat", "commonpath"]
+ "samefile", "sameopenfile", "samestat", "commonpath", "isjunction"]
def _get_bothseps(path):
if isinstance(path, bytes):
@@ -267,6 +267,24 @@ def islink(path):
return False
return stat.S_ISLNK(st.st_mode)
+
+# Is a path a junction?
+
+if hasattr(os.stat_result, 'st_reparse_tag'):
+ def isjunction(path):
+ """Test whether a path is a junction"""
+ try:
+ st = os.lstat(path)
+ except (OSError, ValueError, AttributeError):
+ return False
+ return bool(st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT)
+else:
+ def isjunction(path):
+ """Test whether a path is a junction"""
+ os.fspath(path)
+ return False
+
+
# Being true for dangling symbolic links is also useful.
def lexists(path):