Fixed determining if folder is writable

This commit is contained in:
dankito 2024-09-20 05:49:42 +02:00
parent b5dbf92b9b
commit abc9ceb29e
1 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,9 @@ import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlSchema import app.cash.sqldelight.db.SqlSchema
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import java.io.File import java.io.File
import java.nio.file.Files
import kotlin.io.path.Path
import kotlin.io.path.absolutePathString
val dataDirectory: File = determineDataDirectory() val dataDirectory: File = determineDataDirectory()
@ -27,10 +30,11 @@ actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema<QueryResult.A
private fun determineDataDirectory(): File { private fun determineDataDirectory(): File {
val currentDir = File(System.getProperty("user.dir")) val currentDir = Path(System.getProperty("user.dir"))
val dataDir = if (currentDir.canWrite()) { // if the current directory is writable, use that one (the default for development) // if the current directory is writable, use that one (the default for development)
File(currentDir, "data") val dataDir = if (Files.isWritable(currentDir)) { // couldn't believe it, but java.io.File returned folder is writable for "C:\\Program Files\\"
File(currentDir.absolutePathString(), "data")
} else { // otherwise use .bankmeister dir in user's home dir (the default for releases) } else { // otherwise use .bankmeister dir in user's home dir (the default for releases)
val userHome = System.getProperty("user.home") val userHome = System.getProperty("user.home")
File(userHome, ".bankmeister") File(userHome, ".bankmeister")