summaryrefslogtreecommitdiffstats
path: root/Modules
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 /Modules
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 'Modules')
-rw-r--r--Modules/clinic/posixmodule.c.h34
-rw-r--r--Modules/posixmodule.c20
2 files changed, 53 insertions, 1 deletions
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index 1ad96ea..f9f6ca3 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -10269,6 +10269,38 @@ exit:
return return_value;
}
+PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
+"is_junction($self, /)\n"
+"--\n"
+"\n"
+"Return True if the entry is a junction; cached per entry.");
+
+#define OS_DIRENTRY_IS_JUNCTION_METHODDEF \
+ {"is_junction", _PyCFunction_CAST(os_DirEntry_is_junction), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_junction__doc__},
+
+static int
+os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class);
+
+static PyObject *
+os_DirEntry_is_junction(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ int _return_value;
+
+ if (nargs) {
+ PyErr_SetString(PyExc_TypeError, "is_junction() takes no arguments");
+ goto exit;
+ }
+ _return_value = os_DirEntry_is_junction_impl(self, defining_class);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(os_DirEntry_stat__doc__,
"stat($self, /, *, follow_symlinks=True)\n"
"--\n"
@@ -11517,4 +11549,4 @@ exit:
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=90f5e6995114e5ca input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4192d8e09e216300 input=a9049054013a1b77]*/
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 98fc264..45e71ee 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -13633,6 +13633,25 @@ os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class)
#endif
}
+/*[clinic input]
+os.DirEntry.is_junction -> bool
+ defining_class: defining_class
+ /
+
+Return True if the entry is a junction; cached per entry.
+[clinic start generated code]*/
+
+static int
+os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class)
+/*[clinic end generated code: output=7061a07b0ef2cd1f input=475cd36fb7d4723f]*/
+{
+#ifdef MS_WINDOWS
+ return self->win32_lstat.st_reparse_tag == IO_REPARSE_TAG_MOUNT_POINT;
+#else
+ return 0;
+#endif
+}
+
static PyObject *
DirEntry_fetch_stat(PyObject *module, DirEntry *self, int follow_symlinks)
{
@@ -13927,6 +13946,7 @@ static PyMethodDef DirEntry_methods[] = {
OS_DIRENTRY_IS_DIR_METHODDEF
OS_DIRENTRY_IS_FILE_METHODDEF
OS_DIRENTRY_IS_SYMLINK_METHODDEF
+ OS_DIRENTRY_IS_JUNCTION_METHODDEF
OS_DIRENTRY_STAT_METHODDEF
OS_DIRENTRY_INODE_METHODDEF
OS_DIRENTRY___FSPATH___METHODDEF