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.

Commit cc43b35

Browse files
SamMousajoelwurtz
authored andcommitted
Basic implementation of symlink traversal (#293)
1 parent a089906 commit cc43b35

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Context/ContextBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private function getFileFromDisk($directory, $source)
383383
if (!\array_key_exists($hash, $this->files)) {
384384
// Check if source is a directory or a file.
385385
if (\is_dir($source)) {
386-
$this->fs->mirror($source, $directory.'/'.$hash);
386+
$this->fs->mirror($source, $directory.'/'.$hash, null, ['copy_on_windows' => true]);
387387
} else {
388388
$this->fs->copy($source, $directory.'/'.$hash);
389389
}

tests/Context/ContextBuilderTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,31 @@ public function testTar(): void
269269
$this->assertInternalType('string', $content);
270270
$this->assertSame($context->toTar(), $content);
271271
}
272+
273+
public function testTraverseSymlinks(): void
274+
{
275+
$contextBuilder = new ContextBuilder();
276+
$dir = \tempnam('', '');
277+
\unlink($dir);
278+
\mkdir($dir);
279+
$file = $dir.'/test';
280+
281+
\file_put_contents($file, 'abc');
282+
283+
$linkFile = $file.'-symlink';
284+
\symlink($file, $linkFile);
285+
286+
$contextBuilder->addFile('/foo', $dir);
287+
288+
$context = $contextBuilder->getContext();
289+
290+
$filename = \preg_replace(<<<DOCKERFILE
291+
#FROM base
292+
ADD (.+?) /foo#
293+
DOCKERFILE
294+
, '$1', $context->getDockerfileContent());
295+
\unlink($file);
296+
$context->setCleanup(false);
297+
$this->assertStringEqualsFile($context->getDirectory().'/'.$filename.'/test-symlink', 'abc');
298+
}
272299
}

0 commit comments

Comments
 (0)