From a4918e0e949f7f344f46fbf56b2237bbcbe52eb0 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 6 Aug 2019 11:12:25 +0200 Subject: [PATCH] Keep attachment files for a while --- .../java/eu/faircode/email/WorkerCleanup.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 1f936b1480..1458ea41f6 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -147,15 +147,16 @@ public class WorkerCleanup extends Worker { Log.i("Cleanup attachment files"); File[] attachments = new File(context.getFilesDir(), "attachments").listFiles(); if (attachments != null) - for (File file : attachments) { - long id = Long.parseLong(file.getName().split("\\.")[0]); - EntityAttachment attachment = db.attachment().getAttachment(id); - if (attachment == null || !attachment.available) { - Log.i("Deleting " + file); - if (!file.delete()) - Log.w("Error deleting " + file); + for (File file : attachments) + if (manual || file.lastModified() + KEEP_FILES_DURATION < now) { + long id = Long.parseLong(file.getName().split("\\.")[0]); + EntityAttachment attachment = db.attachment().getAttachment(id); + if (attachment == null || !attachment.available) { + Log.i("Deleting " + file); + if (!file.delete()) + Log.w("Error deleting " + file); + } } - } // Cleanup cached images Log.i("Cleanup cached image files");