From 4287896945a201b031252087e6f163f58730473f Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sat, 10 Mar 2018 12:09:04 +0100 Subject: [PATCH] Removed some public fields --- src/backups/mod.rs | 4 ++-- src/repository/bundledb/db.rs | 5 +++-- src/repository/bundledb/writer.rs | 9 ++++++--- src/repository/mod.rs | 10 +++++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/backups/mod.rs b/src/backups/mod.rs index 5b1709e..0c8e0e6 100644 --- a/src/backups/mod.rs +++ b/src/backups/mod.rs @@ -77,11 +77,11 @@ impl BackupRepository { } pub fn get_config(&self) -> &Config { - &self.repo.config + self.repo.get_config() } pub fn set_config(&mut self, config: Config) { - self.repo.config = config; + self.repo.set_config(config); } pub fn get_layout(&self) -> &RepositoryLayout { diff --git a/src/repository/bundledb/db.rs b/src/repository/bundledb/db.rs index f7c7b9b..61aff9f 100644 --- a/src/repository/bundledb/db.rs +++ b/src/repository/bundledb/db.rs @@ -117,7 +117,7 @@ fn load_bundles( pub struct BundleDb { - pub layout: Arc, + layout: Arc, uploader: Option>, crypto: Arc, local_bundles: HashMap, @@ -284,6 +284,7 @@ impl BundleDb { encryption: Option, ) -> Result { Ok(try!(BundleWriter::new( + self.layout.clone(), mode, hash_method, compression, @@ -346,7 +347,7 @@ impl BundleDb { } pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result { - let mut bundle = try!(bundle.finish(self)); + let mut bundle = try!(bundle.finish()); if bundle.info.mode == BundleMode::Meta { try!(self.copy_remote_bundle_to_cache(&bundle)) } diff --git a/src/repository/bundledb/writer.rs b/src/repository/bundledb/writer.rs index 15a919b..34b3958 100644 --- a/src/repository/bundledb/writer.rs +++ b/src/repository/bundledb/writer.rs @@ -45,6 +45,7 @@ quick_error!{ pub struct BundleWriter { + layout: Arc, mode: BundleMode, hash_method: HashMethod, data: Vec, @@ -59,6 +60,7 @@ pub struct BundleWriter { impl BundleWriter { pub fn new( + layout: Arc, mode: BundleMode, hash_method: HashMethod, compression: Option, @@ -72,6 +74,7 @@ impl BundleWriter { None => None, }; Ok(BundleWriter { + layout, mode, hash_method, data: vec![], @@ -99,7 +102,7 @@ impl BundleWriter { Ok(self.chunk_count - 1) } - pub fn finish(mut self, db: &BundleDb) -> Result { + pub fn finish(mut self) -> Result { if let Some(stream) = self.compression_stream { try!(stream.finish(&mut self.data).map_err( BundleWriterError::Compression @@ -115,7 +118,7 @@ impl BundleWriter { if let Some(ref encryption) = self.encryption { 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))); try!(file.write_all(&HEADER_STRING).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(&chunk_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() .to_path_buf(); Ok(StoredBundle { diff --git a/src/repository/mod.rs b/src/repository/mod.rs index e2d02eb..4eb6620 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -75,7 +75,7 @@ impl index::Key for Hash { pub struct Repository { layout: Arc, - pub config: Config, + config: Config, index: Index, crypto: Arc, bundle_map: BundleMap, @@ -399,6 +399,14 @@ impl Repository { pub fn set_clean(&mut self) { self.dirty = false; } + + pub fn get_config(&self) -> &Config { + &self.config + } + + pub fn set_config(&mut self, config: Config) { + self.config = config; + } }