Delete related files when deleting a database.

The journal file was not being deleted when an account was deleted.
Over time, one can end up with a collection of dead journal files.
This commit is contained in:
Joe Steele 2013-09-20 18:13:04 -04:00
parent 823c9ff1c5
commit 1afff1e38f
1 changed files with 17 additions and 1 deletions

View File

@ -5,10 +5,12 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Build;
import android.util.Log;
import com.fsck.k9.K9;
@ -479,7 +481,7 @@ public class LockableDatabase {
} catch (Exception e) {
}
try {
storageManager.getDatabase(uUid, mStorageProviderId).delete();
deleteDatabase(storageManager.getDatabase(uUid, mStorageProviderId));
} catch (Exception e) {
Log.i(K9.LOG_TAG, "LockableDatabase: delete(): Unable to delete backing DB file", e);
}
@ -495,4 +497,18 @@ public class LockableDatabase {
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void deleteDatabase(File database) {
boolean deleted = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
deleted = SQLiteDatabase.deleteDatabase(database);
} else {
deleted = database.delete();
deleted |= new File(database.getPath() + "-journal").delete();
}
if (!deleted) {
Log.i(K9.LOG_TAG,
"LockableDatabase: deleteDatabase(): No files deleted.");
}
}
}