fix gps metadata being stripped from exports (#1165)#1207
Open
Waynting wants to merge 1 commit into
Open
Conversation
write_image_with_metadata has three branches for sourcing the original image's metadata: the .rrdata sidecar, kamadak-exif, and rawler. Only the kamadak and rawler branches had GPS-reading code. Opening any image triggers persist_exif_if_missing, which writes a sidecar -- from then on the sidecar branch fires on every export, silently bypassing both GPS code paths. Affects JPEG (as reported) and any RAW the user has opened. Lift GPS reading into two helpers (apply_gps_from_kamadak, apply_gps_from_rawler) and run them at the tail of the function, unconditionally when !strip_gps. The sidecar/kamadak/rawler branches now handle only the non-GPS metadata they always did. Re-read GPS from the source file rather than parsing the lossy display strings stored in the sidecar. Add two regression tests using only existing project deps (tempfile, image, little_exif, kamadak-exif). The first reproduces the bug trigger (real GPS + .rrdata sidecar) and asserts GPS is preserved; the second asserts the strip toggle still works. Bonus: kamadak helper now also writes GPSAltitudeRef -- the rawler branch already did this, added for symmetry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1165. GPS EXIF (location data) was always being stripped on export, even with Remove location data turned off.
Root cause
write_image_with_metadatahas three branches for sourcing the original image's metadata: the.rrdatasidecar, kamadak-exif (JPEG/PNG), and rawler (RAW). Only the kamadak and rawler branches had GPS-reading code.Opening any image in the app triggers
persist_exif_if_missing(image_loader.rs:81), which writes the.rrdatasidecar. From then on the sidecar branch fires on every export — silently bypassing both GPS code paths. So in practicestrip_gps=falsedid nothing for any image you'd opened in the editor.Affects JPEG (as reported) and RAW (same mechanism, just less likely to be noticed).
Fix
GPS reading is orthogonal to the rest of the metadata sourcing. Lifted GPS reading out of the per-branch logic into two helpers and added a single tail call that runs unconditionally when
!strip_gps:The sidecar / kamadak / rawler branches now handle only the non-GPS metadata they always did. GPS is re-read from the source file rather than parsed back from the sidecar's display strings (lossy —
"40 deg 26' 12.345\""can't round-trip cleanly into the rationalslittle_exifneeds).Behavior table
keep_metadata=falseTests
Added two regression tests in
exif_processing::tests. No new dependencies —tempfile,image,little_exif,kamadak-exifare all already in the project.issue_1165_gps_preserved_when_sidecar_exists_and_strip_gps_false— reproduces the exact bug trigger (real GPS tags +.rrdatasidecar viapersist_exif_if_missing), asserts GPS lat/lon/alt are preserved in the exported bytes.issue_1165_gps_stripped_when_strip_gps_true— asserts the toggle still works.Both pass:
Also verified:
cargo fmt --checkclean on the filecargo clippy --lib --tests --no-deps— no new warnings introducedNotes
GPSAltitudeRef(above/below sea-level reference). The rawler branch already wrote it; added for symmetry. Harmless if downstream readers don't expect it.get_string_valclosure is now defined in two places (the helper + the inline kamadak branch). Kept this PR narrow; happy to lift it to a module-level helper in a follow-up if you'd like.Test plan
cargo test --lib exif_processing::testscargo fmt -- --check src/exif_processing.rscargo clippy --lib --tests --no-depsexiftool -GPS:all exported.jpgshows coords