rust/utils: Add AtomicFile

This type helps to perform atomic operations by writing to a temporary
file and renaming it to the actual filename when the
`AtomicFile::finish` function is called. If the `AtomicFile::finish`
function is never called, the temporary file is automatically removed
when it goes out of scope. It utilizes the `renameat2` [1] libc function
and its semantics.

[1] https://man7.org/linux/man-pages/man2/renameat.2.html
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-11-11 10:27:21 +00:00
committed by Steffen Eiden
parent 171432852b
commit 938fe2a744
3 changed files with 322 additions and 7 deletions
+7
View File
@@ -36,6 +36,13 @@ pub enum Error {
source: std::io::Error,
},
#[error("Cannot rename '{src}' to '{dst}'")]
FileAccessRename {
src: String,
dst: String,
source: std::io::Error,
},
#[error("Cannot encode secrets (Too many secrets)")]
ManySecrets,