Merge pull request #1059 from matthiasbeyer/libimagentrylink/header-location

libimagentrylink: Fix header locations
This commit is contained in:
Matthias Beyer 2017-09-09 20:35:34 +02:00 committed by GitHub
commit 4420f7a518
4 changed files with 17 additions and 13 deletions

View file

@ -376,10 +376,10 @@ mod tests {
} }
fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<&'a Value> { fn get_entry_links<'a>(entry: &'a FileLockEntry<'a>) -> TomlQueryResult<&'a Value> {
match entry.get_header().read(&"imag.links".to_owned()) { match entry.get_header().read(&"links.internal".to_owned()) {
Err(e) => Err(e), Err(e) => Err(e),
Ok(Some(v)) => Ok(v), Ok(Some(v)) => Ok(v),
Ok(None) => panic!("Didn't find 'imag.links' in {:?}", entry), Ok(None) => panic!("Didn't find 'links' in {:?}", entry),
} }
} }

View file

@ -34,6 +34,10 @@ This section contains the changelog from the last release to the next release.
* Fixed bugs * Fixed bugs
* The config loading in `libimagrt` * The config loading in `libimagrt`
[was fixed](http://git.imag-pim.org/imag/commit/?id=9193d50f96bce099665d2eb716bcaa29a8d9b8ff). [was fixed](http://git.imag-pim.org/imag/commit/?id=9193d50f96bce099665d2eb716bcaa29a8d9b8ff).
* `libimagentrylink` used `imag` as the location for putting links in
entries. This is not allowed because this namespace is reserved for the
store itself. This bug was fixed, links are now located in the `links`
namespace in the header of an entry.
* Minor changes * Minor changes
* If building from a `nix-shell`, the mozilla rust overlay is expected to be * If building from a `nix-shell`, the mozilla rust overlay is expected to be
present present

View file

@ -41,7 +41,7 @@ use libimagstore::storeid::IntoStoreId;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt; use toml_query::insert::TomlValueInsertExt;
use error::LinkErrorKind as LEK; use error::LinkErrorKind as LEK;
use error::LinkError as LE; use error::LinkError as LE;
@ -69,7 +69,7 @@ impl Link for Entry {
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> { fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
self.get_header() self.get_header()
.read("imag.content.url") .read("links.external.url")
.chain_err(|| LEK::EntryHeaderReadError) .chain_err(|| LEK::EntryHeaderReadError)
.and_then(|opt| match opt { .and_then(|opt| match opt {
Some(&Value::String(ref s)) => { Some(&Value::String(ref s)) => {
@ -82,7 +82,7 @@ impl Link for Entry {
} }
fn get_url(&self) -> Result<Option<Url>> { fn get_url(&self) -> Result<Option<Url>> {
match self.get_header().read("imag.content.url") { match self.get_header().read("links.external.url") {
Ok(Some(&Value::String(ref s))) => { Ok(Some(&Value::String(ref s))) => {
Url::parse(&s[..]) Url::parse(&s[..])
.map(Some) .map(Some)
@ -350,10 +350,10 @@ impl ExternalLinker for Entry {
{ {
let hdr = file.deref_mut().get_header_mut(); let hdr = file.deref_mut().get_header_mut();
let mut table = match hdr.read("imag.content") { let mut table = match hdr.read("links.external.content") {
Ok(Some(&Value::Table(ref table))) => table.clone(), Ok(Some(&Value::Table(ref table))) => table.clone(),
Ok(Some(_)) => { Ok(Some(_)) => {
warn!("There is a value at 'imag.content' which is not a table."); warn!("There is a value at 'links.external.content' which is not a table.");
warn!("Going to override this value"); warn!("Going to override this value");
BTreeMap::new() BTreeMap::new()
}, },
@ -366,7 +366,7 @@ impl ExternalLinker for Entry {
debug!("setting URL = '{:?}", v); debug!("setting URL = '{:?}", v);
table.insert(String::from("url"), v); table.insert(String::from("url"), v);
if let Err(e) = hdr.set("imag.content", Value::Table(table)) { if let Err(e) = hdr.insert("links.external.content", Value::Table(table)) {
return Err(e).chain_err(|| LEK::StoreWriteError); return Err(e).chain_err(|| LEK::StoreWriteError);
} else { } else {
debug!("Setting URL worked"); debug!("Setting URL worked");

View file

@ -27,7 +27,7 @@ use libimagstore::store::Entry;
use libimagstore::store::Result as StoreResult; use libimagstore::store::Result as StoreResult;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt; use toml_query::insert::TomlValueInsertExt;
use error::LinkErrorKind as LEK; use error::LinkErrorKind as LEK;
use error::LinkError as LE; use error::LinkError as LE;
@ -392,7 +392,7 @@ impl InternalLinker for Entry {
fn get_internal_links(&self) -> Result<LinkIter> { fn get_internal_links(&self) -> Result<LinkIter> {
let res = self let res = self
.get_header() .get_header()
.read("imag.links") .read("links.internal")
.chain_err(|| LEK::EntryHeaderReadError) .chain_err(|| LEK::EntryHeaderReadError)
.map(|r| r.cloned()); .map(|r| r.cloned());
process_rw_result(res) process_rw_result(res)
@ -426,7 +426,7 @@ impl InternalLinker for Entry {
})); }));
let res = self let res = self
.get_header_mut() .get_header_mut()
.set("imag.links", Value::Array(new_links)) .insert("links.interal", Value::Array(new_links))
.chain_err(|| LEK::EntryHeaderReadError); .chain_err(|| LEK::EntryHeaderReadError);
process_rw_result(res) process_rw_result(res)
} }
@ -497,7 +497,7 @@ fn rewrite_links<I: Iterator<Item = Link>>(header: &mut Value, links: I) -> Resu
debug!("Setting new link array: {:?}", links); debug!("Setting new link array: {:?}", links);
let process = header let process = header
.set("imag.links", Value::Array(links)) .insert("links.internal", Value::Array(links))
.chain_err(|| LEK::EntryHeaderReadError); .chain_err(|| LEK::EntryHeaderReadError);
process_rw_result(process).map(|_| ()) process_rw_result(process).map(|_| ())
} }
@ -525,7 +525,7 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
let res = target let res = target
.get_header_mut() .get_header_mut()
.set("imag.links", Value::Array(links)) .insert("links.internal", Value::Array(links))
.chain_err(|| LEK::EntryHeaderReadError); .chain_err(|| LEK::EntryHeaderReadError);
process_rw_result(res).map(|_| ()) process_rw_result(res).map(|_| ())