11//! Coffee mod implementation
22use std:: collections:: HashMap ;
33use std:: fmt:: Debug ;
4- use std:: path:: Path ;
54use std:: vec:: Vec ;
65
76use async_trait:: async_trait;
@@ -21,7 +20,7 @@ use coffee_lib::plugin_manager::PluginManager;
2120use coffee_lib:: repository:: Repository ;
2221use coffee_lib:: types:: response:: * ;
2322use 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;
2524use coffee_lib:: { commit_id, error, get_repo_info, sh} ;
2625use coffee_storage:: model:: repository:: { Kind , Repository as RepositoryInfo } ;
2726use coffee_storage:: nosql_db:: NoSQlStorage ;
@@ -427,8 +426,8 @@ impl PluginManager for CoffeeManager {
427426 Ok ( ( ) )
428427 }
429428
430- async fn add_remote ( & mut self , name : & str , url : & str ) -> Result < ( ) , CoffeeError > {
431- if self . repos . contains_key ( name) {
429+ async fn add_remote ( & mut self , name : & str , url : & str , force : bool ) -> Result < ( ) , CoffeeError > {
430+ if !force && self . repos . contains_key ( name) {
432431 return Err ( error ! ( "repository with name: {name} already exists" ) ) ;
433432 }
434433 let url = URL :: new ( & self . config . path ( ) , url, name) ;
@@ -544,17 +543,22 @@ 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 , true ) . await ?;
554557 }
555558 nurse_actions
556- . push ( NurseStatus :: MovingGlobalRepostoryTo ( network. to_owned ( ) ) ) ;
559+ . push ( NurseStatus :: MovingGlobalRepostoryTo ( network. 1 . to_owned ( ) ) ) ;
557560 }
561+ let global_repo = format ! ( "{}/repositories" , self . config. root_path) ;
558562 rm_dir_if_exist ( & global_repo) . await ?;
559563 }
560564 }
@@ -587,7 +591,6 @@ impl PluginManager for CoffeeManager {
587591 . get_mut ( repo_name)
588592 . ok_or_else ( || error ! ( "repository with name: {repo_name} not found" ) ) ?;
589593
590- repo. change_root_path ( & self . config . path ( ) ) ;
591594 match repo. recover ( ) . await {
592595 Ok ( _) => {
593596 log:: info!( "repository {} recovered" , repo_name. clone( ) ) ;
0 commit comments