From c36250e42f34152afd04dc57b20caa0c5b08fa91 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 14 Feb 2018 00:20:23 +0100 Subject: [PATCH] Adapt to new libimagentryref API --- lib/entry/libimagentrymarkdown/Cargo.toml | 7 ++++- .../libimagentrymarkdown/src/processor.rs | 30 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/entry/libimagentrymarkdown/Cargo.toml b/lib/entry/libimagentrymarkdown/Cargo.toml index d7981b58..7ed53b79 100644 --- a/lib/entry/libimagentrymarkdown/Cargo.toml +++ b/lib/entry/libimagentrymarkdown/Cargo.toml @@ -29,6 +29,11 @@ env_logger = "0.5" libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" } libimagentrylink = { version = "0.7.0", path = "../../../lib/entry/libimagentrylink/" } -libimagentryref = { version = "0.7.0", path = "../../../lib/entry/libimagentryref/" } libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil/" } +[dependencies.libimagentryref] +version = "0.7.0" +path = "../../../lib/entry/libimagentryref/" +default-features = false +features = [ "generators", "generators-sha512" ] + diff --git a/lib/entry/libimagentrymarkdown/src/processor.rs b/lib/entry/libimagentrymarkdown/src/processor.rs index 15d60d4c..7203d9a5 100644 --- a/lib/entry/libimagentrymarkdown/src/processor.rs +++ b/lib/entry/libimagentrymarkdown/src/processor.rs @@ -17,6 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::path::Path; +use std::result::Result as RResult; + use error::MarkdownError as ME; use error::MarkdownErrorKind as MEK; use error::*; @@ -25,7 +28,8 @@ use link::extract_links; use libimagentrylink::external::ExternalLinker; use libimagentrylink::internal::InternalLinker; use libimagentryref::refstore::RefStore; -use libimagentryref::flags::RefFlags; +use libimagentryref::refstore::UniqueRefPathGenerator; +use libimagentryref::generators::sha512::Sha512; use libimagstore::store::Entry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; @@ -34,6 +38,25 @@ use std::path::PathBuf; use url::Url; + +pub struct UniqueMarkdownRefGenerator; + +impl UniqueRefPathGenerator for UniqueMarkdownRefGenerator { + type Error = ME; + + fn collection() -> &'static str { + "ref" // we can only use this collection, as we don't know about context + } + + fn unique_hash>(path: A) -> RResult { + Sha512::unique_hash(path).map_err(ME::from) + } + + fn postprocess_storeid(sid: StoreId) -> RResult { + Ok(sid) // don't do anything + } +} + /// A link Processor which collects the links from a Markdown and passes them on to /// `libimagentrylink` functionality /// @@ -136,15 +159,12 @@ impl LinkProcessor { continue } - let flags = RefFlags::default() - .with_content_hashing(false) - .with_permission_tracking(false); trace!("URL = {:?}", url); trace!("URL.path() = {:?}", url.path()); trace!("URL.host_str() = {:?}", url.host_str()); let path = url.host_str().unwrap_or_else(|| url.path()); let path = PathBuf::from(path); - let mut target = RefStore::create(store, path, flags)?; + let mut target = store.create_ref::(path)?; entry.add_internal_link(&mut target)?; },