Skip to content

Commit

Permalink
fixup! feat(core): nurse clean up the global repository
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Apr 12, 2024
1 parent 2a1fa61 commit 0151c5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
15 changes: 6 additions & 9 deletions coffee_cmd/src/coffee_term/command_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,15 @@ pub fn show_nurse_verify(nurse_verify: &ChainOfResponsibilityStatus) -> Result<(
}
}
Defect::CoffeeGlobalrepoCleanup(networks) => {
let defect = format!(
"Global repository migration completed for the networks: {}",
networks
.iter()
.map(|(network, _)| format!("{network} "))
.collect::<String>()
.trim_end()
);
let defect = "Network specific repository missing";
let networks = networks
.iter()
.map(|(network, _)| network.clone())
.collect::<Vec<String>>();
table.push([
term::format::positive("●").into(),
term::format::bold(defect.to_owned()),
term::format::highlight("_".to_owned()),
term::format::highlight(networks.join(", ")),
]);
}
}
Expand Down
23 changes: 12 additions & 11 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Coffee mod implementation
use std::collections::HashMap;
use std::fmt::Debug;
use std::path::Path;
use std::vec::Vec;

Check warning on line 4 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `Vec` is imported redundantly

Check warning on line 4 in coffee_core/src/coffee.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `Vec` is imported redundantly

use async_trait::async_trait;
Expand All @@ -21,7 +20,7 @@ use coffee_lib::plugin_manager::PluginManager;
use coffee_lib::repository::Repository;
use coffee_lib::types::response::*;
use coffee_lib::url::URL;
use coffee_lib::utils::{check_dir_or_make_if_missing, copy_dir_if_exist, rm_dir_if_exist};
use coffee_lib::utils::rm_dir_if_exist;
use coffee_lib::{commit_id, error, get_repo_info, sh};
use coffee_storage::model::repository::{Kind, Repository as RepositoryInfo};
use coffee_storage::nosql_db::NoSQlStorage;
Expand Down Expand Up @@ -544,17 +543,20 @@ impl PluginManager for CoffeeManager {
let mut actions = self.patch_repository_locally_absent(repos.to_vec()).await?;
nurse_actions.append(&mut actions);
}
// FIXME: this should act just for a single network not for everyone
Defect::CoffeeGlobalrepoCleanup(networks) => {
let global_repo = format!("{}/repositories", self.config.root_path);
for (network, path) in networks {
log::info!("{network} - {path}");
check_dir_or_make_if_missing(path.to_owned()).await?;
if !Path::exists(Path::new(&path)) {
copy_dir_if_exist(&global_repo, path).await?;
for network in networks {
log::debug!("reindexing repository for the network `{:?}`", network);
let iter = self
.repos
.iter()
.map(|(name, repo)| (name.to_owned(), repo.url()))
.collect::<Vec<(String, URL)>>();
for (name, url) in iter {
self.add_remote(&name, &url.url_string).await?;
}
nurse_actions
.push(NurseStatus::MovingGlobalRepostoryTo(network.to_owned()));
}
let global_repo = format!("{}/repositories", self.config.root_path);
rm_dir_if_exist(&global_repo).await?;
}
}
Expand Down Expand Up @@ -587,7 +589,6 @@ impl PluginManager for CoffeeManager {
.get_mut(repo_name)
.ok_or_else(|| error!("repository with name: {repo_name} not found"))?;

repo.change_root_path(&self.config.path());
match repo.recover().await {
Ok(_) => {
log::info!("repository {} recovered", repo_name.clone());
Expand Down
8 changes: 4 additions & 4 deletions coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ impl Repository for Github {
}
}

fn change_root_path(&mut self, path: &str) {
self.url.set_coffee_path(path);
}

async fn upgrade(
&mut self,
plugins: &Vec<Plugin>,
Expand Down Expand Up @@ -343,6 +339,10 @@ impl Repository for Github {
fn as_any(&self) -> &dyn Any {
self
}

fn plugins(&mut self) -> &mut Vec<Plugin> {
&mut self.plugins
}
}

impl From<StorageRepository> for Github {
Expand Down
9 changes: 4 additions & 5 deletions coffee_lib/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ pub trait Repository: Any {
/// recover the repository from the commit id.
async fn recover(&mut self) -> Result<(), CoffeeError>;

/// While migrating there is a possibility that we should
/// move an old repository into a new path. So this
/// is semplyfing this process.
fn change_root_path(&mut self, path: &str);

/// return the name of the repository.
fn name(&self) -> String;

/// return the url of the repository.
fn url(&self) -> URL;

fn as_any(&self) -> &dyn Any;

/// Return the vector of plugin
/// that are inside the repository
fn plugins(&mut self) -> &mut Vec<Plugin>;
}

0 comments on commit 0151c5c

Please sign in to comment.