Fix the 6 issues reported by Sonar.
This commit is contained in:
parent
8b2121ae99
commit
2452d8aa91
7 changed files with 24 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import android.net.Uri
|
|||
import io.element.android.features.createroom.impl.configureroom.RoomPrivacy
|
||||
import io.element.android.features.createroom.impl.di.CreateRoomScope
|
||||
import io.element.android.features.createroom.impl.userlist.UserListDataStore
|
||||
import io.element.android.libraries.androidutils.file.safeDelete
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
@ -36,7 +37,7 @@ class CreateRoomDataStore @Inject constructor(
|
|||
private val createRoomConfigFlow: MutableStateFlow<CreateRoomConfig> = MutableStateFlow(CreateRoomConfig())
|
||||
private var cachedAvatarUri: Uri? = null
|
||||
set(value) {
|
||||
field?.path?.let { File(it) }?.delete()
|
||||
field?.path?.let { File(it) }?.safeDelete()
|
||||
field = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,7 @@ fun ConfirmAccountProviderView(
|
|||
id = if (state.isAccountCreation) {
|
||||
R.string.screen_account_provider_signup_subtitle
|
||||
} else {
|
||||
// Use same value for now.
|
||||
R.string.screen_account_provider_signup_subtitle
|
||||
R.string.screen_account_provider_signin_subtitle
|
||||
},
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<string name="screen_account_provider_form_notice">"Enter a search term or a domain address."</string>
|
||||
<string name="screen_account_provider_form_subtitle">"Search for a company, community, or private server."</string>
|
||||
<string name="screen_account_provider_form_title">"Find an account provider"</string>
|
||||
<string name="screen_account_provider_signin_subtitle">"This is where you conversations will live — just like you would use an email provider to keep your emails."</string>
|
||||
<string name="screen_account_provider_signin_title">"You’re about to sign in to %s"</string>
|
||||
<string name="screen_account_provider_signup_subtitle">"This is where you conversations will live — just like you would use an email provider to keep your emails."</string>
|
||||
<string name="screen_account_provider_signup_title">"You’re about to create an account on %s"</string>
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ fun File.safeDelete() {
|
|||
)
|
||||
}
|
||||
|
||||
fun File.safeRenameTo(dest: File) {
|
||||
tryOrNull(
|
||||
onError = {
|
||||
Timber.e(it, "Error, unable to rename file $path to ${dest.path}")
|
||||
},
|
||||
operation = {
|
||||
if (renameTo(dest).not()) {
|
||||
Timber.w("Warning, unable to rename file $path to ${dest.path}")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun Context.createTmpFile(baseDir: File = cacheDir, extension: String? = null): File {
|
||||
val suffix = extension?.let { ".$extension" }
|
||||
return File.createTempFile(UUID.randomUUID().toString(), suffix, baseDir).apply { mkdirs() }
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import androidx.exifinterface.media.ExifInterface
|
|||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.androidutils.file.createTmpFile
|
||||
import io.element.android.libraries.androidutils.file.getFileName
|
||||
import io.element.android.libraries.androidutils.file.safeRenameTo
|
||||
import io.element.android.libraries.androidutils.media.runAndRelease
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
|
|
@ -133,7 +134,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
private fun MediaUploadInfo.postProcess(uri: Uri): MediaUploadInfo {
|
||||
val name = context.getFileName(uri) ?: return this
|
||||
val renamedFile = File(context.cacheDir, name).also {
|
||||
file.renameTo(it)
|
||||
file.safeRenameTo(it)
|
||||
}
|
||||
return when (this) {
|
||||
is MediaUploadInfo.AnyFile -> copy(file = renamedFile)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.net.Uri
|
|||
import com.otaliastudios.transcoder.Transcoder
|
||||
import com.otaliastudios.transcoder.TranscoderListener
|
||||
import io.element.android.libraries.androidutils.file.createTmpFile
|
||||
import io.element.android.libraries.androidutils.file.safeDelete
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
|
|
@ -46,12 +47,12 @@ class VideoCompressor @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onTranscodeCanceled() {
|
||||
tmpFile.delete()
|
||||
tmpFile.safeDelete()
|
||||
close()
|
||||
}
|
||||
|
||||
override fun onTranscodeFailed(exception: Throwable) {
|
||||
tmpFile.delete()
|
||||
tmpFile.safeDelete()
|
||||
close(exception)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.push.impl.notifications
|
|||
|
||||
import android.content.Context
|
||||
import io.element.android.libraries.androidutils.file.EncryptedFileFactory
|
||||
import io.element.android.libraries.androidutils.file.safeDelete
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
|
|
@ -70,7 +71,7 @@ class NotificationEventPersistence @Inject constructor(
|
|||
fun persistEvents(queuedEvents: NotificationEventQueue) {
|
||||
Timber.tag(loggerTag.value).d("Serializing ${queuedEvents.rawEvents().size} NotifiableEvent(s)")
|
||||
// Always delete file before writing, or encryptedFile.openFileOutput() will throw
|
||||
file.delete()
|
||||
file.safeDelete()
|
||||
if (queuedEvents.isEmpty()) return
|
||||
try {
|
||||
encryptedFile.openFileOutput().use { fos ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue