From d2e6e78680492f8c3cf81f97aa2a1d2aba85b79b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 7 Mar 2024 23:17:16 +0100 Subject: add AtLocation.link method wrapping os.link --- linuxnamespaces/atlocation.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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: -- cgit v1.2.3