Fixed/improved cleanup

This commit is contained in:
M66B 2023-12-11 19:46:33 +01:00
parent 8655d3bb7c
commit 00049edd12
1 changed files with 27 additions and 14 deletions

View File

@ -113,6 +113,7 @@ public class WorkerCleanup extends Worker {
// Check message files
Log.i("Checking message files");
try (Cursor cursor = db.message().getMessageWithContent()) {
while (cursor.moveToNext()) {
long mid = cursor.getLong(0);
EntityMessage message = db.message().getMessage(mid);
if (message != null) {
@ -123,10 +124,12 @@ public class WorkerCleanup extends Worker {
}
}
}
}
// Check attachments files
Log.i("Checking attachments files");
try (Cursor cursor = db.attachment().getAttachmentAvailable()) {
while (cursor.moveToNext()) {
long aid = cursor.getLong(0);
EntityAttachment attachment = db.attachment().getAttachment(aid);
if (attachment != null) {
@ -137,6 +140,7 @@ public class WorkerCleanup extends Worker {
}
}
}
}
// Delete old attachments
if (cleanup_attachments) {
@ -211,6 +215,15 @@ public class WorkerCleanup extends Worker {
// Cleanup message files
Log.breadcrumb("worker", "cleanup", "message files");
{
File[] files = new File(context.getFilesDir(), "messages").listFiles();
for (File file : files) {
if (file.isDirectory())
cleanupMessageFiles(db, manual, file.listFiles());
else
cleanupMessageFiles(db, manual, new File[]{file});
}
}
cleanupMessageFiles(db, manual, Helper.listFiles(new File(context.getFilesDir(), "messages")).toArray(new File[0]));
cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "revision").listFiles());
cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "references").listFiles());