BUG: XMP metadata export permanently overwrites file modification timestamp (mtime), destroying photo dates
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
調査の方向性
backend/app/utils/xmp/containers/png.py の _atomic_replace と、backend/app/utils/xmp/exporter.py のタイムスタンプ処理を読んでください。PNG コンテナのテストでアトミックな置換がどのようにカバーされているかを確認し、元のアクセス時刻と変更時刻を保持したうえで、関連するテストを実行してください。エクスポートした PNG が元の mtime を保持すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 322
- フォーク
- 793
- 平均マージ
- 6日 11時間
- マージ済み PR(30日)
- 21
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AOSSIE-Org/PictoPy のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
AOSSIE-Org/PictoPy#1786 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
BUG: Semantic search sees portrait phone photos sideways (SigLIP ignores EXIF orientation)対応中かも @omkar-suryavanshi が 2 日前に担当しました。 オープンbug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
AOSSIE-Org/PictoPy#1780 · コメント 5 件 ·
メンテナーはふだん 3 日以内に返信
-
BUG: Share password loses leading/trailing spaces so the password you set doesn't work対応中かも @swastiksharma45 が 4 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
AOSSIE-Org/PictoPy#1779 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
BUG: PROD: Face search shows "No Matches Found" for every empty result, even when AI tagging is off対応中かも @Piyush0000 が 1 日前に担当しました。 オープンbug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
AOSSIE-Org/PictoPy#1770 · コメント 4 件 ·
メンテナーはふだん 3 日以内に返信
-
BUG: Add images to album: success message shows requested count, not number actually added対応中かも @riyanshbhosale が 7 日前に担当しました。 オープンbug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
AOSSIE-Org/PictoPy#1740 · コメント 4 件 ·
メンテナーはふだん 3 日以内に返信
AOSSIE-Org/PictoPy の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 89/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
smk762/argus-atlas#97 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
xdslproject/xdsl#6842 ·
メンテナーはふだん 1 日以内に返信