summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-03-07 23:17:16 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-03-07 23:17:16 +0100
commitd2e6e78680492f8c3cf81f97aa2a1d2aba85b79b (patch)
tree9b7df7d7e4d43159f8c8be6cc6e66b1e21f7abfb
parentd401e94ca5f7945d3da2c2927bfb038da3a066dd (diff)
downloadpython-linuxnamespaces-d2e6e78680492f8c3cf81f97aa2a1d2aba85b79b.tar.gz
add AtLocation.link method wrapping os.link
-rw-r--r--linuxnamespaces/atlocation.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py
index 6f0b8d9..70f9a77 100644
--- a/linuxnamespaces/atlocation.py
+++ b/linuxnamespaces/atlocation.py
@@ -217,6 +217,29 @@ class AtLocation:
follow_symlinks=follow_symlinks,
)
+ def link(self, dst: "AtLocationLike") -> None:
+ """Wrapper for os.link supplying src_dir_fd, dst_dir_fd and
+ follow_symlinks.
+ """
+ if self.flags & AtFlags.AT_NO_AUTOMOUNT != AtFlags.NONE:
+ raise NotImplementedError(
+ "link on AtFlags with unsupported source flags"
+ )
+ dst = AtLocation(dst)
+ if dst.flags != AtFlags.NONE:
+ raise NotImplementedError(
+ "link on AtFlags with unsupported destination flags"
+ )
+ os.link(
+ self.location,
+ dst.location,
+ src_dir_fd=self.fd_or_none,
+ dst_dir_fd=dst.fd_or_none,
+ follow_symlinks=(
+ self.flags & AtFlags.AT_SYMLINK_NOFOLLOW != AtFlags.NONE
+ ),
+ )
+
def mkdir(self, mode: int = 0o777) -> None:
"""Wrapper for os.mkdir supplying path and dir_fd."""
if self.flags != AtFlags.NONE: