Fix the 6 issues reported by Sonar.

This commit is contained in:
Benoit Marty 2023-06-16 18:08:20 +02:00
parent 8b2121ae99
commit 2452d8aa91
7 changed files with 24 additions and 7 deletions

View file

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