Skip to content

Commit da6ec9a

Browse files
committed
Only add class.pth if it exists in base directory
1 parent 6c516f8 commit da6ec9a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ public function run(): int {
6868
$z= ZipFile::create($this->target->asFile()->out());
6969

7070
$sources= iterator_to_array($this->sources);
71-
$total= sizeof($sources) + 1;
71+
$total= sizeof($sources);
72+
73+
// Add class path file to root if existant
74+
$p= new Path($this->sources->base, 'class.pth');
75+
if ($p->exists()) {
76+
$file= $z->add(new ZipFileEntry('class.pth'));
77+
$file->out()->write(preg_replace($this->exclude.'m', '?$1', file_get_contents($p)));
78+
Console::writeLinef("\e[34m => [1/%d] class.pth\e[0m", ++$total);
79+
}
80+
81+
// Add all other sources
7282
foreach ($sources as $i => $source) {
7383
Console::writef("\e[34m => [%d/%d] ", $i + 1, $total);
7484
$entries= 0;
@@ -79,10 +89,6 @@ public function run(): int {
7989
Console::writeLine("\e[0m");
8090
}
8191

82-
$file= $z->add(new ZipFileEntry('class.pth'));
83-
$file->out()->write(preg_replace($this->exclude.'m', '?$1', file_get_contents('class.pth')));
84-
Console::writeLinef("\e[34m => [%1\$d/%1\$d] class.pth\e[0m", $total);
85-
8692
$z->close();
8793
Console::writeLine();
8894
Console::writeLine('Wrote ', number_format(filesize($this->target)), ' bytes');

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function single_file() {
6565
$file= $zip->next();
6666
Assert::equals('file.txt', $file->getName());
6767
Assert::equals(4, $file->getSize());
68+
Assert::false($zip->hasNext());
6869
}
6970

7071
#[Test]
@@ -74,6 +75,7 @@ public function single_directory() {
7475
$dir= $zip->next();
7576
Assert::equals('src'.DIRECTORY_SEPARATOR, $dir->getName());
7677
Assert::true($dir->isDirectory());
78+
Assert::false($zip->hasNext());
7779
}
7880

7981
#[Test]
@@ -91,5 +93,7 @@ public function file_inside_directory() {
9193
$file= $zip->next();
9294
Assert::equals('src'.DIRECTORY_SEPARATOR.'file.txt', $file->getName());
9395
Assert::equals(4, $file->getSize());
96+
97+
Assert::false($zip->hasNext());
9498
}
9599
}

0 commit comments

Comments
 (0)