Better accounting of orphaned attachments

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-02-12 10:15:34 -06:00
committed by GitHub
parent e9917bf934
commit a4e9e98739

View File

@@ -19,6 +19,8 @@ import z from 'zod';
import GrowingFile from 'growing-file';
import lodash from 'lodash';
import { pathExists } from 'fs-extra';
import pMap from 'p-map';
import { access } from 'node:fs/promises';
import {
type DecryptAttachmentToSinkOptionsType,
@@ -462,6 +464,22 @@ function deleteOrphanedAttachments({
`cleanupOrphanedAttachments: ${totalAttachmentsFound} attachments and \
${totalDownloadsFound} downloads found on disk`
);
const attachmentsFolder = getAttachmentsPath(userDataPath);
// It's possible that messages and attachments have been deleted since we first
// checked the contents of the attachments folder, so for better accounting, we
// check once more that they still exist.
await pMap(
orphanedAttachments,
async path => {
try {
await access(join(attachmentsFolder, path));
} catch (e) {
orphanedAttachments.delete(path);
}
},
{ concurrency: 20 }
);
if (orphanedAttachments.size > 0) {
log.error(`${orphanedAttachments.size} orphaned attachment(s) found`);