nebula-plugins / gradle-ospackage-plugin

Gradle plugin for constructing linux packages, specifically RPM and DEBs.
Apache License 2.0
368 stars 129 forks source link

FileCopyDetails.setMode not respected - CopySpec fileMode overrides #427

Open aldendaley opened 1 year ago

aldendaley commented 1 year ago

When configuring into-from CopySpec details for the ospackage/buildRpm, fileMode can be set for all files applicable to the the copy. There may be a need to set different file permissions on individual files. This can be accomplished through FileCopyDetails.setMode(), under a filesMatching(..) block. Gradle's native distribution plugin output from installDist respects the individually set modes, but the RPM doesn't.

ospackage {
    (..)
    into '/some/path/filePermissionTest'

    fileMode = 0664

    into('destDir1') {
        fileMode = 0644

        from ('srcDir1') {
            // srcDir1\file.txt
            // srcDir1\file.sh

            fileMode = 0640

            filesMatching('**/*.sh') {
                it.setMode(0700)
            }
        }
    }
}

installDist output and expected outcome - the .sh script is 0700

-rwx------. file.sh
-rw-r-----. file.txt

Installed RPM output - the .sh script gets the spec's fileMode 0640

-rw-r-----. file.sh
-rw-r-----. file.txt

https://github.com/nebula-plugins/gradle-ospackage-plugin/blob/ae9152c02ca066b0a3da99e6ccb7da46a083cb9d/src/main/groovy/com/netflix/gradle/plugins/rpm/RpmCopyAction.groovy#LL164C16-L164C16

The RpmCopyAction.visitFile looks like it will always apply the fileMode from the spec - would I be wrong in thinking visitFile(..) should not reference the spec's fileMode at all, and always rely on the fileDetails.mode?

int fileMode = lookup(specToLookAt, 'fileMode') ?: fileDetails.mode

becomes

int fileMode = fileDetails.mode