Rewrite set_external_links()
This commit is contained in:
parent
f482c2564b
commit
22a64dbc30
1 changed files with 32 additions and 35 deletions
|
@ -171,44 +171,41 @@ impl ExternalLinker for Entry {
|
||||||
debug!("Hash = '{:?}'", hash);
|
debug!("Hash = '{:?}'", hash);
|
||||||
debug!("StoreId = '{:?}'", file_id);
|
debug!("StoreId = '{:?}'", file_id);
|
||||||
|
|
||||||
let mut file = {
|
// retrieve the file from the store, which implicitely creates the entry if it does not
|
||||||
if let Ok(mut file) = store.retrieve(file_id.clone()) { // retrieve the file from the store
|
// exist
|
||||||
debug!("Woha, there is already a file for this link: '{:?}'", link);
|
let file = store.retrieve(file_id.clone());
|
||||||
file
|
if file.is_err() {
|
||||||
} else { // or
|
debug!("Failed to create or retrieve an file for this link '{:?}'", link);
|
||||||
debug!("Generating file for link = '{:?}' on id = {:?}", link, file_id);
|
return Err(LE::new(LEK::StoreWriteError, Some(Box::new(file.err().unwrap()))));
|
||||||
let res = store.create(file_id) // create it
|
}
|
||||||
.and_then(|mut file| {
|
let mut file = file.unwrap();
|
||||||
{
|
|
||||||
debug!("Generating header content!");
|
|
||||||
let mut hdr = file.deref_mut().get_header_mut();
|
|
||||||
|
|
||||||
// Write the URI into the header
|
debug!("Generating header content!");
|
||||||
match hdr.set("imag.content", Value::Table(BTreeMap::new())) {
|
{
|
||||||
Ok(_) => {
|
let mut hdr = file.deref_mut().get_header_mut();
|
||||||
let v = Value::String(link.serialize());
|
|
||||||
debug!("setting URL = '{:?}", v);
|
|
||||||
hdr.set("imag.content.uri", v);
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
debug!("Failed to generate a table in header at 'imag.content'");
|
|
||||||
Err(e)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}.map(|_| file)
|
|
||||||
})
|
|
||||||
.map_err(|e| LE::new(LEK::StoreWriteError, Some(Box::new(e))));
|
|
||||||
|
|
||||||
// And if that fails we can error
|
let mut table = match hdr.read("imag.content") {
|
||||||
if let Err(e) = res {
|
Ok(Some(Value::Table(table))) => table,
|
||||||
debug!("Failed to create or retrieve an file for this link '{:?}'", link);
|
Ok(Some(_)) => {
|
||||||
return Err(e);
|
warn!("There is a value at 'imag.content' which is not a table.");
|
||||||
}
|
warn!("Going to override this value");
|
||||||
debug!("Success creating or retrieving an file for this link '{:?}'", link);
|
BTreeMap::new()
|
||||||
res.unwrap()
|
},
|
||||||
|
Ok(None) => BTreeMap::new(),
|
||||||
|
Err(e) => return Err(LE::new(LEK::StoreWriteError, Some(Box::new(e)))),
|
||||||
|
};
|
||||||
|
|
||||||
|
let v = Value::String(link.serialize());
|
||||||
|
|
||||||
|
debug!("setting URL = '{:?}", v);
|
||||||
|
table.insert(String::from("url"), v);
|
||||||
|
|
||||||
|
if let Err(e) = hdr.set("imag.content", Value::Table(table)) {
|
||||||
|
return Err(LE::new(LEK::StoreWriteError, Some(Box::new(e))));
|
||||||
|
} else {
|
||||||
|
debug!("Setting URL worked");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// then add an internal link to the new file or return an error if this fails
|
// then add an internal link to the new file or return an error if this fails
|
||||||
if let Err(e) = self.add_internal_link(file.deref_mut()) {
|
if let Err(e) = self.add_internal_link(file.deref_mut()) {
|
||||||
|
|
Loading…
Reference in a new issue