Fix header locations

Also change that the implementation uses toml_query::set instead of
toml_query::insert.

Inserting values creates intermediate tables, set doesn't. And we really
want that convenience here, as the code is complex enough on its own.
This commit is contained in:
Matthias Beyer 2017-09-07 22:13:00 +02:00
parent 374027df3c
commit 8aa5c2d82d
3 changed files with 15 additions and 11 deletions

View file

@ -34,6 +34,10 @@ This section contains the changelog from the last release to the next release.
* Fixed bugs
* The config loading in `libimagrt`
[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
* If building from a `nix-shell`, the mozilla rust overlay is expected to be
present

View file

@ -41,7 +41,7 @@ use libimagstore::storeid::IntoStoreId;
use libimagutil::debug_result::*;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt;
use toml_query::insert::TomlValueInsertExt;
use error::LinkErrorKind as LEK;
use error::LinkError as LE;
@ -69,7 +69,7 @@ impl Link for Entry {
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
self.get_header()
.read("imag.content.url")
.read("links.external.url")
.chain_err(|| LEK::EntryHeaderReadError)
.and_then(|opt| match opt {
Some(&Value::String(ref s)) => {
@ -82,7 +82,7 @@ impl Link for Entry {
}
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))) => {
Url::parse(&s[..])
.map(Some)
@ -350,10 +350,10 @@ impl ExternalLinker for Entry {
{
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(_)) => {
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");
BTreeMap::new()
},
@ -366,7 +366,7 @@ impl ExternalLinker for Entry {
debug!("setting 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);
} else {
debug!("Setting URL worked");

View file

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