From 1c265b6e11c3ef27fb066176a6f1ddf6453dfe64 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 22 Mar 2024 18:34:02 +0100 Subject: add os.stat wrapper AtLocation.stat --- linuxnamespaces/atlocation.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py index 08c0de5..c534150 100644 --- a/linuxnamespaces/atlocation.py +++ b/linuxnamespaces/atlocation.py @@ -313,6 +313,23 @@ class AtLocation: assert self.location return os.rmdir(self.location, dir_fd=self.fd_or_none) + def stat(self) -> os.stat_result: + """Wrapper for os.stat supplying dir_fd and follow_symlinks.""" + if self.flags == AtFlags.AT_EMPTY_PATH: + return os.stat(self.fd) + follow_symlinks = True + if self.flags == AtFlags.AT_SYMLINK_NOFOLLOW: + follow_symlinks = True + elif self.flags != AtFlags.NONE: + raise NotImplementedError( + "stat is not supported for an AtFlags with given flags" + ) + return os.stat( + self.location, + dir_fd=self.fd_or_none, + follow_symlinks=follow_symlinks, + ) + def symlink_to(self, linktarget: PathConvertible) -> None: """Create a symlink at self pointing to linktarget. Note that this method has its arguments reversed compared to the usual os.symlink, -- cgit v1.2.3