Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dirMode handling and setgid fallback #443

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,21 @@ class DebCopyAction extends AbstractPackagingCopyAction<Deb> {
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,11 +181,14 @@ class RpmCopyAction extends AbstractPackagingCopyAction<Rpm> {

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

}

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 << """
Expand All @@ -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'))
Expand All @@ -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 << """
Expand All @@ -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'))
Expand Down Expand Up @@ -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
}
}
Loading