Merge branch 'libimagentrymarkdown/refactor-libimagref-api-usage' into libimagentryref/refactor

This commit is contained in:
Matthias Beyer 2018-02-19 12:17:53 +01:00
commit 88ffe8084c
2 changed files with 31 additions and 6 deletions

View file

@ -29,6 +29,11 @@ env_logger = "0.5"
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" } libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
libimagentrylink = { version = "0.7.0", path = "../../../lib/entry/libimagentrylink/" } 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/" } 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" ]

View file

@ -17,6 +17,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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::MarkdownError as ME;
use error::MarkdownErrorKind as MEK; use error::MarkdownErrorKind as MEK;
use error::*; use error::*;
@ -25,7 +28,8 @@ use link::extract_links;
use libimagentrylink::external::ExternalLinker; use libimagentrylink::external::ExternalLinker;
use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::InternalLinker;
use libimagentryref::refstore::RefStore; use libimagentryref::refstore::RefStore;
use libimagentryref::flags::RefFlags; use libimagentryref::refstore::UniqueRefPathGenerator;
use libimagentryref::generators::sha512::Sha512;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
@ -34,6 +38,25 @@ use std::path::PathBuf;
use url::Url; 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<A: AsRef<Path>>(path: A) -> RResult<String, Self::Error> {
Sha512::unique_hash(path).map_err(ME::from)
}
fn postprocess_storeid(sid: StoreId) -> RResult<StoreId, Self::Error> {
Ok(sid) // don't do anything
}
}
/// A link Processor which collects the links from a Markdown and passes them on to /// A link Processor which collects the links from a Markdown and passes them on to
/// `libimagentrylink` functionality /// `libimagentrylink` functionality
/// ///
@ -136,15 +159,12 @@ impl LinkProcessor {
continue continue
} }
let flags = RefFlags::default()
.with_content_hashing(false)
.with_permission_tracking(false);
trace!("URL = {:?}", url); trace!("URL = {:?}", url);
trace!("URL.path() = {:?}", url.path()); trace!("URL.path() = {:?}", url.path());
trace!("URL.host_str() = {:?}", url.host_str()); trace!("URL.host_str() = {:?}", url.host_str());
let path = url.host_str().unwrap_or_else(|| url.path()); let path = url.host_str().unwrap_or_else(|| url.path());
let path = PathBuf::from(path); let path = PathBuf::from(path);
let mut target = RefStore::create(store, path, flags)?; let mut target = store.create_ref::<UniqueMarkdownRefGenerator, PathBuf>(path)?;
entry.add_internal_link(&mut target)?; entry.add_internal_link(&mut target)?;
}, },