Merge pull request #1302 from matthiasbeyer/libimagdiary/fix-set-isflag
libimagdiary: Add "isflag" support
This commit is contained in:
commit
461bebe60a
5 changed files with 25 additions and 2 deletions
|
@ -32,3 +32,5 @@ libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror"
|
|||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
|
||||
libimagentryview = { version = "0.7.0", path = "../../../lib/entry/libimagentryview" }
|
||||
libimagentryutil = { version = "0.7.0", path = "../../../lib/entry/libimagentryutil" }
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ use std::cmp::Ordering;
|
|||
use libimagstore::store::FileLockEntry;
|
||||
use libimagstore::store::Store;
|
||||
use libimagerror::trace::trace_error;
|
||||
use libimagentryutil::isa::Is;
|
||||
|
||||
use chrono::offset::Local;
|
||||
use chrono::Datelike;
|
||||
|
@ -29,6 +30,7 @@ use itertools::Itertools;
|
|||
use chrono::naive::NaiveDateTime;
|
||||
use chrono::Timelike;
|
||||
|
||||
use entry::IsDiaryEntry;
|
||||
use entry::DiaryEntry;
|
||||
use diaryid::DiaryId;
|
||||
use error::DiaryErrorKind as DEK;
|
||||
|
@ -63,7 +65,9 @@ impl Diary for Store {
|
|||
let ndt = dt.naive_local();
|
||||
let id = DiaryId::new(String::from(diary_name), ndt.year(), ndt.month(), ndt.day(), 0, 0, 0);
|
||||
|
||||
self.retrieve(id).chain_err(|| DEK::StoreReadError)
|
||||
let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?;
|
||||
let _ = entry.set_isflag::<IsDiaryEntry>()?;
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
|
||||
|
@ -77,7 +81,9 @@ impl Diary for Store {
|
|||
ndt.minute(),
|
||||
ndt.second());
|
||||
|
||||
self.retrieve(id).chain_err(|| DEK::StoreReadError)
|
||||
let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?;
|
||||
let _ = entry.set_isflag::<IsDiaryEntry>()?;
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
// Get an iterator for iterating over all entries
|
||||
|
|
|
@ -18,17 +18,27 @@
|
|||
//
|
||||
|
||||
use libimagstore::store::Entry;
|
||||
use libimagentryutil::isa::Is;
|
||||
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
||||
|
||||
use diaryid::DiaryId;
|
||||
use diaryid::FromStoreId;
|
||||
use error::Result;
|
||||
|
||||
provide_kindflag_path!(pub IsDiaryEntry, "diary.is_diary_entry");
|
||||
|
||||
pub trait DiaryEntry {
|
||||
fn is_diary_entry(&self) -> Result<bool>;
|
||||
fn diary_id(&self) -> Result<DiaryId>;
|
||||
}
|
||||
|
||||
impl DiaryEntry for Entry {
|
||||
|
||||
/// Check whether the entry is a diary entry by checking its headers
|
||||
fn is_diary_entry(&self) -> Result<bool> {
|
||||
self.is::<IsDiaryEntry>().map_err(From::from)
|
||||
}
|
||||
|
||||
/// Get the diary id for this entry.
|
||||
///
|
||||
/// TODO: calls Option::unwrap() as it assumes that an existing Entry has an ID that is parsable
|
||||
|
|
|
@ -22,6 +22,10 @@ error_chain! {
|
|||
DiaryError, DiaryErrorKind, ResultExt, Result;
|
||||
}
|
||||
|
||||
links {
|
||||
EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
|
||||
}
|
||||
|
||||
errors {
|
||||
StoreWriteError {
|
||||
description("Error writing store")
|
||||
|
|
|
@ -43,6 +43,7 @@ extern crate itertools;
|
|||
#[macro_use] extern crate error_chain;
|
||||
|
||||
#[macro_use] extern crate libimagstore;
|
||||
#[macro_use] extern crate libimagentryutil;
|
||||
extern crate libimagerror;
|
||||
extern crate libimagentryedit;
|
||||
extern crate libimagentryview;
|
||||
|
|
Loading…
Reference in a new issue