Move responsibility for extracting names from paths lower

This commit is contained in:
Lucien Greathouse
2021-08-24 17:59:53 -04:00
parent d484098781
commit 8954def25c
8 changed files with 86 additions and 68 deletions

View File

@@ -9,12 +9,15 @@ use crate::{
snapshot::{InstanceContext, InstanceSnapshot},
};
use super::util::PathExt;
pub fn snapshot_json_model(
context: &InstanceContext,
vfs: &Vfs,
path: &Path,
instance_name: &str,
) -> anyhow::Result<Option<InstanceSnapshot>> {
let name = path.file_name_trim_end(".model.json")?;
let contents = vfs.read(path)?;
let contents_str = str::from_utf8(&contents)
.with_context(|| format!("File was not valid UTF-8: {}", path.display()))?;
@@ -28,7 +31,7 @@ pub fn snapshot_json_model(
let mut snapshot = instance
.core
.into_snapshot(instance_name.to_owned())
.into_snapshot(name.to_owned())
.with_context(|| format!("Could not load JSON model: {}", path.display()))?;
snapshot.metadata = snapshot
@@ -133,7 +136,6 @@ mod test {
&InstanceContext::default(),
&mut vfs,
Path::new("/foo.model.json"),
"foo",
)
.unwrap()
.unwrap();