From 6b5a5db205bd5eaf40f2a8ba2445219ed0694366 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 1 Nov 2018 18:39:07 +0100 Subject: [PATCH] ArchiveUtils: Also restore Unix mode bits when unzip-ing Unfortunately, we still need to make BoyerLc executable manually. --- scanner/src/main/kotlin/scanners/BoyterLc.kt | 3 +-- utils/src/main/kotlin/ArchiveUtils.kt | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scanner/src/main/kotlin/scanners/BoyterLc.kt b/scanner/src/main/kotlin/scanners/BoyterLc.kt index 7eb108902f20f..293bc78beb413 100644 --- a/scanner/src/main/kotlin/scanners/BoyterLc.kt +++ b/scanner/src/main/kotlin/scanners/BoyterLc.kt @@ -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) } diff --git a/utils/src/main/kotlin/ArchiveUtils.kt b/utils/src/main/kotlin/ArchiveUtils.kt index 2c0fc1daa027e..4d7a37f6db87f 100644 --- a/utils/src/main/kotlin/ArchiveUtils.kt +++ b/utils/src/main/kotlin/ArchiveUtils.kt @@ -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) + } + } } } }