add use_zip
This commit is contained in:
@@ -7,9 +7,10 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
# cargo b --features sequoia_openpgp
|
||||
default = [] # "sequoia_openpgp"
|
||||
sequoia_openpgp = ["sequoia-openpgp"]
|
||||
# cargo b --features use_sequoia_openpgp
|
||||
default = [] # "use_sequoia_openpgp"
|
||||
use_zip = []
|
||||
use_sequoia_openpgp = ["sequoia-openpgp"]
|
||||
|
||||
[dependencies]
|
||||
dirs = "2.0.1"
|
||||
|
||||
33
src/main.rs
33
src/main.rs
@@ -1,11 +1,12 @@
|
||||
// #[macro_use]
|
||||
// extern crate lazy_static;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
#[cfg(feature = "use_sequoia_openpgp")]
|
||||
extern crate sequoia_openpgp as openpgp;
|
||||
mod oss_util;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
#[cfg(feature = "use_sequoia_openpgp")]
|
||||
mod pgp_util;
|
||||
mod config_util;
|
||||
#[cfg(not(feature = "use_zip"))]
|
||||
mod zip_util;
|
||||
mod opt;
|
||||
|
||||
@@ -21,7 +22,7 @@ use rust_util::{
|
||||
};
|
||||
use oss_util::*;
|
||||
use config_util::*;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
#[cfg(feature = "use_sequoia_openpgp")]
|
||||
use pgp_util::OpenPGPTool;
|
||||
use opt::Options;
|
||||
|
||||
@@ -127,12 +128,31 @@ fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem,
|
||||
if options.verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Compress file: {} -> {}", target, temp_zip_file));
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "use_zip"))]
|
||||
let zip_file = || {
|
||||
if let Err(e) = zip_util::zip_file(target, temp_zip_file) {
|
||||
print_message(MessageType::ERROR, &format!("Error in zip file: {}, at item index: {}", e, item_index));
|
||||
return Ok(());
|
||||
return false;
|
||||
};
|
||||
true
|
||||
};
|
||||
#[cfg(feature = "use_zip")]
|
||||
let zip_file = || {
|
||||
let mut cmd = std::process::Command::new("zip");
|
||||
cmd.args(&[temp_zip_file, target]);
|
||||
if let Err(e) = rust_util::util_cmd::run_command_and_wait(&mut cmd) {
|
||||
print_message(MessageType::ERROR, &format!("Error in zip file: {}, at item index: {}", e, item_index));
|
||||
return false;
|
||||
}
|
||||
true
|
||||
};
|
||||
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
if !zip_file() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(feature = "use_sequoia_openpgp")]
|
||||
let enc_file_by_pgp = || {
|
||||
let open_pgp_tool = match OpenPGPTool::from_file(encrypt_pubkey_file) {
|
||||
Ok(t) => t, Err(e) => {
|
||||
@@ -150,8 +170,7 @@ fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem,
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "sequoia_openpgp"))]
|
||||
#[cfg(not(feature = "use_sequoia_openpgp"))]
|
||||
let enc_file_by_pgp = || {
|
||||
let mut cmd = std::process::Command::new("gpg");
|
||||
cmd.args(&["-e", "-r", encrypt_pubkey_file, "-o", temp_pgp_file, temp_zip_file]);
|
||||
|
||||
Reference in New Issue
Block a user