BUG: XMP metadata export permanently overwrites file modification timestamp (mtime), destroying photo dates
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
Leggi _atomic_replace in backend/app/utils/xmp/containers/png.py e la gestione dei timestamp in backend/app/utils/xmp/exporter.py. Verifica come i test del contenitore PNG coprono la sostituzione atomica, poi esegui i test pertinenti dopo aver conservato i timestamp originali di accesso e modifica. Il lavoro è completato quando un PNG esportato mantiene il suo mtime originale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
What happened?
In backend/app/utils/xmp/exporter.py, the metadata export service explicitly documents and relies on preserving the file's modification timestamp (mtime) so folder rescans and external sync services do not treat the file as freshly edited:
# backend/app/utils/xmp/exporter.py:119-122
if outcome is WriteOutcome.WRITTEN:
# The write kept mtime but changed the size; without this the
# folder rescan would treat the file as edited.
db_refresh_image_file_stat(image_id, stat.st_size, int(stat.st_mtime))
summary["written"] += 1
However, examining _atomic_replace in backend/app/utils/xmp/containers/png.py:
# backend/app/utils/xmp/containers/png.py:145-175
def _atomic_replace(path: str, content: bytes, before: os.stat_result) -> None:
...
fd, tmp_path = tempfile.mkstemp(dir=directory, suffix=".tmp")
try:
with os.fdopen(fd, "wb") as tmp:
tmp.write(content)
tmp.flush()
os.fsync(tmp.fileno())
try:
os.chmod(tmp_path, before.st_mode & 0o777)
except OSError:
pass
now = os.stat(path)
if (now.st_size, now.st_mtime_ns) != (before.st_size, before.st_mtime_ns):
raise FileChangedError(f"{path} changed during metadata write")
os.replace(tmp_path, path)
_atomic_replace preserves file permissions via os.chmod, but never calls os.utime() to restore the original timestamps.
When os.replace(tmp_path, path) replaces the target file, the file's modification time (mtime) is permanently overwritten with the current wall-clock time.
Impact
- Destruction of Photo Dates: Many images (such as screenshots, scans, converted PNGs, or photos shared via messaging apps) do not have internal EXIF
DateTimeOriginaltags. For these images, PictoPy and external viewers rely on filesystemmtimeas the photo creation date. Exporting metadata resets theirmtimeto the current timestamp, permanently destroying their original chronological order. - Rescan and Sync Loops: Filesystem watchers and backup tools detect the updated
mtimeas a new external modification, triggering unnecessary re-indexing and synchronization churn.
Steps to Reproduce
- Choose a PNG image and note its
stat.st_mtime(e.g. dated 2 years ago). - Enable or trigger XMP metadata export (
POST /metadata-export/run). - Check
stat.st_mtimeof the file after the export completes. - The file's
mtimehas changed to the current execution timestamp rather than preserving the original timestamp.
Expected Behavior
_atomic_replace should preserve before.st_atime_ns and before.st_mtime_ns on tmp_path before calling os.replace, ensuring the file modification timestamp remains unchanged after metadata embedding.
Proposed Fix
In backend/app/utils/xmp/containers/png.py, preserve the timestamp using os.utime:
try:
os.utime(tmp_path, ns=(before.st_atime_ns, before.st_mtime_ns))
except OSError:
pass
os.replace(tmp_path, path)
Record
- I agree to follow this project's Code of Conduct
- Lingua principale
- Python
- Stelle
- 322
- Fork
- 793
- Merge medio
- 6g 11h
- PR unite (30g)
- 21
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di AOSSIE-Org/PictoPy
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
AOSSIE-Org/PictoPy#1786 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
BUG: Semantic search sees portrait phone photos sideways (SigLIP ignores EXIF orientation)Forse già presa @omkar-suryavanshi l’ha presa 2 giorni fa. Apertabug enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
AOSSIE-Org/PictoPy#1780 · 5 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
BUG: Share password loses leading/trailing spaces so the password you set doesn't workForse già presa @swastiksharma45 l’ha presa 4 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
AOSSIE-Org/PictoPy#1779 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
BUG: PROD: Face search shows "No Matches Found" for every empty result, even when AI tagging is offForse già presa @Piyush0000 l’ha presa 1 giorno fa. Apertabug enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
AOSSIE-Org/PictoPy#1770 · 4 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
BUG: Add images to album: success message shows requested count, not number actually addedForse già presa @riyanshbhosale l’ha presa 7 giorni fa. Apertabug enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
AOSSIE-Org/PictoPy#1740 · 4 commenti ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di AOSSIE-Org/PictoPy
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 89/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
smk762/argus-atlas#97 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
xdslproject/xdsl#6842 ·
I maintainer di solito rispondono entro 1 giorno