src/backup/catalog_blob.rs: moved catalog impl. from pxar
And avoid loading catalog into memory.
This commit is contained in:
@ -626,6 +626,33 @@ impl BackupClient {
|
||||
self.canceller.cancel();
|
||||
}
|
||||
|
||||
pub fn upload_blob<R: std::io::Read>(
|
||||
&self,
|
||||
mut reader: R,
|
||||
file_name: &str,
|
||||
) -> impl Future<Item=BackupStats, Error=Error> {
|
||||
|
||||
let h2 = self.h2.clone();
|
||||
let file_name = file_name.to_owned();
|
||||
|
||||
futures::future::ok(())
|
||||
.and_then(move |_| {
|
||||
let mut raw_data = Vec::new();
|
||||
// fixme: avoid loading into memory
|
||||
reader.read_to_end(&mut raw_data)?;
|
||||
Ok(raw_data)
|
||||
})
|
||||
.and_then(move |raw_data| {
|
||||
let csum = openssl::sha::sha256(&raw_data);
|
||||
let param = json!({"encoded-size": raw_data.len(), "file-name": file_name });
|
||||
let size = raw_data.len() as u64; // fixme: should be decoded size instead??
|
||||
h2.upload("blob", Some(param), raw_data)
|
||||
.map(move |_| {
|
||||
BackupStats { size, csum }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn upload_blob_from_data(
|
||||
&self,
|
||||
data: Vec<u8>,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use failure::*;
|
||||
|
||||
use std::io::{Write, Seek};
|
||||
use std::thread;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::os::unix::io::FromRawFd;
|
||||
@ -14,6 +14,8 @@ use nix::sys::stat::Mode;
|
||||
use nix::dir::Dir;
|
||||
|
||||
use crate::pxar;
|
||||
use crate::backup::CatalogBlobWriter;
|
||||
|
||||
use crate::tools::wrapped_reader_stream::WrappedReaderStream;
|
||||
|
||||
/// Stream implementation to encode and upload .pxar archives.
|
||||
@ -37,13 +39,13 @@ impl Drop for PxarBackupStream {
|
||||
|
||||
impl PxarBackupStream {
|
||||
|
||||
pub fn new(
|
||||
pub fn new<W: Write + Seek + Send + 'static>(
|
||||
mut dir: Dir,
|
||||
path: PathBuf,
|
||||
device_set: Option<HashSet<u64>>,
|
||||
verbose: bool,
|
||||
skip_lost_and_found: bool,
|
||||
catalog: Arc<Mutex<crate::pxar::catalog::SimpleCatalog>>,
|
||||
catalog: Arc<Mutex<CatalogBlobWriter<W>>>,
|
||||
) -> Result<Self, Error> {
|
||||
|
||||
let (rx, tx) = nix::unistd::pipe()?;
|
||||
@ -74,12 +76,12 @@ impl PxarBackupStream {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open(
|
||||
pub fn open<W: Write + Seek + Send + 'static>(
|
||||
dirname: &Path,
|
||||
device_set: Option<HashSet<u64>>,
|
||||
verbose: bool,
|
||||
skip_lost_and_found: bool,
|
||||
catalog: Arc<Mutex<crate::pxar::catalog::SimpleCatalog>>,
|
||||
catalog: Arc<Mutex<CatalogBlobWriter<W>>>,
|
||||
) -> Result<Self, Error> {
|
||||
|
||||
let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
|
||||
|
Reference in New Issue
Block a user