diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index 5213c16..434c1d8 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -183,7 +183,6 @@ impl BundleDb { Ok(()) } - #[inline] pub fn open(layout: RepositoryLayout, crypto: Arc>) -> Result<(Self, Vec, Vec), BundleDbError> { let mut self_ = Self::new(layout, crypto); let (new, gone) = try!(self_.load_bundle_list()); @@ -193,7 +192,6 @@ impl BundleDb { Ok((self_, new, gone)) } - #[inline] pub fn create(layout: RepositoryLayout) -> Result<(), BundleDbError> { try!(fs::create_dir_all(layout.remote_bundles_path()).context(&layout.remote_bundles_path() as &Path)); try!(fs::create_dir_all(layout.local_bundles_path()).context(&layout.local_bundles_path() as &Path)); @@ -214,6 +212,7 @@ impl BundleDb { } } + #[inline] fn get_bundle(&self, stored: &StoredBundle) -> Result { let base_path = self.layout.base_path(); Ok(try!(BundleReader::load(base_path.join(&stored.path), self.crypto.clone()))) @@ -244,7 +243,6 @@ impl BundleDb { Ok(()) } - #[inline] pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result { let mut bundle = try!(bundle.finish(&self)); if bundle.info.mode == BundleMode::Meta { @@ -262,7 +260,6 @@ impl BundleDb { Ok(bundle.info) } - #[inline] pub fn finish_uploads(&mut self) -> Result<(), BundleDbError> { let mut uploader = None; mem::swap(&mut self.uploader, &mut uploader); @@ -273,7 +270,6 @@ impl BundleDb { } } - #[inline] pub fn get_chunk_list(&self, bundle: &BundleId) -> Result { let mut bundle = try!(self.get_stored_bundle(bundle).and_then(|stored| self.get_bundle(&stored))); Ok(try!(bundle.get_chunk_list()).clone()) @@ -289,7 +285,6 @@ impl BundleDb { self.remote_bundles.values().map(|b| &b.info).collect() } - #[inline] pub fn delete_local_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> { if let Some(bundle) = self.local_bundles.remove(bundle) { let path = self.layout.base_path().join(&bundle.path); @@ -298,7 +293,6 @@ impl BundleDb { Ok(()) } - #[inline] pub fn delete_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> { try!(self.delete_local_bundle(bundle)); if let Some(bundle) = self.remote_bundles.remove(bundle) { @@ -309,7 +303,6 @@ impl BundleDb { } } - #[inline] pub fn check(&mut self, full: bool) -> Result<(), BundleDbError> { for stored in self.remote_bundles.values() { let mut bundle = try!(self.get_bundle(stored)); diff --git a/src/bundledb/mod.rs b/src/bundledb/mod.rs index 3f5378f..ab8c687 100644 --- a/src/bundledb/mod.rs +++ b/src/bundledb/mod.rs @@ -25,12 +25,14 @@ pub static HEADER_VERSION: u8 = 1; pub struct BundleId(pub Hash); impl Serialize for BundleId { + #[inline] fn serialize(&self, ser: S) -> Result { self.0.serialize(ser) } } impl Deserialize for BundleId { + #[inline] fn deserialize(de: D) -> Result { let hash = try!(Hash::deserialize(de)); Ok(BundleId(hash)) @@ -43,6 +45,7 @@ impl BundleId { self.0.to_string() } + #[inline] pub fn random() -> Self { BundleId(Hash{high: rand::random(), low: rand::random()}) } diff --git a/src/bundledb/reader.rs b/src/bundledb/reader.rs index 404b318..cef97e4 100644 --- a/src/bundledb/reader.rs +++ b/src/bundledb/reader.rs @@ -153,7 +153,6 @@ impl BundleReader { Ok(self.chunks.as_ref().unwrap()) } - #[inline] fn load_encoded_contents(&self) -> Result, BundleReaderError> { debug!("Load bundle data {} ({:?})", self.info.id, self.info.mode); let mut file = BufReader::new(try!(File::open(&self.path).context(&self.path as &Path))); @@ -163,7 +162,6 @@ impl BundleReader { Ok(data) } - #[inline] fn decode_contents(&self, mut data: Vec) -> Result, BundleReaderError> { if let Some(ref encryption) = self.info.encryption { data = try!(self.crypto.lock().unwrap().decrypt(&encryption, &data).context(&self.path as &Path)); @@ -183,7 +181,6 @@ impl BundleReader { self.load_encoded_contents().and_then(|data| self.decode_contents(data)) } - #[inline] pub fn get_chunk_position(&mut self, id: usize) -> Result<(usize, usize), BundleReaderError> { if id >= self.info.chunk_count { return Err(BundleReaderError::NoSuchChunk(self.id(), id)) diff --git a/src/chunker/mod.rs b/src/chunker/mod.rs index 75ec1b6..d63bd59 100644 --- a/src/chunker/mod.rs +++ b/src/chunker/mod.rs @@ -58,7 +58,6 @@ pub enum Chunker { impl IChunker for Chunker { - #[inline] fn get_type(&self) -> ChunkerType { match *self { Chunker::Ae(ref c) => c.get_type(), @@ -92,7 +91,6 @@ serde_impl!(ChunkerType(u64) { impl ChunkerType { - #[inline] pub fn from(name: &str, avg_size: usize, seed: u64) -> Result { match name { "ae" => Ok(ChunkerType::Ae(avg_size)), @@ -102,7 +100,6 @@ impl ChunkerType { } } - #[inline] pub fn from_string(name: &str) -> Result { let (name, size) = if let Some(pos) = name.find('/') { let size = try!(usize::from_str(&name[pos+1..]).map_err(|_| "Chunk size must be a number")); @@ -124,7 +121,6 @@ impl ChunkerType { } } - #[inline] pub fn name(&self) -> &'static str { match *self { ChunkerType::Ae(_size) => "ae", @@ -133,7 +129,6 @@ impl ChunkerType { } } - #[inline] pub fn avg_size(&self) -> usize { match *self { ChunkerType::Ae(size) => size, @@ -142,12 +137,10 @@ impl ChunkerType { } } - #[inline] pub fn to_string(&self) -> String { format!("{}/{}", self.name(), self.avg_size()/1024) } - #[inline] pub fn seed(&self) -> u64 { match *self { ChunkerType::Ae(_size) => 0, diff --git a/src/repository/backup.rs b/src/repository/backup.rs index 6d9c97d..63faa2e 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -41,6 +41,7 @@ impl Repository { Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path()))) } + #[inline] pub fn has_backup(&self, name: &str) -> bool { self.layout.backup_path(name).exists() } @@ -222,7 +223,6 @@ impl Repository { Ok(inode) } - #[allow(dead_code)] pub fn create_backup_recursively>(&mut self, path: P, reference: Option<&Backup>, options: &BackupOptions) -> Result { let _lock = try!(self.lock(false)); if self.dirty { @@ -307,7 +307,6 @@ impl Repository { self.get_backup_path(backup, path).map(|mut inodes| inodes.pop().unwrap()) } - #[inline] pub fn find_versions>(&mut self, path: P) -> Result, RepositoryError> { let path = path.as_ref(); let mut versions = HashMap::new(); @@ -325,7 +324,6 @@ impl Repository { Ok(versions) } - #[inline] fn find_differences_recurse(&mut self, inode1: &Inode, inode2: &Inode, path: PathBuf, diffs: &mut Vec<(DiffType, PathBuf)>) -> Result<(), RepositoryError> { if !inode1.is_same_meta(inode2) || inode1.data != inode2.data { diffs.push((DiffType::Mod, path.clone())); diff --git a/src/repository/basic_io.rs b/src/repository/basic_io.rs index 0420179..ec316ee 100644 --- a/src/repository/basic_io.rs +++ b/src/repository/basic_io.rs @@ -54,6 +54,7 @@ impl<'a> Read for ChunkReader<'a> { impl Repository { + #[inline] pub fn get_bundle_id(&self, id: u32) -> Result { self.bundle_map.get(id).ok_or_else(|| IntegrityError::MissingBundleId(id).into()) } @@ -187,7 +188,6 @@ impl Repository { Ok(chunks.into()) } - #[inline] pub fn get_data(&mut self, chunks: &[Chunk]) -> Result, RepositoryError> { let mut data = Vec::with_capacity(chunks.iter().map(|&(_, size)| size).sum::() as usize); try!(self.get_stream(chunks, &mut data)); @@ -199,7 +199,6 @@ impl Repository { ChunkReader::new(self, chunks) } - #[inline] pub fn get_stream(&mut self, chunks: &[Chunk], w: &mut W) -> Result<(), RepositoryError> { for &(ref hash, len) in chunks { let data = try!(try!(self.get_chunk(*hash)).ok_or_else(|| IntegrityError::MissingChunk(hash.clone()))); diff --git a/src/repository/bundle_map.rs b/src/repository/bundle_map.rs index 9611798..fa2c9e0 100644 --- a/src/repository/bundle_map.rs +++ b/src/repository/bundle_map.rs @@ -77,7 +77,6 @@ impl BundleMap { self.0.remove(&id) } - #[inline] pub fn find(&self, bundle: &BundleId) -> Option { for (id, bundle_id) in &self.0 { if bundle == bundle_id { @@ -92,7 +91,6 @@ impl BundleMap { self.0.insert(id, bundle); } - #[inline] pub fn bundles(&self) -> Vec<(u32, BundleId)> { self.0.iter().map(|(id, bundle)| (*id, bundle.clone())).collect() } diff --git a/src/repository/integrity.rs b/src/repository/integrity.rs index b213cbf..3161991 100644 --- a/src/repository/integrity.rs +++ b/src/repository/integrity.rs @@ -118,6 +118,7 @@ impl Repository { Ok(()) } + #[inline] pub fn check_backup(&mut self, backup: &Backup) -> Result<(), RepositoryError> { info!("Checking backup..."); let mut checked = Bitmap::new(self.index.capacity()); @@ -179,6 +180,7 @@ impl Repository { Ok(()) } + #[inline] pub fn check_index(&mut self) -> Result<(), RepositoryError> { info!("Checking index integrity..."); try!(self.index.check()); @@ -186,6 +188,7 @@ impl Repository { self.check_index_chunks() } + #[inline] pub fn check_bundles(&mut self, full: bool) -> Result<(), RepositoryError> { info!("Checking bundle integrity..."); Ok(try!(self.bundles.check(full))) diff --git a/src/repository/layout.rs b/src/repository/layout.rs index 2d5130b..edc003e 100644 --- a/src/repository/layout.rs +++ b/src/repository/layout.rs @@ -10,58 +10,72 @@ impl RepositoryLayout { RepositoryLayout(path.as_ref().to_path_buf()) } + #[inline] pub fn base_path(&self) -> &Path { &self.0 } + #[inline] pub fn config_path(&self) -> PathBuf { self.0.join("config.yaml") } + #[inline] pub fn excludes_path(&self) -> PathBuf { self.0.join("excludes") } + #[inline] pub fn index_path(&self) -> PathBuf { self.0.join("index") } + #[inline] pub fn keys_path(&self) -> PathBuf { self.0.join("keys") } + #[inline] pub fn bundle_map_path(&self) -> PathBuf { self.0.join("bundles.map") } + #[inline] pub fn backups_path(&self) -> PathBuf { self.0.join("remote/backups") } + #[inline] pub fn backup_path(&self, name: &str) -> PathBuf { self.backups_path().join(name) } + #[inline] pub fn remote_path(&self) -> PathBuf { self.0.join("remote") } + #[inline] pub fn remote_exists(&self) -> bool { self.remote_bundles_path().exists() && self.backups_path().exists() && self.remote_locks_path().exists() } + #[inline] pub fn remote_readme_path(&self) -> PathBuf { self.0.join("remote/README.md") } + #[inline] pub fn remote_locks_path(&self) -> PathBuf { self.0.join("remote/locks") } + #[inline] pub fn remote_bundles_path(&self) -> PathBuf { self.0.join("remote/bundles") } + #[inline] pub fn local_bundles_path(&self) -> PathBuf { self.0.join("bundles/cached") } @@ -79,30 +93,37 @@ impl RepositoryLayout { (folder, file.into()) } + #[inline] pub fn remote_bundle_path(&self, count: usize) -> (PathBuf, PathBuf) { self.bundle_path(&BundleId::random(), self.remote_bundles_path(), count) } + #[inline] pub fn local_bundle_path(&self, bundle: &BundleId, count: usize) -> (PathBuf, PathBuf) { self.bundle_path(bundle, self.local_bundles_path(), count) } + #[inline] pub fn temp_bundles_path(&self) -> PathBuf { self.0.join("bundles/temp") } + #[inline] pub fn temp_bundle_path(&self) -> PathBuf { self.temp_bundles_path().join(BundleId::random().to_string().to_owned() + ".bundle") } + #[inline] pub fn local_bundle_cache_path(&self) -> PathBuf { self.0.join("bundles/local.cache") } + #[inline] pub fn remote_bundle_cache_path(&self) -> PathBuf { self.0.join("bundles/remote.cache") } + #[inline] pub fn dirtyfile_path(&self) -> PathBuf { self.0.join("dirty") } diff --git a/src/repository/metadata.rs b/src/repository/metadata.rs index 572506a..e61ce7a 100644 --- a/src/repository/metadata.rs +++ b/src/repository/metadata.rs @@ -206,7 +206,6 @@ impl Inode { Ok(inode) } - #[allow(dead_code)] pub fn create_at>(&self, path: P) -> Result, InodeError> { let full_path = path.as_ref().join(&self.name); let mut file = None; @@ -244,12 +243,14 @@ impl Inode { Ok(file) } + #[inline] pub fn is_same_meta(&self, other: &Inode) -> bool { self.file_type == other.file_type && self.size == other.size && self.mode == other.mode && self.user == other.user && self.group == other.group && self.name == other.name && self.timestamp == other.timestamp && self.symlink_target == other.symlink_target } + #[inline] pub fn is_same_meta_quick(&self, other: &Inode) -> bool { self.timestamp == other.timestamp && self.file_type == other.file_type @@ -308,7 +309,6 @@ impl Repository { Ok(try!(Inode::decode(&try!(self.get_data(chunks))))) } - #[inline] pub fn save_inode_at>(&mut self, inode: &Inode, path: P) -> Result<(), RepositoryError> { if let Some(mut file) = try!(inode.create_at(path.as_ref())) { if let Some(ref contents) = inode.data { diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 9b3758e..53ae60c 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -159,6 +159,7 @@ impl Repository { Ok(try!(self.crypto.lock().unwrap().register_secret_key(public, secret))) } + #[inline] pub fn save_config(&mut self) -> Result<(), RepositoryError> { try!(self.config.save(self.layout.config_path())); Ok(()) @@ -289,12 +290,14 @@ impl Repository { Ok(()) } + #[inline] fn lock(&self, exclusive: bool) -> Result { Ok(try!(self.locks.lock(exclusive))) } + #[inline] pub fn set_clean(&mut self) { - self.dirty = false; + self.dirty = false; } } diff --git a/src/util/chunk.rs b/src/util/chunk.rs index 09009d0..7711583 100644 --- a/src/util/chunk.rs +++ b/src/util/chunk.rs @@ -40,7 +40,6 @@ impl ChunkList { self.0.push(chunk) } - #[inline] pub fn write_to(&self, dst: &mut Write) -> Result<(), io::Error> { for chunk in &self.0 { try!(chunk.0.write_to(dst)); @@ -49,7 +48,6 @@ impl ChunkList { Ok(()) } - #[inline] pub fn read_n_from(n: usize, src: &mut Read) -> Result { let mut chunks = Vec::with_capacity(n); for _ in 0..n { @@ -112,6 +110,7 @@ impl DerefMut for ChunkList { } impl Serialize for ChunkList { + #[inline] fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { let mut buf = Vec::with_capacity(self.encoded_size()); self.write_to(&mut buf).unwrap(); @@ -120,6 +119,7 @@ impl Serialize for ChunkList { } impl Deserialize for ChunkList { + #[inline] fn deserialize(deserializer: D) -> Result where D: serde::Deserializer { let data: Vec = try!(ByteBuf::deserialize(deserializer)).into(); if data.len() % 20 != 0 { diff --git a/src/util/compression.rs b/src/util/compression.rs index 7117c7d..9297308 100644 --- a/src/util/compression.rs +++ b/src/util/compression.rs @@ -72,7 +72,6 @@ impl Compression { format!("{}/{}", self.name(), self.level) } - #[inline] pub fn from_string(name: &str) -> Result { let (name, level) = if let Some(pos) = name.find('/') { let level = try!(u8::from_str(&name[pos+1..]).map_err(|_| CompressionError::UnsupportedCodec(name.to_string()))); @@ -91,7 +90,6 @@ impl Compression { Ok(Compression { method: method, level: level }) } - #[inline] pub fn name(&self) -> &'static str { match self.method { CompressionMethod::Deflate => "deflate", @@ -101,7 +99,6 @@ impl Compression { } } - #[inline] fn codec(&self) -> Result<*mut SquashCodec, CompressionError> { let name = CString::new(self.name().as_bytes()).unwrap(); let codec = unsafe { squash_get_codec(name.as_ptr()) }; @@ -194,7 +191,6 @@ impl Compression { Ok(buf) } - #[inline] pub fn compress_stream(&self) -> Result { let codec = try!(self.codec()); let options = try!(self.options()); @@ -207,7 +203,6 @@ impl Compression { Ok(CompressionStream::new(stream)) } - #[inline] pub fn decompress_stream(&self) -> Result { let codec = try!(self.codec()); let stream = unsafe { squash_stream_new( diff --git a/src/util/encryption.rs b/src/util/encryption.rs index c09d98b..d350ab9 100644 --- a/src/util/encryption.rs +++ b/src/util/encryption.rs @@ -111,7 +111,6 @@ impl Crypto { Crypto { path: PathBuf::new(), keys: HashMap::new() } } - #[inline] pub fn open>(path: P) -> Result { let path = path.as_ref().to_owned(); let mut keys: HashMap = HashMap::default(); @@ -138,7 +137,6 @@ impl Crypto { self.register_secret_key(public, secret) } - #[inline] pub fn load_keypair_from_file>(path: P) -> Result<(PublicKey, SecretKey), EncryptionError> { let keyfile = try!(KeyfileYaml::load(path)); let public = try!(parse_hex(&keyfile.public).map_err(|_| EncryptionError::InvalidKey)); diff --git a/src/util/fs.rs b/src/util/fs.rs index 581edba..c9d8774 100644 --- a/src/util/fs.rs +++ b/src/util/fs.rs @@ -6,6 +6,7 @@ mod linux { use std::ffi::CString; use std::os::unix::ffi::OsStringExt; + #[inline] pub fn chown>(path: P, uid: libc::uid_t, gid: libc::gid_t) -> Result<(), io::Error> { let path = CString::new(path.as_ref().to_path_buf().into_os_string().into_vec()).unwrap(); let result = unsafe { libc::lchown((&path).as_ptr(), uid, gid) }; diff --git a/src/util/lru_cache.rs b/src/util/lru_cache.rs index 78ccec8..29e082c 100644 --- a/src/util/lru_cache.rs +++ b/src/util/lru_cache.rs @@ -52,7 +52,6 @@ impl LruCache { } } - #[inline] fn shrink(&mut self) { let mut tags: Vec = self.items.values().map(|&(_, n)| n).collect(); tags.sort(); diff --git a/src/util/msgpack.rs b/src/util/msgpack.rs index 9a688ff..1962435 100644 --- a/src/util/msgpack.rs +++ b/src/util/msgpack.rs @@ -8,6 +8,7 @@ pub use rmp_serde::decode::Error as DecodeError; pub use rmp_serde::encode::Error as EncodeError; +#[inline] pub fn encode(t: &T) -> Result, EncodeError> { let mut data = Vec::new(); { @@ -17,17 +18,20 @@ pub fn encode(t: &T) -> Result, EncodeError> { Ok(data) } +#[inline] pub fn encode_to_stream(t: &T, w: &mut Write) -> Result<(), EncodeError> { let mut writer = rmp_serde::Serializer::new(w); t.serialize(&mut writer) } +#[inline] pub fn decode(data: &[u8]) -> Result { let data = Cursor::new(data); let mut reader = rmp_serde::Deserializer::new(data); T::deserialize(&mut reader) } +#[inline] pub fn decode_from_stream(r: &mut Read) -> Result { let mut reader = rmp_serde::Deserializer::new(r); T::deserialize(&mut reader)