Skip to content

Commit

Permalink
fix(abg): fix file handle leak in jar creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Aug 22, 2024
1 parent b99bf8e commit 907a009
Showing 1 changed file with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.typesafegithub.workflows.mavenbinding

import com.intellij.util.io.PagedFileStorage
import java.io.BufferedInputStream
import java.io.File
import java.io.FileInputStream
Expand Down Expand Up @@ -30,7 +29,6 @@ internal fun OutputStream.createZipFile(contents: Path) =
zipFile(file.toFile(), zipOutputStream)
}
}
zipOutputStream.flush()
}

/**
Expand Down Expand Up @@ -61,17 +59,8 @@ private fun zipDirectory(
lastAccessTime = FileTime.fromMillis(0)
}
zos.putNextEntry(zipEntry)
val bis =
BufferedInputStream(
FileInputStream(file),
)
var bytesRead: Long = 0
val bytesIn = ByteArray(PagedFileStorage.BUFFER_SIZE)
var read: Int
while ((bis.read(bytesIn).also { read = it }) != -1) {
zos.write(bytesIn, 0, read)
bytesRead += read.toLong()
}
BufferedInputStream(FileInputStream(file))
.use { it.copyTo(zos) }
zos.closeEntry()
}
}
Expand All @@ -97,18 +86,7 @@ private fun zipFile(
lastAccessTime = FileTime.fromMillis(0)
}
zos.putNextEntry(zipEntry)
val bis =
BufferedInputStream(
FileInputStream(
file,
),
)
var bytesRead: Long = 0
val bytesIn = ByteArray(PagedFileStorage.BUFFER_SIZE)
var read: Int
while ((bis.read(bytesIn).also { read = it }) != -1) {
zos.write(bytesIn, 0, read)
bytesRead += read.toLong()
}
BufferedInputStream(FileInputStream(file))
.use { it.copyTo(zos) }
zos.closeEntry()
}

0 comments on commit 907a009

Please sign in to comment.