1
1
//! Coffee mod implementation
2
2
use std:: collections:: HashMap ;
3
3
use std:: fmt:: Debug ;
4
- use std:: path:: Path ;
5
4
use std:: vec:: Vec ;
6
5
7
6
use async_trait:: async_trait;
@@ -21,7 +20,7 @@ use coffee_lib::plugin_manager::PluginManager;
21
20
use coffee_lib:: repository:: Repository ;
22
21
use coffee_lib:: types:: response:: * ;
23
22
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;
25
24
use coffee_lib:: { commit_id, error, get_repo_info, sh} ;
26
25
use coffee_storage:: model:: repository:: { Kind , Repository as RepositoryInfo } ;
27
26
use coffee_storage:: nosql_db:: NoSQlStorage ;
@@ -427,8 +426,8 @@ impl PluginManager for CoffeeManager {
427
426
Ok ( ( ) )
428
427
}
429
428
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) {
432
431
return Err ( error ! ( "repository with name: {name} already exists" ) ) ;
433
432
}
434
433
let url = URL :: new ( & self . config . path ( ) , url, name) ;
@@ -544,17 +543,21 @@ impl PluginManager for CoffeeManager {
544
543
let mut actions = self . patch_repository_locally_absent ( repos. to_vec ( ) ) . await ?;
545
544
nurse_actions. append ( & mut actions) ;
546
545
}
547
- 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 ?;
546
+ Defect :: CoffeeGlobalRepoCleanup ( networks) => {
547
+ for network in networks {
548
+ log:: debug!( "reindexing repository for the network `{:?}`" , network) ;
549
+ let iter = self
550
+ . repos
551
+ . iter ( )
552
+ . map ( |( name, repo) | ( name. to_owned ( ) , repo. url ( ) ) )
553
+ . collect :: < Vec < ( String , URL ) > > ( ) ;
554
+ for ( name, url) in iter {
555
+ self . add_remote ( & name, & url. url_string , true ) . await ?;
554
556
}
555
557
nurse_actions
556
- . push ( NurseStatus :: MovingGlobalRepostoryTo ( network. to_owned ( ) ) ) ;
558
+ . push ( NurseStatus :: MovingGlobalRepostoryTo ( network. 1 . to_owned ( ) ) ) ;
557
559
}
560
+ let global_repo = format ! ( "{}/repositories" , self . config. root_path) ;
558
561
rm_dir_if_exist ( & global_repo) . await ?;
559
562
}
560
563
}
@@ -587,7 +590,6 @@ impl PluginManager for CoffeeManager {
587
590
. get_mut ( repo_name)
588
591
. ok_or_else ( || error ! ( "repository with name: {repo_name} not found" ) ) ?;
589
592
590
- repo. change_root_path ( & self . config . path ( ) ) ;
591
593
match repo. recover ( ) . await {
592
594
Ok ( _) => {
593
595
log:: info!( "repository {} recovered" , repo_name. clone( ) ) ;
0 commit comments