1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Added some defensive code to prevent crashes caused by the LocalStore getting in a bad state due to issue 1205 (still being worked on). This fixes issue 1214.

This commit is contained in:
Bao-Long Nguyen-Trong 2010-02-11 21:16:37 +00:00
parent 8d8233bcc0
commit 6fe2dad5cc

View File

@ -269,7 +269,7 @@ public class LocalStore extends Store implements Serializable
long attachmentLength = 0;
attachmentLength =+ getSize(mInternalAttachmentsDir);
if (useExternalAttachmentDir())
if (usesExternalAttachmentDir())
{
attachmentLength =+ getSize(mExternalAttachmentsDir);
}
@ -283,6 +283,12 @@ public class LocalStore extends Store implements Serializable
long attachmentLength = 0;
File[] files = attachmentsDir.listFiles();
if (files==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File file : files)
{
if (file.exists())
@ -290,6 +296,7 @@ public class LocalStore extends Store implements Serializable
attachmentLength += file.length();
}
}
}
return attachmentLength;
}
@ -422,7 +429,7 @@ public class LocalStore extends Store implements Serializable
}
delete(mInternalAttachmentsDir);
if (useExternalAttachmentDir())
if (usesExternalAttachmentDir())
{
delete(mExternalAttachmentsDir);
}
@ -440,6 +447,12 @@ public class LocalStore extends Store implements Serializable
private void delete(File attachmentsDir) {
try {
File[] attachments = attachmentsDir.listFiles();
if (attachments==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File attachment : attachments)
{
if (attachment.exists())
@ -452,6 +465,7 @@ public class LocalStore extends Store implements Serializable
attachmentsDir.delete();
}
}
}
catch (Exception e)
{
Log.w(K9.LOG_TAG, null, e);
@ -472,7 +486,7 @@ public class LocalStore extends Store implements Serializable
mDb.update("attachments", cv, null, null);
}
pruneCachedAttachments(force, mInternalAttachmentsDir);
if (useExternalAttachmentDir())
if (usesExternalAttachmentDir())
{
pruneCachedAttachments(force, mExternalAttachmentsDir);
}
@ -484,6 +498,12 @@ public class LocalStore extends Store implements Serializable
private void pruneCachedAttachments(boolean force, File attachmentsDir) throws MessagingException
{
File[] files = attachmentsDir.listFiles();
if (files==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File file : files)
{
if (file.exists())
@ -545,6 +565,7 @@ public class LocalStore extends Store implements Serializable
}
}
}
}
public void resetVisibleLimits()
{
@ -2603,8 +2624,12 @@ public class LocalStore extends Store implements Serializable
private File getAttachmentsDir()
{
if (useExternalAttachmentDir())
if (usesExternalAttachmentDir())
{
if (!mExternalAttachmentsDir.exists())
{
mExternalAttachmentsDir.mkdirs();
}
return mExternalAttachmentsDir;
}
else {
@ -2612,7 +2637,7 @@ public class LocalStore extends Store implements Serializable
}
}
private boolean useExternalAttachmentDir()
private boolean usesExternalAttachmentDir()
{
if (mAccount.isStoreAttachmentOnSdCard()) {
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))