Skip to content

Commit 736bd1f

Browse files
committed
Check if the given path exists in add()
1 parent 66bf004 commit 736bd1f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ public function __construct(Path $target, Sources $sources, string $exclude= '#(
3030
private function add(ZipArchiveWriter $zip, Path $path, Path $base, $prefix= '') {
3131
if (preg_match($this->exclude, $path->toString('/'))) return;
3232

33-
$stat= lstat($path);
34-
$relative= $prefix.$path->relativeTo($base);
33+
// Check if the given path exists, suppressing any warnings
34+
if (false === ($stat= lstat($path))) {
35+
\xp::gc(__FILE__, __LINE__ - 1);
36+
return;
37+
}
3538

3639
// Handle the following file types:
3740
// - Links: Resolve, then handle link targets
3841
// - Files: Add to ZIP
3942
// - Folders: Recursively add all subfolders and files therein
43+
$relative= $prefix.$path->relativeTo($base);
4044
if (Sources::IS_LINK === ($stat['mode'] & Sources::IS_LINK)) {
4145
$target= new Path(readlink($path));
4246
$resolved= Path::real($target->isAbsolute() ? $target : [$path->parent(), $target], $base);
43-
if (!$resolved->exists()) return;
44-
4547
if ($resolved->isFile()) {
4648
$base= new Path(dirname($resolved));
4749
$relative= dirname($relative);

0 commit comments

Comments
 (0)