Removed some public fields

This commit is contained in:
Dennis Schwerdel 2018-03-10 12:09:04 +01:00
parent 048a48873a
commit 4287896945
4 changed files with 20 additions and 8 deletions

View File

@ -77,11 +77,11 @@ impl BackupRepository {
} }
pub fn get_config(&self) -> &Config { pub fn get_config(&self) -> &Config {
&self.repo.config self.repo.get_config()
} }
pub fn set_config(&mut self, config: Config) { pub fn set_config(&mut self, config: Config) {
self.repo.config = config; self.repo.set_config(config);
} }
pub fn get_layout(&self) -> &RepositoryLayout { pub fn get_layout(&self) -> &RepositoryLayout {

View File

@ -117,7 +117,7 @@ fn load_bundles(
pub struct BundleDb { pub struct BundleDb {
pub layout: Arc<ChunkRepositoryLayout>, layout: Arc<ChunkRepositoryLayout>,
uploader: Option<Arc<BundleUploader>>, uploader: Option<Arc<BundleUploader>>,
crypto: Arc<Crypto>, crypto: Arc<Crypto>,
local_bundles: HashMap<BundleId, StoredBundle>, local_bundles: HashMap<BundleId, StoredBundle>,
@ -284,6 +284,7 @@ impl BundleDb {
encryption: Option<Encryption>, encryption: Option<Encryption>,
) -> Result<BundleWriter, BundleDbError> { ) -> Result<BundleWriter, BundleDbError> {
Ok(try!(BundleWriter::new( Ok(try!(BundleWriter::new(
self.layout.clone(),
mode, mode,
hash_method, hash_method,
compression, compression,
@ -346,7 +347,7 @@ impl BundleDb {
} }
pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result<BundleInfo, BundleDbError> { pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result<BundleInfo, BundleDbError> {
let mut bundle = try!(bundle.finish(self)); let mut bundle = try!(bundle.finish());
if bundle.info.mode == BundleMode::Meta { if bundle.info.mode == BundleMode::Meta {
try!(self.copy_remote_bundle_to_cache(&bundle)) try!(self.copy_remote_bundle_to_cache(&bundle))
} }

View File

@ -45,6 +45,7 @@ quick_error!{
pub struct BundleWriter { pub struct BundleWriter {
layout: Arc<ChunkRepositoryLayout>,
mode: BundleMode, mode: BundleMode,
hash_method: HashMethod, hash_method: HashMethod,
data: Vec<u8>, data: Vec<u8>,
@ -59,6 +60,7 @@ pub struct BundleWriter {
impl BundleWriter { impl BundleWriter {
pub fn new( pub fn new(
layout: Arc<ChunkRepositoryLayout>,
mode: BundleMode, mode: BundleMode,
hash_method: HashMethod, hash_method: HashMethod,
compression: Option<Compression>, compression: Option<Compression>,
@ -72,6 +74,7 @@ impl BundleWriter {
None => None, None => None,
}; };
Ok(BundleWriter { Ok(BundleWriter {
layout,
mode, mode,
hash_method, hash_method,
data: vec![], data: vec![],
@ -99,7 +102,7 @@ impl BundleWriter {
Ok(self.chunk_count - 1) Ok(self.chunk_count - 1)
} }
pub fn finish(mut self, db: &BundleDb) -> Result<StoredBundle, BundleWriterError> { pub fn finish(mut self) -> Result<StoredBundle, BundleWriterError> {
if let Some(stream) = self.compression_stream { if let Some(stream) = self.compression_stream {
try!(stream.finish(&mut self.data).map_err( try!(stream.finish(&mut self.data).map_err(
BundleWriterError::Compression BundleWriterError::Compression
@ -115,7 +118,7 @@ impl BundleWriter {
if let Some(ref encryption) = self.encryption { if let Some(ref encryption) = self.encryption {
chunk_data = try!(self.crypto.encrypt(encryption, &chunk_data)); chunk_data = try!(self.crypto.encrypt(encryption, &chunk_data));
} }
let mut path = db.layout.temp_bundle_path(); let mut path = self.layout.temp_bundle_path();
let mut file = BufWriter::new(try!(File::create(&path).context(&path as &Path))); let mut file = BufWriter::new(try!(File::create(&path).context(&path as &Path)));
try!(file.write_all(&HEADER_STRING).context(&path as &Path)); try!(file.write_all(&HEADER_STRING).context(&path as &Path));
try!(file.write_all(&[HEADER_VERSION]).context(&path as &Path)); try!(file.write_all(&[HEADER_VERSION]).context(&path as &Path));
@ -145,7 +148,7 @@ impl BundleWriter {
try!(file.write_all(&info_data).context(&path as &Path)); try!(file.write_all(&info_data).context(&path as &Path));
try!(file.write_all(&chunk_data).context(&path as &Path)); try!(file.write_all(&chunk_data).context(&path as &Path));
try!(file.write_all(&self.data).context(&path as &Path)); try!(file.write_all(&self.data).context(&path as &Path));
path = path.strip_prefix(db.layout.base_path()) path = path.strip_prefix(self.layout.base_path())
.unwrap() .unwrap()
.to_path_buf(); .to_path_buf();
Ok(StoredBundle { Ok(StoredBundle {

View File

@ -75,7 +75,7 @@ impl index::Key for Hash {
pub struct Repository { pub struct Repository {
layout: Arc<ChunkRepositoryLayout>, layout: Arc<ChunkRepositoryLayout>,
pub config: Config, config: Config,
index: Index<Hash, Location>, index: Index<Hash, Location>,
crypto: Arc<Crypto>, crypto: Arc<Crypto>,
bundle_map: BundleMap, bundle_map: BundleMap,
@ -399,6 +399,14 @@ impl Repository {
pub fn set_clean(&mut self) { pub fn set_clean(&mut self) {
self.dirty = false; self.dirty = false;
} }
pub fn get_config(&self) -> &Config {
&self.config
}
pub fn set_config(&mut self, config: Config) {
self.config = config;
}
} }