Skip to content

Commit

Permalink
Fix IOUtils#getResources resource leak
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Sep 28, 2024
1 parent 24929dc commit 9636f9a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions nova/src/main/kotlin/xyz/xenondevs/nova/util/data/IOUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlin.io.path.extension
import kotlin.io.path.inputStream
import kotlin.io.path.outputStream
import kotlin.math.max
import kotlin.streams.asSequence

private val ZIP_FILE = ZipFile(NOVA.novaJar)

Expand All @@ -29,17 +28,20 @@ private val ZIP_FILE = ZipFile(NOVA.novaJar)
*
* @param directory The directory the resources should be in
*/
internal fun getResources(directory: String = ""): Sequence<String> {
return ZIP_FILE.stream().asSequence().filter {
it.name.startsWith(directory) && !it.isDirectory && !it.name.endsWith(".class")
}.map(ZipEntry::getName)
internal fun getResources(directory: String = ""): List<String> {
return ZIP_FILE.stream()
.filter { it.name.startsWith(directory) && !it.isDirectory && !it.name.endsWith(".class") }
.map(ZipEntry::getName)
.toList()
}

// FIXME: resource leak
internal fun getResources(file: File, directory: String = ""): Sequence<String> {
return ZipFile(file).stream().asSequence().filter {
it.name.startsWith(directory) && !it.isDirectory && !it.name.endsWith(".class")
}.map(ZipEntry::getName)
internal fun getResources(file: File, directory: String = ""): List<String> {
return ZipFile(file).use {
it.stream()
.filter { it.name.startsWith(directory) && !it.isDirectory && !it.name.endsWith(".class") }
.map(ZipEntry::getName)
.toList()
}
}

/**
Expand Down

0 comments on commit 9636f9a

Please sign in to comment.