Skip to content

Commit

Permalink
fix FileNotFoundException: ~.maestro/sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Jul 29, 2024
1 parent 8b5eeb0 commit 6b238df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 5 additions & 1 deletion maestro-cli/src/main/java/maestro/cli/db/KeyValueStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import kotlin.concurrent.write
class KeyValueStore(private val dbFile: File) {
private val lock = ReentrantReadWriteLock()

init {
dbFile.createNewFile()
}

fun get(key: String): String? = lock.read { getCurrentDB()[key] }

fun set(key: String, value: String) = lock.write {
Expand Down Expand Up @@ -40,4 +44,4 @@ class KeyValueStore(private val dbFile: File) {
.joinToString("\n")
)
}
}
}
14 changes: 5 additions & 9 deletions maestro-cli/src/main/java/maestro/cli/session/SessionStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ object SessionStore {

private val keyValueStore by lazy {
KeyValueStore(
Paths
.get(
System.getProperty("user.home"),
".maestro",
"sessions"
)
dbFile = Paths
.get(System.getProperty("user.home"), ".maestro", "sessions")
.toFile()
.also { it.parentFile.mkdirs() }
)
Expand All @@ -23,8 +19,8 @@ object SessionStore {
fun heartbeat(sessionId: String, platform: Platform) {
synchronized(keyValueStore) {
keyValueStore.set(
key(sessionId, platform),
System.currentTimeMillis().toString()
key = key(sessionId, platform),
value = System.currentTimeMillis().toString(),
)

pruneInactiveSessions()
Expand Down Expand Up @@ -74,4 +70,4 @@ object SessionStore {
return "${platform}_$sessionId"
}

}
}

0 comments on commit 6b238df

Please sign in to comment.