Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Basic implementation of symlink traversal #293

Merged
merged 1 commit into from
Feb 21, 2018
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
2 changes: 1 addition & 1 deletion src/Context/ContextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Context/ContextBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<<DOCKERFILE
#FROM base
ADD (.+?) /foo#
DOCKERFILE
, '$1', $context->getDockerfileContent());
\unlink($file);
$context->setCleanup(false);
$this->assertStringEqualsFile($context->getDirectory().'/'.$filename.'/test-symlink', 'abc');
}
}