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
+12 -7
View File
@@ -4,19 +4,24 @@
//!
//! Copyright IBM Corp. 2023, 2024
mod cli;
mod file;
mod hexslice;
mod log;
mod tmpfile;
pub use crate::cli::{get_reader_from_cli_file_arg, get_writer_from_cli_file_arg};
pub use crate::cli::{print_cli_error, print_error};
pub use crate::cli::{CertificateOptions, DeprecatedVerbosityOptions, VerbosityOptions};
pub use crate::cli::{STDIN, STDOUT};
pub use crate::hexslice::HexSlice;
pub use crate::log::PvLogger;
pub use crate::tmpfile::TemporaryDirectory;
pub use ::log::LevelFilter;
pub use crate::{
cli::{
get_reader_from_cli_file_arg, get_writer_from_cli_file_arg, print_cli_error, print_error,
CertificateOptions, DeprecatedVerbosityOptions, VerbosityOptions, STDIN, STDOUT,
},
file::{AtomicFile, AtomicFileOperation},
hexslice::HexSlice,
log::PvLogger,
tmpfile::TemporaryDirectory,
};
/// Get the s390-tools release string
///
/// Provides the s390-tools release string.