|
|
@ -82,6 +82,32 @@ public class WorkerCleanup extends Worker {
|
|
|
|
" before=" + new Date(keep_time) + " deleted=" + messages);
|
|
|
|
" before=" + new Date(keep_time) + " deleted=" + messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manual) {
|
|
|
|
|
|
|
|
// Check message files
|
|
|
|
|
|
|
|
Log.i("Checking message files");
|
|
|
|
|
|
|
|
List<Long> mids = db.message().getMessageWithContent();
|
|
|
|
|
|
|
|
for (Long mid : mids) {
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(mid);
|
|
|
|
|
|
|
|
File file = message.getFile(context);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
|
|
|
Log.w("Message file missing id=" + mid);
|
|
|
|
|
|
|
|
db.message().setMessageContent(mid, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check attachments files
|
|
|
|
|
|
|
|
Log.i("Checking attachments files");
|
|
|
|
|
|
|
|
List<Long> aids = db.attachment().getAttachmentAvailable();
|
|
|
|
|
|
|
|
for (Long aid : aids) {
|
|
|
|
|
|
|
|
EntityAttachment attachment = db.attachment().getAttachment(aid);
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
|
|
|
Log.w("Attachment file missing id=" + aid);
|
|
|
|
|
|
|
|
db.attachment().setAvailable(aid, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long now = new Date().getTime();
|
|
|
|
long now = new Date().getTime();
|
|
|
|
|
|
|
|
|
|
|
|
List<File> files = new ArrayList<>();
|
|
|
|
List<File> files = new ArrayList<>();
|
|
|
@ -103,7 +129,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
Log.i("Cleanup message files");
|
|
|
|
Log.i("Cleanup message files");
|
|
|
|
for (File file : files) {
|
|
|
|
for (File file : files) {
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
if (db.message().countMessage(id) == 0) {
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
if (message == null || !message.content) {
|
|
|
|
Log.i("Deleting " + file);
|
|
|
|
Log.i("Deleting " + file);
|
|
|
|
if (!file.delete())
|
|
|
|
if (!file.delete())
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
@ -116,7 +143,8 @@ public class WorkerCleanup extends Worker {
|
|
|
|
if (attachments != null)
|
|
|
|
if (attachments != null)
|
|
|
|
for (File file : attachments) {
|
|
|
|
for (File file : attachments) {
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
long id = Long.parseLong(file.getName().split("\\.")[0]);
|
|
|
|
if (db.attachment().countAttachment(id) == 0) {
|
|
|
|
EntityAttachment attachment = db.attachment().getAttachment(id);
|
|
|
|
|
|
|
|
if (attachment == null || !attachment.available) {
|
|
|
|
Log.i("Deleting " + file);
|
|
|
|
Log.i("Deleting " + file);
|
|
|
|
if (!file.delete())
|
|
|
|
if (!file.delete())
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
@ -135,32 +163,6 @@ public class WorkerCleanup extends Worker {
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
Log.w("Error deleting " + file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (manual) {
|
|
|
|
|
|
|
|
// Check message files
|
|
|
|
|
|
|
|
Log.i("Checking message files");
|
|
|
|
|
|
|
|
List<Long> mids = db.message().getMessageWithContent();
|
|
|
|
|
|
|
|
for (Long mid : mids) {
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(mid);
|
|
|
|
|
|
|
|
File file = message.getFile(context);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
|
|
|
Log.w("Message file missing id=" + mid);
|
|
|
|
|
|
|
|
db.message().setMessageContent(mid, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check attachments files
|
|
|
|
|
|
|
|
Log.i("Checking attachments files");
|
|
|
|
|
|
|
|
List<Long> aids = db.attachment().getAttachmentAvailable();
|
|
|
|
|
|
|
|
for (Long aid : aids) {
|
|
|
|
|
|
|
|
EntityAttachment attachment = db.attachment().getAttachment(aid);
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
|
|
|
Log.w("Attachment file missing id=" + aid);
|
|
|
|
|
|
|
|
db.attachment().setUnavailable(aid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Cleanup contacts");
|
|
|
|
Log.i("Cleanup contacts");
|
|
|
|
int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION);
|
|
|
|
int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION);
|
|
|
|
Log.i("Deleted contacts=" + contacts);
|
|
|
|
Log.i("Deleted contacts=" + contacts);
|
|
|
|