mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-20 07:37:15 +00:00
fixes in FileKeyValueRepo
This commit is contained in:
parent
5ef3bb746b
commit
aa2d598689
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.11.8
|
||||
|
||||
* `Repos`:
|
||||
* `Common`:
|
||||
* Fixes in `FileKeyValueRepo`
|
||||
|
||||
## 0.11.7
|
||||
|
||||
* `Common`:
|
||||
|
@ -99,7 +99,9 @@ class FileWriteKeyValueRepo(
|
||||
override val onValueRemoved: Flow<String> = _onValueRemoved.asSharedFlow()
|
||||
|
||||
init {
|
||||
folder.mkdirs()
|
||||
if (!folder.mkdirs() && !folder.exists()) {
|
||||
error("Unable to create folder ${folder.absolutePath}")
|
||||
}
|
||||
filesChangedProcessingScope ?.let {
|
||||
it.launch {
|
||||
try {
|
||||
@ -144,15 +146,17 @@ class FileWriteKeyValueRepo(
|
||||
}
|
||||
|
||||
override suspend fun set(toSet: Map<String, File>) {
|
||||
supervisorScope {
|
||||
val scope = CoroutineScope(currentCoroutineContext())
|
||||
toSet.map { (filename, fileSource) ->
|
||||
launch {
|
||||
scope.launch {
|
||||
val file = File(folder, filename)
|
||||
|
||||
file.delete()
|
||||
fileSource.copyTo(file, overwrite = true)
|
||||
_onNewValue.emit(filename to file)
|
||||
if (!file.exists()) {
|
||||
error("Can't create file $file with new content")
|
||||
}
|
||||
_onNewValue.emit(filename to file)
|
||||
}
|
||||
}.joinAll()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user