diff --git a/crates/engine/src/cmds_file.rs b/crates/engine/src/cmds_file.rs index 6e6c8792..48e754fc 100644 --- a/crates/engine/src/cmds_file.rs +++ b/crates/engine/src/cmds_file.rs @@ -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(), } diff --git a/crates/engine/src/web_tests.rs b/crates/engine/src/web_tests.rs index 2d04c05c..61ebc084 100644 --- a/crates/engine/src/web_tests.rs +++ b/crates/engine/src/web_tests.rs @@ -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"".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"); + }); +}