diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 2ab491207..4f2a6076c 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -138,7 +138,8 @@ jobs: echo "::notice::No Metal toolchain on this runner: GPUI compiles its shaders at run time" echo "LAUNCHER_FEATURES=gpui/runtime_shaders" >> "$GITHUB_ENV" fi - - run: cargo test --release --locked --lib ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} + # Every test target (the library, the binary, tests/), on each system the launcher ships for. + - run: cargo test --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} - run: cargo build --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} - name: The version is the release's run: | diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index af0588af6..bde1037b3 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2681,10 +2681,22 @@ dependencies = [ "zip", ] +[[package]] +name = "horizon-mods" +version = "0.1.0" +dependencies = [ + "log", + "serde", + "serde_json", + "toml 1.1.8+spec-1.1.0", + "zip", +] + [[package]] name = "horizon-port-pack" version = "0.1.0" dependencies = [ + "horizon-mods", "serde", "serde_json", "sha1", diff --git a/launcher/src/modpacks.rs b/launcher/src/modpacks.rs index 6d4553a14..6ff53e4be 100644 --- a/launcher/src/modpacks.rs +++ b/launcher/src/modpacks.rs @@ -241,7 +241,8 @@ mod tests { .map(|a| a.to_string_lossy().into_owned()) .collect(); assert_eq!(args.len(), 4); - assert!(args[1].ends_with("a/carry") && args[3].ends_with("b/carry")); + assert_eq!(Path::new(&args[1]), work.join("mods").join("a").join("carry")); + assert_eq!(Path::new(&args[3]), work.join("mods").join("b").join("carry")); assert_eq!(cmd.get_current_dir(), Some(profile_home(&work).as_path())); assert!(profile_home(&work).is_dir()); fs::remove_dir_all(&root).unwrap(); diff --git a/launcher/src/sources.rs b/launcher/src/sources.rs index aafdb51e4..f6a9753ea 100644 --- a/launcher/src/sources.rs +++ b/launcher/src/sources.rs @@ -426,16 +426,26 @@ fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { std::os::unix::fs::symlink(target, link) } -/// Symlinks need developer mode on Windows: a junction for a folder, a hard link for a file. +/// Symlinks need developer mode on Windows: a junction for a folder, a hard link for a file (a +/// copy on another volume). #[cfg(windows)] fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { + use std::os::windows::process::CommandExt; if !target.is_dir() { return fs::hard_link(target, link).or_else(|_| fs::copy(target, link).map(|_| ())); } + // Always quoted: cmd reads `&`, `^` or `(` in an unquoted path (a user folder may have + // them) as its own syntax. A Windows path never holds a quote. + let quoted = |path: &Path| { + let mut arg = std::ffi::OsString::from("\""); + arg.push(path); + arg.push("\""); + arg + }; let status = std::process::Command::new("cmd") .args(["/C", "mklink", "/J"]) - .arg(link) - .arg(target) + .raw_arg(quoted(link)) + .raw_arg(quoted(target)) .stdout(std::process::Stdio::null()) .status()?; match status.success() { diff --git a/launcher/src/sources_tests.rs b/launcher/src/sources_tests.rs index f603aaf0a..381d19f27 100644 --- a/launcher/src/sources_tests.rs +++ b/launcher/src/sources_tests.rs @@ -94,15 +94,25 @@ fn resolve_with( } } +/// Whether `a` and `b` are one file, as a symlink (Unix) or a hard link (Windows) makes them: +/// a byte written through `a` shows in `b`. Both are left as they were. +fn same_file(a: &Path, b: &Path) -> bool { + use std::io::Write; + let (before_a, before_b) = (fs::read(a).unwrap(), fs::read(b).unwrap()); + let mut file = fs::OpenOptions::new().write(true).open(a).unwrap(); + file.write_all(&[!before_a[0]]).unwrap(); + drop(file); + let same = fs::read(b).unwrap() != before_b; + fs::write(a, &before_a).unwrap(); + same +} + /// The linked folder is the official layout, pointing at the launcher's files. fn assert_linked(linked: &Path, base: &Path, jar: &str) { let v = linked.join("versions/26.3"); assert_eq!(fs::read(v.join("26.3.jar")).unwrap(), CLIENT); assert_eq!(fs::read(v.join("26.3.json")).unwrap(), MANIFEST); - assert_eq!( - fs::canonicalize(v.join("26.3.jar")).unwrap(), - fs::canonicalize(base.join(jar)).unwrap() - ); + assert!(same_file(&v.join("26.3.jar"), &base.join(jar))); assert_eq!( fs::read(linked.join("libraries/org/lib/1/lib-1.jar")).unwrap(), b"lib" @@ -110,6 +120,19 @@ fn assert_linked(linked: &Path, base: &Path, jar: &str) { assert!(linked.join("assets/indexes/30.json").is_file()); } +/// Folders whose names cmd would read as its own syntax unquoted are still linked (Windows makes +/// a junction through `mklink /J`; a name without spaces isn't quoted by itself). +#[test] +fn folders_with_ampersands_are_linked() { + let s = Scratch::new("a&b(c)"); + let jar = "libraries/com/mojang/minecraft/26.3/minecraft-26.3-client.jar"; + let dir = s.launcher("Prism&Co", "", jar); + let linked = s.0.join("linked&here"); + let got = resolve_with(&dir, &[], &linked, &Mojang::new(MANIFEST)).unwrap(); + assert_eq!(got, linked); + assert_linked(&linked, &dir, jar); +} + #[test] fn maven_names_become_repository_paths() { assert_eq!( @@ -295,10 +318,9 @@ fn relinking_follows_the_launcher_the_files_now_come_from() { let modrinth = s.0.join("ModrinthApp"); s.write("ModrinthApp/meta/versions/26.3/26.3.jar", CLIENT); resolve_with(&modrinth, &[], &linked, &mojang).unwrap(); - assert_eq!( - fs::canonicalize(linked.join("versions/26.3/26.3.jar")).unwrap(), - fs::canonicalize(modrinth.join("meta/versions/26.3/26.3.jar")).unwrap() - ); + let jar = linked.join("versions/26.3/26.3.jar"); + assert!(same_file(&jar, &modrinth.join("meta/versions/26.3/26.3.jar"))); + assert!(!same_file(&jar, &prism.join(prism_jar))); // The Modrinth App folder has no libraries or assets: the old links are gone, and the // folders they pointed at are untouched. assert!(fs::symlink_metadata(linked.join("libraries")).is_err());