summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/lib/link.py
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-11-06 00:54:48 +0000
committerClaude <noreply@anthropic.com>2026-11-06 00:54:48 +0000
commit7aba3deae3ff17d032c37e07d2929d1426b34278 (patch)
tree9c482f9acda1599bd2f9bed95a6a46b75e634e80 /plugins/claude-security/scripts/lib/link.py
parent5472f5f56e0070feeeb464318b316714fe3e9105 (diff)
parentb8331dd69ab3e132bbf8cd6e89b5d8c1747e21b1 (diff)
Merge remote-tracking branch 'origin/main' into add-plugin/xcodeadd-plugin/xcode
Diffstat (limited to 'plugins/claude-security/scripts/lib/link.py')
-rw-r--r--plugins/claude-security/scripts/lib/link.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/claude-security/scripts/lib/link.py b/plugins/claude-security/scripts/lib/link.py
new file mode 100644
index 00000000..4c70b542
--- /dev/null
+++ b/plugins/claude-security/scripts/lib/link.py
@@ -0,0 +1,23 @@
+"""Whether a path is a link that a removal must not be sent through."""
+
+from __future__ import annotations
+
+import os
+import stat
+
+
+def is_link(path: str | os.PathLike[str]) -> bool:
+ """Whether `path` is a symbolic link or, on Windows, a directory junction.
+
+ False for a path that is absent or cannot be examined.
+ """
+ try:
+ status = os.lstat(path)
+ except OSError:
+ return False
+ if stat.S_ISLNK(status.st_mode):
+ return True
+ if os.name == "nt":
+ reparse_point = status.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
+ return bool(reparse_point) and status.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT
+ return False