Skip to content

Commit

Permalink
Merge pull request #332 from steven-aerts/fix_321
Browse files Browse the repository at this point in the history
Fix #321 copydetails relative path outside sourceBase
  • Loading branch information
rpalcolea authored May 28, 2019
2 parents 23decc1 + c69937a commit 96c2456
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final class GradleUtils {
static Tuple2<String, String> relativizeSymlink(FileCopyDetails details, File target) {
String sourcePath = details.file.path
String sourceBasePath = sourcePath.substring(0, sourcePath.length() - details.relativeSourcePath.pathString.length())
if (!target.path.startsWith(sourceBasePath)) {
// target is below sourceBasePath
return null
}
String sourceRelative = target.path.substring(sourceBasePath.length())
String sourceBase = details.path.substring(0, details.path.indexOf(sourceRelative))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import nebula.test.ProjectSpec
import nebula.test.dependencies.DependencyGraph
import nebula.test.dependencies.GradleDependencyGenerator
import org.apache.commons.io.FileUtils
import org.gradle.api.tasks.TaskExecutionException
import org.redline_rpm.header.Flags
import spock.lang.Issue
import spock.lang.Unroll
Expand Down Expand Up @@ -1338,4 +1337,31 @@ class DebPluginTest extends ProjectSpec {
packagedSymlink.isSymbolicLink()
packagedSymlink.linkName == '../source'
}
@Issue("https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/321")
def 'resolve symlinks outside build directory'() {
File outsideProjectDir = new File(projectDir.parentFile, projectDir.name + "-outside")
File source = new File(outsideProjectDir, "source")
if (outsideProjectDir.exists()) {
outsideProjectDir.deleteDir()
}
source.mkdirs()
def txtFile = new File(source, "test.txt")
txtFile.createNewFile()
File packageDir = new File(projectDir,"package")
java.nio.file.Files.createSymbolicLink(packageDir.toPath(), projectDir.toPath().relativize(outsideProjectDir.toPath()))
when:
project.apply plugin: 'nebula.deb'
Deb debTask = project.task([type: Deb], 'buildDeb', {
from('package')
})
debTask.copy()
then:
def scan = new Scanner(debTask.archiveFile.get().asFile)
scan.getEntry('./source/').isDirectory()
scan.getEntry("./source/test.txt").isFile()
}
}

0 comments on commit 96c2456

Please sign in to comment.