mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-02-15 07:28:59 +00:00
Better accounting of orphaned attachments
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
@@ -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`);
|
||||
|
||||
Reference in New Issue
Block a user