Remove old concepts
This commit is contained in:
parent
97e863f8fb
commit
73af121882
6 changed files with 0 additions and 415 deletions
|
@ -1,100 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; version
|
||||
// 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use toml::Value;
|
||||
|
||||
use error::RefError as RE;
|
||||
use error::RefErrorKind as REK;
|
||||
use error::Result;
|
||||
|
||||
pub struct RefFlags {
|
||||
content_hashing: bool,
|
||||
permission_tracking: bool,
|
||||
}
|
||||
|
||||
impl RefFlags {
|
||||
|
||||
/// Read the RefFlags from a TOML document
|
||||
///
|
||||
/// Assumes that the whole TOML tree is passed. So this looks up `ref.flags` to get the flags.
|
||||
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
|
||||
pub fn read(v: &Value) -> Result<RefFlags> {
|
||||
fn get_field(v: &Value, key: &str) -> Result<bool> {
|
||||
use toml_query::read::TomlValueReadTypeExt;
|
||||
v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
|
||||
}
|
||||
|
||||
Ok(RefFlags {
|
||||
content_hashing: get_field(v, "ref.flags.content_hashing")?,
|
||||
permission_tracking: get_field(v, "ref.flags.permission_tracking")?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Alias for `RefFlags::content_hashing()`
|
||||
pub fn is_often_moving(self, b: bool) -> RefFlags {
|
||||
self.with_content_hashing(b)
|
||||
}
|
||||
|
||||
pub fn with_content_hashing(mut self, b: bool) -> RefFlags {
|
||||
self.content_hashing = b;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_permission_tracking(mut self, b: bool) -> RefFlags {
|
||||
self.permission_tracking = b;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
pub fn get_content_hashing(&self) -> bool {
|
||||
self.content_hashing
|
||||
}
|
||||
|
||||
pub fn get_permission_tracking(&self) -> bool {
|
||||
self.permission_tracking
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Into<Value> for RefFlags {
|
||||
|
||||
/// Build a TOML::Value from this RefFlags object.
|
||||
///
|
||||
/// Returns a Map which should be set in `ref.flags` in the header.
|
||||
fn into(self) -> Value {
|
||||
let mut btm = BTreeMap::new();
|
||||
btm.insert(String::from("content_hashing"), Value::Boolean(self.content_hashing));
|
||||
btm.insert(String::from("permission_tracking"), Value::Boolean(self.permission_tracking));
|
||||
return Value::Table(btm)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Default for RefFlags {
|
||||
|
||||
fn default() -> RefFlags {
|
||||
RefFlags {
|
||||
content_hashing: false,
|
||||
permission_tracking: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; version
|
||||
// 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::io::Read;
|
||||
|
||||
use crypto::sha1::Sha1;
|
||||
use crypto::digest::Digest;
|
||||
|
||||
use error::Result;
|
||||
|
||||
/// The Hasher trait is used to implement custom hashing functions for the ref library.
|
||||
/// This means that one can define how the hash of a reference is constructed from the content of
|
||||
/// the file to ref to.
|
||||
pub trait Hasher {
|
||||
|
||||
fn hash_name(&self) -> &'static str;
|
||||
fn create_hash<R: Read>(&mut self, pb: &PathBuf, contents: &mut R) -> Result<String>;
|
||||
|
||||
}
|
||||
|
||||
pub struct DefaultHasher {
|
||||
hasher: Sha1,
|
||||
}
|
||||
|
||||
impl DefaultHasher {
|
||||
|
||||
pub fn new() -> DefaultHasher {
|
||||
DefaultHasher { hasher: Sha1::new() }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Hasher for DefaultHasher {
|
||||
|
||||
fn hash_name(&self) -> &'static str {
|
||||
"default"
|
||||
}
|
||||
|
||||
fn create_hash<R: Read>(&mut self, _: &PathBuf, c: &mut R) -> Result<String> {
|
||||
let mut s = String::new();
|
||||
c.read_to_string(&mut s)?;
|
||||
self.hasher.input_str(&s[..]);
|
||||
Ok(self.hasher.result_str())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; version
|
||||
// 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
pub mod nbytes;
|
|
@ -1,66 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; version
|
||||
// 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::result::Result as RResult;
|
||||
|
||||
use crypto::sha1::Sha1;
|
||||
use crypto::digest::Digest;
|
||||
|
||||
use hasher::Hasher;
|
||||
use error::Result;
|
||||
use error::RefError as RE;
|
||||
|
||||
pub struct NBytesHasher {
|
||||
hasher: Sha1,
|
||||
n: usize,
|
||||
}
|
||||
|
||||
impl NBytesHasher {
|
||||
|
||||
pub fn new(n: usize) -> NBytesHasher {
|
||||
NBytesHasher {
|
||||
hasher: Sha1::new(),
|
||||
n: n,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Hasher for NBytesHasher {
|
||||
|
||||
fn hash_name(&self) -> &'static str {
|
||||
"n-bytes-hasher"
|
||||
}
|
||||
|
||||
fn create_hash<R: Read>(&mut self, _: &PathBuf, contents: &mut R) -> Result<String> {
|
||||
let s : String = contents
|
||||
.bytes()
|
||||
.take(self.n)
|
||||
.collect::<RResult<Vec<u8>, _>>()
|
||||
.map_err(From::from)
|
||||
.and_then(|v| String::from_utf8(v).map_err(RE::from))?;
|
||||
|
||||
self.hasher.input_str(&s[..]);
|
||||
Ok(self.hasher.result_str())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -51,10 +51,6 @@ extern crate libimagentrylist;
|
|||
module_entry_path_mod!("ref");
|
||||
|
||||
pub mod error;
|
||||
pub mod flags;
|
||||
pub mod hasher;
|
||||
pub mod hashers;
|
||||
pub mod lister;
|
||||
pub mod reference;
|
||||
pub mod refstore;
|
||||
mod util;
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
//
|
||||
// imag - the personal information management suite for the commandline
|
||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; version
|
||||
// 2.1 of the License.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
|
||||
use std::default::Default;
|
||||
use std::io::stdout;
|
||||
use std::io::Write;
|
||||
use std::ops::Deref;
|
||||
|
||||
use libimagentrylist::lister::Lister;
|
||||
use libimagentrylist::error::Result;
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagentrylist::error::ListErrorKind as LEK;
|
||||
use libimagentrylist::error as lerror;
|
||||
|
||||
use reference::Ref;
|
||||
|
||||
pub struct RefLister {
|
||||
check_dead: bool,
|
||||
check_changed: bool,
|
||||
check_changed_content: bool,
|
||||
check_changed_permiss: bool,
|
||||
}
|
||||
|
||||
impl RefLister {
|
||||
|
||||
pub fn new() -> RefLister {
|
||||
RefLister::default()
|
||||
}
|
||||
|
||||
pub fn check_dead(mut self, b: bool) -> RefLister {
|
||||
self.check_dead = b;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn check_changed(mut self, b: bool) -> RefLister {
|
||||
self.check_changed = b;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn check_changed_content(mut self, b: bool) -> RefLister {
|
||||
self.check_changed_content = b;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn check_changed_permiss(mut self, b: bool) -> RefLister {
|
||||
self.check_changed_permiss = b;
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Default for RefLister {
|
||||
|
||||
fn default() -> RefLister {
|
||||
RefLister {
|
||||
check_dead: false,
|
||||
check_changed: false,
|
||||
check_changed_content: false,
|
||||
check_changed_permiss: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Lister for RefLister {
|
||||
|
||||
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
|
||||
|
||||
debug!("Called list()");
|
||||
let (r, n) = entries.fold((Ok(()), 0), |(accu, i), entry| {
|
||||
debug!("fold({:?}, {:?})", accu, entry);
|
||||
let r = accu.and_then(|_| {
|
||||
debug!("Listing Entry: {:?}", entry);
|
||||
{
|
||||
let is_dead = if self.check_dead {
|
||||
if lerror::ResultExt::chain_err(entry.fs_link_exists(), || LEK::FormatError)? {
|
||||
"dead"
|
||||
} else {
|
||||
"alive"
|
||||
}
|
||||
} else {
|
||||
"not checked"
|
||||
};
|
||||
|
||||
let is_changed = if self.check_changed {
|
||||
if check_changed(entry.deref()) { "changed" } else { "unchanged" }
|
||||
} else {
|
||||
"not checked"
|
||||
};
|
||||
|
||||
let is_changed_content = if self.check_changed_content {
|
||||
if check_changed_content(entry.deref()) { "changed" } else { "unchanged" }
|
||||
} else {
|
||||
"not checked"
|
||||
};
|
||||
|
||||
let is_changed_permiss = if self.check_changed_permiss {
|
||||
if check_changed_permiss(entry.deref()) { "changed" } else { "unchanged" }
|
||||
} else {
|
||||
"not checked"
|
||||
};
|
||||
|
||||
Ok(format!("{} | {} | {} | {} | {} | {}",
|
||||
is_dead,
|
||||
is_changed,
|
||||
is_changed_content,
|
||||
is_changed_permiss,
|
||||
entry.get_path_hash().unwrap_or_else(|_| String::from("Cannot get hash")),
|
||||
entry.get_location()))
|
||||
}
|
||||
.and_then(|s| {
|
||||
lerror::ResultExt::chain_err(write!(stdout(), "{}\n", s), || LEK::FormatError)
|
||||
})
|
||||
})
|
||||
.map(|_| ());
|
||||
(r, i + 1)
|
||||
});
|
||||
debug!("Iterated over {} entries", n);
|
||||
r
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn check_changed<R: Ref>(r: &R) -> bool {
|
||||
check_changed_content(r) && check_changed_permiss(r)
|
||||
}
|
||||
|
||||
fn check_changed_content<R: Ref>(r: &R) -> bool {
|
||||
r.get_current_hash()
|
||||
.and_then(|hash| r.get_stored_hash().map(|stored| (hash, stored)))
|
||||
.map(|(hash, stored)| hash == stored)
|
||||
.unwrap_or_else(|e| {
|
||||
warn!("Could not check whether the ref changed on the FS");
|
||||
trace_error(&e);
|
||||
|
||||
// We continue here and tell the callee that this reference is unchanged
|
||||
false
|
||||
})
|
||||
}
|
||||
|
||||
fn check_changed_permiss<R: Ref>(_: &R) -> bool {
|
||||
warn!("Permission changes tracking not supported yet.");
|
||||
false
|
||||
}
|
||||
|
Loading…
Reference in a new issue