mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
fix(storage): release core before clearing cache
This commit is contained in:
@@ -77,8 +77,8 @@ class CoreRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_state.update { it.copy(isInitialized = false, status = null) }
|
_state.update { it.copy(isInitialized = false, status = null) }
|
||||||
previousCore?.shutdown()
|
|
||||||
core = null
|
core = null
|
||||||
|
disposeCore(previousCore)
|
||||||
core = VnidropCore.initializeWithNetworkConfig(appDataDir, sink, relaySettings.toNative())
|
core = VnidropCore.initializeWithNetworkConfig(appDataDir, sink, relaySettings.toNative())
|
||||||
currentAppDataDir = appDataDir
|
currentAppDataDir = appDataDir
|
||||||
currentRelaySettings = relaySettings
|
currentRelaySettings = relaySettings
|
||||||
@@ -87,8 +87,9 @@ class CoreRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun shutdown() {
|
override fun shutdown() {
|
||||||
core?.shutdown()
|
val activeCore = core
|
||||||
core = null
|
core = null
|
||||||
|
disposeCore(activeCore)
|
||||||
currentAppDataDir = null
|
currentAppDataDir = null
|
||||||
_state.value = CoreState()
|
_state.value = CoreState()
|
||||||
}
|
}
|
||||||
@@ -183,8 +184,8 @@ class CoreRepository(
|
|||||||
val appDataDir = requireNotNull(currentAppDataDir) { "Core data directory is unavailable" }
|
val appDataDir = requireNotNull(currentAppDataDir) { "Core data directory is unavailable" }
|
||||||
val relaySettings = currentRelaySettings
|
val relaySettings = currentRelaySettings
|
||||||
_state.update { it.copy(isInitialized = false, status = null) }
|
_state.update { it.copy(isInitialized = false, status = null) }
|
||||||
activeCore.shutdown()
|
|
||||||
core = null
|
core = null
|
||||||
|
disposeCore(activeCore)
|
||||||
var reclaimed = 0UL
|
var reclaimed = 0UL
|
||||||
try {
|
try {
|
||||||
reclaimed = clearInactiveTransferCache(appDataDir)
|
reclaimed = clearInactiveTransferCache(appDataDir)
|
||||||
@@ -196,6 +197,16 @@ class CoreRepository(
|
|||||||
reclaimed
|
reclaimed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun disposeCore(activeCore: VnidropCore?) {
|
||||||
|
if (activeCore == null) return
|
||||||
|
try {
|
||||||
|
activeCore.shutdown()
|
||||||
|
} finally {
|
||||||
|
// UniFFI owns the Rust Arc; explicit disposal releases Windows file handles before cache deletion.
|
||||||
|
activeCore.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun receivedArtifacts(): Result<List<ReceivedArtifactModel>> = runCore { activeCore ->
|
override suspend fun receivedArtifacts(): Result<List<ReceivedArtifactModel>> = runCore { activeCore ->
|
||||||
activeCore.listReceivedArtifacts().map { artifact ->
|
activeCore.listReceivedArtifacts().map { artifact ->
|
||||||
ReceivedArtifactModel(
|
ReceivedArtifactModel(
|
||||||
|
|||||||
Reference in New Issue
Block a user