Loading app/core/src/main/java/com/fsck/k9/preferences/Storage.java +7 −2 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ public class Storage { private volatile ConcurrentMap<String, String> storage = new ConcurrentHashMap<>(); private static final int DB_VERSION = 2; private static final int DB_VERSION = 3; private static final String DB_NAME = "preferences_storage"; private ThreadLocal<ConcurrentMap<String, String>> workingStorage = new ThreadLocal<>(); Loading Loading @@ -264,11 +264,16 @@ public class Storage { } private void writeValue(SQLiteDatabase mDb, String key, String value) { if (value == null) { mDb.delete("preferences_storage", "primkey = ?", new String[] { key }); return; } ContentValues cv = new ContentValues(); cv.put("primkey", key); cv.put("value", value); long result = mDb.insert("preferences_storage", "primkey", cv); long result = mDb.update("preferences_storage", cv, "primkey = ?", new String[] { key }); if (result == -1) { Timber.e("Error writing key '%s', value = '%s'", key, value); Loading app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo3.kt 0 → 100644 +45 −0 Original line number Diff line number Diff line package com.fsck.k9.preferences.migrations import android.database.sqlite.SQLiteDatabase /** * Rewrite folder name values of "-NONE-" to `null` */ class StorageMigrationTo3( private val db: SQLiteDatabase, private val migrationsHelper: StorageMigrationsHelper ) { fun rewriteFolderNone() { val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids") if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) { return } val accountUuids = accountUuidsListValue.split(",") for (accountUuid in accountUuids) { rewriteAccount(accountUuid) } } private fun rewriteAccount(accountUuid: String) { rewriteFolderValue("$accountUuid.archiveFolderName") rewriteFolderValue("$accountUuid.autoExpandFolderName") rewriteFolderValue("$accountUuid.draftsFolderName") rewriteFolderValue("$accountUuid.sentFolderName") rewriteFolderValue("$accountUuid.spamFolderName") rewriteFolderValue("$accountUuid.trashFolderName") } private fun rewriteFolderValue(key: String) { val folderValue = migrationsHelper.readValue(db, key) if (folderValue == OLD_FOLDER_VALUE) { migrationsHelper.writeValue(db, key, NEW_FOLDER_VALUE) } } companion object { private const val OLD_FOLDER_VALUE = "-NONE-" private val NEW_FOLDER_VALUE = null } } app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrations.kt +1 −0 Original line number Diff line number Diff line Loading @@ -8,5 +8,6 @@ internal object StorageMigrations { val oldVersion = db.version if (oldVersion <= 1) StorageMigrationTo2.urlEncodeUserNameAndPassword(db, migrationsHelper) if (oldVersion <= 2) StorageMigrationTo3(db, migrationsHelper).rewriteFolderNone() } } Loading
app/core/src/main/java/com/fsck/k9/preferences/Storage.java +7 −2 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ public class Storage { private volatile ConcurrentMap<String, String> storage = new ConcurrentHashMap<>(); private static final int DB_VERSION = 2; private static final int DB_VERSION = 3; private static final String DB_NAME = "preferences_storage"; private ThreadLocal<ConcurrentMap<String, String>> workingStorage = new ThreadLocal<>(); Loading Loading @@ -264,11 +264,16 @@ public class Storage { } private void writeValue(SQLiteDatabase mDb, String key, String value) { if (value == null) { mDb.delete("preferences_storage", "primkey = ?", new String[] { key }); return; } ContentValues cv = new ContentValues(); cv.put("primkey", key); cv.put("value", value); long result = mDb.insert("preferences_storage", "primkey", cv); long result = mDb.update("preferences_storage", cv, "primkey = ?", new String[] { key }); if (result == -1) { Timber.e("Error writing key '%s', value = '%s'", key, value); Loading
app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrationTo3.kt 0 → 100644 +45 −0 Original line number Diff line number Diff line package com.fsck.k9.preferences.migrations import android.database.sqlite.SQLiteDatabase /** * Rewrite folder name values of "-NONE-" to `null` */ class StorageMigrationTo3( private val db: SQLiteDatabase, private val migrationsHelper: StorageMigrationsHelper ) { fun rewriteFolderNone() { val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids") if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) { return } val accountUuids = accountUuidsListValue.split(",") for (accountUuid in accountUuids) { rewriteAccount(accountUuid) } } private fun rewriteAccount(accountUuid: String) { rewriteFolderValue("$accountUuid.archiveFolderName") rewriteFolderValue("$accountUuid.autoExpandFolderName") rewriteFolderValue("$accountUuid.draftsFolderName") rewriteFolderValue("$accountUuid.sentFolderName") rewriteFolderValue("$accountUuid.spamFolderName") rewriteFolderValue("$accountUuid.trashFolderName") } private fun rewriteFolderValue(key: String) { val folderValue = migrationsHelper.readValue(db, key) if (folderValue == OLD_FOLDER_VALUE) { migrationsHelper.writeValue(db, key, NEW_FOLDER_VALUE) } } companion object { private const val OLD_FOLDER_VALUE = "-NONE-" private val NEW_FOLDER_VALUE = null } }
app/core/src/main/java/com/fsck/k9/preferences/migrations/StorageMigrations.kt +1 −0 Original line number Diff line number Diff line Loading @@ -8,5 +8,6 @@ internal object StorageMigrations { val oldVersion = db.version if (oldVersion <= 1) StorageMigrationTo2.urlEncodeUserNameAndPassword(db, migrationsHelper) if (oldVersion <= 2) StorageMigrationTo3(db, migrationsHelper).rewriteFolderNone() } }