mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 04:58:42 +00:00

* Optimize `CratesToml::load_from_reader`: Avoid dup monomorphization * Optimize `CratesToml::write_to_writer`: Avoid dup monomophization * Optimize `create_if_not_exist`: Take `&path` to avoid dup monomorphization * Fix `CratesToml::write_to_path`: Use exclusive file lock to prevent race conditions. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
13 lines
347 B
Rust
13 lines
347 B
Rust
use std::{fs, io, path::Path};
|
|
|
|
/// Returned file is readable and writable.
|
|
pub(crate) fn create_if_not_exist(path: &Path) -> io::Result<fs::File> {
|
|
let mut options = fs::File::options();
|
|
options.read(true).write(true);
|
|
|
|
options
|
|
.clone()
|
|
.create_new(true)
|
|
.open(path)
|
|
.or_else(|_| options.open(path))
|
|
}
|