diff --git a/coffee_cmd/src/coffee_term/command_show.rs b/coffee_cmd/src/coffee_term/command_show.rs index 28497d8..ec48a99 100644 --- a/coffee_cmd/src/coffee_term/command_show.rs +++ b/coffee_cmd/src/coffee_term/command_show.rs @@ -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::() - .trim_end() - ); + let defect = "Network specific repository missing"; + let networks = networks + .iter() + .map(|(network, _)| network.clone()) + .collect::>(); table.push([ term::format::positive("●").into(), term::format::bold(defect.to_owned()), - term::format::highlight("_".to_owned()), + term::format::highlight(networks.join(", ")), ]); } } diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 0ed4adf..02a6a90 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -1,7 +1,6 @@ //! Coffee mod implementation use std::collections::HashMap; use std::fmt::Debug; -use std::path::Path; use std::vec::Vec; use async_trait::async_trait; @@ -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; @@ -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::>(); + 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?; } } @@ -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()); diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index fa6f7e2..1e6d5ff 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -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, @@ -343,6 +339,10 @@ impl Repository for Github { fn as_any(&self) -> &dyn Any { self } + + fn plugins(&mut self) -> &mut Vec { + &mut self.plugins + } } impl From for Github { diff --git a/coffee_lib/src/repository.rs b/coffee_lib/src/repository.rs index 586a51d..ffa7ee8 100644 --- a/coffee_lib/src/repository.rs +++ b/coffee_lib/src/repository.rs @@ -34,11 +34,6 @@ 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; @@ -46,4 +41,8 @@ pub trait Repository: Any { 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; }