commit
f38f1487c5
7 changed files with 29 additions and 9 deletions
|
|
@ -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() }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue