1+ use std:: error:: Error ;
2+ use bx:: network:: url:: Url ;
3+ use colored:: { ColoredString , Colorize } ;
4+ use std:: { env, fs} ;
5+ use std:: path:: PathBuf ;
6+ use std:: sync:: Arc ;
7+ use std:: time:: Duration ;
8+ use tokio:: sync:: RwLock ;
9+
110use crate :: core:: services_all:: AllServices ;
211use crate :: core:: services_local:: LocalServices ;
312use crate :: core:: services_network:: NetworkServices ;
@@ -7,14 +16,7 @@ use crate::sys_config::software_config::SoftwareConfig;
716use crate :: terminal:: cmd:: Cmd ;
817use crate :: utils:: logger:: Logger ;
918use crate :: { log_error, log_info, log_warning} ;
10- use bx:: network:: url:: Url ;
11- use bx:: path:: Directory ;
12- use colored:: { ColoredString , Colorize } ;
13- use std:: env;
14- use std:: path:: PathBuf ;
15- use std:: sync:: Arc ;
16- use std:: time:: Duration ;
17- use tokio:: sync:: RwLock ;
19+
1820
1921#[ cfg( feature = "rest-api" ) ]
2022use crate :: rest_api:: restapi_main:: ApiMain ;
@@ -72,13 +74,13 @@ impl Cloud {
7274 CloudConfig :: check ( & url) . await ;
7375
7476 // check folder
75- Cloud :: check_folder ( ) ;
77+ Cloud :: check_folder ( ) . expect ( "Checking Folder failed" ) ;
7678
7779 // check software config file
7880 SoftwareConfig :: check ( & url) . await ;
7981
8082 // check the software files
81- Cloud :: check_software ( ) . await ;
83+ Cloud :: check_software ( ) . await . expect ( "Checking Software failed" ) ;
8284
8385 // NodeServer
8486 {
@@ -252,46 +254,48 @@ impl Cloud {
252254 }
253255 }
254256
255- pub fn check_folder ( ) {
257+ pub fn check_folder ( ) -> Result < ( ) , Box < dyn Error > > {
256258 let config_path = CloudConfig :: get ( ) . get_cloud_path ( ) ;
257259
258260 // create task folder
259- Directory :: create_path ( & config_path. get_task_folder_path ( ) ) ;
261+ fs :: create_dir_all ( & config_path. get_task_folder_path ( ) ) ? ;
260262
261263 // create template folder
262- Directory :: create_path ( & config_path. get_template_folder_path ( ) ) ;
264+ fs :: create_dir_all ( & config_path. get_template_folder_path ( ) ) ? ;
263265
264266 // create service temp folder
265- Directory :: create_path ( & config_path. get_service_folder ( ) . get_temp_folder_path ( ) ) ;
267+ fs :: create_dir_all ( & config_path. get_service_folder ( ) . get_temp_folder_path ( ) ) ? ;
266268
267269 // create service static folder
268- Directory :: create_path ( & config_path. get_service_folder ( ) . get_static_folder_path ( ) ) ;
270+ fs :: create_dir_all ( & config_path. get_service_folder ( ) . get_static_folder_path ( ) ) ? ;
269271
270272 // create system_plugins_folder
271- Directory :: create_path (
273+ fs :: create_dir_all (
272274 & config_path
273275 . get_system_folder ( )
274276 . get_system_plugins_folder_path ( ) ,
275- ) ;
277+ ) ? ;
276278
277279 // create software_files_folder
278- Directory :: create_path (
280+ fs :: create_dir_all (
279281 & config_path
280282 . get_system_folder ( )
281283 . get_software_files_folder_path ( ) ,
282- ) ;
284+ ) ? ;
283285
284286 // create software_lib_folder
285- Directory :: create_path (
287+ fs :: create_dir_all (
286288 & config_path
287289 . get_system_folder ( )
288290 . get_software_lib_folder_path ( ) ,
289- ) ;
291+ ) ? ;
290292 log_info ! ( "All Folders are safe :=)" ) ;
293+ Ok ( ( ) )
291294 }
292295
293296 // check software && system plugins
294- pub async fn check_software ( ) {
297+ pub async fn check_software ( ) -> Result < ( ) , Box < dyn Error > > {
298+ // Todo: refactoren 'check_software()'
295299 let software_types = SoftwareConfig :: get ( ) . get_software_types ( ) ;
296300 let cloud_config_system = CloudConfig :: get ( ) . get_cloud_path ( ) . get_system_folder ( ) ;
297301
@@ -309,9 +313,9 @@ impl Cloud {
309313 . join ( & software_type_name) ;
310314
311315 // create the software types folder
312- Directory :: create_path ( & software_path) ;
313- Directory :: create_path ( & system_plugins_path) ;
314- Directory :: create_path ( & software_lib_path) ;
316+ fs :: create_dir_all ( & software_path) ? ;
317+ fs :: create_dir_all ( & system_plugins_path) ? ;
318+ fs :: create_dir_all ( & software_lib_path) ? ;
315319
316320 // iter to software names
317321 for software in software_type. get_software_names ( ) {
@@ -344,7 +348,7 @@ impl Cloud {
344348 }
345349 Err ( e) => {
346350 log_error ! ( "{}" , e. to_string( ) ) ;
347- panic ! ( "Can not download the software {}" , software_file_url ) ;
351+ return Err ( e ) ;
348352 }
349353 }
350354 }
@@ -369,10 +373,7 @@ impl Cloud {
369373 }
370374 Err ( e) => {
371375 log_error ! ( "{}" , e. to_string( ) ) ;
372- panic ! (
373- "Can not download the Software System Plugin {}" ,
374- software. get_system_plugin( ) . get_download( )
375- ) ;
376+ return Err ( e) ;
376377 }
377378 }
378379 }
@@ -387,7 +388,7 @@ impl Cloud {
387388 {
388389 let mut path = software_lib_path. clone ( ) ;
389390 path. pop ( ) ;
390- Directory :: create_path ( & path) ;
391+ fs :: create_dir_all ( & path) ? ;
391392
392393 match Url :: download_file ( & url_str, & software_lib_path) . await {
393394 Ok ( _) => log_info ! (
@@ -405,6 +406,7 @@ impl Cloud {
405406 }
406407 }
407408 }
409+ Ok ( ( ) )
408410 }
409411}
410412
0 commit comments