Skip to content

Commit

Permalink
windows symlinks
Browse files Browse the repository at this point in the history
BrianHenryIE committed Apr 26, 2024

Verified

This commit was signed with the committer’s verified signature.
farfromrefug farfromrefuge
1 parent 95d6905 commit 1cdb99c
Showing 2 changed files with 4 additions and 17 deletions.
17 changes: 2 additions & 15 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public function cleanup(array $sourceFiles): void
if (is_link($absolutePath)) {
unlink($absolutePath);
} elseif (false !== strpos('WIN', PHP_OS)
&& substr(strrchr(strtolower($absolutePath), '.'), 1) === 'lnk'
&& stat($absolutePath)['nlink'] !== lstat($absolutePath)['nlink']
) {
/**
* `unlink()` will not work on Windows. `rmdir()` will not work if there are files in the directory.
@@ -77,20 +77,7 @@ public function cleanup(array $sourceFiles): void
* @see https://www.php.net/manual/en/function.is-link.php#113263
* @see https://stackoverflow.com/a/18262809/336146
*/
rmdir($file->getRealPath());
}

if (is_link()) {
/**
* `unlink()` will not work on Windows. `rimdir()` will not work if there are files in the directory.
*
* @see https://stackoverflow.com/a/18262809/336146
*/
if (false === strpos('WIN', PHP_OS)) {
unlink($absolutePath);
} else {
rmdir($absolutePath);
}
rmdir($absolutePath);
}

if ($absolutePath !== realpath($absolutePath)) {
4 changes: 2 additions & 2 deletions tests/Integration/Util/IntegrationTestCase.php
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ protected function deleteDir($dir)
if (is_link($file)) {
unlink($file);
} elseif (false !== strpos('WIN', PHP_OS)
&& substr(strrchr(strtolower($file->getRealPath()), '.'), 1) === 'lnk'
&& stat($file)['nlink'] !== lstat($file)['nlink']
) {
/**
* `unlink()` will not work on Windows. `rmdir()` will not work if there are files in the directory.
@@ -100,7 +100,7 @@ protected function deleteDir($dir)
* @see https://www.php.net/manual/en/function.is-link.php#113263
* @see https://stackoverflow.com/a/18262809/336146
*/
rmdir($file->getRealPath());
rmdir($file);
} elseif ($file->isDir()) {
rmdir($file->getRealPath());
} elseif (is_readable($file->getRealPath())) {

0 comments on commit 1cdb99c

Please sign in to comment.