Skip to content

Commit f03b15d

Browse files
committed
refactor: use Files.createTempFile() directly
1 parent 15ff252 commit f03b15d

File tree

1 file changed

+8
-2
lines changed
  • commons/src/main/kotlin/org/fossify/commons/extensions

1 file changed

+8
-2
lines changed

commons/src/main/kotlin/org/fossify/commons/extensions/Activity.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,19 @@ private fun BaseSimpleActivity.renameCasually(
12741274

12751275
fun Activity.createTempFile(file: File): File? {
12761276
return if (file.isDirectory) {
1277-
createTempDir("temp", "${System.currentTimeMillis()}", file.parentFile)
1277+
val dir = File.createTempFile("temp", "${System.currentTimeMillis()}", file.parentFile)
1278+
dir.delete()
1279+
if (dir.mkdir()) {
1280+
return dir
1281+
} else {
1282+
throw IOException("Unable to create temporary directory $dir.")
1283+
}
12781284
} else {
12791285
if (isRPlus()) {
12801286
// this can throw FileSystemException, lets catch and handle it at the place calling this function
12811287
kotlin.io.path.createTempFile(file.parentFile.toPath(), "temp", "${System.currentTimeMillis()}").toFile()
12821288
} else {
1283-
createTempFile("temp", "${System.currentTimeMillis()}", file.parentFile)
1289+
File.createTempFile("temp", "${System.currentTimeMillis()}", file.parentFile)
12841290
}
12851291
}
12861292
}

0 commit comments

Comments
 (0)