diff --git a/src/main/groovy/com/netflix/gradle/plugins/deb/DebCopyAction.groovy b/src/main/groovy/com/netflix/gradle/plugins/deb/DebCopyAction.groovy index ba4bf627..4ddc7794 100755 --- a/src/main/groovy/com/netflix/gradle/plugins/deb/DebCopyAction.groovy +++ b/src/main/groovy/com/netflix/gradle/plugins/deb/DebCopyAction.groovy @@ -131,20 +131,21 @@ class DebCopyAction extends AbstractPackagingCopyAction { def specCreateDirectoryEntry = lookup(specToLookAt, 'createDirectoryEntry') boolean createDirectoryEntry = specCreateDirectoryEntry!=null ? specCreateDirectoryEntry : task.createDirectoryEntry if (createDirectoryEntry) { - logger.debug "adding directory {}", dirDetails.relativePath.pathString String user = lookup(specToLookAt, 'user') ?: task.user Integer uid = (Integer) lookup(specToLookAt, 'uid') ?: task.uid ?: 0 String group = lookup(specToLookAt, 'permissionGroup') ?: task.permissionGroup Integer gid = (Integer) lookup(specToLookAt, 'gid') ?: task.gid ?: 0 - Boolean setgid = lookup(specToLookAt, 'setgid') ?: task.setgid - - int fileMode = FilePermissionUtil.getUnixPermission(dirDetails) + Boolean setgid = lookup(specToLookAt, 'setgid') + int dirMode = FilePermissionUtil.getUnixPermission(dirDetails) + if (setgid == null) { + setgid = task.setgid + } if (setgid) { - fileMode = fileMode | 02000 + dirMode = dirMode | 02000 } - debFileVisitorStrategy.addDirectory(dirDetails, user, uid, group, gid, fileMode) + debFileVisitorStrategy.addDirectory(dirDetails, user, uid, group, gid, dirMode) } } diff --git a/src/main/groovy/com/netflix/gradle/plugins/packaging/SystemPackagingExtension.groovy b/src/main/groovy/com/netflix/gradle/plugins/packaging/SystemPackagingExtension.groovy index 1564928c..2432edc6 100755 --- a/src/main/groovy/com/netflix/gradle/plugins/packaging/SystemPackagingExtension.groovy +++ b/src/main/groovy/com/netflix/gradle/plugins/packaging/SystemPackagingExtension.groovy @@ -47,7 +47,7 @@ class SystemPackagingExtension { File signingKeyRingFile String user String permissionGroup // Group is used by Gradle on tasks. - Boolean setgid + boolean setgid /** * In Debian, this is the Section and has to be provided. Valid values are: admin, cli-mono, comm, database, debug, diff --git a/src/main/groovy/com/netflix/gradle/plugins/rpm/RpmCopyAction.groovy b/src/main/groovy/com/netflix/gradle/plugins/rpm/RpmCopyAction.groovy index 2152268d..bf9e0610 100755 --- a/src/main/groovy/com/netflix/gradle/plugins/rpm/RpmCopyAction.groovy +++ b/src/main/groovy/com/netflix/gradle/plugins/rpm/RpmCopyAction.groovy @@ -36,8 +36,6 @@ import org.redline_rpm.payload.Directive import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.nio.channels.FileChannel - import static com.netflix.gradle.plugins.utils.GradleUtils.lookup @CompileDynamic @@ -183,11 +181,14 @@ class RpmCopyAction extends AbstractPackagingCopyAction { if (createDirectoryEntry) { logger.debug 'adding directory {}', dirDetails.relativePath.pathString - int dirMode = lookup(specToLookAt, 'dirMode') ?: FilePermissionUtil.getUnixPermission(dirDetails) + int dirMode = FilePermissionUtil.getDirMode(specToLookAt) ?: FilePermissionUtil.getUnixPermission(dirDetails) Directive directive = (Directive) lookup(specToLookAt, 'fileType') ?: task.fileType String user = lookup(specToLookAt, 'user') ?: task.user String group = lookup(specToLookAt, 'permissionGroup') ?: task.permissionGroup - Boolean setgid = lookup(specToLookAt, 'setgid') ?: task.setgid + Boolean setgid = lookup(specToLookAt, 'setgid') + if (setgid == null) { + setgid = task.setgid + } if (setgid) { dirMode = dirMode | 02000 } diff --git a/src/test/groovy/com/netflix/gradle/plugins/rpm/RpmPluginIntegrationTest.groovy b/src/test/groovy/com/netflix/gradle/plugins/rpm/RpmPluginIntegrationTest.groovy index 464f1dfd..1e0ceb8f 100644 --- a/src/test/groovy/com/netflix/gradle/plugins/rpm/RpmPluginIntegrationTest.groovy +++ b/src/test/groovy/com/netflix/gradle/plugins/rpm/RpmPluginIntegrationTest.groovy @@ -17,10 +17,10 @@ class RpmPluginIntegrationTest extends BaseIntegrationTestKitSpec { @Issue("https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/82") def "rpm task is marked up-to-date when setting arch or os property"() { - given: - File libDir = new File(projectDir, 'lib') - libDir.mkdirs() - new File(libDir, 'a.java').text = "public class A { }" + given: + File libDir = new File(projectDir, 'lib') + libDir.mkdirs() + new File(libDir, 'a.java').text = "public class A { }" buildFile << ''' plugins { id 'com.netflix.nebula.rpm' @@ -167,7 +167,7 @@ task buildRpm(type: Rpm) { def scanFiles = Scanner.scan(file('build/distributions/sample-1.0.0.noarch.rpm')).files ['./usr/local/myproduct', './usr/local/myproduct/bin', './usr/local/myproduct/bin/apple', './usr/share/myproduct', './usr/share/myproduct/etc', './usr/share/myproduct/etc/banana'] == scanFiles*.name - [ DIR, DIR, FILE, DIR, DIR, FILE] == scanFiles*.type + [DIR, DIR, FILE, DIR, DIR, FILE] == scanFiles*.type } @@ -200,10 +200,10 @@ task buildRpm(type: Rpm) { then: def scan = Scanner.scan(file('build/distributions/sample-1.0.0.noarch.rpm')) - def scannerApple = scan.files.find { it.name =='./usr/local/myproduct/bin/apple'} + def scannerApple = scan.files.find { it.name == './usr/local/myproduct/bin/apple' } scannerApple.asString() == '/usr/local/myproduct/apple' } - + def 'verifyCopySpecCanComeFromExtension'() { given: File srcDir = new File(projectDir, 'src') @@ -302,9 +302,9 @@ task buildRpm(type: Rpm) { given: File packageDir = directory("package") packageDir.mkdirs() - File target = new File(packageDir,"my-script.sh") + File target = new File(packageDir, "my-script.sh") target.createNewFile() - File file = new File(packageDir,'bin/my-symlink') + File file = new File(packageDir, 'bin/my-symlink') FileUtils.forceMkdirParent(file) java.nio.file.Files.createSymbolicLink(file.toPath(), target.toPath()) buildFile << """ @@ -320,7 +320,7 @@ task buildRpm(type: Rpm) { """ when: - runTasks('buildRpm', '--warning-mode', 'none') + runTasks('buildRpm') then: def scan = Scanner.scan(this.file('build/distributions/example-3.noarch.rpm')) @@ -333,9 +333,9 @@ task buildRpm(type: Rpm) { given: File packageDir = directory("package") packageDir.mkdirs() - File target = new File(packageDir,"my-script.sh") + File target = new File(packageDir, "my-script.sh") target.createNewFile() - File file = new File(packageDir,'bin/my-symlink') + File file = new File(packageDir, 'bin/my-symlink') FileUtils.forceMkdirParent(file) java.nio.file.Files.createSymbolicLink(file.toPath(), target.toPath()) buildFile << """ @@ -353,7 +353,7 @@ task buildRpm(type: Rpm) { """ when: - runTasks('buildRpm', '--warning-mode', 'none') + runTasks('buildRpm') then: def scan = Scanner.scan(this.file('build/distributions/example-4.noarch.rpm')) @@ -440,6 +440,94 @@ buildRpm { def scanFiles = Scanner.scan(file('build/distributions/sample-1.0.0.noarch.rpm')).files ['./usr/share/myproduct/etc/banana'] == scanFiles*.name - [ FILE] == scanFiles*.type - } + [FILE] == scanFiles*.type + } + + def 'setgid can be set in rpm and deb'() { + given: + File emptyFolder = new File(projectDir, 'test/someFolder/sub') + emptyFolder.mkdirs() + buildFile << """ +plugins { + id 'com.netflix.nebula.ospackage' } + +version = '1.0.0' + +ospackage { + addParentDirs false +} + +buildRpm { + packageName = 'sample' + + from(${GradleUtils.quotedIfPresent(emptyFolder.parentFile.path)}) { + createDirectoryEntry = true + setgid = ${setgidValue} + dirPermissions { + unix(0644) + } + into '/usr/share/myproduct/etc/' + } +} +""" + when: + runTasks('buildRpm') + + then: + def scanFiles = Scanner.scan(file('build/distributions/sample-1.0.0.noarch.rpm')).files + + ['./usr/share/myproduct/etc/sub'] == scanFiles*.name + [DIR] == scanFiles*.type + [expectedPermissions] == scanFiles*.permissions + + where: + setgidValue | expectedPermissions + true | 1444 + false | 0644 + } + + def 'setgid in ospackage extension propagates to rpm and deb'() { + given: + File emptyFolder = new File(projectDir, 'test/someFolder/sub') + emptyFolder.mkdirs() + buildFile << """ +plugins { + id 'com.netflix.nebula.ospackage' +} + +version = '1.0.0' + +ospackage { + addParentDirs false + setgid = ${setgidValue} +} + +buildRpm { + packageName = 'sample' + + from(${GradleUtils.quotedIfPresent(emptyFolder.parentFile.path)}) { + createDirectoryEntry = true + dirPermissions { + unix(0644) + } + into '/usr/share/myproduct/etc/' + } +} +""" + when: + runTasks('buildRpm', '--warning-mode', 'all', '--stacktrace') + + then: + def scanFiles = Scanner.scan(file('build/distributions/sample-1.0.0.noarch.rpm')).files + + ['./usr/share/myproduct/etc/sub'] == scanFiles*.name + [DIR] == scanFiles*.type + [expectedPermissions] == scanFiles*.permissions + + where: + setgidValue | expectedPermissions + true | 1444 + false | 0644 + } +} \ No newline at end of file