add swtch for sequoia_openpgp
This commit is contained in:
49
src/main.rs
49
src/main.rs
@@ -1,7 +1,9 @@
|
||||
// #[macro_use]
|
||||
// extern crate lazy_static;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
extern crate sequoia_openpgp as openpgp;
|
||||
mod oss_util;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
mod pgp_util;
|
||||
mod config_util;
|
||||
mod zip_util;
|
||||
@@ -19,6 +21,7 @@ use rust_util::{
|
||||
};
|
||||
use oss_util::*;
|
||||
use config_util::*;
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
use pgp_util::OpenPGPTool;
|
||||
use opt::Options;
|
||||
|
||||
@@ -106,13 +109,6 @@ fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem,
|
||||
print_message(MessageType::DEBUG, &format!("New backup file: {}", new_file));
|
||||
}
|
||||
|
||||
let open_pgp_tool = match OpenPGPTool::from_file(encrypt_pubkey_file) {
|
||||
Ok(t) => t, Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Error in load pgp file: {}, at item index: {}", e, item_index));
|
||||
return Ok(());
|
||||
},
|
||||
};
|
||||
|
||||
let secs = get_current_secs();
|
||||
let temp_zip_file = &format!("temp_file_{}.zip", secs);
|
||||
let temp_pgp_file = &format!("temp_file_{}.gpg", secs);
|
||||
@@ -136,15 +132,40 @@ fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem,
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if options.verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Encrypt file: {} -> {}", temp_zip_file, temp_pgp_file));
|
||||
}
|
||||
if let Err(e) = open_pgp_tool.encrypt_file(temp_zip_file, temp_pgp_file, false) {
|
||||
print_message(MessageType::ERROR, &format!("Error in encrypt file: {}, at item index: {}", e, item_index));
|
||||
remove_temp_files();
|
||||
return Ok(());
|
||||
#[cfg(feature = "sequoia_openpgp")]
|
||||
let enc_file_by_pgp = || {
|
||||
let open_pgp_tool = match OpenPGPTool::from_file(encrypt_pubkey_file) {
|
||||
Ok(t) => t, Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Error in load pgp file: {}, at item index: {}", e, item_index));
|
||||
return false;
|
||||
},
|
||||
};
|
||||
if options.verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Encrypt file: {} -> {}", temp_zip_file, temp_pgp_file));
|
||||
}
|
||||
if let Err(e) = open_pgp_tool.encrypt_file(temp_zip_file, temp_pgp_file, false) {
|
||||
print_message(MessageType::ERROR, &format!("Error in encrypt file: {}, at item index: {}", e, item_index));
|
||||
remove_temp_files();
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "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]);
|
||||
if let Err(e) = rust_util::util_cmd::run_command_and_wait(&mut cmd) {
|
||||
print_message(MessageType::ERROR, &format!("Error in encrypt file: {}, at item index: {}", e, item_index));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if !enc_file_by_pgp() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let file_temp_pgp_file = match File::open(temp_pgp_file) {
|
||||
Ok(f) => f, Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Error in open file: {}, at item index: {}", e, item_index));
|
||||
|
||||
Reference in New Issue
Block a user