From 13332cf06b90ae52158b6583570edca6a9723d71 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 1 Nov 2026 18:32:33 +0100 Subject: [PATCH] fix(storage): a pass on a database this installation does not recognise only reports While a restore's reset is still pending, or the database names another installation, the nightly pass judges and reports but deletes nothing, whatever the restored switch says. --- .../src/nest/storage/storage-reclaim.service.ts | 7 ++++++- .../nest/storage/storage-reclaim.service.test.ts | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/server/src/nest/storage/storage-reclaim.service.ts b/server/src/nest/storage/storage-reclaim.service.ts index ac3796df6..53a96e0e0 100644 --- a/server/src/nest/storage/storage-reclaim.service.ts +++ b/server/src/nest/storage/storage-reclaim.service.ts @@ -258,7 +258,12 @@ export class StorageReclaimService implements OnModuleInit { private async pass(reportOnly: boolean, now: Date): Promise { const wallStart = Date.now(); const installId = this.install.installId(); - const deleting = !reportOnly && installId !== null && (await readReclaimDeleteEnabled(this.appSettings, installId)); + // A database this installation does not recognise (a restore whose reset did not run yet) only reports. + const deleting = + !reportOnly && + installId !== null && + (await this.install.databaseIsThis(installId)) && + (await readReclaimDeleteEnabled(this.appSettings, installId)); const ctx: PassContext = { now: now.getTime(), installId, diff --git a/server/tests/unit/nest/storage/storage-reclaim.service.test.ts b/server/tests/unit/nest/storage/storage-reclaim.service.test.ts index 03bd24653..38e5ac246 100644 --- a/server/tests/unit/nest/storage/storage-reclaim.service.test.ts +++ b/server/tests/unit/nest/storage/storage-reclaim.service.test.ts @@ -10,7 +10,7 @@ * an owner marker of another install keeps its hands off; a restore, or a * database naming another install, resets the switch, the marks, the queue * and the reports but keeps this install's id, and so does a restore's reset - * file whatever id the database names. RCLS-001 to RCLS-045. + * file whatever id the database names. RCLS-001 to RCLS-046. */ import { AppSettings } from '../../../../src/db/entities/AppSettings.entity'; import { AuditLog } from '../../../../src/db/entities/AuditLog.entity'; @@ -890,6 +890,20 @@ describe('StorageReclaimService: a pass that stops, and a restore', () => { expect((await reclaim.state()).deleteEnabled).toBe(false); }); + it('RCLS-046: while a restore's reset is still pending, the nightly pass only reports, whatever the switch says', async () => { + const sentinel = path.join(dataRoot, 'reclaim-reset'); + await markedWeekOld(['orphan.jpg']); + fs.writeFileSync(sentinel, 'pending'); + try { + const report = await reclaim.run({ now: WEEK_LATER }); + expect(report.mode).toBe('report'); + expect(report.categories.covers.deleted.objects).toBe(0); + expect(fs.existsSync(objectPath('covers', 'orphan.jpg'))).toBe(true); + } finally { + fs.rmSync(sentinel, { force: true }); + } + }); + it('RCLS-045: a reset file that cannot be removed is reset again on the next start, and the database is not this', async () => { const install = t.get(StorageInstallService); const sentinel = path.join(dataRoot, 'reclaim-reset');