diff options
author | Helmut Grohne <helmut@subdivi.de> | 2024-03-07 23:33:38 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2024-03-07 23:33:38 +0100 |
commit | 97be9fda277e739c92ec18ce02f760dc6cd908cc (patch) | |
tree | 93e114f03ce2fadfd698d8cafbfa71e30ca53460 | |
parent | d2e6e78680492f8c3cf81f97aa2a1d2aba85b79b (diff) | |
download | python-linuxnamespaces-97be9fda277e739c92ec18ce02f760dc6cd908cc.tar.gz |
add AtLocation.rename method wrapping os.rename
-rw-r--r-- | linuxnamespaces/atlocation.py | 18 |
1 files changed, 18 insertions, 0 deletions
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: |