mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-28 09:09:32 +01:00
fix(engine): a bare .xfl's package is "." so reopening finds its tab
import_package returned an empty folder for a bare "walk.xfl", which same_file can't resolve, so reopening it imported the package a second time. It now returns ".", which Import::of and the tab lookup both resolve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b474a01a27
commit
ef01fc0b5d
2 files changed
+19
-7
No files matched your search
@@ -204,15 +204,11 @@ impl Import {
|
||||
/// The import of `source`, as the disk has it now.
|
||||
pub fn of(source: &std::path::Path) -> Import {
|
||||
let package = import_package(source);
|
||||
// "." or "walk/sub/.." has no name of its own, and nor does the empty folder a bare
|
||||
// "walk.xfl" is in: resolve it, or the suggestion would land inside the package as
|
||||
// "animation.anicraft".
|
||||
// "." or "walk/sub/.." has no name of its own: resolve it, or the suggestion would land
|
||||
// inside the package as "animation.anicraft".
|
||||
let package = match package.file_name() {
|
||||
Some(_) => package,
|
||||
None => {
|
||||
let here = if package.as_os_str().is_empty() { std::path::Path::new(".") } else { package.as_path() };
|
||||
std::fs::canonicalize(here).unwrap_or(package)
|
||||
}
|
||||
None => std::fs::canonicalize(&package).unwrap_or(package),
|
||||
};
|
||||
// A folder's whole name ("walk.v2" stays "walk.v2"); a file's without its extension.
|
||||
let name = if crate::vfs::is_dir(&package) { package.file_name() } else { package.file_stem() };
|
||||
@@ -230,6 +226,8 @@ pub fn import_package(path: &std::path::Path) -> PathBuf {
|
||||
&& path.extension().is_some_and(|e| e.eq_ignore_ascii_case("xfl"))
|
||||
&& path.parent().is_some_and(|d| crate::vfs::is_file(&d.join("DOMDocument.xml")));
|
||||
match path.parent() {
|
||||
// A bare "walk.xfl" is in the current folder: "." resolves, an empty path doesn't.
|
||||
Some(folder) if xfl_file && folder.as_os_str().is_empty() => PathBuf::from("."),
|
||||
Some(folder) if xfl_file => folder.to_path_buf(),
|
||||
_ => path.to_path_buf(),
|
||||
}
|
||||
|
||||
@@ -103,3 +103,17 @@ fn imports_read_picked_files() {
|
||||
assert!(err.contains(".fla"), "an XFL folder can't come from a browser: {err}");
|
||||
});
|
||||
}
|
||||
|
||||
/// A bare "walk.xfl" stands for the current folder, as a path that resolves, so reopening it
|
||||
/// finds the tab its import has (ADR 0009). Run on the in-memory store, so the test needs no
|
||||
/// working directory of its own.
|
||||
#[test]
|
||||
fn a_bare_xfl_files_package_is_a_folder_that_resolves() {
|
||||
in_browser(|| {
|
||||
vfs::put(Path::new("DOMDocument.xml"), b"<DOMDocument/>".to_vec()).unwrap();
|
||||
vfs::put(Path::new("walk.xfl"), b"PROXY".to_vec()).unwrap();
|
||||
let package = crate::import_package(Path::new("walk.xfl"));
|
||||
assert_eq!(package, Path::new("."), "the current folder, not an empty path");
|
||||
assert_eq!(crate::import_package(Path::new("walk.fla")), Path::new("walk.fla"), "a file that isn't an XFL proxy is its own package");
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user