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

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