From 64c0b37558eb6dc898ec66e5c85d428880dae11b Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Fri, 19 Jul 2024 11:52:08 +0300 Subject: [PATCH] fix: Create Keyguard downloads directory if it doesn't exist --- .../kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt | 3 +++ .../kotlin/com/artemchep/keyguard/copy/DataDirectory.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt b/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt index 6e68c1e1..816988fa 100644 --- a/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt +++ b/common/src/androidMain/kotlin/com/artemchep/keyguard/copy/DirsServiceAndroid.kt @@ -49,6 +49,9 @@ class DirsServiceAndroid( val downloadsDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) val file = downloadsDir.resolve(fileName) + // Ensure the parent directory does exist + // before writing the file. + file.parentFile?.mkdirs() file.outputStream() .use { write(it) diff --git a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt index 14682300..297f9f46 100644 --- a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt +++ b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/DataDirectory.kt @@ -47,6 +47,9 @@ class DataDirectory( .bind() .let(::File) val file = downloadsDir.resolve(fileName) + // Ensure the parent directory does exist + // before writing the file. + file.parentFile?.mkdirs() file.outputStream() .use { write(it)