now can run

This commit is contained in:
2020-03-30 00:48:57 +08:00
parent 9af3cae5a0
commit 86eb80dd73
4 changed files with 39 additions and 28 deletions

View File

@@ -62,37 +62,49 @@ pub struct OSSBackupdConfig {
pub items: Vec<OSSBackupdConfigItem>,
}
impl OSSBackupdConfig {
pub fn get_host(&self) -> String {
match &self.host {
Some(h) => remove_start_end_slash(&h),
None => "default_host".to_owned(),
}
}
pub fn get_prefix(&self) -> String {
match &self.prefix {
Some(p) => remove_start_end_slash(&p),
None => "default_oss_backupd".to_owned(),
}
}
}
impl OSSBackupdConfigItem {
pub fn make_oss_key(&self, oss_backupd_config: &OSSBackupdConfig, suffix: &str) -> String {
real_make_oss_key(oss_backupd_config, &self, suffix)
}
pub fn get_file_name(&self) -> String {
match &self.file_name {
Some(f) => f.clone(),
None => "default_file_name".to_owned(),
}
}
}
fn real_make_oss_key(oss_backupd_config: &OSSBackupdConfig, oss_backupd_config_item: &OSSBackupdConfigItem, suffix: &str) -> String {
let mut key = String::with_capacity(1024);
key.push_str(&(if oss_backupd_config.prefix.is_some() {
remove_start_end_slash(&oss_backupd_config.prefix.as_ref().unwrap().as_str())
} else {
"default_oss_backupd".to_string()
}));
key.push_str(&oss_backupd_config.get_prefix());
key.push_str("/");
key.push_str(&(if oss_backupd_config.host.is_some() {
remove_start_end_slash(&oss_backupd_config.host.as_ref().unwrap().as_str())
} else {
"default_host".to_string()
}));
key.push_str(&oss_backupd_config.get_host());
key.push_str("/");
key.push_str(if oss_backupd_config_item.file_name.is_some() {
oss_backupd_config_item.file_name.as_ref().unwrap().as_str()
} else {
"default_file_name"
});
key.push_str(&oss_backupd_config_item.get_file_name());
key.push_str("_");
let ymdhms = Utc::now().format("%Y%m%d_%H%M%S").to_string();
key.push_str(&ymdhms);
if suffix != "" {
if !suffix.is_empty() {
key.push_str(&format!(".{}", suffix));
}