diff --git a/CHANGELOG b/CHANGELOG index b1abd3839..ed4fc3baa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ KeePassDX(3.4.0) * Add editable chars fields #539 * Add color for special password chars #454 * Passphrase implementation #218 + * Fix small bugs #1282 KeePassDX(3.3.3) * Fix shared otpauth link if database not open #1274 diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt index 004906cdf..189a14dbf 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/Database.kt @@ -913,53 +913,24 @@ class Database { try { val saveUri = databaseCopyUri ?: this.fileUri if (saveUri != null) { - if (saveUri.scheme == "file") { - saveUri.path?.let { filename -> - val tempFile = File("$filename.tmp") - - var fileOutputStream: FileOutputStream? = null - try { - fileOutputStream = FileOutputStream(tempFile) - val pmo = mDatabaseKDB?.let { DatabaseOutputKDB(it, fileOutputStream) } - ?: mDatabaseKDBX?.let { DatabaseOutputKDBX(it, fileOutputStream) } - pmo?.output() - } catch (e: Exception) { - throw IOException(e) - } finally { - fileOutputStream?.close() - } - - // Force data to disk before continuing - try { - fileOutputStream?.fd?.sync() - } catch (e: SyncFailedException) { - // Ignore if fsync fails. We tried. - } - - if (!tempFile.renameTo(File(filename))) { - throw IOException() - } - } - } else { - var outputStream: OutputStream? = null - try { - outputStream = contentResolver.openOutputStream(saveUri, "rwt") - outputStream?.let { definedOutputStream -> - val databaseOutput = - mDatabaseKDB?.let { DatabaseOutputKDB(it, definedOutputStream) } - ?: mDatabaseKDBX?.let { - DatabaseOutputKDBX( - it, - definedOutputStream - ) - } - databaseOutput?.output() - } - } catch (e: Exception) { - throw IOException(e) - } finally { - outputStream?.close() + var outputStream: OutputStream? = null + try { + outputStream = UriUtil.getUriOutputStream(contentResolver, saveUri) + outputStream?.let { definedOutputStream -> + val databaseOutput = + mDatabaseKDB?.let { DatabaseOutputKDB(it, definedOutputStream) } + ?: mDatabaseKDBX?.let { + DatabaseOutputKDBX( + it, + definedOutputStream + ) + } + databaseOutput?.output() } + } catch (e: Exception) { + throw IOException(e) + } finally { + outputStream?.close() } if (databaseCopyUri == null) { this.dataModifiedSinceLastLoading = false diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/UriUtil.kt b/app/src/main/java/com/kunzisoft/keepass/utils/UriUtil.kt index 5cd542d4f..ea75ec5a3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/utils/UriUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/utils/UriUtil.kt @@ -69,7 +69,7 @@ object UriUtil { return null return when { isFileScheme(fileUri) -> fileUri.path?.let { FileOutputStream(it) } - isContentScheme(fileUri) -> contentResolver.openOutputStream(fileUri, "rwt") + isContentScheme(fileUri) -> contentResolver.openOutputStream(fileUri, "wt") else -> null } } diff --git a/fastlane/metadata/android/en-US/changelogs/106.txt b/fastlane/metadata/android/en-US/changelogs/106.txt index 85ea65924..46ba28606 100644 --- a/fastlane/metadata/android/en-US/changelogs/106.txt +++ b/fastlane/metadata/android/en-US/changelogs/106.txt @@ -3,4 +3,5 @@ * Add advanced password filters #1052 * Add editable chars fields #539 * Add color for special password chars #454 - * Passphrase implementation #218 \ No newline at end of file + * Passphrase implementation #218 + * Fix small bugs #1282 \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/106.txt b/fastlane/metadata/android/fr-FR/changelogs/106.txt index 51055571e..a316ab8f6 100644 --- a/fastlane/metadata/android/fr-FR/changelogs/106.txt +++ b/fastlane/metadata/android/fr-FR/changelogs/106.txt @@ -3,4 +3,5 @@ * Ajout des filtres de mots de passe avancés #1052 * Ajout de champs éditable de génération #539 * Ajout des couleurs pour chaque caractère spécial de mots de passe #454 - * Phrases secrètes #218 \ No newline at end of file + * Phrases secrètes #218 + * Correction de petits bugs #1282 \ No newline at end of file