src/api2/backup/environment.rs: new helper add_blob()

This commit is contained in:
Dietmar Maurer 2019-06-24 09:35:37 +02:00
parent cb08ac3efe
commit 46bd880041
2 changed files with 26 additions and 13 deletions

View File

@ -384,6 +384,30 @@ impl BackupEnvironment {
Ok(()) Ok(())
} }
pub fn add_blob(&self, file_name: &str, data: Vec<u8>) -> Result<(), Error> {
let mut path = self.datastore.base_path();
path.push(self.backup_dir.relative_path());
path.push(file_name);
let blob_len = data.len();
let orig_len = data.len(); // fixme:
let mut blob = DataBlob::from_raw(data)?;
// always comput CRC at server side
blob.set_crc(blob.compute_crc());
let raw_data = blob.raw_data();
crate::tools::file_set_contents(&path, raw_data, None)?;
self.log(format!("add blob {:?} ({} bytes, comp: {})", path, orig_len, blob_len));
let mut state = self.state.lock().unwrap();
state.file_counter += 1;
Ok(())
}
/// Mark backup as finished /// Mark backup as finished
pub fn finish_backup(&self) -> Result<(), Error> { pub fn finish_backup(&self) -> Result<(), Error> {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();

View File

@ -245,13 +245,10 @@ fn upload_blob(
let mut file_name = tools::required_string_param(&param, "file-name")?.to_owned(); let mut file_name = tools::required_string_param(&param, "file-name")?.to_owned();
let encoded_size = tools::required_integer_param(&param, "encoded-size")? as usize; let encoded_size = tools::required_integer_param(&param, "encoded-size")? as usize;
file_name.push_str(".blob");
let env: &BackupEnvironment = rpcenv.as_ref(); let env: &BackupEnvironment = rpcenv.as_ref();
let mut path = env.datastore.base_path(); file_name.push_str(".blob");
path.push(env.backup_dir.relative_path());
path.push(&file_name);
let env2 = env.clone(); let env2 = env.clone();
let env3 = env.clone(); let env3 = env.clone();
@ -267,15 +264,7 @@ fn upload_blob(
bail!("got blob with unexpected length ({} != {})", encoded_size, data.len()); bail!("got blob with unexpected length ({} != {})", encoded_size, data.len());
} }
let orig_len = data.len(); // fixme: env2.add_blob(&file_name, data)?;
let mut blob = DataBlob::from_raw(data)?;
// always comput CRC at server side
blob.set_crc(blob.compute_crc());
tools::file_set_contents(&path, blob.raw_data(), None)?;
env2.debug(format!("upload blob {:?} ({} bytes, comp: {})", path, orig_len, encoded_size));
Ok(()) Ok(())
}) })