From c756a372a3cc5a2a58719187dedfedaef0f39884 Mon Sep 17 00:00:00 2001 From: cristibctr Date: Sun, 25 Oct 2026 15:32:57 +0200 Subject: [PATCH] Fix stale Windows resource pack overlays Invalidate version 3 overlays that can omit untouched vanilla resources. Cover folder and ZIP pack cache recovery, and use a writable timestamp handle in the Windows cache test. Co-Authored-By: OpenAI Codex --- crates/horizon-client/src/packs/cache.rs | 75 +++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/packs/cache.rs b/crates/horizon-client/src/packs/cache.rs index efcf01e4a..51b7a9f1d 100644 --- a/crates/horizon-client/src/packs/cache.rs +++ b/crates/horizon-client/src/packs/cache.rs @@ -8,7 +8,8 @@ use std::io::Read; use std::{collections::BTreeSet, fs, io, path::Path, path::PathBuf}; // Bump when overlay/merge semantics change. Markers are disposable cache data. -const VERSION: u32 = 3; +// Version 3 could omit untouched vanilla directories on Windows (#1649, #1688). +const VERSION: u32 = 4; #[derive(Default, Serialize, Deserialize)] pub(super) struct Dependencies { @@ -421,6 +422,73 @@ mod tests { out } + #[test] + #[cfg(not(unix))] + fn texture_only_packs_rebuild_incomplete_windows_v3_overlays() { + let f = Fixture::new(); + let blockstate = "assets/minecraft/blockstates/oak_stairs.json"; + let model = "assets/minecraft/models/block/oak_stairs.json"; + let texture = "assets/minecraft/textures/block/stone.png"; + let font = "assets/minecraft/textures/font/ascii.png"; + f.write(&format!("vanilla/{blockstate}"), br#"{"variants":{}}"#); + f.write(&format!("vanilla/{model}"), br#"{"elements":[]}"#); + f.write(&format!("vanilla/{texture}"), b"vanilla texture"); + f.write(&format!("vanilla/{font}"), b"vanilla font"); + let folder = f.dir_pack("textures"); + f.write(&format!("textures/{texture}"), b"pack texture"); + f.write( + "textures.zip", + &archive( + &[ + ( + "pack.mcmeta", + br#"{"pack":{"description":"test","pack_format":97}}"#.to_vec(), + ), + (texture, b"pack texture".to_vec()), + ], + true, + ), + ); + let zip = packs::pack( + "zip".into(), + Text::empty(), + Source::Zip(f.0.join("textures.zip")), + ) + .unwrap(); + let vanilla = f.0.join("vanilla"); + for pack in [folder, zip] { + let out = f.0.join(format!("cached-{}", pack.id)); + let selected = std::slice::from_ref(&pack); + packs::build_overlay(&vanilla, selected, &out).unwrap(); + let check = || { + for name in [blockstate, model, font] { + assert_eq!( + fs::read(out.join(name)).unwrap(), + fs::read(vanilla.join(name)).unwrap() + ); + } + assert_eq!(fs::read(out.join(texture)).unwrap(), b"pack texture"); + }; + check(); + // Before #1688, Windows silently omitted untouched directories. + // A v3 marker still validates because it checks only source files. + let marker_path = marker_path(&out); + let mut marker: Marker = + serde_json::from_slice(&fs::read(&marker_path).unwrap()).unwrap(); + marker.version = 3; + for dir in ["blockstates", "models", "textures/font"] { + fs::remove_dir_all(out.join("assets/minecraft").join(dir)).unwrap(); + } + fs::write(&marker_path, serde_json::to_vec(&marker).unwrap()).unwrap(); + assert!(marker.dependencies.valid()); + packs::build_overlay(&vanilla, selected, &out).unwrap(); + check(); + // The repaired overlay also remains complete on a cache hit. + packs::build_overlay(&vanilla, selected, &out).unwrap(); + check(); + } + } + #[test] fn directory_inputs_config_and_owned_output_recovery() { let f = Fixture::new(); @@ -456,7 +524,10 @@ mod tests { let path = f.0.join(format!("high/{resource}")); let original_time = fs::metadata(&path).unwrap().modified().unwrap(); fs::write(&path, br#"{"p":"c"}"#).unwrap(); - fs::File::open(path) + // Windows requires a writable handle to restore the timestamp. + fs::OpenOptions::new() + .write(true) + .open(path) .unwrap() .set_times(fs::FileTimes::new().set_modified(original_time)) .unwrap();