From 77d9e7a7535e237372a82bb7e87ca99ed9ab30ee Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 26 May 2024 17:50:11 -0700 Subject: [PATCH] symlinks --- src/Cleanup.php | 12 +------ .../Integration/Util/IntegrationTestCase.php | 35 +++---------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/src/Cleanup.php b/src/Cleanup.php index 378fefe0..271fbc43 100644 --- a/src/Cleanup.php +++ b/src/Cleanup.php @@ -62,15 +62,7 @@ public function cleanup(array $sourceFiles): void $absolutePath = $this->workingDir . $relativeDirectoryPath; - // Fix for Windows paths. - $absolutePath = str_replace(['\\','/'], DIRECTORY_SEPARATOR, $absolutePath); - - $filesystem = new \Symfony\Component\Filesystem\Filesystem(); - $isSymlink = function ($path) use ($filesystem): bool { - return ! is_null($filesystem->readlink($path)); - }; - - if ($isSymlink($absolutePath)) { + if ($absolutePath !== realpath($absolutePath)) { if (false !== strpos('WIN', PHP_OS)) { /** * `unlink()` will not work on Windows. `rmdir()` will not work if there are files in the directory. @@ -83,9 +75,7 @@ public function cleanup(array $sourceFiles): void } else { unlink($absolutePath); } - } - if ($absolutePath !== realpath($absolutePath)) { continue; } diff --git a/tests/Integration/Util/IntegrationTestCase.php b/tests/Integration/Util/IntegrationTestCase.php index 0efa8996..c1a55041 100644 --- a/tests/Integration/Util/IntegrationTestCase.php +++ b/tests/Integration/Util/IntegrationTestCase.php @@ -9,6 +9,8 @@ use BrianHenryIE\Strauss\Console\Commands\Compose; use BrianHenryIE\Strauss\TestCase; +use League\Flysystem\Filesystem; +use League\Flysystem\Local\LocalFilesystemAdapter; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use Symfony\Component\Console\Input\InputInterface; @@ -85,35 +87,8 @@ protected function deleteDir($dir) return; } - $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); - $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - - $filesystem = new \Symfony\Component\Filesystem\Filesystem(); - $isSymlink = function ($path) use ($filesystem): bool { - return ! is_null($filesystem->readlink($path)); - }; - - /** @var \SplFileInfo $file */ - foreach ($files as $file) { - if ($isSymlink($file->getPath())) { - if (false !== strpos('WIN', PHP_OS)) { - /** - * `unlink()` will not work on Windows. `rmdir()` will not work if there are files in the directory. - * "On windows, take care that `is_link()` returns false for Junctions." - * - * @see https://www.php.net/manual/en/function.is-link.php#113263 - * @see https://stackoverflow.com/a/18262809/336146 - */ - rmdir($file->getPath()); - } else { - unlink($file->getPath()); - } - } elseif ($file->isDir()) { - rmdir($file->getPath()); - } elseif (is_readable($file->getPath())) { - unlink($file->getPath()); - } - } - rmdir($dir); + $filesystem = new Filesystem(new LocalFilesystemAdapter('/')); + + $filesystem->deleteDirectory($dir); } }