Skip to content

Commit 401c02d

Browse files
committed
Fixed createIfNotExists logic
1 parent d3bdf16 commit 401c02d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

common/src/main/kotlin/com/lambda/util/FileUtils.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ object FileUtils {
9090
* @param block Lambda executed if the file doesn't exist or the file is empty
9191
*/
9292
inline fun File.createIfNotExists(block: (File) -> Unit): File {
93-
if (length() == 0L) block(this)
93+
if (length() == 0L) {
94+
parentFile.mkdirs()
95+
createNewFile()
9496

95-
parentFile.mkdirs()
96-
createNewFile()
97+
block(this)
98+
}
9799

98100
return this
99101
}

0 commit comments

Comments
 (0)