Issue 318

When performing a database upgrade, clear all cached attachments and
attachment thumbnails
This commit is contained in:
Daniel Applebaum 2009-02-25 03:35:25 +00:00
parent 2615d70a1d
commit 6f8a243bcc
2 changed files with 35 additions and 7 deletions

View file

@ -94,23 +94,35 @@ public class LocalStore extends Store implements Serializable {
if (!parentDir.exists()) {
parentDir.mkdirs();
}
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
if (mDb.getVersion() != DB_VERSION) {
doDbUpgrade(mDb);
}
mAttachmentsDir = new File(mPath + "_att");
if (!mAttachmentsDir.exists()) {
mAttachmentsDir.mkdirs();
}
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
if (mDb.getVersion() != DB_VERSION) {
doDbUpgrade(mDb, application);
}
}
private void doDbUpgrade ( SQLiteDatabase mDb) {
private void doDbUpgrade ( SQLiteDatabase mDb, Application application) {
Log.i(Email.LOG_TAG, String.format("Upgrading database from version %d to version %d",
mDb.getVersion(), DB_VERSION));
try
{
pruneCachedAttachments(true);
}
catch (MessagingException me)
{
Log.e(Email.LOG_TAG, "Exception while force pruning attachments during DB update", me);
}
AttachmentProvider.clear(application);
mDb.execSQL("DROP TABLE IF EXISTS folders");
mDb.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
+ "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER, status TEXT)");

View file

@ -10,6 +10,7 @@ import java.util.List;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
@ -82,6 +83,21 @@ public class AttachmentProvider extends ContentProvider {
}
return true;
}
public static void clear(Context lContext) {
/*
* We use the cache dir as a temporary directory (since Android doesn't give us one) so
* on startup we'll clean up any .tmp files from the last run.
*/
File[] files = lContext.getCacheDir().listFiles();
for (File file : files) {
try {
Log.d(Email.LOG_TAG, "Deleting file " + file.getCanonicalPath());
}
catch (IOException ioe) {} // No need to log failure to log
file.delete();
}
}
@Override
public String getType(Uri uri) {