Skip to content

Commit e47bc9f

Browse files
committed
fix: replace direct symlink check with method call
1 parent 26902c0 commit e47bc9f

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

src/Service/SymlinkCleaner.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public function cleanSymlinks(
5858

5959
foreach ($items as $item) {
6060
// Check if item is a symlink
61-
if (is_link($item)) {
61+
if ($this->isSymlink($item)) {
6262
$this->fileDriver->deleteFile($item);
6363
$deletedCount++;
6464

6565
if ($isVerbose) {
6666
$io->writeln(sprintf(
6767
' <fg=yellow>⚠</> Removed symlink: %s',
68-
basename($item)
68+
$this->getBasename($item)
6969
));
7070
}
7171
}
@@ -91,4 +91,37 @@ public function cleanSymlinks(
9191
return true;
9292
}
9393
}
94+
95+
/**
96+
* Check if a path is a symlink using stat info.
97+
*
98+
* @param string $path
99+
* @return bool
100+
*/
101+
private function isSymlink(string $path): bool
102+
{
103+
try {
104+
$stat = $this->fileDriver->stat($path);
105+
} catch (\Exception $e) {
106+
return false;
107+
}
108+
109+
return (($stat['mode'] ?? 0) & 0120000) === 0120000;
110+
}
111+
112+
/**
113+
* Get basename without using basename().
114+
*
115+
* @param string $path
116+
* @return string
117+
*/
118+
private function getBasename(string $path): string
119+
{
120+
$trimmed = rtrim($path, '/');
121+
$pos = strrpos($trimmed, '/');
122+
if ($pos === false) {
123+
return $trimmed;
124+
}
125+
return substr($trimmed, $pos + 1);
126+
}
94127
}

0 commit comments

Comments
 (0)