summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-20 12:40:39 +0200
committerGitHub <noreply@github.com>2017-09-20 12:40:39 +0200
commit4b906f27b1e11f2fec64b06dae5f4a258976da68 (patch)
tree8d0014baa07962203012b7417883a25fc829c2fa
parent00256effdb4f9fea877b06a1761ee5f682d7574a (diff)
parentc558addbd6d4dd526b357a13090baeecf633052e (diff)
downloadimag-4b906f27b1e11f2fec64b06dae5f4a258976da68.zip
imag-4b906f27b1e11f2fec64b06dae5f4a258976da68.tar.gz
Merge pull request #1080 from matthiasbeyer/libimagentrytag/header-location
Do not use "imag" namespace in header
-rw-r--r--bin/core/imag-tag/src/main.rs68
-rw-r--r--lib/core/libimagstore/src/store.rs3
-rw-r--r--lib/entry/libimagentrytag/src/tagable.rs10
3 files changed, 54 insertions, 27 deletions
diff --git a/bin/core/imag-tag/src/main.rs b/bin/core/imag-tag/src/main.rs
index f1dd010..55485a3 100644
--- a/bin/core/imag-tag/src/main.rs
+++ b/bin/core/imag-tag/src/main.rs
@@ -97,16 +97,24 @@ fn alter(rt: &Runtime, id: PathBuf, add: Option<Vec<Tag>>, rem: Option<Vec<Tag>>
match rt.store().get(path) {
Ok(Some(mut e)) => {
+ debug!("Entry header now = {:?}", e.get_header());
+
add.map(|tags| {
- for tag in tags {
- debug!("Adding tag '{:?}'", tag);
- if let Err(e) = e.add_tag(tag) {
- trace_error(&e);
+ debug!("Adding tags = '{:?}'", tags);
+ for tag in tags {
+ debug!("Adding tag '{:?}'", tag);
+ if let Err(e) = e.add_tag(tag) {
+ trace_error(&e);
+ } else {
+ debug!("Adding tag worked");
+ }
}
- }
- }); // it is okay to ignore a None here
+ }); // it is okay to ignore a None here
+
+ debug!("Entry header now = {:?}", e.get_header());
rem.map(|tags| {
+ debug!("Removing tags = '{:?}'", tags);
for tag in tags {
debug!("Removing tag '{:?}'", tag);
if let Err(e) = e.remove_tag(tag) {
@@ -114,6 +122,9 @@ fn alter(rt: &Runtime, id: PathBuf, add: Option<Vec<Tag>>, rem: Option<Vec<Tag>>
}
}
}); // it is okay to ignore a None here
+
+ debug!("Entry header now = {:?}", e.get_header());
+
},
Ok(None) => {
@@ -255,7 +266,7 @@ mod tests {
}
fn get_entry_tags<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<Option<&'a Value>> {
- entry.get_header().read(&"imag.tags".to_owned())
+ entry.get_header().read(&"tag.values".to_owned())
}
fn tags_toml_value<'a, I: IntoIterator<Item = &'static str>>(tags: I) -> Value {
@@ -271,11 +282,12 @@ mod tests {
fn test_tag_add_adds_tag() {
setup_logging();
debug!("Generating runtime");
- let rt = generate_test_runtime(vec!["test", "--add", "foo"]).unwrap();
+ let name = "test-tag-add-adds-tags";
+ let rt = generate_test_runtime(vec![name, "--add", "foo"]).unwrap();
debug!("Creating default entry");
- create_test_default_entry(&rt, "test").unwrap();
- let id = PathBuf::from(String::from("test"));
+ create_test_default_entry(&rt, name).unwrap();
+ let id = PathBuf::from(String::from(name));
debug!("Getting 'add' tags");
let add = get_add_tags(rt.cli());
@@ -290,7 +302,13 @@ mod tests {
debug!("Altered");
let test_entry = rt.store().get(id).unwrap().unwrap();
- let test_tags = get_entry_tags(&test_entry).unwrap().unwrap();
+
+ let test_tags = get_entry_tags(&test_entry);
+ assert!(test_tags.is_ok(), "Should be Ok(_) = {:?}", test_tags);
+
+ let test_tags = test_tags.unwrap();
+ assert!(test_tags.is_some(), "Should be Some(_) = {:?}", test_tags);
+ let test_tags = test_tags.unwrap();
assert_ne!(*test_tags, tags_toml_value(vec![]));
assert_eq!(*test_tags, tags_toml_value(vec!["foo"]));
@@ -300,7 +318,8 @@ mod tests {
fn test_tag_add_more_than_remove_adds_tags() {
setup_logging();
debug!("Generating runtime");
- let rt = generate_test_runtime(vec!["test",
+ let name = "test-tag-add-more-than-remove-adds-tags";
+ let rt = generate_test_runtime(vec![name,
"--add", "foo",
"--add", "bar",
"--add", "baz",
@@ -311,8 +330,8 @@ mod tests {
]).unwrap();
debug!("Creating default entry");
- create_test_default_entry(&rt, "test").unwrap();
- let id = PathBuf::from(String::from("test"));
+ create_test_default_entry(&rt, name).unwrap();
+ let id = PathBuf::from(String::from(name));
// Manually add tags
let add = get_add_tags(rt.cli());
@@ -335,11 +354,12 @@ mod tests {
fn test_tag_remove_removes_tag() {
setup_logging();
debug!("Generating runtime");
- let rt = generate_test_runtime(vec!["test", "--remove", "foo"]).unwrap();
+ let name = "test-tag-remove-removes-tag";
+ let rt = generate_test_runtime(vec![name, "--remove", "foo"]).unwrap();
debug!("Creating default entry");
- create_test_default_entry(&rt, "test").unwrap();
- let id = PathBuf::from(String::from("test"));
+ create_test_default_entry(&rt, name).unwrap();
+ let id = PathBuf::from(String::from(name));
// Manually add tags
let add = Some(vec![ "foo".to_owned() ]);
@@ -362,11 +382,12 @@ mod tests {
fn test_tag_remove_removes_only_to_remove_tag() {
setup_logging();
debug!("Generating runtime");
- let rt = generate_test_runtime(vec!["test", "--remove", "foo"]).unwrap();
+ let name = "test-tag-remove-removes-only-to-remove-tag-doesnt-crash-on-nonexistent-tag";
+ let rt = generate_test_runtime(vec![name, "--remove", "foo"]).unwrap();
debug!("Creating default entry");
- create_test_default_entry(&rt, "test").unwrap();
- let id = PathBuf::from(String::from("test"));
+ create_test_default_entry(&rt, name).unwrap();
+ let id = PathBuf::from(String::from(name));
// Manually add tags
let add = Some(vec![ "foo".to_owned(), "bar".to_owned() ]);
@@ -389,11 +410,12 @@ mod tests {
fn test_tag_remove_removes_but_doesnt_crash_on_nonexistent_tag() {
setup_logging();
debug!("Generating runtime");
- let rt = generate_test_runtime(vec!["test", "--remove", "foo", "--remove", "bar"]).unwrap();
+ let name = "test-tag-remove-removes-but-doesnt-crash-on-nonexistent-tag";
+ let rt = generate_test_runtime(vec![name, "--remove", "foo", "--remove", "bar"]).unwrap();
debug!("Creating default entry");
- create_test_default_entry(&rt, "test").unwrap();
- let id = PathBuf::from(String::from("test"));
+ create_test_default_entry(&rt, name).unwrap();
+ let id = PathBuf::from(String::from(name));
// Manually add tags
let add = Some(vec![ "foo".to_owned() ]);
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index 5ba3754..72793a5 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -566,6 +566,7 @@ impl Store {
debug!("Writing Entry");
try!(se.write_entry(&entry.entry));
if modify_presence {
+ debug!("Modifying ppresence of {} -> Present", entry.get_location());
se.status = StoreEntryStatus::Present;
}
@@ -887,6 +888,7 @@ impl<'a> Drop for FileLockEntry<'a> {
/// intended for production use, though).
fn drop(&mut self) {
use libimagerror::trace::trace_error_dbg;
+ trace!("Dropping: {:?} - from FileLockEntry::drop()", self.get_location());
match self.store._update(self, true) {
Err(e) => {
trace_error_dbg(&e);
@@ -902,6 +904,7 @@ impl<'a> Drop for FileLockEntry<'a> {
/// This will not silently ignore errors but prints the result of the _update() call for testing
fn drop(&mut self) {
+ trace!("Dropping: {:?} - from FileLockEntry::drop() (test impl)", self.get_location());
let _ = self.store._update(self, true).map_err(|e| trace_error(&e));
}
diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs
index 65c3275..7b9687a 100644
--- a/lib/entry/libimagentrytag/src/tagable.rs
+++ b/lib/entry/libimagentrytag/src/tagable.rs
@@ -22,7 +22,7 @@ use itertools::Itertools;
use libimagstore::store::Entry;
use toml_query::read::TomlValueReadExt;
-use toml_query::set::TomlValueSetExt;
+use toml_query::insert::TomlValueInsertExt;
use error::TagErrorKind;
use error::TagError as TE;
@@ -49,7 +49,7 @@ pub trait Tagable {
impl Tagable for Value {
fn get_tags(&self) -> Result<Vec<Tag>> {
- let tags = try!(self.read("imag.tags").chain_err(|| TagErrorKind::HeaderReadError));
+ let tags = try!(self.read("tag.values").chain_err(|| TagErrorKind::HeaderReadError));
match tags {
Some(&Value::Array(ref tags)) => {
@@ -85,7 +85,8 @@ impl Tagable for Value {
}
let a = ts.iter().unique().map(|t| Value::String(t.clone())).collect();
- self.set("imag.tags", Value::Array(a))
+ debug!("Setting tags = {:?}", a);
+ self.insert("tag.values", Value::Array(a))
.map(|_| ())
.chain_err(|| TagErrorKind::HeaderWriteError)
}
@@ -98,6 +99,7 @@ impl Tagable for Value {
self.get_tags()
.map(|mut tags| {
+ debug!("Pushing tag = {:?} to list = {:?}", t, tags);
tags.push(t);
self.set_tags(&tags.into_iter().unique().collect::<Vec<_>>()[..])
})
@@ -119,7 +121,7 @@ impl Tagable for Value {
}
fn has_tag(&self, t: TagSlice) -> Result<bool> {
- let tags = try!(self.read("imag.tags").chain_err(|| TagErrorKind::HeaderReadError));
+ let tags = try!(self.read("tag.values").chain_err(|| TagErrorKind::HeaderReadError));
if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) {
return Err(TagErrorKind::TagTypeError.into());