feat: skip tinyenc when encrypt

This commit is contained in:
2023-10-01 11:45:53 +08:00
parent 895fc5a5d3
commit 0f7f60e3ff
2 changed files with 10 additions and 13 deletions

View File

@@ -57,14 +57,15 @@ pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
debugging!("Cmd encrypt: {:?}", cmd_encrypt);
let start = Instant::now();
let mut succeed_count = 0;
let mut skipped_count = 0;
let mut failed_count = 0;
let mut total_len = 0_u64;
for path in &cmd_encrypt.paths {
let start_encrypt_single = Instant::now();
match encrypt_single(path, &envelops, &cmd_encrypt) {
Ok(len) => {
succeed_count += 1;
total_len += len;
if len > 0 { succeed_count += 1; } else { skipped_count += 1; }
success!(
"Encrypt {} succeed, cost {} ms, file size {} byte(s)",
path.to_str().unwrap_or("N/A"),
@@ -80,10 +81,11 @@ pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
}
if (succeed_count + failed_count) > 1 {
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,
total_len,
failed_count,
skipped_count,
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> {
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);

View File

@@ -26,16 +26,6 @@ pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
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<()> {
let path = path.as_ref();
match fs::metadata(path) {