mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-06 17:10:48 +08:00
[Review] FileCacheStrategy: delete temp file on closure
This commit is contained in:
parent
2abeb329f6
commit
98545e6f6f
@ -82,10 +82,15 @@ public interface FileCacheStrategy {
|
|||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun newCache(input: InputStream, formatName: String?): ExternalResource {
|
override fun newCache(input: InputStream, formatName: String?): ExternalResource {
|
||||||
return createTempFile().apply {
|
val file = createTempFile()
|
||||||
|
return file.apply {
|
||||||
deleteOnExit()
|
deleteOnExit()
|
||||||
outputStream().use { out -> input.copyTo(out) }
|
outputStream().use { out -> input.copyTo(out) }
|
||||||
}.toExternalResource(formatName)
|
}.toExternalResource(formatName).apply {
|
||||||
|
closed.invokeOnCompletion {
|
||||||
|
kotlin.runCatching { file.delete() }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user