Skip to content

Commit

Permalink
Merge install cache and trust cache into one
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 25, 2024
1 parent 94b210e commit c6c364d
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 381 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async-signal = "0.2"
async-once-cell = "0.5"
clap = { version = "4.5", features = ["derive"] }
const_format = "0.2"
dashmap = "5.5"
dashmap = { version = "5.5", features = ["serde"] }
dialoguer = "0.11"
dirs = "5.0"
futures = "0.3"
Expand All @@ -29,7 +29,7 @@ reqwest = { version = "0.12", default-features = false, features = [
] }
secrecy = "0.8"
semver = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
serde_with = { version = "3.7", features = ["macros"] }
tempfile = "3.3"
Expand Down
6 changes: 3 additions & 3 deletions lib/manifests/aftman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use toml_edit::{DocumentMut, Formatted, Item, Value};
use crate::{
result::{AftmanError, AftmanResult},
tool::{ToolAlias, ToolSpec},
util::{load_from_file_fallible, save_to_file},
util::{load_from_file, save_to_file},
};

pub const MANIFEST_FILE_NAME: &str = "aftman.toml";
Expand Down Expand Up @@ -37,7 +37,7 @@ impl AftmanManifest {
*/
pub async fn load_or_create(dir: impl AsRef<Path>) -> AftmanResult<Self> {
let path = dir.as_ref().join(MANIFEST_FILE_NAME);
match load_from_file_fallible(path).await {
match load_from_file(path).await {
Ok(manifest) => Ok(manifest),
Err(AftmanError::FileNotFound(_)) => {
let new = Self::default();
Expand All @@ -57,7 +57,7 @@ impl AftmanManifest {
pub async fn load(dir: impl AsRef<Path>) -> AftmanResult<Self> {
let path = dir.as_ref().join(MANIFEST_FILE_NAME);
tracing::trace!(?path, "Loading manifest");
load_from_file_fallible(path).await
load_from_file(path).await
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/manifests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use toml_edit::{DocumentMut, Formatted, Item, Value};
use crate::{
result::{AftmanError, AftmanResult},
sources::ArtifactProvider,
util::{load_from_file_fallible, save_to_file},
util::{load_from_file, save_to_file},
};

pub const MANIFEST_FILE_NAME: &str = "auth.toml";
Expand Down Expand Up @@ -36,7 +36,7 @@ impl AuthManifest {
*/
pub async fn load_or_create(dir: impl AsRef<Path>) -> AftmanResult<Self> {
let path = dir.as_ref().join(MANIFEST_FILE_NAME);
match load_from_file_fallible(path).await {
match load_from_file(path).await {
Ok(manifest) => Ok(manifest),
Err(AftmanError::FileNotFound(_)) => {
let new = Self::default();
Expand All @@ -56,7 +56,7 @@ impl AuthManifest {
pub async fn load(dir: impl AsRef<Path>) -> AftmanResult<Self> {
let path = dir.as_ref().join(MANIFEST_FILE_NAME);
tracing::trace!(?path, "Loading manifest");
load_from_file_fallible(path).await
load_from_file(path).await
}

/**
Expand Down
39 changes: 12 additions & 27 deletions lib/storage/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

use crate::result::{AftmanError, AftmanResult};

use super::{InstallCache, ToolStorage, TrustCache};
use super::{ToolCache, ToolStorage};

/**
Aftman's home directory - this is where Aftman stores its
Expand All @@ -19,9 +19,8 @@ use super::{InstallCache, ToolStorage, TrustCache};
pub struct Home {
path: Arc<Path>,
did_save: Arc<AtomicBool>,
trust_cache: TrustCache,
install_cache: InstallCache,
tool_storage: ToolStorage,
tool_cache: ToolCache,
}

impl Home {
Expand All @@ -32,18 +31,14 @@ impl Home {
let path: Arc<Path> = path.into().into();
let did_save = Arc::new(AtomicBool::new(false));

let (trust_cache, install_cache, tool_storage) = tokio::try_join!(
TrustCache::load(&path),
InstallCache::load(&path),
ToolStorage::load(&path),
)?;
let (tool_storage, tool_cache) =
tokio::try_join!(ToolStorage::load(&path), ToolCache::load(&path))?;

Ok(Self {
path,
did_save,
trust_cache,
install_cache,
tool_storage,
tool_cache,
})
}

Expand Down Expand Up @@ -77,34 +72,24 @@ impl Home {
}

/**
Returns a reference to the `TrustCache` for this `Home`.
*/
pub fn trust_cache(&self) -> &TrustCache {
&self.trust_cache
}

/**
Returns a reference to the `InstallCache` for this `Home`.
Returns a reference to the `ToolStorage` for this `Home`.
*/
pub fn install_cache(&self) -> &InstallCache {
&self.install_cache
pub fn tool_storage(&self) -> &ToolStorage {
&self.tool_storage
}

/**
Returns a reference to the `ToolStorage` for this `Home`.
Returns a reference to the `ToolCache` for this `Home`.
*/
pub fn tool_storage(&self) -> &ToolStorage {
&self.tool_storage
pub fn tool_cache(&self) -> &ToolCache {
&self.tool_cache
}

/**
Saves the contents of this `Home` to disk.
*/
pub async fn save(&self) -> AftmanResult<()> {
tokio::try_join!(
self.trust_cache.save(&self.path),
self.install_cache.save(&self.path),
)?;
self.tool_cache.save(&self.path).await?;
self.did_save.store(true, Ordering::SeqCst);
Ok(())
}
Expand Down
169 changes: 0 additions & 169 deletions lib/storage/install_cache.rs

This file was deleted.

6 changes: 2 additions & 4 deletions lib/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod home;
mod install_cache;
mod tool_cache;
mod tool_storage;
mod trust_cache;

pub use self::home::Home;
pub use self::install_cache::InstallCache;
pub use self::tool_cache::ToolCache;
pub use self::tool_storage::ToolStorage;
pub use self::trust_cache::TrustCache;
Loading

0 comments on commit c6c364d

Please sign in to comment.