Merge pull request #626 from vector-im/feature/bma/sonar

Sonar
This commit is contained in:
Benoit Marty 2023-06-21 10:41:26 +02:00 committed by GitHub
commit f38f1487c5
7 changed files with 29 additions and 9 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() }