add lay_static, debug
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1075,6 +1075,7 @@ dependencies = [
|
|||||||
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ sequoia-openpgp = "0.12.0"
|
|||||||
oss-rust-sdk = "0.1.12"
|
oss-rust-sdk = "0.1.12"
|
||||||
chrono = "0.4.10"
|
chrono = "0.4.10"
|
||||||
zip = "0.5.3"
|
zip = "0.5.3"
|
||||||
|
lazy_static = "1.3.0"
|
||||||
rust_util = { git = "https://github.com/jht5945/rust_util" }
|
rust_util = { git = "https://github.com/jht5945/rust_util" }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -1,3 +1,5 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
extern crate sequoia_openpgp as openpgp;
|
extern crate sequoia_openpgp as openpgp;
|
||||||
pub mod oss_util;
|
pub mod oss_util;
|
||||||
pub mod pgp_util;
|
pub mod pgp_util;
|
||||||
@@ -71,15 +73,25 @@ fn main() -> XResult<()> {
|
|||||||
// TODO call it!
|
// 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<()> {
|
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);
|
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)? {
|
let meta_file_content = match oss_client.get_file_content(bucket_name, meta_file_key)? {
|
||||||
None => "[]".to_string(),
|
None => "[]".to_string(),
|
||||||
Some(c) => c,
|
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)?;
|
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)?;
|
oss_client.put_file_content(bucket_name, meta_file_key, &new_meta_file_content)?;
|
||||||
if !removed_file.is_empty() {
|
if !removed_file.is_empty() {
|
||||||
for rm_file in removed_file {
|
for rm_file in removed_file {
|
||||||
let rm_file_key = &format!("{}/{}", path, rm_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)?;
|
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};
|
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref IS_DEBUG: bool = is_env_on("DEBUG");
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub version: bool,
|
pub version: bool,
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user