Rewrite: StoreId::new_baseless() -> StoreId::new()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
b66371f79b
commit
642702b724
9 changed files with 21 additions and 21 deletions
|
@ -168,8 +168,8 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
||||||
} else {
|
} else {
|
||||||
debug!("Linking internally: {:?} -> {:?}", from, entry);
|
debug!("Linking internally: {:?} -> {:?}", from, entry);
|
||||||
|
|
||||||
let from_id = StoreId::new_baseless(PathBuf::from(from)).map_err_trace_exit_unwrap();
|
let from_id = StoreId::new(PathBuf::from(from)).map_err_trace_exit_unwrap();
|
||||||
let entr_id = StoreId::new_baseless(PathBuf::from(entry)).map_err_trace_exit_unwrap();
|
let entr_id = StoreId::new(PathBuf::from(entry)).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if from_id == entr_id {
|
if from_id == entr_id {
|
||||||
error!("Cannot link entry with itself. Exiting");
|
error!("Cannot link entry with itself. Exiting");
|
||||||
|
@ -366,13 +366,13 @@ mod tests {
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
path.set_file_name(name);
|
path.set_file_name(name);
|
||||||
|
|
||||||
let default_entry = Entry::new(StoreId::new_baseless(PathBuf::from("")).unwrap())
|
let default_entry = Entry::new(StoreId::new(PathBuf::from("")).unwrap())
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
debug!("Default entry constructed");
|
debug!("Default entry constructed");
|
||||||
|
|
||||||
let id = StoreId::new_baseless(path)?;
|
let id = StoreId::new(path)?;
|
||||||
debug!("StoreId constructed: {:?}", id);
|
debug!("StoreId constructed: {:?}", id);
|
||||||
|
|
||||||
let mut entry = rt.store().create(id.clone())?;
|
let mut entry = rt.store().create(id.clone())?;
|
||||||
|
|
|
@ -72,7 +72,7 @@ fn main() {
|
||||||
.cli()
|
.cli()
|
||||||
.value_of("source")
|
.value_of("source")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(StoreId::new_baseless)
|
.map(StoreId::new)
|
||||||
.unwrap() // unwrap safe by clap
|
.unwrap() // unwrap safe by clap
|
||||||
.map_err_trace_exit_unwrap();
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ fn main() {
|
||||||
.cli()
|
.cli()
|
||||||
.value_of("dest")
|
.value_of("dest")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(StoreId::new_baseless)
|
.map(StoreId::new)
|
||||||
.unwrap() // unwrap safe by clap
|
.unwrap() // unwrap safe by clap
|
||||||
.map_err_trace_exit_unwrap();
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
|
|
|
@ -264,11 +264,11 @@ mod tests {
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
path.set_file_name(name);
|
path.set_file_name(name);
|
||||||
|
|
||||||
let default_entry = Entry::new(StoreId::new_baseless(PathBuf::from("")).unwrap())
|
let default_entry = Entry::new(StoreId::new(PathBuf::from("")).unwrap())
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let id = StoreId::new_baseless(path)?;
|
let id = StoreId::new(path)?;
|
||||||
let mut entry = rt.store().create(id.clone())?;
|
let mut entry = rt.store().create(id.clone())?;
|
||||||
entry.get_content_mut().push_str(&default_entry);
|
entry.get_content_mut().push_str(&default_entry);
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ mod tests {
|
||||||
debug!("Add-tags: {:?}", add);
|
debug!("Add-tags: {:?}", add);
|
||||||
|
|
||||||
debug!("Altering things");
|
debug!("Altering things");
|
||||||
alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, None);
|
alter(&rt, StoreId::new(id.clone()).unwrap(), add, None);
|
||||||
debug!("Altered");
|
debug!("Altered");
|
||||||
|
|
||||||
let test_entry = rt.store().get(id).unwrap().unwrap();
|
let test_entry = rt.store().get(id).unwrap().unwrap();
|
||||||
|
@ -338,7 +338,7 @@ mod tests {
|
||||||
debug!("Rem-tags: {:?}", rem);
|
debug!("Rem-tags: {:?}", rem);
|
||||||
|
|
||||||
debug!("Altering things");
|
debug!("Altering things");
|
||||||
alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
|
alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
|
||||||
debug!("Altered");
|
debug!("Altered");
|
||||||
|
|
||||||
let test_entry = rt.store().get(id).unwrap().unwrap();
|
let test_entry = rt.store().get(id).unwrap().unwrap();
|
||||||
|
@ -366,7 +366,7 @@ mod tests {
|
||||||
debug!("Rem-tags: {:?}", rem);
|
debug!("Rem-tags: {:?}", rem);
|
||||||
|
|
||||||
debug!("Altering things");
|
debug!("Altering things");
|
||||||
alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
|
alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
|
||||||
debug!("Altered");
|
debug!("Altered");
|
||||||
|
|
||||||
let test_entry = rt.store().get(id).unwrap().unwrap();
|
let test_entry = rt.store().get(id).unwrap().unwrap();
|
||||||
|
@ -394,7 +394,7 @@ mod tests {
|
||||||
debug!("Rem-tags: {:?}", rem);
|
debug!("Rem-tags: {:?}", rem);
|
||||||
|
|
||||||
debug!("Altering things");
|
debug!("Altering things");
|
||||||
alter(&rt, StoreId::new_baseless(id.clone()).unwrap(), add, rem);
|
alter(&rt, StoreId::new(id.clone()).unwrap(), add, rem);
|
||||||
debug!("Altered");
|
debug!("Altered");
|
||||||
|
|
||||||
let test_entry = rt.store().get(id).unwrap().unwrap();
|
let test_entry = rt.store().get(id).unwrap().unwrap();
|
||||||
|
|
|
@ -414,7 +414,7 @@ impl<'a> Runtime<'a> {
|
||||||
trace!("Got IDs = {}", buf);
|
trace!("Got IDs = {}", buf);
|
||||||
buf.lines()
|
buf.lines()
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|id| StoreId::new_baseless(id).map_err(Error::from))
|
.map(|id| StoreId::new(id).map_err(Error::from))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl<'a> From<&'a String> for TimeTrackingTag {
|
||||||
|
|
||||||
impl IntoStoreId for TimeTrackingTag {
|
impl IntoStoreId for TimeTrackingTag {
|
||||||
fn into_storeid(self) -> Result<StoreId> {
|
fn into_storeid(self) -> Result<StoreId> {
|
||||||
StoreId::new_baseless(PathBuf::from(self.0))
|
StoreId::new(PathBuf::from(self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl DatePathCompiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreId::new_baseless(PathBuf::from(s))
|
StoreId::new(PathBuf::from(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -568,7 +568,7 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
|
||||||
.map(|link| {
|
.map(|link| {
|
||||||
debug!("Matching the link: {:?}", link);
|
debug!("Matching the link: {:?}", link);
|
||||||
match link {
|
match link {
|
||||||
Value::String(s) => StoreId::new_baseless(PathBuf::from(s))
|
Value::String(s) => StoreId::new(PathBuf::from(s))
|
||||||
.map(|s| Link::Id { link: s })
|
.map(|s| Link::Id { link: s })
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
,
|
,
|
||||||
|
@ -588,7 +588,7 @@ fn process_rw_result(links: Result<Option<Value>>) -> Result<LinkIter> {
|
||||||
debug!("Ok, here we go with building a Link::Annotated");
|
debug!("Ok, here we go with building a Link::Annotated");
|
||||||
match (link, anno) {
|
match (link, anno) {
|
||||||
(Value::String(link), Value::String(anno)) => {
|
(Value::String(link), Value::String(anno)) => {
|
||||||
StoreId::new_baseless(PathBuf::from(link))
|
StoreId::new(PathBuf::from(link))
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
.map(|link| {
|
.map(|link| {
|
||||||
Link::Annotated {
|
Link::Annotated {
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl<'a> RefStore<'a> for Store {
|
||||||
fn get_ref<RPG: UniqueRefPathGenerator, H: AsRef<str>>(&'a self, hash: H)
|
fn get_ref<RPG: UniqueRefPathGenerator, H: AsRef<str>>(&'a self, hash: H)
|
||||||
-> Result<Option<FileLockEntry<'a>>>
|
-> Result<Option<FileLockEntry<'a>>>
|
||||||
{
|
{
|
||||||
let sid = StoreId::new_baseless(PathBuf::from(format!("{}/{}", RPG::collection(), hash.as_ref())))
|
let sid = StoreId::new(PathBuf::from(format!("{}/{}", RPG::collection(), hash.as_ref())))
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
|
||||||
debug!("Getting: {:?}", sid);
|
debug!("Getting: {:?}", sid);
|
||||||
|
@ -104,7 +104,7 @@ impl<'a> RefStore<'a> for Store {
|
||||||
{
|
{
|
||||||
let hash = RPG::unique_hash(&path)?;
|
let hash = RPG::unique_hash(&path)?;
|
||||||
let pathbuf = PathBuf::from(format!("{}/{}", RPG::collection(), hash));
|
let pathbuf = PathBuf::from(format!("{}/{}", RPG::collection(), hash));
|
||||||
let sid = StoreId::new_baseless(pathbuf.clone())?;
|
let sid = StoreId::new(pathbuf.clone())?;
|
||||||
|
|
||||||
debug!("Creating: {:?}", sid);
|
debug!("Creating: {:?}", sid);
|
||||||
self.create(sid)
|
self.create(sid)
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> {
|
||||||
vals.into_iter()
|
vals.into_iter()
|
||||||
.fold(Ok(vec![]), |acc, elem| {
|
.fold(Ok(vec![]), |acc, elem| {
|
||||||
acc.and_then(|mut v| {
|
acc.and_then(|mut v| {
|
||||||
let elem = StoreId::new_baseless(PathBuf::from(String::from(elem)))?;
|
let elem = StoreId::new(PathBuf::from(String::from(elem)))?;
|
||||||
v.push(elem);
|
v.push(elem);
|
||||||
Ok(v)
|
Ok(v)
|
||||||
})
|
})
|
||||||
|
@ -70,7 +70,7 @@ pub fn get_or_select_id(matches: &ArgMatches, store_path: &PathBuf) -> Result<Ve
|
||||||
.or_else(|_| {
|
.or_else(|_| {
|
||||||
let path = store_path.clone();
|
let path = store_path.clone();
|
||||||
let p = pick_file(default_menu_cmd, path)?;
|
let p = pick_file(default_menu_cmd, path)?;
|
||||||
let id = StoreId::new_baseless(p)?;
|
let id = StoreId::new(p)?;
|
||||||
Ok(vec![id])
|
Ok(vec![id])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue