Skip to content

Commit

Permalink
Check for symlinks before deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Dec 6, 2023
1 parent 8c7a6c7 commit 03b8814
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 03b8814

Please sign in to comment.