Fixed determining if folder is writable
This commit is contained in:
parent
b5dbf92b9b
commit
abc9ceb29e
|
@ -6,6 +6,9 @@ import app.cash.sqldelight.db.SqlDriver
|
|||
import app.cash.sqldelight.db.SqlSchema
|
||||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.absolutePathString
|
||||
|
||||
|
||||
val dataDirectory: File = determineDataDirectory()
|
||||
|
@ -27,10 +30,11 @@ actual fun createSqlDriverDriver(dbName: String, schema: SqlSchema<QueryResult.A
|
|||
|
||||
|
||||
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)
|
||||
File(currentDir, "data")
|
||||
// if the current directory is writable, use that one (the default for development)
|
||||
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)
|
||||
val userHome = System.getProperty("user.home")
|
||||
File(userHome, ".bankmeister")
|
||||
|
|
Loading…
Reference in New Issue