|
|
|
@ -225,7 +225,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
// Cleanup message files
|
|
|
|
|
Log.i("Cleanup message files");
|
|
|
|
|
for (File file : files)
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now) {
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now)
|
|
|
|
|
try {
|
|
|
|
|
String name = file.getName().split("\\.")[0];
|
|
|
|
|
int us = name.indexOf('_');
|
|
|
|
|
if (us > 0)
|
|
|
|
@ -237,6 +238,9 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
|
Log.e(file.getAbsolutePath(), ex);
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cleanup raw message files
|
|
|
|
@ -245,7 +249,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
File[] raws = new File(context.getFilesDir(), "raw").listFiles();
|
|
|
|
|
if (raws != null)
|
|
|
|
|
for (File file : raws)
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now) {
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now)
|
|
|
|
|
try {
|
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
if (manual && cleanup_attachments && message != null) {
|
|
|
|
@ -260,6 +265,9 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
|
Log.e(file.getAbsolutePath(), ex);
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -268,7 +276,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
File[] attachments = new File(context.getFilesDir(), "attachments").listFiles();
|
|
|
|
|
if (attachments != null)
|
|
|
|
|
for (File file : attachments)
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now) {
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now)
|
|
|
|
|
try {
|
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
|
EntityAttachment attachment = db.attachment().getAttachment(id);
|
|
|
|
|
if (attachment == null || !attachment.available) {
|
|
|
|
@ -276,6 +285,9 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
|
Log.e(file.getAbsolutePath(), ex);
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cleanup cached images
|
|
|
|
@ -283,7 +295,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
File[] images = new File(context.getCacheDir(), "images").listFiles();
|
|
|
|
|
if (images != null)
|
|
|
|
|
for (File file : images)
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now) {
|
|
|
|
|
if (manual || file.lastModified() + KEEP_FILES_DURATION < now)
|
|
|
|
|
try {
|
|
|
|
|
long id = Long.parseLong(file.getName().split("[_\\.]")[0]);
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
if (manual || message == null ||
|
|
|
|
@ -292,6 +305,9 @@ public class WorkerCleanup extends Worker {
|
|
|
|
|
if (!file.delete())
|
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
|
Log.e(file.getAbsolutePath(), ex);
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cleanup shared files
|
|
|
|
|