add user assign config, -c -config

This commit is contained in:
2019-12-14 23:32:00 +08:00
parent dc1ab83d28
commit 795ff60e3e
2 changed files with 23 additions and 5 deletions

View File

@@ -195,8 +195,8 @@ pub fn get_string_value(json: &json::JsonValue, key: &str) -> Option<String> {
} }
} }
pub fn get_config_json() -> Option<json::JsonValue> { pub fn get_config_json(custom_oss_backupd_config: Option<&str>) -> Option<json::JsonValue> {
let config_content = get_config_content()?; let config_content = get_config_content(custom_oss_backupd_config)?;
match json::parse(&config_content) { match json::parse(&config_content) {
Err(e) => { Err(e) => {
print_message(MessageType::ERROR, &format!("Parse config json failed: {}", e)); print_message(MessageType::ERROR, &format!("Parse config json failed: {}", e));
@@ -206,7 +206,24 @@ pub fn get_config_json() -> Option<json::JsonValue> {
} }
} }
pub fn get_config_content() -> Option<String> { pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<String> {
if custom_oss_backupd_config.is_some() {
let custom_oss_backupd_config_unrwaped = custom_oss_backupd_config.unwrap();
let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_unrwaped);
if custom_oss_backupd_config_path.exists() {
match fs::read_to_string(custom_oss_backupd_config_path) {
Err(e) => {
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", custom_oss_backupd_config_unrwaped, e));
return None;
},
Ok(o) => return Some(o),
};
} else {
print_message(MessageType::ERROR, &format!("Custom config file not found: {}", custom_oss_backupd_config_unrwaped));
return None;
}
}
// is not assigned by -c or --conifg FILE
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() {
match fs::read_to_string(oss_backupd_config_path) { match fs::read_to_string(oss_backupd_config_path) {

View File

@@ -13,7 +13,7 @@ use rust_util::{
util_msg::*, util_msg::*,
}; };
use oss_util::*; use oss_util::*;
// use config_util::*; use config_util::*;
// use pgp_util::OpenPGPTool; // use pgp_util::OpenPGPTool;
use opt::{ use opt::{
Options, Options,
@@ -44,7 +44,8 @@ fn main() -> XResult<()> {
// let openpgp_client = OpenPGPTool::from_file("sample.gpg")?; // let openpgp_client = OpenPGPTool::from_file("sample.gpg")?;
// openpgp_client.encrypt_file("a", "b.asc", true)?; // openpgp_client.encrypt_file("a", "b.asc", true)?;
// let config_json = get_config_json(); let config_json = get_config_json(None); // TODO
// let j = config_json.unwrap(); // let j = config_json.unwrap();
// println!("{}", j); // println!("{}", j);
// let c = parse_config(&j); // let c = parse_config(&j);