diff --git a/src/Context/ContextBuilder.php b/src/Context/ContextBuilder.php index 3643113a..74a4308b 100644 --- a/src/Context/ContextBuilder.php +++ b/src/Context/ContextBuilder.php @@ -383,7 +383,7 @@ private function getFileFromDisk($directory, $source) if (!\array_key_exists($hash, $this->files)) { // Check if source is a directory or a file. if (\is_dir($source)) { - $this->fs->mirror($source, $directory.'/'.$hash); + $this->fs->mirror($source, $directory.'/'.$hash, null, ['copy_on_windows' => true]); } else { $this->fs->copy($source, $directory.'/'.$hash); } diff --git a/tests/Context/ContextBuilderTest.php b/tests/Context/ContextBuilderTest.php index 81b7217c..828faa63 100644 --- a/tests/Context/ContextBuilderTest.php +++ b/tests/Context/ContextBuilderTest.php @@ -269,4 +269,31 @@ public function testTar(): void $this->assertInternalType('string', $content); $this->assertSame($context->toTar(), $content); } + + public function testTraverseSymlinks(): void + { + $contextBuilder = new ContextBuilder(); + $dir = \tempnam('', ''); + \unlink($dir); + \mkdir($dir); + $file = $dir.'/test'; + + \file_put_contents($file, 'abc'); + + $linkFile = $file.'-symlink'; + \symlink($file, $linkFile); + + $contextBuilder->addFile('/foo', $dir); + + $context = $contextBuilder->getContext(); + + $filename = \preg_replace(<<getDockerfileContent()); + \unlink($file); + $context->setCleanup(false); + $this->assertStringEqualsFile($context->getDirectory().'/'.$filename.'/test-symlink', 'abc'); + } }