From 4af0ee055a10c8cb278229b25fc1ceff0ee51c8a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 7 Aug 2019 10:10:14 +0200 Subject: [PATCH] api: always use complete file names (including add exctensions) --- src/api2/backup.rs | 24 ++++++++---------------- src/api2/backup/upload_chunk.rs | 6 ++++-- src/bin/proxmox-backup-client.rs | 23 ++++++++++++----------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/api2/backup.rs b/src/api2/backup.rs index a8c6ed63..87599f45 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -228,11 +228,9 @@ fn create_dynamic_index( let name = tools::required_string_param(¶m, "archive-name")?.to_owned(); - let mut archive_name = name.clone(); - if !archive_name.ends_with(".pxar") { + let archive_name = name.clone(); + if !archive_name.ends_with(".pxar.didx") { bail!("wrong archive extension: '{}'", archive_name); - } else { - archive_name.push_str(".didx"); } let mut path = env.backup_dir.relative_path(); @@ -270,11 +268,9 @@ fn create_fixed_index( let name = tools::required_string_param(¶m, "archive-name")?.to_owned(); let size = tools::required_integer_param(¶m, "size")? as usize; - let mut archive_name = name.clone(); - if !archive_name.ends_with(".img") { + let archive_name = name.clone(); + if !archive_name.ends_with(".img.fidx") { bail!("wrong archive extension: '{}'", archive_name); - } else { - archive_name.push_str(".fidx"); } let mut path = env.backup_dir.relative_path(); @@ -502,12 +498,10 @@ fn dynamic_chunk_index( let env: &BackupEnvironment = rpcenv.as_ref(); - let mut archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned(); + let archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned(); - if !archive_name.ends_with(".pxar") { + if !archive_name.ends_with(".pxar.didx") { bail!("wrong archive extension: '{}'", archive_name); - } else { - archive_name.push_str(".didx"); } let empty_response = { @@ -575,12 +569,10 @@ fn fixed_chunk_index( let env: &BackupEnvironment = rpcenv.as_ref(); - let mut archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned(); + let archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned(); - if !archive_name.ends_with(".img") { + if !archive_name.ends_with(".img.fidx") { bail!("wrong archive extension: '{}'", archive_name); - } else { - archive_name.push_str(".fidx"); } let empty_response = { diff --git a/src/api2/backup/upload_chunk.rs b/src/api2/backup/upload_chunk.rs index 355941ba..b72d8de2 100644 --- a/src/api2/backup/upload_chunk.rs +++ b/src/api2/backup/upload_chunk.rs @@ -242,13 +242,15 @@ fn upload_blob( rpcenv: Box, ) -> Result { - let mut file_name = tools::required_string_param(¶m, "file-name")?.to_owned(); + let file_name = tools::required_string_param(¶m, "file-name")?.to_owned(); let encoded_size = tools::required_integer_param(¶m, "encoded-size")? as usize; let env: &BackupEnvironment = rpcenv.as_ref(); - file_name.push_str(".blob"); + if !file_name.ends_with(".blob") { + bail!("wrong blob file extension: '{}'", file_name); + } let env2 = env.clone(); let env3 = env.clone(); diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 4ef2e69d..aff79a30 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -519,14 +519,15 @@ fn create_backup( }; let file_type = metadata.file_type(); - let extension = Path::new(target).extension().map(|s| s.to_str().unwrap()).unwrap(); + let extension = target.rsplit('.').next() + .ok_or(format_err!("missing target file extenion '{}'", target))?; match extension { "pxar" => { if !file_type.is_dir() { bail!("got unexpected file type (expected directory)"); } - upload_list.push((BackupType::PXAR, filename.to_owned(), target.to_owned(), 0)); + upload_list.push((BackupType::PXAR, filename.to_owned(), format!("{}.didx", target), 0)); } "img" => { @@ -538,19 +539,19 @@ fn create_backup( if size == 0 { bail!("got zero-sized file '{}'", filename); } - upload_list.push((BackupType::IMAGE, filename.to_owned(), target.to_owned(), size)); + upload_list.push((BackupType::IMAGE, filename.to_owned(), format!("{}.fidx", target), size)); } "conf" => { if !file_type.is_file() { bail!("got unexpected file type (expected regular file)"); } - upload_list.push((BackupType::CONFIG, filename.to_owned(), target.to_owned(), metadata.len())); + upload_list.push((BackupType::CONFIG, filename.to_owned(), format!("{}.blob", target), metadata.len())); } "log" => { if !file_type.is_file() { bail!("got unexpected file type (expected regular file)"); } - upload_list.push((BackupType::LOGFILE, filename.to_owned(), target.to_owned(), metadata.len())); + upload_list.push((BackupType::LOGFILE, filename.to_owned(), format!("{}.blob", target), metadata.len())); } _ => { bail!("got unknown archive extension '{}'", extension); @@ -599,12 +600,12 @@ fn create_backup( BackupType::CONFIG => { println!("Upload config file '{}' to '{:?}' as {}", filename, repo, target); let stats = client.upload_blob_from_file(&filename, &target, crypt_config.clone(), true).wait()?; - file_list.push((target, stats)); + file_list.push((format!("{}.blob", target), stats)); } BackupType::LOGFILE => { // fixme: remove - not needed anymore ? println!("Upload log file '{}' to '{:?}' as {}", filename, repo, target); let stats = client.upload_blob_from_file(&filename, &target, crypt_config.clone(), true).wait()?; - file_list.push((target, stats)); + file_list.push((format!("{}.blob", target), stats)); } BackupType::PXAR => { println!("Upload directory '{}' to '{:?}' as {}", filename, repo, target); @@ -618,7 +619,7 @@ fn create_backup( skip_lost_and_found, crypt_config.clone(), )?; - file_list.push((target, stats)); + file_list.push((format!("{}.didx", target), stats)); } BackupType::IMAGE => { println!("Upload image '{}' to '{:?}' as {}", filename, repo, target); @@ -631,7 +632,7 @@ fn create_backup( verbose, crypt_config.clone(), )?; - file_list.push((target, stats)); + file_list.push((format!("{}.fidx", target), stats)); } } } @@ -640,7 +641,7 @@ fn create_backup( let target = "rsa-encrypted.key"; println!("Upload RSA encoded key to '{:?}' as {}", repo, target); let stats = client.upload_blob_from_data(rsa_encrypted_key, target, None, false, false).wait()?; - file_list.push((target.to_owned(), stats)); + file_list.push((format!("{}.blob", target), stats)); // openssl rsautl -decrypt -inkey master-private.pem -in rsa-encrypted.key -out t /* @@ -672,7 +673,7 @@ fn create_backup( println!("Upload index.json to '{:?}'", repo); let index_data = serde_json::to_string_pretty(&index)?.into(); - client.upload_blob_from_data(index_data, "index.json", crypt_config.clone(), true, true).wait()?; + client.upload_blob_from_data(index_data, "index.json.blob", crypt_config.clone(), true, true).wait()?; client.finish().wait()?;