summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-03-22 18:34:02 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-03-22 18:34:02 +0100
commit1c265b6e11c3ef27fb066176a6f1ddf6453dfe64 (patch)
tree93a19c3dcf7ffdd4141b12a203444ba9611a1b16
parentde6b129187ea1655b550ed274bd06dd7dc72d43a (diff)
downloadpython-linuxnamespaces-1c265b6e11c3ef27fb066176a6f1ddf6453dfe64.tar.gz
add os.stat wrapper AtLocation.stat
-rw-r--r--linuxnamespaces/atlocation.py17
1 files changed, 17 insertions, 0 deletions
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,