diff --git a/src/Cleanup.php b/src/Cleanup.php index 01e6e19d..511e016a 100644 --- a/src/Cleanup.php +++ b/src/Cleanup.php @@ -25,6 +25,7 @@ class Cleanup public function __construct(StraussConfig $config, string $workingDir) { $this->vendorDirectory = $config->getVendorDirectory(); + $this->workingDir = $workingDir; $this->isDeleteVendorFiles = $config->isDeleteVendorFiles() && $config->getTargetDirectory() !== $config->getVendorDirectory(); $this->isDeleteVendorPackages = $config->isDeleteVendorPackages() && $config->getTargetDirectory() !== $config->getVendorDirectory(); @@ -53,12 +54,24 @@ public function cleanup(array $sourceFiles): void foreach ($package_dirs as $package_dir) { $relativeDirectoryPath = $this->vendorDirectory . $package_dir; + $absolutePath = $this->workingDir . $relativeDirectoryPath; + + if ($absolutePath !== realpath($absolutePath)) { + continue; + } + $this->filesystem->deleteDir($relativeDirectoryPath); } } elseif ($this->isDeleteVendorFiles) { foreach ($sourceFiles as $sourceFile) { $relativeFilepath = $this->vendorDirectory . $sourceFile; + $absolutePath = $this->workingDir . $relativeFilepath; + + if ($absolutePath !== realpath($absolutePath)) { + continue; + } + $this->filesystem->delete($relativeFilepath); } }