migrating to fsstore works
This commit is contained in:
@@ -145,6 +145,13 @@ impl MizeError {
|
||||
panic!();
|
||||
}
|
||||
|
||||
pub fn location(mut self, location: MizeCodeLocation) -> MizeError {
|
||||
|
||||
self.code_location = Some(location);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Instance {
|
||||
|
||||
instance.init();
|
||||
|
||||
debug!("instance inited with conifg: {}", instance.get("0/config")?.as_data_full()?);
|
||||
debug!("instance inited with config: {}", instance.get("0/config")?.as_data_full()?);
|
||||
|
||||
return Ok(instance);
|
||||
}
|
||||
@@ -85,15 +85,18 @@ impl Instance {
|
||||
debug!("overwriting instance config again with the one passed to Instance::with_config()");
|
||||
instance.set("0", config);
|
||||
|
||||
//debug!("instance inited with conifg: {}", instance.get("0/config")?);
|
||||
debug!("instance inited with conifg: no");
|
||||
debug!("instance inited with conifg: {}", instance.get("0/config")?);
|
||||
|
||||
Ok(instance)
|
||||
}
|
||||
|
||||
pub fn migrate_to_store(&mut self, new_store: Box<dyn Store>) -> MizeResult<()> {
|
||||
println!("MIGRATING");
|
||||
let old_store = &self.store;
|
||||
|
||||
let inst_data = self.store.get_value_data_full(self.id_from_string("0".to_owned()))?;
|
||||
new_store.set(self.id_from_string("0".to_owned()), inst_data.to_owned())?;
|
||||
|
||||
for id in old_store.id_iter()? {
|
||||
let data = self.store.get_value_data_full(self.id_from_string(id?))?;
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ impl Item<'_> {
|
||||
|
||||
impl<'a> Display for Item<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let item_data = self.as_data_full().map_err(|_| std::fmt::Error)?;
|
||||
write!(f, "{}", item_data);
|
||||
//let item_data = self.as_data_full().map_err(|_| std::fmt::Error)?;
|
||||
write!(f, "Item with id: {}", self.id());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,9 @@ impl ItemData {
|
||||
|
||||
pub fn item_data_get_path(data: &CborValue, path: Vec<String>) -> MizeResult<&CborValue> {
|
||||
let mut path_iter = path.clone().into_iter();
|
||||
//println!("data: {:?}", data);
|
||||
//println!("path: {:?}", path);
|
||||
|
||||
let path_el = match path_iter.nth(0) {
|
||||
Some(val) => val,
|
||||
None => return Ok(data), // our base case
|
||||
@@ -129,8 +132,11 @@ pub fn item_data_get_path(data: &CborValue, path: Vec<String>) -> MizeResult<&Cb
|
||||
match data {
|
||||
CborValue::Map(ref map) => {
|
||||
for (key, val) in map {
|
||||
//println!("key: {:?}", key);
|
||||
//println!("path_el: {}", path_el);
|
||||
if let CborValue::Text(key_str) = key {
|
||||
if key_str == &path_el {
|
||||
println!("setting sub_data to: {:?}", val);
|
||||
sub_data = val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ impl Store for MemStore {
|
||||
}
|
||||
|
||||
fn next_id(&self, prev_id_str: &str) -> MizeResult<Option<String>> {
|
||||
println!("next_id: prev_id_str: {}", prev_id_str);
|
||||
let inner = self.inner.lock()?;
|
||||
|
||||
let mut id = str_to_u64(prev_id_str)?;
|
||||
@@ -99,6 +100,7 @@ impl Store for MemStore {
|
||||
}
|
||||
|
||||
if inner.map.contains_key(&id) {
|
||||
println!("returning: {}", id);
|
||||
return Ok(Some(format!("{}", id)));
|
||||
|
||||
} else {
|
||||
@@ -139,7 +141,20 @@ pub fn get_raw_from_cbor<'a>(value: &'a CborValue, path: Vec<&String>) -> MizeRe
|
||||
Some(val) => val,
|
||||
None => {
|
||||
// our base case
|
||||
return Err(MizeError::new().msg("path is empty"));
|
||||
let ret_val = match value {
|
||||
CborValue::Bytes(vec) => {
|
||||
trace!("[ {} ] ret value: {:?}", "RET".yellow(), &vec[..]);
|
||||
return Ok(&vec[..]);
|
||||
},
|
||||
CborValue::Text(string) => {
|
||||
trace!("[ {} ] ret value: {:?}", "RET".yellow(), string.as_bytes());
|
||||
return Ok(string.as_bytes());
|
||||
},
|
||||
other => {
|
||||
return Err(MizeError::new()
|
||||
.msg("path is empty and the value is neither Bytes nor Text"));
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
trace!("hoooooooo: {:?}", path_el);
|
||||
@@ -181,7 +196,7 @@ pub fn get_raw_from_cbor<'a>(value: &'a CborValue, path: Vec<&String>) -> MizeRe
|
||||
trace!("[ {} ] ret value: {:?}", "RET".yellow(), ret_value);
|
||||
return ret_value;
|
||||
},
|
||||
_ => Err(MizeError::new().msg("get_raw_from_cbor: value is not Bytes, Text or Map")),
|
||||
_ => Err(MizeError::new().msg("get_raw_from_cbor: value is not a map, text or bytes")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user