feat: skip tinyenc when encrypt
This commit is contained in:
@@ -57,14 +57,15 @@ pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
|
|||||||
debugging!("Cmd encrypt: {:?}", cmd_encrypt);
|
debugging!("Cmd encrypt: {:?}", cmd_encrypt);
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut succeed_count = 0;
|
let mut succeed_count = 0;
|
||||||
|
let mut skipped_count = 0;
|
||||||
let mut failed_count = 0;
|
let mut failed_count = 0;
|
||||||
let mut total_len = 0_u64;
|
let mut total_len = 0_u64;
|
||||||
for path in &cmd_encrypt.paths {
|
for path in &cmd_encrypt.paths {
|
||||||
let start_encrypt_single = Instant::now();
|
let start_encrypt_single = Instant::now();
|
||||||
match encrypt_single(path, &envelops, &cmd_encrypt) {
|
match encrypt_single(path, &envelops, &cmd_encrypt) {
|
||||||
Ok(len) => {
|
Ok(len) => {
|
||||||
succeed_count += 1;
|
|
||||||
total_len += len;
|
total_len += len;
|
||||||
|
if len > 0 { succeed_count += 1; } else { skipped_count += 1; }
|
||||||
success!(
|
success!(
|
||||||
"Encrypt {} succeed, cost {} ms, file size {} byte(s)",
|
"Encrypt {} succeed, cost {} ms, file size {} byte(s)",
|
||||||
path.to_str().unwrap_or("N/A"),
|
path.to_str().unwrap_or("N/A"),
|
||||||
@@ -80,10 +81,11 @@ pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
|
|||||||
}
|
}
|
||||||
if (succeed_count + failed_count) > 1 {
|
if (succeed_count + failed_count) > 1 {
|
||||||
success!(
|
success!(
|
||||||
"Encrypt succeed {} file(s) {} byte(s), failed {} file(s), total cost {} ms",
|
"Encrypt succeed {} file(s) {} byte(s), failed {} file(s), skipped {} file(s), total cost {} ms",
|
||||||
succeed_count,
|
succeed_count,
|
||||||
total_len,
|
total_len,
|
||||||
failed_count,
|
failed_count,
|
||||||
|
skipped_count,
|
||||||
start.elapsed().as_millis(),
|
start.elapsed().as_millis(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,12 @@ pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
|
|||||||
|
|
||||||
fn encrypt_single(path: &PathBuf, envelops: &[&TinyEncryptConfigEnvelop], cmd_encrypt: &CmdEncrypt) -> XResult<u64> {
|
fn encrypt_single(path: &PathBuf, envelops: &[&TinyEncryptConfigEnvelop], cmd_encrypt: &CmdEncrypt) -> XResult<u64> {
|
||||||
let path_display = format!("{}", path.display());
|
let path_display = format!("{}", path.display());
|
||||||
util::require_none_tiny_enc_file_and_exists(path)?;
|
if path_display.ends_with(util::TINY_ENC_FILE_EXT) {
|
||||||
|
information!("Tiny enc file skipped: {}", path_display);
|
||||||
|
return Ok(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
util::require_file_exists(path)?;
|
||||||
|
|
||||||
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
||||||
|
|
||||||
|
|||||||
10
src/util.rs
10
src/util.rs
@@ -26,16 +26,6 @@ pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn require_none_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
|
|
||||||
let path = path.as_ref();
|
|
||||||
let path_display = format!("{}", path.display());
|
|
||||||
if path_display.ends_with(TINY_ENC_FILE_EXT) {
|
|
||||||
return simple_error!("File is already tiny encrypt file: {}", &path_display);
|
|
||||||
}
|
|
||||||
require_file_exists(path)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn require_file_exists(path: impl AsRef<Path>) -> XResult<()> {
|
pub fn require_file_exists(path: impl AsRef<Path>) -> XResult<()> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
match fs::metadata(path) {
|
match fs::metadata(path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user