Skip to content

Commit

Permalink
BoyterLc: Avoid creating temporary files for HTTP downloads
Browse files Browse the repository at this point in the history
This reduces file I/O to increase general performance.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information
sschuberth committed Jul 30, 2019
1 parent 648fe53 commit 56a9160
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions scanner/src/main/kotlin/scanners/BoyterLc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ import java.time.Instant

import okhttp3.Request

import okio.buffer
import okio.sink

class BoyterLc(name: String, config: ScannerConfiguration) : LocalScanner(name, config) {
class Factory : AbstractScannerFactory<BoyterLc>("BoyterLc") {
override fun create(config: ScannerConfiguration) = BoyterLc(scannerName, config)
Expand Down Expand Up @@ -89,7 +86,8 @@ class BoyterLc(name: String, config: ScannerConfiguration) : LocalScanner(name,
else -> throw IllegalArgumentException("Unsupported operating system.")
}

val url = "https://github.com/boyter/lc/releases/download/v$scannerVersion/lc-$scannerVersion-$platform.zip"
val archive = "lc-$scannerVersion-$platform.zip"
val url = "https://github.com/boyter/lc/releases/download/v$scannerVersion/$archive"

log.info { "Downloading $scannerName from $url... " }

Expand All @@ -106,16 +104,10 @@ class BoyterLc(name: String, config: ScannerConfiguration) : LocalScanner(name,
log.info { "Retrieved $scannerName from local cache." }
}

val scannerArchive = createTempFile("ort", url.substringAfterLast("/"))
scannerArchive.sink().buffer().use { it.writeAll(body.source()) }

val unpackDir = createTempDir("ort", "$scannerName-$scannerVersion").apply { deleteOnExit() }

log.info { "Unpacking '$scannerArchive' to '$unpackDir'... " }
scannerArchive.unpack(unpackDir)
if (!scannerArchive.delete()) {
log.warn { "Unable to delete temporary file '$scannerArchive'." }
}
log.info { "Unpacking '$archive' to '$unpackDir'... " }
body.byteStream().unpack(archive, unpackDir)

if (!Os.isWindows) {
// The Linux version is distributed as a ZIP, but without having the Unix executable mode bits stored.
Expand Down

0 comments on commit 56a9160

Please sign in to comment.