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>
This commit is contained in:
parent
860c58cbdf
commit
029a3c448e
2 changed files with 22 additions and 7 deletions
|
@ -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))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()?;
|
||||
|
|
Loading…
Reference in a new issue