Sane inline

This commit is contained in:
Dennis Schwerdel 2017-04-10 20:35:28 +02:00 committed by Dennis Schwerdel
parent 26d73e79a4
commit fcbc2e131f
17 changed files with 43 additions and 38 deletions

View File

@ -183,7 +183,6 @@ impl BundleDb {
Ok(()) Ok(())
} }
#[inline]
pub fn open(layout: RepositoryLayout, crypto: Arc<Mutex<Crypto>>) -> Result<(Self, Vec<BundleInfo>, Vec<BundleInfo>), BundleDbError> { pub fn open(layout: RepositoryLayout, crypto: Arc<Mutex<Crypto>>) -> Result<(Self, Vec<BundleInfo>, Vec<BundleInfo>), BundleDbError> {
let mut self_ = Self::new(layout, crypto); let mut self_ = Self::new(layout, crypto);
let (new, gone) = try!(self_.load_bundle_list()); let (new, gone) = try!(self_.load_bundle_list());
@ -193,7 +192,6 @@ impl BundleDb {
Ok((self_, new, gone)) Ok((self_, new, gone))
} }
#[inline]
pub fn create(layout: RepositoryLayout) -> Result<(), BundleDbError> { 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.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)); 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<BundleReader, BundleDbError> { fn get_bundle(&self, stored: &StoredBundle) -> Result<BundleReader, BundleDbError> {
let base_path = self.layout.base_path(); let base_path = self.layout.base_path();
Ok(try!(BundleReader::load(base_path.join(&stored.path), self.crypto.clone()))) Ok(try!(BundleReader::load(base_path.join(&stored.path), self.crypto.clone())))
@ -244,7 +243,6 @@ impl BundleDb {
Ok(()) Ok(())
} }
#[inline]
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(&self));
if bundle.info.mode == BundleMode::Meta { if bundle.info.mode == BundleMode::Meta {
@ -262,7 +260,6 @@ impl BundleDb {
Ok(bundle.info) Ok(bundle.info)
} }
#[inline]
pub fn finish_uploads(&mut self) -> Result<(), BundleDbError> { pub fn finish_uploads(&mut self) -> Result<(), BundleDbError> {
let mut uploader = None; let mut uploader = None;
mem::swap(&mut self.uploader, &mut uploader); mem::swap(&mut self.uploader, &mut uploader);
@ -273,7 +270,6 @@ impl BundleDb {
} }
} }
#[inline]
pub fn get_chunk_list(&self, bundle: &BundleId) -> Result<ChunkList, BundleDbError> { pub fn get_chunk_list(&self, bundle: &BundleId) -> Result<ChunkList, BundleDbError> {
let mut bundle = try!(self.get_stored_bundle(bundle).and_then(|stored| self.get_bundle(&stored))); let mut bundle = try!(self.get_stored_bundle(bundle).and_then(|stored| self.get_bundle(&stored)));
Ok(try!(bundle.get_chunk_list()).clone()) Ok(try!(bundle.get_chunk_list()).clone())
@ -289,7 +285,6 @@ impl BundleDb {
self.remote_bundles.values().map(|b| &b.info).collect() self.remote_bundles.values().map(|b| &b.info).collect()
} }
#[inline]
pub fn delete_local_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> { pub fn delete_local_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> {
if let Some(bundle) = self.local_bundles.remove(bundle) { if let Some(bundle) = self.local_bundles.remove(bundle) {
let path = self.layout.base_path().join(&bundle.path); let path = self.layout.base_path().join(&bundle.path);
@ -298,7 +293,6 @@ impl BundleDb {
Ok(()) Ok(())
} }
#[inline]
pub fn delete_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> { pub fn delete_bundle(&mut self, bundle: &BundleId) -> Result<(), BundleDbError> {
try!(self.delete_local_bundle(bundle)); try!(self.delete_local_bundle(bundle));
if let Some(bundle) = self.remote_bundles.remove(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> { pub fn check(&mut self, full: bool) -> Result<(), BundleDbError> {
for stored in self.remote_bundles.values() { for stored in self.remote_bundles.values() {
let mut bundle = try!(self.get_bundle(stored)); let mut bundle = try!(self.get_bundle(stored));

View File

@ -25,12 +25,14 @@ pub static HEADER_VERSION: u8 = 1;
pub struct BundleId(pub Hash); pub struct BundleId(pub Hash);
impl Serialize for BundleId { impl Serialize for BundleId {
#[inline]
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> { fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
self.0.serialize(ser) self.0.serialize(ser)
} }
} }
impl Deserialize for BundleId { impl Deserialize for BundleId {
#[inline]
fn deserialize<D: serde::Deserializer>(de: D) -> Result<Self, D::Error> { fn deserialize<D: serde::Deserializer>(de: D) -> Result<Self, D::Error> {
let hash = try!(Hash::deserialize(de)); let hash = try!(Hash::deserialize(de));
Ok(BundleId(hash)) Ok(BundleId(hash))
@ -43,6 +45,7 @@ impl BundleId {
self.0.to_string() self.0.to_string()
} }
#[inline]
pub fn random() -> Self { pub fn random() -> Self {
BundleId(Hash{high: rand::random(), low: rand::random()}) BundleId(Hash{high: rand::random(), low: rand::random()})
} }

View File

@ -153,7 +153,6 @@ impl BundleReader {
Ok(self.chunks.as_ref().unwrap()) Ok(self.chunks.as_ref().unwrap())
} }
#[inline]
fn load_encoded_contents(&self) -> Result<Vec<u8>, BundleReaderError> { fn load_encoded_contents(&self) -> Result<Vec<u8>, BundleReaderError> {
debug!("Load bundle data {} ({:?})", self.info.id, self.info.mode); 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))); let mut file = BufReader::new(try!(File::open(&self.path).context(&self.path as &Path)));
@ -163,7 +162,6 @@ impl BundleReader {
Ok(data) Ok(data)
} }
#[inline]
fn decode_contents(&self, mut data: Vec<u8>) -> Result<Vec<u8>, BundleReaderError> { fn decode_contents(&self, mut data: Vec<u8>) -> Result<Vec<u8>, BundleReaderError> {
if let Some(ref encryption) = self.info.encryption { if let Some(ref encryption) = self.info.encryption {
data = try!(self.crypto.lock().unwrap().decrypt(&encryption, &data).context(&self.path as &Path)); 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)) 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> { pub fn get_chunk_position(&mut self, id: usize) -> Result<(usize, usize), BundleReaderError> {
if id >= self.info.chunk_count { if id >= self.info.chunk_count {
return Err(BundleReaderError::NoSuchChunk(self.id(), id)) return Err(BundleReaderError::NoSuchChunk(self.id(), id))

View File

@ -58,7 +58,6 @@ pub enum Chunker {
impl IChunker for Chunker { impl IChunker for Chunker {
#[inline]
fn get_type(&self) -> ChunkerType { fn get_type(&self) -> ChunkerType {
match *self { match *self {
Chunker::Ae(ref c) => c.get_type(), Chunker::Ae(ref c) => c.get_type(),
@ -92,7 +91,6 @@ serde_impl!(ChunkerType(u64) {
impl ChunkerType { impl ChunkerType {
#[inline]
pub fn from(name: &str, avg_size: usize, seed: u64) -> Result<Self, &'static str> { pub fn from(name: &str, avg_size: usize, seed: u64) -> Result<Self, &'static str> {
match name { match name {
"ae" => Ok(ChunkerType::Ae(avg_size)), "ae" => Ok(ChunkerType::Ae(avg_size)),
@ -102,7 +100,6 @@ impl ChunkerType {
} }
} }
#[inline]
pub fn from_string(name: &str) -> Result<Self, &'static str> { pub fn from_string(name: &str) -> Result<Self, &'static str> {
let (name, size) = if let Some(pos) = name.find('/') { 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")); 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 { pub fn name(&self) -> &'static str {
match *self { match *self {
ChunkerType::Ae(_size) => "ae", ChunkerType::Ae(_size) => "ae",
@ -133,7 +129,6 @@ impl ChunkerType {
} }
} }
#[inline]
pub fn avg_size(&self) -> usize { pub fn avg_size(&self) -> usize {
match *self { match *self {
ChunkerType::Ae(size) => size, ChunkerType::Ae(size) => size,
@ -142,12 +137,10 @@ impl ChunkerType {
} }
} }
#[inline]
pub fn to_string(&self) -> String { pub fn to_string(&self) -> String {
format!("{}/{}", self.name(), self.avg_size()/1024) format!("{}/{}", self.name(), self.avg_size()/1024)
} }
#[inline]
pub fn seed(&self) -> u64 { pub fn seed(&self) -> u64 {
match *self { match *self {
ChunkerType::Ae(_size) => 0, ChunkerType::Ae(_size) => 0,

View File

@ -41,6 +41,7 @@ impl Repository {
Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path()))) Ok(try!(Backup::get_all_from(&self.crypto.lock().unwrap(), self.layout.backups_path())))
} }
#[inline]
pub fn has_backup(&self, name: &str) -> bool { pub fn has_backup(&self, name: &str) -> bool {
self.layout.backup_path(name).exists() self.layout.backup_path(name).exists()
} }
@ -222,7 +223,6 @@ impl Repository {
Ok(inode) Ok(inode)
} }
#[allow(dead_code)]
pub fn create_backup_recursively<P: AsRef<Path>>(&mut self, path: P, reference: Option<&Backup>, options: &BackupOptions) -> Result<Backup, RepositoryError> { pub fn create_backup_recursively<P: AsRef<Path>>(&mut self, path: P, reference: Option<&Backup>, options: &BackupOptions) -> Result<Backup, RepositoryError> {
let _lock = try!(self.lock(false)); let _lock = try!(self.lock(false));
if self.dirty { if self.dirty {
@ -307,7 +307,6 @@ impl Repository {
self.get_backup_path(backup, path).map(|mut inodes| inodes.pop().unwrap()) self.get_backup_path(backup, path).map(|mut inodes| inodes.pop().unwrap())
} }
#[inline]
pub fn find_versions<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<(String, Inode)>, RepositoryError> { pub fn find_versions<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<(String, Inode)>, RepositoryError> {
let path = path.as_ref(); let path = path.as_ref();
let mut versions = HashMap::new(); let mut versions = HashMap::new();
@ -325,7 +324,6 @@ impl Repository {
Ok(versions) Ok(versions)
} }
#[inline]
fn find_differences_recurse(&mut self, inode1: &Inode, inode2: &Inode, path: PathBuf, diffs: &mut Vec<(DiffType, PathBuf)>) -> Result<(), RepositoryError> { 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 { if !inode1.is_same_meta(inode2) || inode1.data != inode2.data {
diffs.push((DiffType::Mod, path.clone())); diffs.push((DiffType::Mod, path.clone()));

View File

@ -54,6 +54,7 @@ impl<'a> Read for ChunkReader<'a> {
impl Repository { impl Repository {
#[inline]
pub fn get_bundle_id(&self, id: u32) -> Result<BundleId, RepositoryError> { pub fn get_bundle_id(&self, id: u32) -> Result<BundleId, RepositoryError> {
self.bundle_map.get(id).ok_or_else(|| IntegrityError::MissingBundleId(id).into()) self.bundle_map.get(id).ok_or_else(|| IntegrityError::MissingBundleId(id).into())
} }
@ -187,7 +188,6 @@ impl Repository {
Ok(chunks.into()) Ok(chunks.into())
} }
#[inline]
pub fn get_data(&mut self, chunks: &[Chunk]) -> Result<Vec<u8>, RepositoryError> { pub fn get_data(&mut self, chunks: &[Chunk]) -> Result<Vec<u8>, RepositoryError> {
let mut data = Vec::with_capacity(chunks.iter().map(|&(_, size)| size).sum::<u32>() as usize); let mut data = Vec::with_capacity(chunks.iter().map(|&(_, size)| size).sum::<u32>() as usize);
try!(self.get_stream(chunks, &mut data)); try!(self.get_stream(chunks, &mut data));
@ -199,7 +199,6 @@ impl Repository {
ChunkReader::new(self, chunks) ChunkReader::new(self, chunks)
} }
#[inline]
pub fn get_stream<W: Write>(&mut self, chunks: &[Chunk], w: &mut W) -> Result<(), RepositoryError> { pub fn get_stream<W: Write>(&mut self, chunks: &[Chunk], w: &mut W) -> Result<(), RepositoryError> {
for &(ref hash, len) in chunks { for &(ref hash, len) in chunks {
let data = try!(try!(self.get_chunk(*hash)).ok_or_else(|| IntegrityError::MissingChunk(hash.clone()))); let data = try!(try!(self.get_chunk(*hash)).ok_or_else(|| IntegrityError::MissingChunk(hash.clone())));

View File

@ -77,7 +77,6 @@ impl BundleMap {
self.0.remove(&id) self.0.remove(&id)
} }
#[inline]
pub fn find(&self, bundle: &BundleId) -> Option<u32> { pub fn find(&self, bundle: &BundleId) -> Option<u32> {
for (id, bundle_id) in &self.0 { for (id, bundle_id) in &self.0 {
if bundle == bundle_id { if bundle == bundle_id {
@ -92,7 +91,6 @@ impl BundleMap {
self.0.insert(id, bundle); self.0.insert(id, bundle);
} }
#[inline]
pub fn bundles(&self) -> Vec<(u32, BundleId)> { pub fn bundles(&self) -> Vec<(u32, BundleId)> {
self.0.iter().map(|(id, bundle)| (*id, bundle.clone())).collect() self.0.iter().map(|(id, bundle)| (*id, bundle.clone())).collect()
} }

View File

@ -118,6 +118,7 @@ impl Repository {
Ok(()) Ok(())
} }
#[inline]
pub fn check_backup(&mut self, backup: &Backup) -> Result<(), RepositoryError> { pub fn check_backup(&mut self, backup: &Backup) -> Result<(), RepositoryError> {
info!("Checking backup..."); info!("Checking backup...");
let mut checked = Bitmap::new(self.index.capacity()); let mut checked = Bitmap::new(self.index.capacity());
@ -179,6 +180,7 @@ impl Repository {
Ok(()) Ok(())
} }
#[inline]
pub fn check_index(&mut self) -> Result<(), RepositoryError> { pub fn check_index(&mut self) -> Result<(), RepositoryError> {
info!("Checking index integrity..."); info!("Checking index integrity...");
try!(self.index.check()); try!(self.index.check());
@ -186,6 +188,7 @@ impl Repository {
self.check_index_chunks() self.check_index_chunks()
} }
#[inline]
pub fn check_bundles(&mut self, full: bool) -> Result<(), RepositoryError> { pub fn check_bundles(&mut self, full: bool) -> Result<(), RepositoryError> {
info!("Checking bundle integrity..."); info!("Checking bundle integrity...");
Ok(try!(self.bundles.check(full))) Ok(try!(self.bundles.check(full)))

View File

@ -10,58 +10,72 @@ impl RepositoryLayout {
RepositoryLayout(path.as_ref().to_path_buf()) RepositoryLayout(path.as_ref().to_path_buf())
} }
#[inline]
pub fn base_path(&self) -> &Path { pub fn base_path(&self) -> &Path {
&self.0 &self.0
} }
#[inline]
pub fn config_path(&self) -> PathBuf { pub fn config_path(&self) -> PathBuf {
self.0.join("config.yaml") self.0.join("config.yaml")
} }
#[inline]
pub fn excludes_path(&self) -> PathBuf { pub fn excludes_path(&self) -> PathBuf {
self.0.join("excludes") self.0.join("excludes")
} }
#[inline]
pub fn index_path(&self) -> PathBuf { pub fn index_path(&self) -> PathBuf {
self.0.join("index") self.0.join("index")
} }
#[inline]
pub fn keys_path(&self) -> PathBuf { pub fn keys_path(&self) -> PathBuf {
self.0.join("keys") self.0.join("keys")
} }
#[inline]
pub fn bundle_map_path(&self) -> PathBuf { pub fn bundle_map_path(&self) -> PathBuf {
self.0.join("bundles.map") self.0.join("bundles.map")
} }
#[inline]
pub fn backups_path(&self) -> PathBuf { pub fn backups_path(&self) -> PathBuf {
self.0.join("remote/backups") self.0.join("remote/backups")
} }
#[inline]
pub fn backup_path(&self, name: &str) -> PathBuf { pub fn backup_path(&self, name: &str) -> PathBuf {
self.backups_path().join(name) self.backups_path().join(name)
} }
#[inline]
pub fn remote_path(&self) -> PathBuf { pub fn remote_path(&self) -> PathBuf {
self.0.join("remote") self.0.join("remote")
} }
#[inline]
pub fn remote_exists(&self) -> bool { pub fn remote_exists(&self) -> bool {
self.remote_bundles_path().exists() && self.backups_path().exists() && self.remote_locks_path().exists() self.remote_bundles_path().exists() && self.backups_path().exists() && self.remote_locks_path().exists()
} }
#[inline]
pub fn remote_readme_path(&self) -> PathBuf { pub fn remote_readme_path(&self) -> PathBuf {
self.0.join("remote/README.md") self.0.join("remote/README.md")
} }
#[inline]
pub fn remote_locks_path(&self) -> PathBuf { pub fn remote_locks_path(&self) -> PathBuf {
self.0.join("remote/locks") self.0.join("remote/locks")
} }
#[inline]
pub fn remote_bundles_path(&self) -> PathBuf { pub fn remote_bundles_path(&self) -> PathBuf {
self.0.join("remote/bundles") self.0.join("remote/bundles")
} }
#[inline]
pub fn local_bundles_path(&self) -> PathBuf { pub fn local_bundles_path(&self) -> PathBuf {
self.0.join("bundles/cached") self.0.join("bundles/cached")
} }
@ -79,30 +93,37 @@ impl RepositoryLayout {
(folder, file.into()) (folder, file.into())
} }
#[inline]
pub fn remote_bundle_path(&self, count: usize) -> (PathBuf, PathBuf) { pub fn remote_bundle_path(&self, count: usize) -> (PathBuf, PathBuf) {
self.bundle_path(&BundleId::random(), self.remote_bundles_path(), count) self.bundle_path(&BundleId::random(), self.remote_bundles_path(), count)
} }
#[inline]
pub fn local_bundle_path(&self, bundle: &BundleId, count: usize) -> (PathBuf, PathBuf) { pub fn local_bundle_path(&self, bundle: &BundleId, count: usize) -> (PathBuf, PathBuf) {
self.bundle_path(bundle, self.local_bundles_path(), count) self.bundle_path(bundle, self.local_bundles_path(), count)
} }
#[inline]
pub fn temp_bundles_path(&self) -> PathBuf { pub fn temp_bundles_path(&self) -> PathBuf {
self.0.join("bundles/temp") self.0.join("bundles/temp")
} }
#[inline]
pub fn temp_bundle_path(&self) -> PathBuf { pub fn temp_bundle_path(&self) -> PathBuf {
self.temp_bundles_path().join(BundleId::random().to_string().to_owned() + ".bundle") self.temp_bundles_path().join(BundleId::random().to_string().to_owned() + ".bundle")
} }
#[inline]
pub fn local_bundle_cache_path(&self) -> PathBuf { pub fn local_bundle_cache_path(&self) -> PathBuf {
self.0.join("bundles/local.cache") self.0.join("bundles/local.cache")
} }
#[inline]
pub fn remote_bundle_cache_path(&self) -> PathBuf { pub fn remote_bundle_cache_path(&self) -> PathBuf {
self.0.join("bundles/remote.cache") self.0.join("bundles/remote.cache")
} }
#[inline]
pub fn dirtyfile_path(&self) -> PathBuf { pub fn dirtyfile_path(&self) -> PathBuf {
self.0.join("dirty") self.0.join("dirty")
} }

View File

@ -206,7 +206,6 @@ impl Inode {
Ok(inode) Ok(inode)
} }
#[allow(dead_code)]
pub fn create_at<P: AsRef<Path>>(&self, path: P) -> Result<Option<File>, InodeError> { pub fn create_at<P: AsRef<Path>>(&self, path: P) -> Result<Option<File>, InodeError> {
let full_path = path.as_ref().join(&self.name); let full_path = path.as_ref().join(&self.name);
let mut file = None; let mut file = None;
@ -244,12 +243,14 @@ impl Inode {
Ok(file) Ok(file)
} }
#[inline]
pub fn is_same_meta(&self, other: &Inode) -> bool { pub fn is_same_meta(&self, other: &Inode) -> bool {
self.file_type == other.file_type && self.size == other.size && self.mode == other.mode 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.user == other.user && self.group == other.group && self.name == other.name
&& self.timestamp == other.timestamp && self.symlink_target == other.symlink_target && self.timestamp == other.timestamp && self.symlink_target == other.symlink_target
} }
#[inline]
pub fn is_same_meta_quick(&self, other: &Inode) -> bool { pub fn is_same_meta_quick(&self, other: &Inode) -> bool {
self.timestamp == other.timestamp self.timestamp == other.timestamp
&& self.file_type == other.file_type && self.file_type == other.file_type
@ -308,7 +309,6 @@ impl Repository {
Ok(try!(Inode::decode(&try!(self.get_data(chunks))))) Ok(try!(Inode::decode(&try!(self.get_data(chunks)))))
} }
#[inline]
pub fn save_inode_at<P: AsRef<Path>>(&mut self, inode: &Inode, path: P) -> Result<(), RepositoryError> { pub fn save_inode_at<P: AsRef<Path>>(&mut self, inode: &Inode, path: P) -> Result<(), RepositoryError> {
if let Some(mut file) = try!(inode.create_at(path.as_ref())) { if let Some(mut file) = try!(inode.create_at(path.as_ref())) {
if let Some(ref contents) = inode.data { if let Some(ref contents) = inode.data {

View File

@ -159,6 +159,7 @@ impl Repository {
Ok(try!(self.crypto.lock().unwrap().register_secret_key(public, secret))) Ok(try!(self.crypto.lock().unwrap().register_secret_key(public, secret)))
} }
#[inline]
pub fn save_config(&mut self) -> Result<(), RepositoryError> { pub fn save_config(&mut self) -> Result<(), RepositoryError> {
try!(self.config.save(self.layout.config_path())); try!(self.config.save(self.layout.config_path()));
Ok(()) Ok(())
@ -289,10 +290,12 @@ impl Repository {
Ok(()) Ok(())
} }
#[inline]
fn lock(&self, exclusive: bool) -> Result<LockHandle, RepositoryError> { fn lock(&self, exclusive: bool) -> Result<LockHandle, RepositoryError> {
Ok(try!(self.locks.lock(exclusive))) Ok(try!(self.locks.lock(exclusive)))
} }
#[inline]
pub fn set_clean(&mut self) { pub fn set_clean(&mut self) {
self.dirty = false; self.dirty = false;
} }

View File

@ -40,7 +40,6 @@ impl ChunkList {
self.0.push(chunk) self.0.push(chunk)
} }
#[inline]
pub fn write_to(&self, dst: &mut Write) -> Result<(), io::Error> { pub fn write_to(&self, dst: &mut Write) -> Result<(), io::Error> {
for chunk in &self.0 { for chunk in &self.0 {
try!(chunk.0.write_to(dst)); try!(chunk.0.write_to(dst));
@ -49,7 +48,6 @@ impl ChunkList {
Ok(()) Ok(())
} }
#[inline]
pub fn read_n_from(n: usize, src: &mut Read) -> Result<Self, io::Error> { pub fn read_n_from(n: usize, src: &mut Read) -> Result<Self, io::Error> {
let mut chunks = Vec::with_capacity(n); let mut chunks = Vec::with_capacity(n);
for _ in 0..n { for _ in 0..n {
@ -112,6 +110,7 @@ impl DerefMut for ChunkList {
} }
impl Serialize for ChunkList { impl Serialize for ChunkList {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut buf = Vec::with_capacity(self.encoded_size()); let mut buf = Vec::with_capacity(self.encoded_size());
self.write_to(&mut buf).unwrap(); self.write_to(&mut buf).unwrap();
@ -120,6 +119,7 @@ impl Serialize for ChunkList {
} }
impl Deserialize for ChunkList { impl Deserialize for ChunkList {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer {
let data: Vec<u8> = try!(ByteBuf::deserialize(deserializer)).into(); let data: Vec<u8> = try!(ByteBuf::deserialize(deserializer)).into();
if data.len() % 20 != 0 { if data.len() % 20 != 0 {

View File

@ -72,7 +72,6 @@ impl Compression {
format!("{}/{}", self.name(), self.level) format!("{}/{}", self.name(), self.level)
} }
#[inline]
pub fn from_string(name: &str) -> Result<Self, CompressionError> { pub fn from_string(name: &str) -> Result<Self, CompressionError> {
let (name, level) = if let Some(pos) = name.find('/') { 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()))); 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 }) Ok(Compression { method: method, level: level })
} }
#[inline]
pub fn name(&self) -> &'static str { pub fn name(&self) -> &'static str {
match self.method { match self.method {
CompressionMethod::Deflate => "deflate", CompressionMethod::Deflate => "deflate",
@ -101,7 +99,6 @@ impl Compression {
} }
} }
#[inline]
fn codec(&self) -> Result<*mut SquashCodec, CompressionError> { fn codec(&self) -> Result<*mut SquashCodec, CompressionError> {
let name = CString::new(self.name().as_bytes()).unwrap(); let name = CString::new(self.name().as_bytes()).unwrap();
let codec = unsafe { squash_get_codec(name.as_ptr()) }; let codec = unsafe { squash_get_codec(name.as_ptr()) };
@ -194,7 +191,6 @@ impl Compression {
Ok(buf) Ok(buf)
} }
#[inline]
pub fn compress_stream(&self) -> Result<CompressionStream, CompressionError> { pub fn compress_stream(&self) -> Result<CompressionStream, CompressionError> {
let codec = try!(self.codec()); let codec = try!(self.codec());
let options = try!(self.options()); let options = try!(self.options());
@ -207,7 +203,6 @@ impl Compression {
Ok(CompressionStream::new(stream)) Ok(CompressionStream::new(stream))
} }
#[inline]
pub fn decompress_stream(&self) -> Result<CompressionStream, CompressionError> { pub fn decompress_stream(&self) -> Result<CompressionStream, CompressionError> {
let codec = try!(self.codec()); let codec = try!(self.codec());
let stream = unsafe { squash_stream_new( let stream = unsafe { squash_stream_new(

View File

@ -111,7 +111,6 @@ impl Crypto {
Crypto { path: PathBuf::new(), keys: HashMap::new() } Crypto { path: PathBuf::new(), keys: HashMap::new() }
} }
#[inline]
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, EncryptionError> { pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, EncryptionError> {
let path = path.as_ref().to_owned(); let path = path.as_ref().to_owned();
let mut keys: HashMap<PublicKey, SecretKey> = HashMap::default(); let mut keys: HashMap<PublicKey, SecretKey> = HashMap::default();
@ -138,7 +137,6 @@ impl Crypto {
self.register_secret_key(public, secret) self.register_secret_key(public, secret)
} }
#[inline]
pub fn load_keypair_from_file<P: AsRef<Path>>(path: P) -> Result<(PublicKey, SecretKey), EncryptionError> { pub fn load_keypair_from_file<P: AsRef<Path>>(path: P) -> Result<(PublicKey, SecretKey), EncryptionError> {
let keyfile = try!(KeyfileYaml::load(path)); let keyfile = try!(KeyfileYaml::load(path));
let public = try!(parse_hex(&keyfile.public).map_err(|_| EncryptionError::InvalidKey)); let public = try!(parse_hex(&keyfile.public).map_err(|_| EncryptionError::InvalidKey));

View File

@ -6,6 +6,7 @@ mod linux {
use std::ffi::CString; use std::ffi::CString;
use std::os::unix::ffi::OsStringExt; use std::os::unix::ffi::OsStringExt;
#[inline]
pub fn chown<P: AsRef<Path>>(path: P, uid: libc::uid_t, gid: libc::gid_t) -> Result<(), io::Error> { pub fn chown<P: AsRef<Path>>(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 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) }; let result = unsafe { libc::lchown((&path).as_ptr(), uid, gid) };

View File

@ -52,7 +52,6 @@ impl<K: Eq+Hash, V> LruCache<K, V> {
} }
} }
#[inline]
fn shrink(&mut self) { fn shrink(&mut self) {
let mut tags: Vec<u64> = self.items.values().map(|&(_, n)| n).collect(); let mut tags: Vec<u64> = self.items.values().map(|&(_, n)| n).collect();
tags.sort(); tags.sort();

View File

@ -8,6 +8,7 @@ pub use rmp_serde::decode::Error as DecodeError;
pub use rmp_serde::encode::Error as EncodeError; pub use rmp_serde::encode::Error as EncodeError;
#[inline]
pub fn encode<T: Serialize>(t: &T) -> Result<Vec<u8>, EncodeError> { pub fn encode<T: Serialize>(t: &T) -> Result<Vec<u8>, EncodeError> {
let mut data = Vec::new(); let mut data = Vec::new();
{ {
@ -17,17 +18,20 @@ pub fn encode<T: Serialize>(t: &T) -> Result<Vec<u8>, EncodeError> {
Ok(data) Ok(data)
} }
#[inline]
pub fn encode_to_stream<T: Serialize>(t: &T, w: &mut Write) -> Result<(), EncodeError> { pub fn encode_to_stream<T: Serialize>(t: &T, w: &mut Write) -> Result<(), EncodeError> {
let mut writer = rmp_serde::Serializer::new(w); let mut writer = rmp_serde::Serializer::new(w);
t.serialize(&mut writer) t.serialize(&mut writer)
} }
#[inline]
pub fn decode<T: Deserialize>(data: &[u8]) -> Result<T, DecodeError> { pub fn decode<T: Deserialize>(data: &[u8]) -> Result<T, DecodeError> {
let data = Cursor::new(data); let data = Cursor::new(data);
let mut reader = rmp_serde::Deserializer::new(data); let mut reader = rmp_serde::Deserializer::new(data);
T::deserialize(&mut reader) T::deserialize(&mut reader)
} }
#[inline]
pub fn decode_from_stream<T: Deserialize>(r: &mut Read) -> Result<T, DecodeError> { pub fn decode_from_stream<T: Deserialize>(r: &mut Read) -> Result<T, DecodeError> {
let mut reader = rmp_serde::Deserializer::new(r); let mut reader = rmp_serde::Deserializer::new(r);
T::deserialize(&mut reader) T::deserialize(&mut reader)