Skip to content

Commit be4fb64

Browse files
authored
Fix .new.png files without base files not showing up in archive loader (#18)
This fixes newly added snapshots not showing when viewing a github artifact. Example url: https://github.com/emilk/egui/actions/runs/20921988555/artifacts/5098563868
1 parent a4cc50b commit be4fb64

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/loaders/archive_loader.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,31 @@ fn get_snapshots(files: &HashMap<PathBuf, Vec<u8>>) -> Vec<Snapshot> {
195195
fn try_create_snapshot(png_path: &Path, files: &HashMap<PathBuf, Vec<u8>>) -> Option<Snapshot> {
196196
let file_name = png_path.file_name()?.to_str()?;
197197

198-
// Skip files that are already variants (.old.png, .new.png, .diff.png)
199-
if file_name.ends_with(".old.png")
200-
|| file_name.ends_with(".new.png")
201-
|| file_name.ends_with(".diff.png")
202-
{
198+
// Skip .old.png and .diff.png files - they are only used as variants
199+
if file_name.ends_with(".old.png") || file_name.ends_with(".diff.png") {
203200
return None;
204201
}
205202

203+
// Handle .new.png files that don't have a corresponding base file
204+
if file_name.ends_with(".new.png") {
205+
let base_path = get_base_path_from_variant(png_path)?;
206+
// If the base file exists, this .new.png will be handled when processing the base file
207+
if files.contains_key(&base_path) {
208+
return None;
209+
}
210+
// No base file exists - this is a newly added snapshot
211+
let new_data = files.get(png_path)?;
212+
return Some(Snapshot {
213+
path: base_path,
214+
old: None,
215+
new: Some(FileReference::Source(ImageSource::Bytes {
216+
uri: Cow::Owned(format!("bytes://{}", png_path.display())),
217+
bytes: eframe::egui::load::Bytes::Shared(new_data.clone().into()),
218+
})),
219+
diff: None,
220+
});
221+
}
222+
206223
// Get variant paths
207224
let old_path = get_variant_path(png_path, "old")?;
208225
let new_path = get_variant_path(png_path, "new")?;
@@ -272,3 +289,13 @@ fn get_variant_path(base_path: &Path, variant: &str) -> Option<PathBuf> {
272289
let parent = base_path.parent().unwrap_or(Path::new(""));
273290
Some(parent.join(format!("{stem}.{variant}.png")))
274291
}
292+
293+
/// Converts a variant path (e.g., "image.new.png") back to the base path ("image.png")
294+
fn get_base_path_from_variant(variant_path: &Path) -> Option<PathBuf> {
295+
let stem = variant_path.file_stem()?.to_str()?;
296+
let base_stem = stem
297+
.strip_suffix(".new")
298+
.or_else(|| stem.strip_suffix(".old"))?;
299+
let parent = variant_path.parent().unwrap_or(Path::new(""));
300+
Some(parent.join(format!("{base_stem}.png")))
301+
}

0 commit comments

Comments
 (0)