From 97c559c07e1423033de6f7781c27f3974033c8f0 Mon Sep 17 00:00:00 2001 From: thehobbit85 Date: Wed, 25 Nov 2026 15:36:20 -0800 Subject: [PATCH] Never take a Mac's ._ metadata files for programs A Mac writes a ._ file beside each file on a drive formatted for Windows, and into archives it packs. #401 kept them out of the native build check only. They could still be picked as the game's setup, listed as programs by name, or make an installed AppImage look like one of two. They're now never a program, a setup or an AppImage. --- src-tauri/src/appimage.rs | 13 +++++++++++++ src-tauri/src/install.rs | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/appimage.rs b/src-tauri/src/appimage.rs index d8a5b3ef..adf8f9ae 100644 --- a/src-tauri/src/appimage.rs +++ b/src-tauri/src/appimage.rs @@ -144,6 +144,7 @@ pub(crate) fn installed_image(dir: &Path) -> Option { .map(|s| s.eq_ignore_ascii_case("appimage")) != Some(true) || !entry.file_type().ok()?.is_file() + || crate::install::mac_metadata(&path) { continue; } @@ -525,6 +526,18 @@ pub(crate) mod tests { bytes } + #[test] + fn a_macs_metadata_file_beside_the_appimage_isnt_a_second_one() { + let d = std::env::temp_dir().join(format!("rl-appledouble-image-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&d); + std::fs::create_dir_all(&d).unwrap(); + std::fs::write(d.join("Game.AppImage"), b"image").unwrap(); + std::fs::write(d.join("._Game.AppImage"), b"\x00\x05\x16\x07AppleDouble").unwrap(); + let got = installed_image(&d); + let _ = std::fs::remove_dir_all(&d); + assert_eq!(got, Some(d.join("Game.AppImage"))); + } + #[cfg(unix)] #[test] fn an_appimage_unpacks_into_a_plain_folder_without_running() { diff --git a/src-tauri/src/install.rs b/src-tauri/src/install.rs index fa8c75b4..1f456a7d 100644 --- a/src-tauri/src/install.rs +++ b/src-tauri/src/install.rs @@ -1497,7 +1497,7 @@ pub fn find_setup(dir: &Path, os: &str, game: Option<&Path>) -> Option } continue; } - if !(is_program(&p, os) || (os == "windows" && is_script(&p))) { + if mac_metadata(&p) || !(is_program(&p, os) || (os == "windows" && is_script(&p))) { continue; } let t = tokens(p.file_stem().and_then(|s| s.to_str()).unwrap_or("")); @@ -1532,7 +1532,16 @@ pub fn looks_like_setup(p: &Path) -> bool { t.iter().any(|x| SETUP_WORDS.contains(&x.as_str())) } +/// A Mac's metadata file ("._Game.exe"), which a Mac writes beside each file on a drive formatted +/// for Windows, or into an archive it packs. It's never a program, whatever its name ends in. +pub fn mac_metadata(p: &Path) -> bool { + p.file_name().is_some_and(|n| n.to_string_lossy().starts_with("._")) +} + pub fn is_program(p: &Path, os: &str) -> bool { + if mac_metadata(p) { + return false; + } let n = p.file_name().and_then(|s| s.to_str()).unwrap_or("").to_lowercase(); if os == "windows" { return n.ends_with(".exe"); @@ -2074,6 +2083,31 @@ mod tests { fs::write(p, vec![7u8; bytes]).unwrap(); } + /// What a Mac writes beside a file on a drive or in an archive: "._" and the file's name. + fn mac_metadata_beside(p: &Path) { + let name = format!("._{}", p.file_name().unwrap().to_string_lossy()); + fs::write(p.with_file_name(name), b"\x00\x05\x16\x07AppleDouble").unwrap(); + } + + #[test] + fn a_macs_metadata_file_is_never_the_setup() { + let d = tmp("appledouble-setup"); + put(&d.join("Game.exe"), 2_000_000); + put(&d.join("Game-setup.exe"), 1_000_000); + mac_metadata_beside(&d.join("Game-setup.exe")); + assert_eq!(find_setup(&d, "windows", Some(Path::new("Game.exe"))), Some(PathBuf::from("Game-setup.exe"))); + } + + #[test] + fn a_macs_metadata_file_is_never_a_linux_program() { + assert!(!is_program(Path::new("/games/x/._game.x86_64"), "linux")); + } + + #[test] + fn a_macs_metadata_file_is_never_a_windows_program() { + assert!(!is_program(Path::new("/games/x/._Game.exe"), "windows")); + } + #[test] fn the_windowed_program_goes_ahead_of_its_command_line_build() { let d = tmp("cli-build");