mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-21 05:01:54 -05:00
Some minor code cleanings and logging for LockableDatabase
This commit is contained in:
parent
eced036d69
commit
9dba60c997
@ -376,24 +376,12 @@ public class LockableDatabase {
|
|||||||
try {
|
try {
|
||||||
final File databaseFile = prepareStorage(mStorageProviderId);
|
final File databaseFile = prepareStorage(mStorageProviderId);
|
||||||
try {
|
try {
|
||||||
if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
|
doOpenOrCreateDb(application, databaseFile);
|
||||||
// internal storage
|
|
||||||
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null);
|
|
||||||
} else {
|
|
||||||
// external storage
|
|
||||||
mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
|
|
||||||
}
|
|
||||||
} catch (SQLiteException e) {
|
} catch (SQLiteException e) {
|
||||||
// try to gracefully handle DB corruption - see issue 2537
|
// try to gracefully handle DB corruption - see issue 2537
|
||||||
Log.w(K9.LOG_TAG, "Unable to open DB " + databaseFile + " - removing file and retrying", e);
|
Log.w(K9.LOG_TAG, "Unable to open DB " + databaseFile + " - removing file and retrying", e);
|
||||||
databaseFile.delete();
|
databaseFile.delete();
|
||||||
if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
|
doOpenOrCreateDb(application, databaseFile);
|
||||||
// internal storage
|
|
||||||
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE, null);
|
|
||||||
} else {
|
|
||||||
// external storage
|
|
||||||
mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
|
if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
|
||||||
mSchemaDefinition.doDbUpgrade(mDb);
|
mSchemaDefinition.doDbUpgrade(mDb);
|
||||||
@ -403,6 +391,17 @@ public class LockableDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doOpenOrCreateDb(final Application application, final File databaseFile) {
|
||||||
|
if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
|
||||||
|
// internal storage
|
||||||
|
mDb = application.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE,
|
||||||
|
null);
|
||||||
|
} else {
|
||||||
|
// external storage
|
||||||
|
mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param providerId
|
* @param providerId
|
||||||
* Never <code>null</code>.
|
* Never <code>null</code>.
|
||||||
@ -412,10 +411,8 @@ public class LockableDatabase {
|
|||||||
protected File prepareStorage(final String providerId) throws UnavailableStorageException {
|
protected File prepareStorage(final String providerId) throws UnavailableStorageException {
|
||||||
final StorageManager storageManager = getStorageManager();
|
final StorageManager storageManager = getStorageManager();
|
||||||
|
|
||||||
final File databaseFile;
|
final File databaseFile = storageManager.getDatabase(uUid, providerId);
|
||||||
final File databaseParentDir;
|
final File databaseParentDir = databaseFile.getParentFile();
|
||||||
databaseFile = storageManager.getDatabase(uUid, providerId);
|
|
||||||
databaseParentDir = databaseFile.getParentFile();
|
|
||||||
if (databaseParentDir.isFile()) {
|
if (databaseParentDir.isFile()) {
|
||||||
// should be safe to unconditionally delete clashing file: user is not supposed to mess with our directory
|
// should be safe to unconditionally delete clashing file: user is not supposed to mess with our directory
|
||||||
databaseParentDir.delete();
|
databaseParentDir.delete();
|
||||||
@ -428,11 +425,8 @@ public class LockableDatabase {
|
|||||||
Utility.touchFile(databaseParentDir, ".nomedia");
|
Utility.touchFile(databaseParentDir, ".nomedia");
|
||||||
}
|
}
|
||||||
|
|
||||||
final File attachmentDir;
|
final File attachmentDir = storageManager.getAttachmentDirectory(uUid, providerId);
|
||||||
final File attachmentParentDir;
|
final File attachmentParentDir = attachmentDir.getParentFile();
|
||||||
attachmentDir = storageManager
|
|
||||||
.getAttachmentDirectory(uUid, providerId);
|
|
||||||
attachmentParentDir = attachmentDir.getParentFile();
|
|
||||||
if (!attachmentParentDir.exists()) {
|
if (!attachmentParentDir.exists()) {
|
||||||
attachmentParentDir.mkdirs();
|
attachmentParentDir.mkdirs();
|
||||||
Utility.touchFile(attachmentParentDir, ".nomedia");
|
Utility.touchFile(attachmentParentDir, ".nomedia");
|
||||||
@ -467,7 +461,8 @@ public class LockableDatabase {
|
|||||||
try {
|
try {
|
||||||
mDb.close();
|
mDb.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (K9.DEBUG)
|
||||||
|
Log.d(K9.LOG_TAG, "Exception caught in DB close: " + e.getMessage());
|
||||||
}
|
}
|
||||||
final StorageManager storageManager = getStorageManager();
|
final StorageManager storageManager = getStorageManager();
|
||||||
try {
|
try {
|
||||||
@ -482,6 +477,8 @@ public class LockableDatabase {
|
|||||||
attachmentDirectory.delete();
|
attachmentDirectory.delete();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (K9.DEBUG)
|
||||||
|
Log.d(K9.LOG_TAG, "Exception caught in clearing attachments: " + e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
deleteDatabase(storageManager.getDatabase(uUid, mStorageProviderId));
|
deleteDatabase(storageManager.getDatabase(uUid, mStorageProviderId));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user