Skip to content

Explicit configured file permissions in FileDetails not respected by Deb and Rpm task #472

Description

@breskeby

we are configuring file permissions explictly in a copySpec like this:

    modulesFiles = { os, architecture ->
      copySpec {
        eachFile {
          if (it.relativePath.segments[-2] == 'bin' || (os == 'darwin' && it.relativePath.segments[-2] == 'MacOS')) {
            // bin files, wherever they are within modules (eg platform specific) should be executable
            // and MacOS is an alternative to bin on macOS
            it.permissions.unix(0755)
          } else {
            it.permissions.unix(0644)
          }
        }
...
...

this stopped working in 12.1.0 due to the workaround I have found here:

static int getUnixPermission(FileCopyDetails details) {
int newApiMode = details.permissions.toUnixNumeric()
// Gradle 9.0 permissions API may not detect executable bits correctly
// Fallback: check the actual file permissions if the API seems wrong
try {
if (details.file?.canExecute() && (newApiMode & 0111) == 0) {
// File is executable but new API didn't detect it - use filesystem check
boolean readable = details.file.canRead()
boolean writable = details.file.canWrite()
boolean executable = details.file.canExecute()
if (readable && writable && executable) {
return 0755 // rwxr-xr-x
} else if (readable && executable) {
return 0555 // r-xr-xr-x
} else {
return 0644 // rw-r--r--
}
}
} catch (Exception e) {
return newApiMode
}
return newApiMode
}

I think we can workaround this in this particular szenario by fixing the initial permissions but I would like to have the ultimate control over the permissiosn set in our packages in the task itself. I don't understand yet what the original issue with the permission api is that caused this but happy to drive this forward. at least having a way to step out of that workaround would be great for us as we explicitly configure the permissions for our system packages all over the place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions