summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-10-17 14:43:21 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-11-06 20:35:18 +0100
commit029a3c448ed02048d479c20a92d9b6ece4550615 (patch)
tree8bea4e7f0098caaec45bd63f2932d66e71314b1e /lib
parent860c58cbdfcb0a8229bcc60183b93be74da07b9f (diff)
Change WikiStore::create_wiki() interface
to also return the index page. This way a user of the library can use the index page entry right away. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/domain/libimagwiki/src/store.rs18
-rw-r--r--lib/domain/libimagwiki/src/wiki.rs11
2 files changed, 22 insertions, 7 deletions
diff --git a/lib/domain/libimagwiki/src/store.rs b/lib/domain/libimagwiki/src/store.rs
index 89b7093b..5ee5bd32 100644
--- a/lib/domain/libimagwiki/src/store.rs
+++ b/lib/domain/libimagwiki/src/store.rs
@@ -17,6 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
+use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
@@ -30,10 +31,10 @@ pub trait WikiStore {
fn get_wiki<'a, 'b>(&'a self, name: &'b str) -> Result<Option<Wiki<'a, 'b>>>;
fn create_wiki<'a, 'b>(&'a self, name: &'b str)
- -> Result<Wiki<'a, 'b>>;
+ -> Result<(Wiki<'a, 'b>, FileLockEntry<'a>)>;
fn retrieve_wiki<'a, 'b>(&'a self, name: &'b str)
- -> Result<Wiki<'a, 'b>>;
+ -> Result<(Wiki<'a, 'b>, FileLockEntry<'a>)>;
}
@@ -59,20 +60,23 @@ impl WikiStore for Store {
/// Ob success, an empty Wiki entry with the name `index` is created inside the wiki. Later, new
/// entries are automatically linked to this entry.
///
- fn create_wiki<'a, 'b>(&'a self, name: &'b str) -> Result<Wiki<'a, 'b>> {
+ fn create_wiki<'a, 'b>(&'a self, name: &'b str) -> Result<(Wiki<'a, 'b>, FileLockEntry<'a>)> {
debug!("Trying to get wiki '{}'", name);
let wiki = Wiki::new(self, name);
- let _ = wiki.create_index_page()?;
- Ok(wiki)
+ let index = wiki.create_index_page()?;
+ Ok((wiki, index))
}
fn retrieve_wiki<'a, 'b>(&'a self, name: &'b str)
- -> Result<Wiki<'a, 'b>>
+ -> Result<(Wiki<'a, 'b>, FileLockEntry<'a>)>
{
match self.get_wiki(name)? {
None => self.create_wiki(name),
- Some(wiki) => Ok(wiki),
+ Some(wiki) => {
+ let index = wiki.get_index_page()?;
+ Ok((wiki, index))
+ },
}
}
diff --git a/lib/domain/libimagwiki/src/wiki.rs b/lib/domain/libimagwiki/src/wiki.rs
index c3888710..5e87c150 100644
--- a/lib/domain/libimagwiki/src/wiki.rs
+++ b/lib/domain/libimagwiki/src/wiki.rs
@@ -30,6 +30,7 @@ use libimagstore::storeid::StoreIdIteratorWithStore;
use libimagentrylink::internal::InternalLinker;
use failure::Fallible as Result;
+use failure::Error;
use failure::err_msg;
pub struct Wiki<'a, 'b>(&'a Store, &'b str);
@@ -56,6 +57,16 @@ impl<'a, 'b> Wiki<'a, 'b> {
self.0.create(sid)
}
+ pub(crate) fn get_index_page(&self) -> Result<FileLockEntry<'a>> {
+ let path = PathBuf::from(format!("{}/index", self.1));
+ let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
+
+ self.0
+ .get(sid)
+ .map_err(Error::from)?
+ .ok_or_else(|| Error::from(err_msg("Missing index")))
+ }
+
pub fn get_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<Option<FileLockEntry<'a>>> {
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;