2

I have created a zip file using OpenJDK 11 and Apache Commons Compress 1.20 which is returned by an API using a Netty server. This zip file contains a gradle wrapper that has executable file permissions (755).

-rwxr-xr-x  1 myuser  mygroup  5766 Aug 24 16:03 gradlew

I zip it with Commons Compress, return it in the API response, and the browser saves the zip to disk.

If I extract the zip file in MacOS Mojave the gradle wrapper file looks like this (with extended file attributes listing):

ls -al@ gradlew
-rwxr-xr-x@  1 myuser  mygroup    5766 Nov 30  1979 gradlew
    com.apple.quarantine        56

Ok, it's quarantined, but still executable. It works fine to execute it.

If I extract the zip file in MacOS Catalina the gradle wrapper file looks like this (with extended file attributes listing):

ls -al@ gradlew
-rw-rw-r--@  1 myuser  mygroup    5766 Nov 30  1979 gradlew
    com.apple.quarantine        57

The executable file permissions have been removed by Catalina. Is there some way to circumvent this, except by adding the executable file permissions after unzipping?

BunnyRabbit
  • 347
  • 1
  • 2
  • 12

1 Answers1

0

I've come across similar issue recently and found the solution at Spring Initializr source code

In short, the solution is to modify permissions of gradlew archive entry to make it executable after unarchiving.

Here is an example of code I used, it is on Kotlin but can be easily converted into Java if required.

val entry = ZipArchiveEntry(file, name)

entry.unixMode = if (Files.isDirectory(path)) {
     UnixStat.DIR_FLAG or UnixStat.DEFAULT_DIR_PERM
} else {
    UnixStat.FILE_FLAG or if (entryName == "gradlew") UnixStat.DEFAULT_DIR_PERM else UnixStat.DEFAULT_FILE_PERM
}
Viacheslav Kormushkin
  • 1,323
  • 2
  • 7
  • 11