Skip to content

Commit 0151c5c

Browse files
fixup! feat(core): nurse clean up the global repository
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 2a1fa61 commit 0151c5c

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

coffee_cmd/src/coffee_term/command_show.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,15 @@ pub fn show_nurse_verify(nurse_verify: &ChainOfResponsibilityStatus) -> Result<(
114114
}
115115
}
116116
Defect::CoffeeGlobalrepoCleanup(networks) => {
117-
let defect = format!(
118-
"Global repository migration completed for the networks: {}",
119-
networks
120-
.iter()
121-
.map(|(network, _)| format!("{network} "))
122-
.collect::<String>()
123-
.trim_end()
124-
);
117+
let defect = "Network specific repository missing";
118+
let networks = networks
119+
.iter()
120+
.map(|(network, _)| network.clone())
121+
.collect::<Vec<String>>();
125122
table.push([
126123
term::format::positive("●").into(),
127124
term::format::bold(defect.to_owned()),
128-
term::format::highlight("_".to_owned()),
125+
term::format::highlight(networks.join(", ")),
129126
]);
130127
}
131128
}

coffee_core/src/coffee.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Coffee mod implementation
22
use std::collections::HashMap;
33
use std::fmt::Debug;
4-
use std::path::Path;
54
use std::vec::Vec;
65

76
use async_trait::async_trait;
@@ -21,7 +20,7 @@ use coffee_lib::plugin_manager::PluginManager;
2120
use coffee_lib::repository::Repository;
2221
use coffee_lib::types::response::*;
2322
use coffee_lib::url::URL;
24-
use coffee_lib::utils::{check_dir_or_make_if_missing, copy_dir_if_exist, rm_dir_if_exist};
23+
use coffee_lib::utils::rm_dir_if_exist;
2524
use coffee_lib::{commit_id, error, get_repo_info, sh};
2625
use coffee_storage::model::repository::{Kind, Repository as RepositoryInfo};
2726
use coffee_storage::nosql_db::NoSQlStorage;
@@ -544,17 +543,20 @@ impl PluginManager for CoffeeManager {
544543
let mut actions = self.patch_repository_locally_absent(repos.to_vec()).await?;
545544
nurse_actions.append(&mut actions);
546545
}
546+
// FIXME: this should act just for a single network not for everyone
547547
Defect::CoffeeGlobalrepoCleanup(networks) => {
548-
let global_repo = format!("{}/repositories", self.config.root_path);
549-
for (network, path) in networks {
550-
log::info!("{network} - {path}");
551-
check_dir_or_make_if_missing(path.to_owned()).await?;
552-
if !Path::exists(Path::new(&path)) {
553-
copy_dir_if_exist(&global_repo, path).await?;
548+
for network in networks {
549+
log::debug!("reindexing repository for the network `{:?}`", network);
550+
let iter = self
551+
.repos
552+
.iter()
553+
.map(|(name, repo)| (name.to_owned(), repo.url()))
554+
.collect::<Vec<(String, URL)>>();
555+
for (name, url) in iter {
556+
self.add_remote(&name, &url.url_string).await?;
554557
}
555-
nurse_actions
556-
.push(NurseStatus::MovingGlobalRepostoryTo(network.to_owned()));
557558
}
559+
let global_repo = format!("{}/repositories", self.config.root_path);
558560
rm_dir_if_exist(&global_repo).await?;
559561
}
560562
}
@@ -587,7 +589,6 @@ impl PluginManager for CoffeeManager {
587589
.get_mut(repo_name)
588590
.ok_or_else(|| error!("repository with name: {repo_name} not found"))?;
589591

590-
repo.change_root_path(&self.config.path());
591592
match repo.recover().await {
592593
Ok(_) => {
593594
log::info!("repository {} recovered", repo_name.clone());

coffee_github/src/repository.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ impl Repository for Github {
233233
}
234234
}
235235

236-
fn change_root_path(&mut self, path: &str) {
237-
self.url.set_coffee_path(path);
238-
}
239-
240236
async fn upgrade(
241237
&mut self,
242238
plugins: &Vec<Plugin>,
@@ -343,6 +339,10 @@ impl Repository for Github {
343339
fn as_any(&self) -> &dyn Any {
344340
self
345341
}
342+
343+
fn plugins(&mut self) -> &mut Vec<Plugin> {
344+
&mut self.plugins
345+
}
346346
}
347347

348348
impl From<StorageRepository> for Github {

coffee_lib/src/repository.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ pub trait Repository: Any {
3434
/// recover the repository from the commit id.
3535
async fn recover(&mut self) -> Result<(), CoffeeError>;
3636

37-
/// While migrating there is a possibility that we should
38-
/// move an old repository into a new path. So this
39-
/// is semplyfing this process.
40-
fn change_root_path(&mut self, path: &str);
41-
4237
/// return the name of the repository.
4338
fn name(&self) -> String;
4439

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

4843
fn as_any(&self) -> &dyn Any;
44+
45+
/// Return the vector of plugin
46+
/// that are inside the repository
47+
fn plugins(&mut self) -> &mut Vec<Plugin>;
4948
}

0 commit comments

Comments
 (0)