add lay_static, debug
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -1,3 +1,5 @@
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate sequoia_openpgp as openpgp;
|
||||
pub mod oss_util;
|
||||
pub mod pgp_util;
|
||||
@@ -71,15 +73,25 @@ fn main() -> XResult<()> {
|
||||
// TODO call it!
|
||||
pub fn process_oss_files(oss_client: &OSSClient, bucket_name: &str, path: &str, meta_file_name: &str, new_file: &str, limit: usize) -> XResult<()> {
|
||||
let meta_file_key = &format!("{}/{}", path, meta_file_name);
|
||||
if *opt::IS_DEBUG {
|
||||
print_message(MessageType::DEBUG, &format!("Read meta file: {}", meta_file_key));
|
||||
}
|
||||
let meta_file_content = match oss_client.get_file_content(bucket_name, meta_file_key)? {
|
||||
None => "[]".to_string(),
|
||||
Some(c) => c,
|
||||
};
|
||||
if *opt::IS_DEBUG {
|
||||
print_message(MessageType::DEBUG, &format!("Read meta file content: {}", &meta_file_content));
|
||||
}
|
||||
let (removed_file, new_meta_file_content) = process_new_backup_file(&meta_file_content, new_file, limit)?;
|
||||
if *opt::IS_DEBUG {
|
||||
print_message(MessageType::DEBUG, &format!("Processed meta file content: {}", &new_meta_file_content));
|
||||
}
|
||||
oss_client.put_file_content(bucket_name, meta_file_key, &new_meta_file_content)?;
|
||||
if !removed_file.is_empty() {
|
||||
for rm_file in removed_file {
|
||||
let rm_file_key = &format!("{}/{}", path, rm_file);
|
||||
print_message(MessageType::INFO, &format!("Remove OSS key: {}", rm_file_key));
|
||||
oss_client.delete_file(bucket_name, rm_file_key)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
use rust_util::XResult;
|
||||
use rust_util::{
|
||||
XResult,
|
||||
util_env::is_env_on,
|
||||
};
|
||||
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref IS_DEBUG: bool = is_env_on("DEBUG");
|
||||
}
|
||||
|
||||
pub struct Options {
|
||||
pub version: bool,
|
||||
pub verbose: bool,
|
||||
|
||||
Reference in New Issue
Block a user