mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-17 07:30:16 -05:00
Issue 318
When performing a database upgrade, clear all cached attachments and attachment thumbnails
This commit is contained in:
parent
2615d70a1d
commit
6f8a243bcc
@ -94,23 +94,35 @@ public class LocalStore extends Store implements Serializable {
|
|||||||
if (!parentDir.exists()) {
|
if (!parentDir.exists()) {
|
||||||
parentDir.mkdirs();
|
parentDir.mkdirs();
|
||||||
}
|
}
|
||||||
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
|
|
||||||
if (mDb.getVersion() != DB_VERSION) {
|
|
||||||
doDbUpgrade(mDb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
mAttachmentsDir = new File(mPath + "_att");
|
mAttachmentsDir = new File(mPath + "_att");
|
||||||
if (!mAttachmentsDir.exists()) {
|
if (!mAttachmentsDir.exists()) {
|
||||||
mAttachmentsDir.mkdirs();
|
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",
|
Log.i(Email.LOG_TAG, String.format("Upgrading database from version %d to version %d",
|
||||||
mDb.getVersion(), DB_VERSION));
|
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("DROP TABLE IF EXISTS folders");
|
||||||
mDb.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
|
mDb.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
|
||||||
+ "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER, status TEXT)");
|
+ "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER, status TEXT)");
|
||||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
@ -83,6 +84,21 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
return true;
|
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
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(Uri uri) {
|
||||||
List<String> segments = uri.getPathSegments();
|
List<String> segments = uri.getPathSegments();
|
||||||
|
Loading…
Reference in New Issue
Block a user