Fixed/improved cleanup

pull/214/head
M66B 1 year ago
parent 8655d3bb7c
commit 00049edd12

@ -113,13 +113,15 @@ public class WorkerCleanup extends Worker {
// Check message files // Check message files
Log.i("Checking message files"); Log.i("Checking message files");
try (Cursor cursor = db.message().getMessageWithContent()) { try (Cursor cursor = db.message().getMessageWithContent()) {
long mid = cursor.getLong(0); while (cursor.moveToNext()) {
EntityMessage message = db.message().getMessage(mid); long mid = cursor.getLong(0);
if (message != null) { EntityMessage message = db.message().getMessage(mid);
File file = message.getFile(context); if (message != null) {
if (!file.exists()) { File file = message.getFile(context);
Log.w("Message file missing id=" + mid); if (!file.exists()) {
db.message().resetMessageContent(mid); Log.w("Message file missing id=" + mid);
db.message().resetMessageContent(mid);
}
} }
} }
} }
@ -127,13 +129,15 @@ public class WorkerCleanup extends Worker {
// Check attachments files // Check attachments files
Log.i("Checking attachments files"); Log.i("Checking attachments files");
try (Cursor cursor = db.attachment().getAttachmentAvailable()) { try (Cursor cursor = db.attachment().getAttachmentAvailable()) {
long aid = cursor.getLong(0); while (cursor.moveToNext()) {
EntityAttachment attachment = db.attachment().getAttachment(aid); long aid = cursor.getLong(0);
if (attachment != null) { EntityAttachment attachment = db.attachment().getAttachment(aid);
File file = attachment.getFile(context); if (attachment != null) {
if (!file.exists()) { File file = attachment.getFile(context);
Log.w("Attachment file missing id=" + aid); if (!file.exists()) {
db.attachment().setAvailable(aid, false); Log.w("Attachment file missing id=" + aid);
db.attachment().setAvailable(aid, false);
}
} }
} }
} }
@ -211,6 +215,15 @@ public class WorkerCleanup extends Worker {
// Cleanup message files // Cleanup message files
Log.breadcrumb("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, 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(), "revision").listFiles());
cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "references").listFiles()); cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "references").listFiles());

Loading…
Cancel
Save