Save files with "wt" #1282

This commit is contained in:
J-Jamet
2022-04-04 12:21:35 +02:00
parent f86a5d1a19
commit 8411134adf
5 changed files with 23 additions and 49 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
}
}

View File

@@ -3,4 +3,5 @@
* Add advanced password filters #1052
* Add editable chars fields #539
* Add color for special password chars #454
* Passphrase implementation #218
* Passphrase implementation #218
* Fix small bugs #1282

View File

@@ -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
* Phrases secrètes #218
* Correction de petits bugs #1282