From c791d23e2fdc8335e6734975ac3bb265b862e3b2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 22 Feb 2021 10:59:07 +0100 Subject: Remove MergedStores The concept of the MergedStores type was okay in the beginning, but it got more and more complex to use properly and most of the time, we used the release/staging stores directly anyways. So this removes the MergedStores type, which is a preparation for the change to have multiple release stores. Signed-off-by: Matthias Beyer --- src/filestore/merged.rs | 98 ------------------------------------------------- src/filestore/mod.rs | 3 -- src/filestore/path.rs | 4 -- 3 files changed, 105 deletions(-) delete mode 100644 src/filestore/merged.rs (limited to 'src/filestore') diff --git a/src/filestore/merged.rs b/src/filestore/merged.rs deleted file mode 100644 index 1503870..0000000 --- a/src/filestore/merged.rs +++ /dev/null @@ -1,98 +0,0 @@ -// -// Copyright (c) 2020-2021 science+computing ag and other contributors -// -// This program and the accompanying materials are made -// available under the terms of the Eclipse Public License 2.0 -// which is available at https://www.eclipse.org/legal/epl-2.0/ -// -// SPDX-License-Identifier: EPL-2.0 -// - -// TODO: The MergedStores is not used at all anymore, because we removed the feature while doing -// the rewrite -#![allow(unused)] - -use std::sync::Arc; -use std::path::Path; - -use anyhow::anyhow; -use anyhow::Result; -use getset::Getters; -use log::trace; -use tokio::sync::RwLock; - -use crate::filestore::path::ArtifactPath; -use crate::filestore::path::FullArtifactPath; -use crate::filestore::ReleaseStore; -use crate::filestore::StagingStore; - - -/// A type that merges the release store and the staging store -/// -/// The stores are not actually merged (on disk or in memory), but the querying mechanism works in -/// a way where it _always_ preferes the staging store over the release store. -/// -#[derive(Clone, Getters)] -pub struct MergedStores { - #[getset(get = "pub")] - release: Arc>, - - #[getset(get = "pub")] - staging: Arc>, -} - -impl MergedStores { - pub fn new(release: Arc>, staging: Arc>) -> Self { - MergedStores { release, staging } - } - - pub async fn get_artifact_by_path(&self, p: &Path) -> Result> { - trace!("Fetching artifact from path: {:?}", p.display()); - let artifact_path = ArtifactPath::new(p.to_path_buf())?; - - let staging = &mut self.staging.write().await.0; - let staging_path = staging - .root_path() - .join(&artifact_path)? - .ok_or_else(|| anyhow!("Does not exist in staging store: {:?}", artifact_path))?; - trace!("staging_path = {:?}", staging_path.display()); - - if staging_path.exists() { - let art = if let Some(art) = staging.get(&artifact_path) { - art - } else { - trace!("Loading path from staging store: {:?}", artifact_path.display()); - staging.load_from_path(&artifact_path) - }; - - return Ok(Some(art.clone())) - } - - let release = &mut self.release.write().await.0; - let release_path = release.root_path() - .join(&artifact_path)? - .ok_or_else(|| anyhow!("Not found in release store: {:?}", artifact_path))?; - trace!("release_path = {:?}", release_path); - - if release_path.exists() { - let art = if let Some(art) = release.get(&artifact_path) { - art - } else { - trace!("Loading path from release store: {:?}", artifact_path.display()); - release.load_from_path(&artifact_path) - }; - return Ok(Some(art.clone())) - } - - Ok(None) - } - - pub async fn get(&self, p: &ArtifactPath) -> Option { - if let Some(a) = self.staging.read().await.get(p).cloned() { - return Some(a) - } - - self.release.read().await.get(p).cloned() - } - -} diff --git a/src/filestore/mod.rs b/src/filestore/mod.rs index 29eb476..8d788e2 100644 --- a/src/filestore/mod.rs +++ b/src/filestore/mod.rs @@ -14,9 +14,6 @@ pub use release::*; mod staging; pub use staging::*; -mod merged; -pub use merged::*; - pub mod path; pub use path::ArtifactPath; diff --git a/src/filestore/path.rs b/src/filestore/path.rs index 19016bd..4d75855 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -154,10 +154,6 @@ impl<'a> FullArtifactPath<'a> { self.0 .0.join(&self.1 .0) } - pub fn exists(&self) -> bool { - self.joined().exists() - } - pub fn display(&self) -> FullArtifactPathDisplay<'a> { FullArtifactPathDisplay(self.0, self.1) } -- cgit v1.2.3