Skip to content

Commit 66bf004

Browse files
committed
Support symlinked files
1 parent 339b0d4 commit 66bf004

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/main/php/xp/lambda/PackageLambda.class.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ private function add(ZipArchiveWriter $zip, Path $path, Path $base, $prefix= '')
4040
if (Sources::IS_LINK === ($stat['mode'] & Sources::IS_LINK)) {
4141
$target= new Path(readlink($path));
4242
$resolved= Path::real($target->isAbsolute() ? $target : [$path->parent(), $target], $base);
43-
if ($resolved->exists()) {
44-
$base= $resolved->isFile() ? new Path(dirname($resolved)) : $resolved;
45-
yield from $this->add($zip, $resolved, $base, $relative.DIRECTORY_SEPARATOR);
43+
if (!$resolved->exists()) return;
44+
45+
if ($resolved->isFile()) {
46+
$base= new Path(dirname($resolved));
47+
$relative= dirname($relative);
48+
} else {
49+
$base= $resolved;
4650
}
51+
yield from $this->add($zip, $resolved, $base, $relative.DIRECTORY_SEPARATOR);
4752
} else if (Sources::IS_FILE === ($stat['mode'] & Sources::IS_FILE)) {
4853
$file= $zip->add(new ZipFileEntry($relative));
4954

src/test/php/com/amazon/aws/lambda/unittest/PackagingTest.class.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,39 @@ public function link_inside_directory($target) {
160160

161161
Assert::false($zip->hasNext());
162162
}
163+
164+
#[Test, Runtime(os: 'Linux'), Values(['../../libs/inc.pth', '%s/libs/inc.pth'])]
165+
public function link_to_file($target) {
166+
$tempDir= $this->tempDir();
167+
168+
$link= sprintf($target, rtrim($tempDir->getURI(), DIRECTORY_SEPARATOR));
169+
$path= $this->create([
170+
'libs/' => [Sources::IS_FOLDER, 0755],
171+
'libs/inc.pth' => [Sources::IS_FILE, 'src/main/php'],
172+
'project' => [Sources::IS_FOLDER, 0755],
173+
'project/src' => [Sources::IS_FOLDER, 0755],
174+
'project/src/file.txt' => [Sources::IS_FILE, 'Test'],
175+
'project/lib' => [Sources::IS_FOLDER, 0755],
176+
'project/lib/inc.pth' => [Sources::IS_LINK, $link],
177+
], $tempDir);
178+
$zip= $this->package(new Sources(new Path($path, 'project'), ['src', 'lib']));
179+
180+
$dir= $zip->next();
181+
Assert::equals('src/', $dir->getName());
182+
Assert::true($dir->isDirectory());
183+
184+
$file= $zip->next();
185+
Assert::equals('src/file.txt', $file->getName());
186+
Assert::equals(4, $file->getSize());
187+
188+
$lib= $zip->next();
189+
Assert::equals('lib/', $lib->getName());
190+
Assert::true($lib->isDirectory());
191+
192+
$path= $zip->next();
193+
Assert::equals('lib/inc.pth', $path->getName());
194+
Assert::equals(12, $path->getSize());
195+
196+
Assert::false($zip->hasNext());
197+
}
163198
}

0 commit comments

Comments
 (0)