From 1f4defe0427d7a46b68585161de4e8a25b1febd6 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sat, 22 Feb 2025 22:51:43 +1100 Subject: [PATCH] Refactor mod crates_manifests to use create_if_not_exist Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> --- crates/binstalk-manifests/src/crates_manifests.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/binstalk-manifests/src/crates_manifests.rs b/crates/binstalk-manifests/src/crates_manifests.rs index 265e1e0d..4181775a 100644 --- a/crates/binstalk-manifests/src/crates_manifests.rs +++ b/crates/binstalk-manifests/src/crates_manifests.rs @@ -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,