diff --git a/Cargo.lock b/Cargo.lock index 27535bd..e98a49b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1075,6 +1075,7 @@ dependencies = [ "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "oss-rust-sdk 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 9b21e6d..6ce03eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ sequoia-openpgp = "0.12.0" oss-rust-sdk = "0.1.12" chrono = "0.4.10" zip = "0.5.3" +lazy_static = "1.3.0" rust_util = { git = "https://github.com/jht5945/rust_util" } diff --git a/src/main.rs b/src/main.rs index 9643f3f..ad05c40 100644 --- a/src/main.rs +++ b/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)?; } } diff --git a/src/opt.rs b/src/opt.rs index ee0ac83..f151df1 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -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,