From 97be9fda277e739c92ec18ce02f760dc6cd908cc Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 7 Mar 2024 23:33:38 +0100 Subject: add AtLocation.rename method wrapping os.rename --- linuxnamespaces/atlocation.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py index 70f9a77..eecfed1 100644 --- a/linuxnamespaces/atlocation.py +++ b/linuxnamespaces/atlocation.py @@ -279,6 +279,24 @@ class AtLocation: os.readlink(os.fspath(self.location), dir_fd=self.fd_or_none) ) + def rename(self, dst: "AtLocationLike") -> None: + """Wrapper for os.rename supplying src_dir_fd and dst_dir_fd.""" + if self.flags != AtFlags.AT_SYMLINK_NOFOLLOW: + raise NotImplementedError( + "rename on AtLocation only supports source flag AT_SYMLINK_NOFOLLOW" + ) + dst = AtLocation(dst) + if dst.flags != AtFlags.AT_SYMLINK_NOFOLLOW: + raise NotImplementedError( + "rename on AtLocation only supports destination flag AT_SYMLINK_NOFOLLOW" + ) + os.rename( + self.location, + dst.location, + src_dir_fd=self.fd_or_none, + dst_dir_fd=dst.fd_or_none, + ) + def rmdir(self) -> None: """Wrapper for os.rmdir supplying path and dir_fd.""" if self.flags != AtFlags.NONE: -- cgit v1.2.3