add fn get_safe_backup_count

This commit is contained in:
2020-04-03 08:03:19 +08:00
parent d1fda09f2e
commit 2f7ff048a7
3 changed files with 13 additions and 8 deletions

View File

@@ -93,6 +93,16 @@ impl OSSBackupdConfigItem {
None => "default_file_name".to_owned(),
}
}
pub fn get_safe_backup_count(&self) -> usize {
let mut backup_count = self.backup_count.unwrap_or(10u32) as usize;
if backup_count < 1_usize {
backup_count = 1_usize;
} else if backup_count > 10000_usize {
backup_count = 10000_usize;
}
backup_count
}
}
fn real_make_oss_key(oss_backupd_config: &OSSBackupdConfig, oss_backupd_config_item: &OSSBackupdConfigItem, suffix: &str) -> String {

View File

@@ -104,12 +104,7 @@ pub fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem
}
let oss_client = OSSClient::new(endpoint, access_key_id, access_key_secret);
let mut backup_count = config_item.backup_count.unwrap_or(10u32) as usize;
if backup_count < 1_usize {
backup_count = 1_usize;
} else if backup_count > 10000_usize {
backup_count = 10000_usize;
}
let backup_count = config_item.get_safe_backup_count();
let meta_file_name = &format!("{}/ossbackupd_meta_{}_{}.json", &oss_backupd_config.get_prefix(), &oss_backupd_config.get_host(), &config_item.get_file_name());
let new_file = format!("{}/{}", path, config_item.make_oss_key(&oss_backupd_config, "gpg"));
@@ -171,7 +166,7 @@ pub fn process_config_item(options: &Options, config_item: &OSSBackupdConfigItem
if options.verbose {
print_message(MessageType::DEBUG, &format!("Upload file: {}", temp_pgp_file));
}
if let Err(e) = oss_client.put_file(bucket, &new_file, oss_util::DEFAULT_URL_VALID_SECS, file_temp_pgp_file) {
if let Err(e) = oss_client.put_file(bucket, &new_file, oss_util::DEFAULT_URL_VALID_IN_SECS, file_temp_pgp_file) {
print_message(MessageType::ERROR, &format!("Error in encrypt file: {}, at item index: {}", e, item_index));
remove_temp_files();
return Ok(());

View File

@@ -15,7 +15,7 @@ use reqwest::{
};
use rust_util::*;
pub const DEFAULT_URL_VALID_SECS: u64 = 1000;
pub const DEFAULT_URL_VALID_IN_SECS: u64 = 1000;
pub const OSS_VERB_GET: &str = "GET";
pub const OSS_VERB_PUT: &str = "PUT";