update use

This commit is contained in:
2020-04-12 01:19:44 +08:00
parent f1ede0bca7
commit b7c747c565
5 changed files with 24 additions and 57 deletions

View File

@@ -1,10 +1,7 @@
use std::{
fs,
path::Path,
cmp::{
min,
max,
},
cmp::{ min, max, },
};
use rust_util::{
iff,
@@ -136,11 +133,10 @@ pub fn parse_config(config_json: &json::JsonValue) -> OSSBackupdConfig {
pub fn get_config_json(custom_oss_backupd_config: Option<&str>, verbose: bool) -> Option<json::JsonValue> {
let config_content = get_config_content(custom_oss_backupd_config, verbose)?;
match json::parse(&config_content) {
Err(e) => {
Ok(o) => Some(o), Err(e) => {
print_message(MessageType::ERROR, &format!("Parse config json failed: {}", e));
None
},
Ok(o) => Some(o),
}
}
@@ -255,11 +251,10 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_val);
if custom_oss_backupd_config_path.exists() {
return match fs::read_to_string(custom_oss_backupd_config_path) {
Err(e) => {
Ok(o) => Some(o), Err(e) => {
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", custom_oss_backupd_config_val, e));
None
},
Ok(o) => Some(o),
};
} else {
print_message(MessageType::ERROR, &format!("Custom config file not found: {}", custom_oss_backupd_config_val));
@@ -273,19 +268,17 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
print_message(MessageType::DEBUG, &format!("Read config from: {}", OSS_BACKUPD_CONFIG));
}
return match fs::read_to_string(oss_backupd_config_path) {
Err(e) => {
Ok(o) => Some(o), Err(e) => {
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", OSS_BACKUPD_CONFIG, e));
None
},
Ok(o) => Some(o),
};
}
let home_dot_oss_backupd_config = & match get_user_home_dir(DOT_OSS_BACKUPD_CONFIG) {
Err(e) => {
Ok(o) => o, Err(e) => {
print_message(MessageType::WARN, &format!("Get user home error: {}", e));
String::new()
},
Ok(o) => o,
};
if !home_dot_oss_backupd_config.is_empty() {
let home_dot_oss_backupd_config_path = Path::new(home_dot_oss_backupd_config);
@@ -294,11 +287,10 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
print_message(MessageType::DEBUG, &format!("Read config from: {}", home_dot_oss_backupd_config));
}
return match fs::read_to_string(home_dot_oss_backupd_config_path) {
Err(e) => {
Ok(o) => Some(o), Err(e) => {
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", home_dot_oss_backupd_config, e));
None
},
Ok(o) => Some(o),
};
}
}
@@ -308,11 +300,10 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
print_message(MessageType::DEBUG, &format!("Read config from: {}", ETC_OSS_BACKUPD_CONFIG));
}
return match fs::read_to_string(etc_oss_backupd_config_path) {
Err(e) => {
Ok(o) => Some(o), Err(e) => {
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", ETC_OSS_BACKUPD_CONFIG, e));
None
},
Ok(o) => Some(o),
};
}