Improved raw message file cleanup

This commit is contained in:
M66B 2019-08-06 11:02:09 +02:00
parent 7a49a7dd89
commit c7597ec2a8
1 changed files with 15 additions and 3 deletions

View File

@ -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();