Skip to content

Commit

Permalink
ArchiveUtils: Also restore Unix mode bits when unzip-ing
Browse files Browse the repository at this point in the history
Unfortunately, we still need to make BoyerLc executable manually.
  • Loading branch information
sschuberth committed Nov 2, 2018
1 parent 17b795a commit 6b5a5db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions scanner/src/main/kotlin/scanners/BoyterLc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class BoyterLc(config: ScannerConfiguration) : LocalScanner(config) {
scannerArchive.unpack(unpackDir)

if (!OS.isWindows) {
// The Linux version is distributed as a ZIP, but our ZIP unpacker seems to be unable to properly handle
// Unix mode bits.
// The Linux version is distributed as a ZIP, but without having the Unix executable mode bits stored.
File(unpackDir, command()).setExecutable(true)
}

Expand Down
9 changes: 9 additions & 0 deletions utils/src/main/kotlin/ArchiveUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ fun File.unpackZip(targetDirectory: File) {
target.outputStream().use { output ->
it.copyTo(output)
}

if (!OS.isWindows) {
// Note: In contrast to Java, Kotlin does not support octal literals, see
// https://kotlinlang.org/docs/reference/basic-types.html#literal-constants.
// The bit-triplets from left to right stand for user, groups, other, respectively.
if (entry.unixMode and 0b001_000_001 != 0) {
target.setExecutable(true, (entry.unixMode and 0b000_000_001) == 0)
}
}
}
}
}
Expand Down

0 comments on commit 6b5a5db

Please sign in to comment.