From 950524929c8dcf8cdf143cda2bea3e99779eb2dc Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 27 Oct 2026 14:23:32 +0100 Subject: [PATCH] fix(archive): stable Reorganize folders, settle trash restores first, retranslate Reorganize Integrating owner review 2 phase 4a (R7) onto the reviewed phase 3 code. - RenamePlanner: a sequence already at its expanded folder, or at the " (n)" of it that filing or an earlier Reorganize gave it, keeps that folder (in the template's case, unless another sequence holds that exact name). The planner seeded its claimed folders with the sequence's own, so "2026-09-28 (2)" was planned to "(3)" and back to "(2)" by the next run; a second Reorganize with the same templates now plans nothing. - MassRenamer: each step settles what a crash or a busy trash entry left in its sequences (SequenceWriter.ReadLocked) and waits, as a sequence deletion does, while a restore from the trash is not settled (FrameTrash.EnsureSettled), before its folder or any file name changes: that restore's journal names files by the names they had. Trash records keep restoring after a Reorganize: into the sequence where it is now, under the record's own name made free (_2) with its companion following. - Jobs.Kind.Move and Admin.Job.Kind.Move now mean "Reorganize": their old "Move archive" translations are removed from the 36 other cultures so they are translated again. - Tests: a second run plans nothing (planner and archive), companions found alike by the trash and Reorganize whatever their case, a photo deleted before a Reorganize comes back beside the new names, a Reorganize waits for a busy restore and settles it first. Co-Authored-By: Claude Opus 5.5 --- docs/ARCHITECTURE.md | 2 +- i18n/ar/Admin.ar.resx | 1 - i18n/ar/Jobs.ar.resx | 1 - i18n/bg/Admin.bg.resx | 1 - i18n/bg/Jobs.bg.resx | 1 - i18n/cs/Admin.cs.resx | 1 - i18n/cs/Jobs.cs.resx | 1 - i18n/da/Admin.da.resx | 1 - i18n/da/Jobs.da.resx | 1 - i18n/de/Admin.de.resx | 1 - i18n/de/Jobs.de.resx | 1 - i18n/el/Admin.el.resx | 1 - i18n/el/Jobs.el.resx | 1 - i18n/es/Admin.es.resx | 1 - i18n/es/Jobs.es.resx | 1 - i18n/et/Admin.et.resx | 1 - i18n/et/Jobs.et.resx | 1 - i18n/fi/Admin.fi.resx | 1 - i18n/fi/Jobs.fi.resx | 1 - i18n/fr/Admin.fr.resx | 1 - i18n/fr/Jobs.fr.resx | 1 - i18n/he/Admin.he.resx | 1 - i18n/he/Jobs.he.resx | 1 - i18n/hi/Admin.hi.resx | 1 - i18n/hi/Jobs.hi.resx | 1 - i18n/hr/Admin.hr.resx | 1 - i18n/hr/Jobs.hr.resx | 1 - i18n/hu/Admin.hu.resx | 1 - i18n/hu/Jobs.hu.resx | 1 - i18n/id/Admin.id.resx | 1 - i18n/id/Jobs.id.resx | 1 - i18n/ja/Admin.ja.resx | 1 - i18n/ja/Jobs.ja.resx | 1 - i18n/ko/Admin.ko.resx | 1 - i18n/ko/Jobs.ko.resx | 1 - i18n/lt/Admin.lt.resx | 1 - i18n/lt/Jobs.lt.resx | 1 - i18n/lv/Admin.lv.resx | 1 - i18n/lv/Jobs.lv.resx | 1 - i18n/ms/Admin.ms.resx | 1 - i18n/ms/Jobs.ms.resx | 1 - i18n/nb/Admin.nb.resx | 1 - i18n/nb/Jobs.nb.resx | 1 - i18n/nl/Admin.nl.resx | 1 - i18n/nl/Jobs.nl.resx | 1 - i18n/pl/Admin.pl.resx | 1 - i18n/pl/Jobs.pl.resx | 1 - i18n/pt-BR/Admin.pt-BR.resx | 1 - i18n/pt-BR/Jobs.pt-BR.resx | 1 - i18n/pt-PT/Admin.pt-PT.resx | 1 - i18n/pt-PT/Jobs.pt-PT.resx | 1 - i18n/ro/Admin.ro.resx | 1 - i18n/ro/Jobs.ro.resx | 1 - i18n/ru/Admin.ru.resx | 1 - i18n/ru/Jobs.ru.resx | 1 - i18n/sk/Admin.sk.resx | 1 - i18n/sk/Jobs.sk.resx | 1 - i18n/sl/Admin.sl.resx | 1 - i18n/sl/Jobs.sl.resx | 1 - i18n/sv/Admin.sv.resx | 1 - i18n/sv/Jobs.sv.resx | 1 - i18n/th/Admin.th.resx | 1 - i18n/th/Jobs.th.resx | 1 - i18n/tr/Admin.tr.resx | 1 - i18n/tr/Jobs.tr.resx | 1 - i18n/uk/Admin.uk.resx | 1 - i18n/uk/Jobs.uk.resx | 1 - i18n/vi/Admin.vi.resx | 1 - i18n/vi/Jobs.vi.resx | 1 - i18n/zh-Hans/Admin.zh-Hans.resx | 1 - i18n/zh-Hans/Jobs.zh-Hans.resx | 1 - i18n/zh-Hant/Admin.zh-Hant.resx | 1 - i18n/zh-Hant/Jobs.zh-Hant.resx | 1 - src/Chronos.Core/Archiving/MassRename.cs | 22 ++++- src/Chronos.Data/Archiving/MassRenamer.cs | 22 ++++- .../Archiving/ReorganizeTests.cs | 38 +++++++++ .../Archiving/FrameTrashTests.cs | 84 +++++++++++++++++++ .../Archiving/ReorganizeTests.cs | 18 ++++ 78 files changed, 183 insertions(+), 75 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 81286adb..2b46a459 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -40,7 +40,7 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S | `Render` | Render plan (timing modes), preparation pass, geometry, `RenderPipeline`, self-test suite | | `Export` | Preset resolution, encoder selection with fallbacks, output naming | | `Video` (+ `Mp4`, `Avi`, `Bitstream`, `Yuv`, `Managed`) | `IVideoEncoderProvider`, MP4 muxer and inspector, AVI-MJPEG, NV12/P010, managed encoders (MJPEG-AVI, GIF, APNG, image sequences) | -| `Archiving` | Archive layout and paths, sidecars (`sequence.json`, `project.json`), scanner, index snapshot, leases, thumbnail packs, verify, adopt, rename plans (`RenamePlanner`: folder, title and file templates, `RenameTemplates`, the plan's fingerprint; `FileRenames`: a sequence's new file names; `FileRenameJournal`: two-phase renames through temporary names, `.chronos/rename-files.json`; `FrameCompanions`: the XMP files that follow a photo) | +| `Archiving` | Archive layout and paths, sidecars (`sequence.json`, `project.json`), scanner, index snapshot, leases, thumbnail packs, verify, adopt, rename plans (`RenamePlanner`: folder, title and file templates, `RenameTemplates`, the plan's fingerprint; `FileRenames`: a sequence's new file names; `FileRenameJournal`: two-phase renames through temporary names, `.chronos/rename-files.json`; `FrameCompanions`: the XMP files that follow a photo, one rule for the trash and Reorganize, matched whatever their case and each folder listed once by `FrameCompanions.Index`) | | `Import` | Card scan, session detection, import plan, hash-verified copy, card eraser (re-hash before delete) | | `Naming` | Folder/file templates and tokens; `FrameNaming` (the naming context and unique file name of a frame, shared by import, upload and Reorganize) | | `Model` | Domain entities and enums (§5) shared by Data, Server and clients | diff --git a/i18n/ar/Admin.ar.resx b/i18n/ar/Admin.ar.resx index c71c277e..b14bc140 100644 --- a/i18n/ar/Admin.ar.resx +++ b/i18n/ar/Admin.ar.resx @@ -146,7 +146,6 @@ استيراد تحليل سريع صيانة - نقل ملفات يتيمة نسخ وكيلة إعادة البناء diff --git a/i18n/ar/Jobs.ar.resx b/i18n/ar/Jobs.ar.resx index 6d6cff6b..3fd64580 100644 --- a/i18n/ar/Jobs.ar.resx +++ b/i18n/ar/Jobs.ar.resx @@ -77,7 +77,6 @@ استيراد تحليل سريع صيانة - نقل الأرشيف ملفات يتيمة نسخ وكيلة إعادة بناء الفهرس diff --git a/i18n/bg/Admin.bg.resx b/i18n/bg/Admin.bg.resx index 57336187..6c576814 100644 --- a/i18n/bg/Admin.bg.resx +++ b/i18n/bg/Admin.bg.resx @@ -128,7 +128,6 @@ Импортиране Бърз анализ Поддръжка - Преместване Осиротели файлове Прокси Преизграждане diff --git a/i18n/bg/Jobs.bg.resx b/i18n/bg/Jobs.bg.resx index ee19203e..cd0265ad 100644 --- a/i18n/bg/Jobs.bg.resx +++ b/i18n/bg/Jobs.bg.resx @@ -75,7 +75,6 @@ Импортиране Бърз анализ Поддръжка - Преместване на архива Осиротели файлове Прокси Преизграждане на индекса diff --git a/i18n/cs/Admin.cs.resx b/i18n/cs/Admin.cs.resx index e8eb73ae..68211d82 100644 --- a/i18n/cs/Admin.cs.resx +++ b/i18n/cs/Admin.cs.resx @@ -137,7 +137,6 @@ Import Rychlá analýza Údržba - Přesun Osiřelé soubory Proxy Sestavení indexu diff --git a/i18n/cs/Jobs.cs.resx b/i18n/cs/Jobs.cs.resx index a015d6c4..c0443157 100644 --- a/i18n/cs/Jobs.cs.resx +++ b/i18n/cs/Jobs.cs.resx @@ -76,7 +76,6 @@ Import Rychlá analýza Údržba - Přesun archivu Osiřelé soubory Proxy Sestavení indexu diff --git a/i18n/da/Admin.da.resx b/i18n/da/Admin.da.resx index 1f892684..2ae1679b 100644 --- a/i18n/da/Admin.da.resx +++ b/i18n/da/Admin.da.resx @@ -128,7 +128,6 @@ Import Hurtig analyse Vedligeholdelse - Flytning Forældreløse filer Proxyer Genopbygning diff --git a/i18n/da/Jobs.da.resx b/i18n/da/Jobs.da.resx index e9a71863..736bee18 100644 --- a/i18n/da/Jobs.da.resx +++ b/i18n/da/Jobs.da.resx @@ -75,7 +75,6 @@ Import Hurtig analyse Vedligeholdelse - Arkivflytning Forældreløse filer Proxyer Indeksgenopbygning diff --git a/i18n/de/Admin.de.resx b/i18n/de/Admin.de.resx index 2f26fc88..3d78f6d1 100644 --- a/i18n/de/Admin.de.resx +++ b/i18n/de/Admin.de.resx @@ -128,7 +128,6 @@ Import Schnellanalyse Wartung - Verschieben Verwaiste Dateien Proxys Neuaufbau diff --git a/i18n/de/Jobs.de.resx b/i18n/de/Jobs.de.resx index 16d67bf4..f20e4d9c 100644 --- a/i18n/de/Jobs.de.resx +++ b/i18n/de/Jobs.de.resx @@ -75,7 +75,6 @@ Import Schnellanalyse Wartung - Archiv verschieben Verwaiste Dateien Proxys Index neu aufbauen diff --git a/i18n/el/Admin.el.resx b/i18n/el/Admin.el.resx index cfb056e5..153d43c9 100644 --- a/i18n/el/Admin.el.resx +++ b/i18n/el/Admin.el.resx @@ -128,7 +128,6 @@ Εισαγωγή Γρήγορη ανάλυση Συντήρηση - Μετακίνηση Ορφανά αρχεία Proxy Αναδόμηση diff --git a/i18n/el/Jobs.el.resx b/i18n/el/Jobs.el.resx index 701b63cd..cc92f21a 100644 --- a/i18n/el/Jobs.el.resx +++ b/i18n/el/Jobs.el.resx @@ -75,7 +75,6 @@ Εισαγωγή Γρήγορη ανάλυση Συντήρηση - Μετακίνηση αρχειοθήκης Ορφανά αρχεία Proxy Αναδόμηση ευρετηρίου diff --git a/i18n/es/Admin.es.resx b/i18n/es/Admin.es.resx index f1d02f6b..22ccf36c 100644 --- a/i18n/es/Admin.es.resx +++ b/i18n/es/Admin.es.resx @@ -128,7 +128,6 @@ Importación Análisis rápido Mantenimiento - Traslado Huérfanos Proxies Reconstrucción diff --git a/i18n/es/Jobs.es.resx b/i18n/es/Jobs.es.resx index dea65e61..2da09f6b 100644 --- a/i18n/es/Jobs.es.resx +++ b/i18n/es/Jobs.es.resx @@ -75,7 +75,6 @@ Importación Análisis rápido Mantenimiento - Traslado de fototeca Huérfanos Proxies Reconstrucción del índice diff --git a/i18n/et/Admin.et.resx b/i18n/et/Admin.et.resx index 56cfeff1..c8179b57 100644 --- a/i18n/et/Admin.et.resx +++ b/i18n/et/Admin.et.resx @@ -128,7 +128,6 @@ Importimine Kiiranalüüs Hooldus - Teisaldamine Orbfailid Proksid Taasloomine diff --git a/i18n/et/Jobs.et.resx b/i18n/et/Jobs.et.resx index 95be7643..3fd70de4 100644 --- a/i18n/et/Jobs.et.resx +++ b/i18n/et/Jobs.et.resx @@ -75,7 +75,6 @@ Importimine Kiiranalüüs Hooldus - Arhiivi teisaldamine Orbfailid Proksid Indeksi taasloomine diff --git a/i18n/fi/Admin.fi.resx b/i18n/fi/Admin.fi.resx index 303e7a22..717facd9 100644 --- a/i18n/fi/Admin.fi.resx +++ b/i18n/fi/Admin.fi.resx @@ -128,7 +128,6 @@ Tuonti Pika-analyysi Ylläpito - Siirto Orvot tiedostot Proxyt Uudelleenluonti diff --git a/i18n/fi/Jobs.fi.resx b/i18n/fi/Jobs.fi.resx index 7485ddec..b1007d3d 100644 --- a/i18n/fi/Jobs.fi.resx +++ b/i18n/fi/Jobs.fi.resx @@ -75,7 +75,6 @@ Tuonti Pika-analyysi Ylläpito - Arkiston siirto Orvot tiedostot Proxyt Indeksin uudelleenluonti diff --git a/i18n/fr/Admin.fr.resx b/i18n/fr/Admin.fr.resx index 1a5fac72..c3a083fe 100644 --- a/i18n/fr/Admin.fr.resx +++ b/i18n/fr/Admin.fr.resx @@ -128,7 +128,6 @@ Importation Analyse rapide Maintenance - Déplacement Orphelins Proxys Reconstruction diff --git a/i18n/fr/Jobs.fr.resx b/i18n/fr/Jobs.fr.resx index 06d232a3..acba7450 100644 --- a/i18n/fr/Jobs.fr.resx +++ b/i18n/fr/Jobs.fr.resx @@ -75,7 +75,6 @@ Importation Analyse rapide Maintenance - Déplacement d'archive Orphelins Proxys Reconstruction d'index diff --git a/i18n/he/Admin.he.resx b/i18n/he/Admin.he.resx index 26db773c..53ecd62f 100644 --- a/i18n/he/Admin.he.resx +++ b/i18n/he/Admin.he.resx @@ -137,7 +137,6 @@ ייבוא ניתוח מהיר תחזוקה - העברה קבצים יתומים פרוקסי בנייה מחדש diff --git a/i18n/he/Jobs.he.resx b/i18n/he/Jobs.he.resx index f46b173b..4de4b5ab 100644 --- a/i18n/he/Jobs.he.resx +++ b/i18n/he/Jobs.he.resx @@ -76,7 +76,6 @@ ייבוא ניתוח מהיר תחזוקה - העברת ארכיון קבצים יתומים פרוקסי בנייה מחדש של האינדקס diff --git a/i18n/hi/Admin.hi.resx b/i18n/hi/Admin.hi.resx index ca581ecb..bbb7b219 100644 --- a/i18n/hi/Admin.hi.resx +++ b/i18n/hi/Admin.hi.resx @@ -128,7 +128,6 @@ आयात त्वरित विश्लेषण रखरखाव - स्थानांतरण अनाथ फ़ाइलें प्रॉक्सी पुनर्निर्माण diff --git a/i18n/hi/Jobs.hi.resx b/i18n/hi/Jobs.hi.resx index 151d3c5a..c67d9f11 100644 --- a/i18n/hi/Jobs.hi.resx +++ b/i18n/hi/Jobs.hi.resx @@ -75,7 +75,6 @@ आयात त्वरित विश्लेषण रखरखाव - संग्रह स्थानांतरण अनाथ फ़ाइलें प्रॉक्सी इंडेक्स पुनर्निर्माण diff --git a/i18n/hr/Admin.hr.resx b/i18n/hr/Admin.hr.resx index 2937f469..e947b511 100644 --- a/i18n/hr/Admin.hr.resx +++ b/i18n/hr/Admin.hr.resx @@ -137,7 +137,6 @@ Uvoz Brza analiza Održavanje - Premještanje Nepovezane datoteke Proxy kopije Ponovna izgradnja diff --git a/i18n/hr/Jobs.hr.resx b/i18n/hr/Jobs.hr.resx index d70db9b4..b10db32a 100644 --- a/i18n/hr/Jobs.hr.resx +++ b/i18n/hr/Jobs.hr.resx @@ -76,7 +76,6 @@ Uvoz Brza analiza Održavanje - Premještanje arhive Nepovezane datoteke Proxy kopije Ponovna izgradnja indeksa diff --git a/i18n/hu/Admin.hu.resx b/i18n/hu/Admin.hu.resx index 61fef1d9..cbeec965 100644 --- a/i18n/hu/Admin.hu.resx +++ b/i18n/hu/Admin.hu.resx @@ -128,7 +128,6 @@ Importálás Gyorselemzés Karbantartás - Áthelyezés Árva fájlok Proxyk Újraépítés diff --git a/i18n/hu/Jobs.hu.resx b/i18n/hu/Jobs.hu.resx index 96228b90..a5000281 100644 --- a/i18n/hu/Jobs.hu.resx +++ b/i18n/hu/Jobs.hu.resx @@ -75,7 +75,6 @@ Importálás Gyorselemzés Karbantartás - Archívum áthelyezése Árva fájlok Proxyk Index újraépítése diff --git a/i18n/id/Admin.id.resx b/i18n/id/Admin.id.resx index a430d102..149f564f 100644 --- a/i18n/id/Admin.id.resx +++ b/i18n/id/Admin.id.resx @@ -128,7 +128,6 @@ Impor Analisis cepat Pemeliharaan - Pemindahan File yatim Proksi Bangun ulang diff --git a/i18n/id/Jobs.id.resx b/i18n/id/Jobs.id.resx index 88064014..b149bc1e 100644 --- a/i18n/id/Jobs.id.resx +++ b/i18n/id/Jobs.id.resx @@ -75,7 +75,6 @@ Impor Analisis cepat Pemeliharaan - Pindahkan arsip File yatim Proksi Bangun ulang indeks diff --git a/i18n/ja/Admin.ja.resx b/i18n/ja/Admin.ja.resx index cdc66a7d..5f55cfa9 100644 --- a/i18n/ja/Admin.ja.resx +++ b/i18n/ja/Admin.ja.resx @@ -128,7 +128,6 @@ インポート 簡易分析 メンテナンス - 移動 孤立ファイル プロキシ 再構築 diff --git a/i18n/ja/Jobs.ja.resx b/i18n/ja/Jobs.ja.resx index edf610a2..060d5e7f 100644 --- a/i18n/ja/Jobs.ja.resx +++ b/i18n/ja/Jobs.ja.resx @@ -75,7 +75,6 @@ インポート 簡易分析 メンテナンス - アーカイブの移動 孤立ファイル プロキシ インデックスの再構築 diff --git a/i18n/ko/Admin.ko.resx b/i18n/ko/Admin.ko.resx index 14736b8c..11e1541e 100644 --- a/i18n/ko/Admin.ko.resx +++ b/i18n/ko/Admin.ko.resx @@ -128,7 +128,6 @@ 가져오기 빠른 분석 유지 관리 - 이동 고아 파일 프록시 재구성 diff --git a/i18n/ko/Jobs.ko.resx b/i18n/ko/Jobs.ko.resx index b98586d1..407b4e15 100644 --- a/i18n/ko/Jobs.ko.resx +++ b/i18n/ko/Jobs.ko.resx @@ -75,7 +75,6 @@ 가져오기 빠른 분석 유지 관리 - 아카이브 이동 고아 파일 프록시 인덱스 재구성 diff --git a/i18n/lt/Admin.lt.resx b/i18n/lt/Admin.lt.resx index f60bf6b2..3468694e 100644 --- a/i18n/lt/Admin.lt.resx +++ b/i18n/lt/Admin.lt.resx @@ -137,7 +137,6 @@ Importavimas Greitoji analizė Priežiūra - Perkėlimas Našlaičiai Tarpinės kopijos Perkūrimas diff --git a/i18n/lt/Jobs.lt.resx b/i18n/lt/Jobs.lt.resx index 42d05c6f..856182bd 100644 --- a/i18n/lt/Jobs.lt.resx +++ b/i18n/lt/Jobs.lt.resx @@ -76,7 +76,6 @@ Importavimas Greitoji analizė Priežiūra - Archyvo perkėlimas Našlaičiai Tarpinės kopijos Indekso perkūrimas diff --git a/i18n/lv/Admin.lv.resx b/i18n/lv/Admin.lv.resx index 6ef314a9..7553aac0 100644 --- a/i18n/lv/Admin.lv.resx +++ b/i18n/lv/Admin.lv.resx @@ -137,7 +137,6 @@ Importēšana Ātrā analīze Apkope - Pārvietošana Bāreņfaili Proxy attēli Pārbūve diff --git a/i18n/lv/Jobs.lv.resx b/i18n/lv/Jobs.lv.resx index 265f2298..23b35635 100644 --- a/i18n/lv/Jobs.lv.resx +++ b/i18n/lv/Jobs.lv.resx @@ -76,7 +76,6 @@ Importēšana Ātrā analīze Apkope - Arhīva pārvietošana Bāreņfaili Proxy attēli Indeksa pārbūve diff --git a/i18n/ms/Admin.ms.resx b/i18n/ms/Admin.ms.resx index 95218687..aa2546a0 100644 --- a/i18n/ms/Admin.ms.resx +++ b/i18n/ms/Admin.ms.resx @@ -128,7 +128,6 @@ Import Analisis pantas Penyelenggaraan - Pindah Fail yatim Proksi Bina semula diff --git a/i18n/ms/Jobs.ms.resx b/i18n/ms/Jobs.ms.resx index 9b0711a6..468b9cef 100644 --- a/i18n/ms/Jobs.ms.resx +++ b/i18n/ms/Jobs.ms.resx @@ -75,7 +75,6 @@ Import Analisis pantas Penyelenggaraan - Pindah arkib Fail yatim Proksi Bina semula indeks diff --git a/i18n/nb/Admin.nb.resx b/i18n/nb/Admin.nb.resx index 5a49ae06..91674875 100644 --- a/i18n/nb/Admin.nb.resx +++ b/i18n/nb/Admin.nb.resx @@ -128,7 +128,6 @@ Import Hurtiganalyse Vedlikehold - Flytting Foreldreløse filer Proxyer Gjenoppbygging diff --git a/i18n/nb/Jobs.nb.resx b/i18n/nb/Jobs.nb.resx index 64b375ee..4e544335 100644 --- a/i18n/nb/Jobs.nb.resx +++ b/i18n/nb/Jobs.nb.resx @@ -75,7 +75,6 @@ Import Hurtiganalyse Vedlikehold - Flytting av arkiv Foreldreløse filer Proxyer Gjenoppbygging av indeks diff --git a/i18n/nl/Admin.nl.resx b/i18n/nl/Admin.nl.resx index 97808c86..b087eba8 100644 --- a/i18n/nl/Admin.nl.resx +++ b/i18n/nl/Admin.nl.resx @@ -128,7 +128,6 @@ Import Snelle analyse Onderhoud - Verplaatsen Verweesde bestanden Proxy's Opnieuw opbouwen diff --git a/i18n/nl/Jobs.nl.resx b/i18n/nl/Jobs.nl.resx index 41a801a8..a0df2b48 100644 --- a/i18n/nl/Jobs.nl.resx +++ b/i18n/nl/Jobs.nl.resx @@ -75,7 +75,6 @@ Import Snelle analyse Onderhoud - Archief verplaatsen Verweesde bestanden Proxy's Index opnieuw opbouwen diff --git a/i18n/pl/Admin.pl.resx b/i18n/pl/Admin.pl.resx index 58c4b442..e74461bd 100644 --- a/i18n/pl/Admin.pl.resx +++ b/i18n/pl/Admin.pl.resx @@ -146,7 +146,6 @@ Import Szybka analiza Konserwacja - Przenoszenie Pliki osierocone Proxy Odbudowa diff --git a/i18n/pl/Jobs.pl.resx b/i18n/pl/Jobs.pl.resx index fe688cc8..5bed5f0a 100644 --- a/i18n/pl/Jobs.pl.resx +++ b/i18n/pl/Jobs.pl.resx @@ -77,7 +77,6 @@ Import Szybka analiza Konserwacja - Przenoszenie archiwum Pliki osierocone Proxy Odbudowa indeksu diff --git a/i18n/pt-BR/Admin.pt-BR.resx b/i18n/pt-BR/Admin.pt-BR.resx index d7cd4787..89b4729e 100644 --- a/i18n/pt-BR/Admin.pt-BR.resx +++ b/i18n/pt-BR/Admin.pt-BR.resx @@ -128,7 +128,6 @@ Importação Análise rápida Manutenção - Movimentação Órfãos Proxies Reconstrução diff --git a/i18n/pt-BR/Jobs.pt-BR.resx b/i18n/pt-BR/Jobs.pt-BR.resx index 00a916df..9720a358 100644 --- a/i18n/pt-BR/Jobs.pt-BR.resx +++ b/i18n/pt-BR/Jobs.pt-BR.resx @@ -75,7 +75,6 @@ Importação Análise rápida Manutenção - Movimentação do acervo Arquivos órfãos Proxies Reconstrução do índice diff --git a/i18n/pt-PT/Admin.pt-PT.resx b/i18n/pt-PT/Admin.pt-PT.resx index b31e0f0d..2cd9413a 100644 --- a/i18n/pt-PT/Admin.pt-PT.resx +++ b/i18n/pt-PT/Admin.pt-PT.resx @@ -128,7 +128,6 @@ Importação Análise rápida Manutenção - Mover Órfãos Proxies Reconstrução diff --git a/i18n/pt-PT/Jobs.pt-PT.resx b/i18n/pt-PT/Jobs.pt-PT.resx index 6343099b..eebfa4f3 100644 --- a/i18n/pt-PT/Jobs.pt-PT.resx +++ b/i18n/pt-PT/Jobs.pt-PT.resx @@ -75,7 +75,6 @@ Importação Análise rápida Manutenção - Mover arquivo Órfãos Proxies Reconstrução do índice diff --git a/i18n/ro/Admin.ro.resx b/i18n/ro/Admin.ro.resx index 5370a861..d63c6594 100644 --- a/i18n/ro/Admin.ro.resx +++ b/i18n/ro/Admin.ro.resx @@ -137,7 +137,6 @@ Import Analiză rapidă Întreținere - Mutare Fișiere orfane Proxy-uri Reconstruire diff --git a/i18n/ro/Jobs.ro.resx b/i18n/ro/Jobs.ro.resx index 9cf142c0..088ea46c 100644 --- a/i18n/ro/Jobs.ro.resx +++ b/i18n/ro/Jobs.ro.resx @@ -76,7 +76,6 @@ Import Analiză rapidă Întreținere - Mutare arhivă Fișiere orfane Proxy-uri Reconstruire index diff --git a/i18n/ru/Admin.ru.resx b/i18n/ru/Admin.ru.resx index e33cf3ec..310ea217 100644 --- a/i18n/ru/Admin.ru.resx +++ b/i18n/ru/Admin.ru.resx @@ -146,7 +146,6 @@ Импорт Быстрый анализ Обслуживание - Перемещение Неучтённые файлы Прокси Перестроение diff --git a/i18n/ru/Jobs.ru.resx b/i18n/ru/Jobs.ru.resx index 1eeaa47c..ff288156 100644 --- a/i18n/ru/Jobs.ru.resx +++ b/i18n/ru/Jobs.ru.resx @@ -77,7 +77,6 @@ Импорт Быстрый анализ Обслуживание - Перемещение архива Неучтённые файлы Прокси Перестроение индекса diff --git a/i18n/sk/Admin.sk.resx b/i18n/sk/Admin.sk.resx index 8b17eeeb..02de4124 100644 --- a/i18n/sk/Admin.sk.resx +++ b/i18n/sk/Admin.sk.resx @@ -137,7 +137,6 @@ Import Rýchla analýza Údržba - Presun Osirotené súbory Proxy Zostavenie indexu diff --git a/i18n/sk/Jobs.sk.resx b/i18n/sk/Jobs.sk.resx index d092c2f3..002aceeb 100644 --- a/i18n/sk/Jobs.sk.resx +++ b/i18n/sk/Jobs.sk.resx @@ -76,7 +76,6 @@ Import Rýchla analýza Údržba - Presun archívu Osirotené súbory Proxy Zostavenie indexu diff --git a/i18n/sl/Admin.sl.resx b/i18n/sl/Admin.sl.resx index 918ba00e..62701fae 100644 --- a/i18n/sl/Admin.sl.resx +++ b/i18n/sl/Admin.sl.resx @@ -137,7 +137,6 @@ Uvoz Hitra analiza Vzdrževanje - Premik Osirotele datoteke Proxyji Ponovna izgradnja diff --git a/i18n/sl/Jobs.sl.resx b/i18n/sl/Jobs.sl.resx index 2a8bdac6..cfa0e799 100644 --- a/i18n/sl/Jobs.sl.resx +++ b/i18n/sl/Jobs.sl.resx @@ -76,7 +76,6 @@ Uvoz Hitra analiza Vzdrževanje - Premik arhiva Osirotele datoteke Proxyji Ponovna izgradnja indeksa diff --git a/i18n/sv/Admin.sv.resx b/i18n/sv/Admin.sv.resx index 6cb1be3f..2f9c51b4 100644 --- a/i18n/sv/Admin.sv.resx +++ b/i18n/sv/Admin.sv.resx @@ -128,7 +128,6 @@ Import Snabbanalys Underhåll - Flytt Överblivna filer Proxyer Återskapande diff --git a/i18n/sv/Jobs.sv.resx b/i18n/sv/Jobs.sv.resx index 692df303..e125ccce 100644 --- a/i18n/sv/Jobs.sv.resx +++ b/i18n/sv/Jobs.sv.resx @@ -75,7 +75,6 @@ Import Snabbanalys Underhåll - Arkivflytt Överblivna filer Proxyer Återskapande av index diff --git a/i18n/th/Admin.th.resx b/i18n/th/Admin.th.resx index 51efe520..41e56ae8 100644 --- a/i18n/th/Admin.th.resx +++ b/i18n/th/Admin.th.resx @@ -128,7 +128,6 @@ นำเข้า การวิเคราะห์แบบเร็ว การบำรุงรักษา - ย้าย ไฟล์กำพร้า พร็อกซี สร้างใหม่ diff --git a/i18n/th/Jobs.th.resx b/i18n/th/Jobs.th.resx index 5ecd45e4..6fa42e39 100644 --- a/i18n/th/Jobs.th.resx +++ b/i18n/th/Jobs.th.resx @@ -75,7 +75,6 @@ นำเข้า การวิเคราะห์แบบเร็ว การบำรุงรักษา - ย้ายคลังภาพ ไฟล์กำพร้า พร็อกซี สร้างดัชนีใหม่ diff --git a/i18n/tr/Admin.tr.resx b/i18n/tr/Admin.tr.resx index 610d4777..6619fa58 100644 --- a/i18n/tr/Admin.tr.resx +++ b/i18n/tr/Admin.tr.resx @@ -128,7 +128,6 @@ İçe aktarma Hızlı analiz Bakım - Taşıma Sahipsiz dosyalar Proxy'ler Yeniden oluşturma diff --git a/i18n/tr/Jobs.tr.resx b/i18n/tr/Jobs.tr.resx index bfd69c33..8408bec3 100644 --- a/i18n/tr/Jobs.tr.resx +++ b/i18n/tr/Jobs.tr.resx @@ -75,7 +75,6 @@ İçe aktarma Hızlı analiz Bakım - Arşivi taşıma Sahipsiz dosyalar Proxy'ler Dizini yeniden oluşturma diff --git a/i18n/uk/Admin.uk.resx b/i18n/uk/Admin.uk.resx index 796387b9..38627d4b 100644 --- a/i18n/uk/Admin.uk.resx +++ b/i18n/uk/Admin.uk.resx @@ -146,7 +146,6 @@ Імпорт Швидкий аналіз Обслуговування - Переміщення Файли-сироти Проксі Перебудова diff --git a/i18n/uk/Jobs.uk.resx b/i18n/uk/Jobs.uk.resx index 758b4369..a5be490d 100644 --- a/i18n/uk/Jobs.uk.resx +++ b/i18n/uk/Jobs.uk.resx @@ -77,7 +77,6 @@ Імпорт Швидкий аналіз Обслуговування - Переміщення архіву Файли-сироти Проксі Перебудова індексу diff --git a/i18n/vi/Admin.vi.resx b/i18n/vi/Admin.vi.resx index e9cfac90..83a564f0 100644 --- a/i18n/vi/Admin.vi.resx +++ b/i18n/vi/Admin.vi.resx @@ -128,7 +128,6 @@ Nhập Phân tích nhanh Bảo trì - Di chuyển Tệp mồ côi Proxy Dựng lại diff --git a/i18n/vi/Jobs.vi.resx b/i18n/vi/Jobs.vi.resx index a1a6957e..0e58f3cd 100644 --- a/i18n/vi/Jobs.vi.resx +++ b/i18n/vi/Jobs.vi.resx @@ -75,7 +75,6 @@ Nhập Phân tích nhanh Bảo trì - Di chuyển kho lưu trữ Tệp mồ côi Proxy Dựng lại chỉ mục diff --git a/i18n/zh-Hans/Admin.zh-Hans.resx b/i18n/zh-Hans/Admin.zh-Hans.resx index 3885e35c..ecd482d6 100644 --- a/i18n/zh-Hans/Admin.zh-Hans.resx +++ b/i18n/zh-Hans/Admin.zh-Hans.resx @@ -128,7 +128,6 @@ 导入 快速分析 维护 - 移动 孤立文件 代理 重建 diff --git a/i18n/zh-Hans/Jobs.zh-Hans.resx b/i18n/zh-Hans/Jobs.zh-Hans.resx index 958e21e9..924f1d68 100644 --- a/i18n/zh-Hans/Jobs.zh-Hans.resx +++ b/i18n/zh-Hans/Jobs.zh-Hans.resx @@ -75,7 +75,6 @@ 导入 快速分析 维护 - 移动档案库 孤立文件 代理 重建索引 diff --git a/i18n/zh-Hant/Admin.zh-Hant.resx b/i18n/zh-Hant/Admin.zh-Hant.resx index 0ed2d64d..7318ecde 100644 --- a/i18n/zh-Hant/Admin.zh-Hant.resx +++ b/i18n/zh-Hant/Admin.zh-Hant.resx @@ -128,7 +128,6 @@ 匯入 快速分析 維護 - 移動 孤立檔案 代理檔 重建 diff --git a/i18n/zh-Hant/Jobs.zh-Hant.resx b/i18n/zh-Hant/Jobs.zh-Hant.resx index de0c5a97..5bb404f2 100644 --- a/i18n/zh-Hant/Jobs.zh-Hant.resx +++ b/i18n/zh-Hant/Jobs.zh-Hant.resx @@ -75,7 +75,6 @@ 匯入 快速分析 維護 - 移動典藏庫 孤立檔案 代理檔 重建索引 diff --git a/src/Chronos.Core/Archiving/MassRename.cs b/src/Chronos.Core/Archiving/MassRename.cs index 2d014611..62df6060 100644 --- a/src/Chronos.Core/Archiving/MassRename.cs +++ b/src/Chronos.Core/Archiving/MassRename.cs @@ -212,7 +212,7 @@ public static class RenamePlanner if (folder is not null && s.Folder.Length > 0 && Blank(folder.ExpandFolder(context with { Title = newTitle })) is { } expanded && !expanded.Equals(s.Folder, StringComparison.Ordinal)) { - newFolder = expanded.Equals(s.Folder, StringComparison.OrdinalIgnoreCase) ? expanded : Unique(expanded, claimed, existsOnDisk); + newFolder = Kept(s.Folder, expanded, taken) ?? Unique(expanded, claimed, existsOnDisk); claimed.Add(newFolder); } var step = new RenameStep(s.SequenceId, s.Folder, newFolder, s.Title, newTitle); @@ -299,6 +299,26 @@ public static class RenamePlanner private static string? Blank(string value) => string.IsNullOrWhiteSpace(value) ? null : value; + /// + /// The folder a sequence keeps (in the template's case) when it already is , or the + /// " (n)" of it that filing or an earlier Reorganize gave it beside another sequence of that name; null when it is + /// neither, or when another sequence holds that name exactly (a case-sensitive file system). Without it a sequence at + /// 2026-09-28 (2) would be planned to (3), its own folder being taken, and back to (2) by the + /// next Reorganize. + /// + private static string? Kept(string current, string expanded, IReadOnlyList occupied) + { + string? same = null; + if (current.Equals(expanded, StringComparison.OrdinalIgnoreCase)) same = expanded; + else if (current.Length > expanded.Length + 3 && current.StartsWith(expanded + " (", StringComparison.OrdinalIgnoreCase) && current[^1] == ')' + && int.TryParse(current.AsSpan(expanded.Length + 2, current.Length - expanded.Length - 3), NumberStyles.None, CultureInfo.InvariantCulture, + out var n) && n >= 2) + same = string.Create(CultureInfo.InvariantCulture, $"{expanded} ({n})"); + // "(02)" is not a number Unique gives: that folder moves to a name of its own. + if (same is null || !same.Equals(current, StringComparison.OrdinalIgnoreCase)) return null; + return same.Equals(current, StringComparison.Ordinal) || !occupied.Any(o => o.Equals(same, StringComparison.Ordinal)) ? same : null; + } + private static string Unique(string folder, HashSet claimed, Func existsOnDisk) { var candidate = folder; diff --git a/src/Chronos.Data/Archiving/MassRenamer.cs b/src/Chronos.Data/Archiving/MassRenamer.cs index 21df1c69..9f73ac82 100644 --- a/src/Chronos.Data/Archiving/MassRenamer.cs +++ b/src/Chronos.Data/Archiving/MassRenamer.cs @@ -113,7 +113,9 @@ public sealed class MassRenamer /// a sequence the plan does not take along, or the photos of a sequence whose files it renames changed; nothing of that /// step was changed (a step found stale only once its folder moved keeps its folder and title, and its journal has the /// next open complete the rest). - /// A file could not be renamed (open elsewhere); the step's files went back to their names. + /// A file could not be renamed (open elsewhere); the step's files went back to their names. Or + /// () a sequence is busy, or holds a restore from the trash whose entry is busy and + /// not settled yet; nothing of that step changed. public Task ApplyAsync(Archive archive, RenamePlan plan, IProgress? progress = null, CancellationToken cancellationToken = default) => ApplyAsync(archive, plan, null, progress is null ? null : n => { @@ -296,6 +298,7 @@ public sealed class MassRenamer result.Dropped.AddRange(follow.Select(c => c.SequenceId)); return; } + foreach (var s in follow.Prepend(step)) Settle(paths, s); RenamePlanner.MoveFolder(paths, step); // Moved with their carrier: only their sidecars and index rows follow, and the names of their files. foreach (var s in follow.Prepend(step)) @@ -312,6 +315,23 @@ public sealed class MassRenamer } } + /// + /// Settles, under the step's leases and before anything of it moves, what a crash or a busy trash entry left in the + /// sequence, as every writer does (): an interrupted rename of its files, photo + /// deletion, restore from the trash or ingest. A restore whose trash entry is busy is not settled yet, and the step + /// waits for it () as a deletion of the sequence does: its journal names the + /// files it moved by the names they had, so neither the folder nor those names change under it. + /// + /// A restore from the trash into the sequence is not settled; nothing of the step changed. + private static void Settle(ArchivePaths paths, RenameStep step) + { + // Where the sequence is now: its folder moves first, so a resumed step may find it at its new place already. + var sequence = paths.Sequence(step.FromFolder); + if (step.MovesFolder && !File.Exists(sequence.ManifestPath)) sequence = paths.Sequence(step.ToFolder); + SequenceWriter.ReadLocked(sequence, step.SequenceId); + FrameTrash.EnsureSettled(sequence); + } + /// The index still has the step's sequence where the plan says (or where it already took it); otherwise stale. /// Not resuming, and the sequence moved or vanished since the plan was made. private async Task StandsAsync(RenameStep step, bool resuming, CancellationToken cancellationToken) diff --git a/tests/Chronos.Core.Tests/Archiving/ReorganizeTests.cs b/tests/Chronos.Core.Tests/Archiving/ReorganizeTests.cs index 90674335..ddd355c0 100644 --- a/tests/Chronos.Core.Tests/Archiving/ReorganizeTests.cs +++ b/tests/Chronos.Core.Tests/Archiving/ReorganizeTests.cs @@ -82,6 +82,22 @@ public sealed class ReorganizeTests(TestContext context) Assert.Count(2, plan.Samples); } + [Test] + public void TheTrashAndReorganizeFindTheSameCompanionsWhateverTheirCase() + { + var sequence = Folder(out _); + var manifest = Sequence("originals/A.CR2", "originals/B.CR2"); + foreach (var file in new[] { "originals/A.CR2", "originals/B.CR2", "originals/a.XMP", "originals/b.cr2.Xmp", "originals/c.xmp" }) Write(sequence, file, file); + var present = FileRenames.ListPresent(sequence, manifest); + var plan = FileRenames.Plan(manifest, null, PathTemplate.Parse("{n:0000}"), present); + Assert.SequenceEqual(["originals/A.CR2>originals/0001.CR2", "originals/a.XMP>originals/0001.XMP", "originals/B.CR2>originals/0002.CR2", + "originals/b.cr2.Xmp>originals/0002.cr2.Xmp"], plan.Moves.Select(m => $"{m.From}>{m.To}")); + var index = new FrameCompanions.Index(sequence); + Assert.SequenceEqual(["originals/a.XMP"], index.Of("originals/A.CR2")); + Assert.SequenceEqual(["originals/b.cr2.Xmp"], index.Of("originals/B.CR2")); + Assert.SequenceEqual(plan.Moves.Where(m => m.Companion).Select(m => m.From), manifest.Frames.SelectMany(f => FrameCompanions.Of(sequence, f.File))); + } + [Test] public void NamesGivenOnceStayAsTheyAre() { @@ -124,6 +140,28 @@ public sealed class ReorganizeTests(TestContext context) Assert.False(keptOnly.Steps.Single().Changes); } + [Test] + public void FoldersTheTemplateGaveAlreadyStayAndASecondRunPlansNothing() + { + // Two sequences of one day filed by the template, the second beside the first; a third elsewhere, a fourth whose + // folder differs only in case, a fifth with a number filing never gives. + const string Template = "{year}/{date} {title}"; + RenameSubject At(string folder) => new(Guid.NewGuid(), folder, "Sunset", Start, null, null, null); + RenameSubject[] subjects = [At("2026/2026-09-28 Sunset"), At("2026/2026-09-28 Sunset (2)"), At("inbox/c"), At("2026/2026-09-28 sunset (4)"), + At("2026/2026-09-28 Sunset (03)")]; + var plan = RenamePlanner.Plan(Guid.NewGuid(), subjects, Template, null, subjects.Select(s => s.Folder), _ => false); + Assert.SequenceEqual([(subjects[2].SequenceId, "2026/2026-09-28 Sunset (3)"), (subjects[3].SequenceId, "2026/2026-09-28 Sunset (4)"), + (subjects[4].SequenceId, "2026/2026-09-28 Sunset (5)")], plan.Steps.Select(s => (s.SequenceId, s.ToFolder))); + + // Where the plan put them, the same template changes nothing. + var moved = plan.Steps.ToDictionary(s => s.SequenceId, s => s.ToFolder); + RenameSubject[] after = [.. subjects.Select(s => moved.TryGetValue(s.SequenceId, out var to) ? s with { Folder = to } : s)]; + var onDisk = after.Select(s => s.Folder).ToHashSet(StringComparer.OrdinalIgnoreCase); + Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), after, Template, null, onDisk, onDisk.Contains).Steps); + // Nor in another order. + Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), [.. after.Reverse()], Template, null, onDisk, onDisk.Contains).Steps); + } + [Test] public void TheFingerprintFollowsWhatThePlanChanges() { diff --git a/tests/Chronos.Data.Tests/Archiving/FrameTrashTests.cs b/tests/Chronos.Data.Tests/Archiving/FrameTrashTests.cs index d3bf3221..a0cb07b0 100644 --- a/tests/Chronos.Data.Tests/Archiving/FrameTrashTests.cs +++ b/tests/Chronos.Data.Tests/Archiving/FrameTrashTests.cs @@ -1127,6 +1127,90 @@ public abstract class FrameTrashTests(TestContext context) : DatabaseTest(contex Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id)); } + /// The files of a sequence as its sidecar names them, after checking that the index names the same ones and that each holds its photo. + private static async Task> FilesAsync(ArchiveFixture fx, Guid id) + { + var sequence = Assert.NotNull(await fx.Db.Sequences.GetAsync(id)); + var folder = fx.Paths.Sequence(sequence.Folder); + var sidecar = ManifestStore.ReadSequence(folder.ManifestPath); + var rows = await fx.Db.Frames.ListBySequenceAsync(id); + Assert.SequenceEqual(sidecar.Frames.Select(f => (f.Id, folder.ArchiveRelative(f.File))), rows.Select(r => (r.Id, r.RelativePath))); + foreach (var frame in sidecar.Frames) Assert.Equal(frame.Sha256, Sha(folder.File(frame.File))); + return [.. sidecar.Frames.Select(f => f.File)]; + } + + [Test] + public async Task PhotosDeletedBeforeAReorganizeComeBackBesideTheNamesItGave() + { + var fx = await FixtureAsync(); + var (sequence, frames) = await UploadedAsync(fx, 4); + var numbered = new RenameTemplates(File: "{n:000}"); + await fx.Service.ApplyRenameAsync(await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], numbered, fx.Ct), null, fx.Ct); + var folder = fx.Paths.Sequence(sequence.Folder); + File.WriteAllText(folder.File("originals/002.xmp"), "second"); + await fx.ScanAsync(); + // The record keeps the names the photo and its companion had: 002.JPG and 002.xmp. + var deleted = await DeleteAsync(fx, (await fx.Db.Sequences.GetAsync(sequence.Id))!, frames[1]); + Assert.SequenceEqual(["originals/002.JPG", "originals/002.xmp"], FrameTrash.ReadEntry(fx.Paths, deleted.Entry.Name)!.Photos.Single().Files.Select(f => f.From)); + + // Moved and renamed since: the photos that stay take 001-003, the deleted photo's name included. + var moved = new RenameTemplates(Folder: "moved/{date}", File: "{n:000}"); + await fx.Service.ApplyRenameAsync(await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], moved, fx.Ct), null, fx.Ct); + Assert.SequenceEqual(["originals/001.JPG", "originals/002.JPG", "originals/003.JPG"], await FilesAsync(fx, sequence.Id)); + + // Restored into the sequence where it is now, under its own name made free: its companion follows that name. + var restored = await fx.Service.RestoreEntryAsync(fx.Archive.Id, deleted.Entry.Name, null, fx.Ct); + Assert.Equal(1, restored.Photos); + var row = (await fx.Db.Sequences.GetAsync(sequence.Id))!; + Assert.Equal("moved/2026-09-28", row.Folder); + Assert.SequenceEqual(["originals/001.JPG", "originals/002_2.JPG", "originals/002.JPG", "originals/003.JPG"], await FilesAsync(fx, sequence.Id)); + var now = fx.Paths.Sequence(row.Folder); + Assert.Equal(frames[1].Sha256, Sha(now.File("originals/002_2.JPG"))); + Assert.Equal("second", File.ReadAllText(now.File("originals/002_2.xmp"))); + Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id)); + Assert.DoesNotContain(TrashKind.Photos, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Select(e => e.Kind)); + } + + [Test] + public async Task AReorganizeWaitsForARestoreItsEntryHoldsThenSettlesItFirst() + { + var fx = await FixtureAsync(); + var (sequence, frames) = await UploadedAsync(fx, 3); + var folder = fx.Paths.Sequence(sequence.Folder); + var deleted = await DeleteAsync(fx, sequence, frames[1]); + // A restore died after moving the original back, before the sidecar; the entry is being emptied meanwhile. + var journal = RestoreJournal(fx, deleted.Entry); + journal.Write(folder); + var back = journal.Photos[0].Moves[0]; + File.Move(fx.Paths.FromRelative(back.To), folder.File(back.From)); + var templates = new RenameTemplates(Folder: "moved/{date}", File: "{n:000}"); + var plan = await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], templates, fx.Ct); + Assert.Equal(2, plan.Steps.Single().FileChanges); + var before = await FilesAsync(fx, sequence.Id); + + using (Assert.NotNull(LeaseFile.TryAcquire(fx.Paths.LocksDirectory, SequenceTrash.EntryLease(deleted.Entry.Name), "other"))) + { + // Neither the folder nor a file name changes under that restore. + await Assert.ThrowsAsync(() => fx.Service.ApplyRenameAsync(plan, null, fx.Ct)); + Assert.Equal(sequence.Folder, (await fx.Db.Sequences.GetAsync(sequence.Id))!.Folder); + Assert.SequenceEqual(before, await FilesAsync(fx, sequence.Id)); + Assert.FileExists(folder.RestoreJournalPath); + Assert.FileExists(folder.File(back.From)); + } + + // Once the entry is free the rename resumes: the restore is settled first (the original goes back into its entry), + // then the folder moves and the files are renamed; the photo then comes back beside them. + Assert.Equal(1, await fx.Service.Renamer.ResumePendingAsync(fx.Archive, fx.Ct)); + Assert.Equal(frames[1].Sha256, Sha(fx.Paths.FromRelative(back.To))); + var row = (await fx.Db.Sequences.GetAsync(sequence.Id))!; + Assert.Equal("moved/2026-09-28", row.Folder); + Assert.FileMissing(fx.Paths.Sequence(row.Folder).RestoreJournalPath); + Assert.SequenceEqual(["originals/001.JPG", "originals/002.JPG"], await FilesAsync(fx, sequence.Id)); + Assert.Equal(1, (await fx.Service.RestoreEntryAsync(fx.Archive.Id, deleted.Entry.Name, null, fx.Ct)).Photos); + Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id)); + Assert.Count(3, await FilesAsync(fx, sequence.Id)); + } + [Test] public async Task ARestoreIntoANewSequenceStoppedBetweenPhotosKeepsItsRecordTrue() { diff --git a/tests/Chronos.Data.Tests/Archiving/ReorganizeTests.cs b/tests/Chronos.Data.Tests/Archiving/ReorganizeTests.cs index 79088761..74082a48 100644 --- a/tests/Chronos.Data.Tests/Archiving/ReorganizeTests.cs +++ b/tests/Chronos.Data.Tests/Archiving/ReorganizeTests.cs @@ -97,6 +97,24 @@ public sealed class ReorganizeTests(TestContext context) Assert.False((await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [id], templates, fx.Ct)).Steps.Any(s => s.Changes)); } + [Test] + public async Task ASecondReorganizeWithTheSameTemplatesPlansNothing() + { + await using var fx = await CreateAsync(context); + var first = await UploadAsync(fx, 2); + var second = await UploadAsync(fx, 2, firstSeed: 20, firstSecond: 3600, key: "upload-2"); + // One day for both: the second sequence's folder gets " (2)". + var templates = new RenameTemplates(Folder: "days/{date}", File: "{date}_{n:000}"); + await fx.Service.ApplyRenameAsync(await fx.Service.PlanReorganizeAsync(fx.Archive.Id, null, templates, fx.Ct), null, fx.Ct); + var folders = new List(); + foreach (var id in new[] { first, second }) folders.Add((await fx.Db.Sequences.GetAsync(id))!.Folder); + Assert.SequenceEqual(["days/2026-09-28", "days/2026-09-28 (2)"], folders.Order(StringComparer.Ordinal)); + + var again = await fx.Service.PlanReorganizeAsync(fx.Archive.Id, null, templates, fx.Ct); + Assert.Count(2, again.Subjects); + Assert.False(again.Steps.Any(s => s.Changes), string.Join(", ", again.Steps.Select(s => $"{s.FromFolder}>{s.ToFolder}"))); + } + [Test] public async Task UploadsAndImportsAreNamedAsReorganizeNamesThem() {