Backport #917 to Rojo 7.4.x branch (#947)

This commit is contained in:
Micah
2024-07-22 12:11:28 -07:00
committed by GitHub
parent 3b721242c1
commit 67b6a7e198
7 changed files with 138 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
use std::{borrow::Cow, collections::HashMap, path::Path};
use std::{borrow::Cow, collections::HashMap, ffi::OsStr, path::Path};
use anyhow::{bail, Context};
use memofs::Vfs;
@@ -19,7 +19,18 @@ pub fn snapshot_project(
vfs: &Vfs,
path: &Path,
) -> anyhow::Result<Option<InstanceSnapshot>> {
let project = Project::load_from_slice(&vfs.read(path)?, path)
let fallback_name = match path.file_name().and_then(OsStr::to_str) {
Some("default.project.json") => path
.parent()
.and_then(Path::file_name)
.and_then(OsStr::to_str),
Some(name) => name.strip_suffix(".project.json"),
None => anyhow::bail!(
"project file does not have valid utf-8 name: {}",
path.display()
),
};
let project = Project::load_exact(vfs, path, fallback_name)
.with_context(|| format!("File was not a valid Rojo project: {}", path.display()))?;
// This is not how I would normally do this, but this is a temporary