style: code style

This commit is contained in:
2020-08-02 23:04:15 +08:00
parent a611649834
commit 5ecf3335b4

View File

@@ -1,17 +1,11 @@
use std::{ use std::{
fs, fs,
path::Path, path::Path,
cmp::{ min, max, }, cmp::{ min, max },
}; };
use rust_util::{ use rust_util::{
iff,
XResult, XResult,
new_box_ioerror, new_box_ioerror,
util_msg::{
print_warn,
print_error,
print_debug,
},
}; };
use chrono::Utc; use chrono::Utc;
@@ -141,7 +135,7 @@ pub fn get_config_json(custom_oss_backupd_config: Option<&str>, verbose: bool) -
let config_content = get_config_content(custom_oss_backupd_config, verbose)?; let config_content = get_config_content(custom_oss_backupd_config, verbose)?;
match json::parse(&config_content) { match json::parse(&config_content) {
Ok(o) => Some(o), Err(e) => { Ok(o) => Some(o), Err(e) => {
print_error(&format!("Parse config json failed: {}", e)); failure!("Parse config json failed: {}", e);
None None
}, },
} }
@@ -251,18 +245,18 @@ fn get_u32_value(json: &json::JsonValue, key: &str) -> Option<u32> {
fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) -> Option<String> { fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) -> Option<String> {
if let Some(custom_oss_backupd_config_val) = custom_oss_backupd_config { if let Some(custom_oss_backupd_config_val) = custom_oss_backupd_config {
if verbose { if verbose {
print_debug(&format!("Read config from: {}", custom_oss_backupd_config_val)); debugging!("Read config from: {}", custom_oss_backupd_config_val);
} }
let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_val); let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_val);
if custom_oss_backupd_config_path.exists() { if custom_oss_backupd_config_path.exists() {
return match fs::read_to_string(custom_oss_backupd_config_path) { return match fs::read_to_string(custom_oss_backupd_config_path) {
Ok(o) => Some(o), Err(e) => { Ok(o) => Some(o), Err(e) => {
print_error(&format!("Read config file {} error: {}", custom_oss_backupd_config_val, e)); failure!("Read config file {} error: {}", custom_oss_backupd_config_val, e);
None None
}, },
}; };
} else { } else {
print_error(&format!("Custom config file not found: {}", custom_oss_backupd_config_val)); failure!("Custom config file not found: {}", custom_oss_backupd_config_val);
return None; return None;
} }
} }
@@ -270,18 +264,18 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
let oss_backupd_config_path = Path::new(OSS_BACKUPD_CONFIG); let oss_backupd_config_path = Path::new(OSS_BACKUPD_CONFIG);
if oss_backupd_config_path.exists() { if oss_backupd_config_path.exists() {
if verbose { if verbose {
print_debug(&format!("Read config from: {}", OSS_BACKUPD_CONFIG)); debugging!("Read config from: {}", OSS_BACKUPD_CONFIG);
} }
return match fs::read_to_string(oss_backupd_config_path) { return match fs::read_to_string(oss_backupd_config_path) {
Ok(o) => Some(o), Err(e) => { Ok(o) => Some(o), Err(e) => {
print_error(&format!("Read config file {} error: {}", OSS_BACKUPD_CONFIG, e)); failure!("Read config file {} error: {}", OSS_BACKUPD_CONFIG, e);
None None
}, },
}; };
} }
let home_dot_oss_backupd_config = & match get_user_home_dir(DOT_OSS_BACKUPD_CONFIG) { let home_dot_oss_backupd_config = & match get_user_home_dir(DOT_OSS_BACKUPD_CONFIG) {
Ok(o) => o, Err(e) => { Ok(o) => o, Err(e) => {
print_warn(&format!("Get user home error: {}", e)); warning!("Get user home error: {}", e);
String::new() String::new()
}, },
}; };
@@ -289,11 +283,11 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
let home_dot_oss_backupd_config_path = Path::new(home_dot_oss_backupd_config); let home_dot_oss_backupd_config_path = Path::new(home_dot_oss_backupd_config);
if home_dot_oss_backupd_config_path.exists() { if home_dot_oss_backupd_config_path.exists() {
if verbose { if verbose {
print_debug(&format!("Read config from: {}", home_dot_oss_backupd_config)); debugging!("Read config from: {}", home_dot_oss_backupd_config);
} }
return match fs::read_to_string(home_dot_oss_backupd_config_path) { return match fs::read_to_string(home_dot_oss_backupd_config_path) {
Ok(o) => Some(o), Err(e) => { Ok(o) => Some(o), Err(e) => {
print_error(&format!("Read config file {} error: {}", home_dot_oss_backupd_config, e)); failure!("Read config file {} error: {}", home_dot_oss_backupd_config, e);
None None
}, },
}; };
@@ -302,17 +296,17 @@ fn get_config_content(custom_oss_backupd_config: Option<&str>, verbose: bool) ->
let etc_oss_backupd_config_path = Path::new(ETC_OSS_BACKUPD_CONFIG); let etc_oss_backupd_config_path = Path::new(ETC_OSS_BACKUPD_CONFIG);
if etc_oss_backupd_config_path.exists() { if etc_oss_backupd_config_path.exists() {
if verbose { if verbose {
print_debug(&format!("Read config from: {}", ETC_OSS_BACKUPD_CONFIG)); debugging!("Read config from: {}", ETC_OSS_BACKUPD_CONFIG);
} }
return match fs::read_to_string(etc_oss_backupd_config_path) { return match fs::read_to_string(etc_oss_backupd_config_path) {
Ok(o) => Some(o), Err(e) => { Ok(o) => Some(o), Err(e) => {
print_error(&format!("Read config file {} error: {}", ETC_OSS_BACKUPD_CONFIG, e)); failure!("Read config file {} error: {}", ETC_OSS_BACKUPD_CONFIG, e);
None None
}, },
}; };
} }
print_error("Cannot find config file"); failure!("Cannot find config file");
None None
} }