mirror of https://github.com/dswd/zvault
Sane inline
This commit is contained in:
parent
26d73e79a4
commit
fcbc2e131f
|
@ -183,7 +183,6 @@ impl BundleDb {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn open(layout: RepositoryLayout, crypto: Arc<Mutex<Crypto>>) -> Result<(Self, Vec<BundleInfo>, Vec<BundleInfo>), 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<BundleReader, BundleDbError> {
|
||||
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<BundleInfo, BundleDbError> {
|
||||
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<ChunkList, BundleDbError> {
|
||||
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));
|
||||
|
|
|
@ -25,12 +25,14 @@ pub static HEADER_VERSION: u8 = 1;
|
|||
pub struct BundleId(pub Hash);
|
||||
|
||||
impl Serialize for BundleId {
|
||||
#[inline]
|
||||
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
|
||||
self.0.serialize(ser)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for BundleId {
|
||||
#[inline]
|
||||
fn deserialize<D: serde::Deserializer>(de: D) -> Result<Self, D::Error> {
|
||||
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()})
|
||||
}
|
||||
|
|
|
@ -153,7 +153,6 @@ impl BundleReader {
|
|||
Ok(self.chunks.as_ref().unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn load_encoded_contents(&self) -> Result<Vec<u8>, 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<u8>) -> Result<Vec<u8>, 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))
|
||||
|
|
|
@ -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<Self, &'static str> {
|
||||
match name {
|
||||
"ae" => Ok(ChunkerType::Ae(avg_size)),
|
||||
|
@ -102,7 +100,6 @@ impl ChunkerType {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_string(name: &str) -> Result<Self, &'static str> {
|
||||
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,
|
||||
|
|
|
@ -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<P: AsRef<Path>>(&mut self, path: P, reference: Option<&Backup>, options: &BackupOptions) -> Result<Backup, RepositoryError> {
|
||||
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<P: AsRef<Path>>(&mut self, path: P) -> Result<Vec<(String, Inode)>, 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()));
|
||||
|
|
|
@ -54,6 +54,7 @@ impl<'a> Read for ChunkReader<'a> {
|
|||
|
||||
|
||||
impl Repository {
|
||||
#[inline]
|
||||
pub fn get_bundle_id(&self, id: u32) -> Result<BundleId, RepositoryError> {
|
||||
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<Vec<u8>, RepositoryError> {
|
||||
let mut data = Vec::with_capacity(chunks.iter().map(|&(_, size)| size).sum::<u32>() as usize);
|
||||
try!(self.get_stream(chunks, &mut data));
|
||||
|
@ -199,7 +199,6 @@ impl Repository {
|
|||
ChunkReader::new(self, chunks)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_stream<W: Write>(&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())));
|
||||
|
|
|
@ -77,7 +77,6 @@ impl BundleMap {
|
|||
self.0.remove(&id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn find(&self, bundle: &BundleId) -> Option<u32> {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -206,7 +206,6 @@ impl Inode {
|
|||
Ok(inode)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create_at<P: AsRef<Path>>(&self, path: P) -> Result<Option<File>, 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<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(ref contents) = inode.data {
|
||||
|
|
|
@ -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<LockHandle, RepositoryError> {
|
||||
Ok(try!(self.locks.lock(exclusive)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_clean(&mut self) {
|
||||
self.dirty = false;
|
||||
self.dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Self, io::Error> {
|
||||
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error> 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<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer {
|
||||
let data: Vec<u8> = try!(ByteBuf::deserialize(deserializer)).into();
|
||||
if data.len() % 20 != 0 {
|
||||
|
|
|
@ -72,7 +72,6 @@ impl Compression {
|
|||
format!("{}/{}", self.name(), self.level)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_string(name: &str) -> Result<Self, CompressionError> {
|
||||
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<CompressionStream, CompressionError> {
|
||||
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<CompressionStream, CompressionError> {
|
||||
let codec = try!(self.codec());
|
||||
let stream = unsafe { squash_stream_new(
|
||||
|
|
|
@ -111,7 +111,6 @@ impl Crypto {
|
|||
Crypto { path: PathBuf::new(), keys: HashMap::new() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, EncryptionError> {
|
||||
let path = path.as_ref().to_owned();
|
||||
let mut keys: HashMap<PublicKey, SecretKey> = HashMap::default();
|
||||
|
@ -138,7 +137,6 @@ impl Crypto {
|
|||
self.register_secret_key(public, secret)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn load_keypair_from_file<P: AsRef<Path>>(path: P) -> Result<(PublicKey, SecretKey), EncryptionError> {
|
||||
let keyfile = try!(KeyfileYaml::load(path));
|
||||
let public = try!(parse_hex(&keyfile.public).map_err(|_| EncryptionError::InvalidKey));
|
||||
|
|
|
@ -6,6 +6,7 @@ mod linux {
|
|||
use std::ffi::CString;
|
||||
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> {
|
||||
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) };
|
||||
|
|
|
@ -52,7 +52,6 @@ impl<K: Eq+Hash, V> LruCache<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn shrink(&mut self) {
|
||||
let mut tags: Vec<u64> = self.items.values().map(|&(_, n)| n).collect();
|
||||
tags.sort();
|
||||
|
|
|
@ -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: Serialize>(t: &T) -> Result<Vec<u8>, EncodeError> {
|
||||
let mut data = Vec::new();
|
||||
{
|
||||
|
@ -17,17 +18,20 @@ pub fn encode<T: Serialize>(t: &T) -> Result<Vec<u8>, EncodeError> {
|
|||
Ok(data)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn encode_to_stream<T: Serialize>(t: &T, w: &mut Write) -> Result<(), EncodeError> {
|
||||
let mut writer = rmp_serde::Serializer::new(w);
|
||||
t.serialize(&mut writer)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn decode<T: Deserialize>(data: &[u8]) -> Result<T, DecodeError> {
|
||||
let data = Cursor::new(data);
|
||||
let mut reader = rmp_serde::Deserializer::new(data);
|
||||
T::deserialize(&mut reader)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn decode_from_stream<T: Deserialize>(r: &mut Read) -> Result<T, DecodeError> {
|
||||
let mut reader = rmp_serde::Deserializer::new(r);
|
||||
T::deserialize(&mut reader)
|
||||
|
|
Loading…
Reference in New Issue