From c7597ec2a88f3230af7223a4b1d0eeab3d9dd1b3 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 6 Aug 2019 11:02:09 +0200 Subject: [PATCH] Improved raw message file cleanup --- .../java/eu/faircode/email/WorkerCleanup.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 23bec5480b..1f936b1480 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -107,7 +107,6 @@ public class WorkerCleanup extends Worker { File[] messages = new File(context.getFilesDir(), "messages").listFiles(); File[] revision = new File(context.getFilesDir(), "revision").listFiles(); File[] references = new File(context.getFilesDir(), "references").listFiles(); - File[] raws = new File(context.getFilesDir(), "raw").listFiles(); if (messages != null) files.addAll(Arrays.asList(messages)); @@ -115,8 +114,6 @@ public class WorkerCleanup extends Worker { files.addAll(Arrays.asList(revision)); if (references != null) files.addAll(Arrays.asList(references)); - if (raws != null) - files.addAll(Arrays.asList(raws)); // Cleanup message files Log.i("Cleanup message files"); @@ -131,6 +128,21 @@ public class WorkerCleanup extends Worker { } } + // Cleanup message files + Log.i("Cleanup raw message files"); + File[] raws = new File(context.getFilesDir(), "raw").listFiles(); + if (raws != null) + for (File file : raws) + if (manual || file.lastModified() + KEEP_FILES_DURATION < now) { + long id = Long.parseLong(file.getName().split("\\.")[0]); + EntityMessage message = db.message().getMessage(id); + if (message == null || message.raw == null || !message.raw) { + Log.i("Deleting " + file); + if (!file.delete()) + Log.w("Error deleting " + file); + } + } + // Cleanup attachment files Log.i("Cleanup attachment files"); File[] attachments = new File(context.getFilesDir(), "attachments").listFiles();