Refactor mod crates_manifests to use create_if_not_exist

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
Jiahao XU 2025-02-22 22:51:43 +11:00 committed by GitHub
parent cee14f9288
commit 1f4defe042
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,8 +12,7 @@ use thiserror::Error as ThisError;
use crate::{
binstall_crates_v1::{Error as BinstallCratesV1Error, Records as BinstallCratesV1Records},
cargo_crates_v1::{CratesToml, CratesTomlParseError},
crate_info::CrateInfo,
CompactString, Version,
crate_info::CrateInfo, helpers::create_if_not_exist, CompactString, Version,
};
#[derive(Debug, Diagnostic, ThisError)]
@ -47,13 +46,7 @@ impl Manifests {
// Read cargo_install_v1_metadata
let manifest_path = cargo_roots.join(".crates.toml");
let cargo_crates_v1 = fs::File::options()
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(manifest_path)
.and_then(FileLock::new_exclusive)?;
let cargo_crates_v1 = create_file_if_not_exist(manifest_path)?;
Ok(Self {
binstall,