Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit d99e0fc

Browse files
committed
Completed the validatePath method
1 parent 6c4a144 commit d99e0fc

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/System/UnixSystem.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,44 @@ public function getComposerCommand()
6868
}
6969

7070
/**
71-
* Returns true if the path is a "valid" path and is writable (event if the complete path does not yet exist).
71+
* Returns true if the path is a "valid" path and is writable (even if the complete path does not yet exist).
7272
* @param string $path
7373
* @return boolean
7474
*/
7575
public function validatePath($path)
7676
{
7777
$absPath = $this->getAbsolutePath($path);
78+
$absPathParts = preg_split('/\//', preg_replace('/(^\/|\/$)/', '', $absPath));
79+
$nSteps = count($absPath);
80+
81+
$tmpPath = '';
82+
$prevReadable = false;
83+
$prevWritable = false;
84+
85+
for ($i=0; $i<$nSteps; $i++) {
86+
$tmpPath .= '/' . $absPathParts[$i];
87+
88+
if (file_exists($tmpPath)) {
89+
if (!is_dir($tmpPath)) {
90+
if (is_link($tmpPath)) {
91+
$linkPath = readlink($tmpPath);
92+
if (false === $linkPath || !is_dir($linkPath)) {
93+
return false;
94+
}
95+
$tmpPath = $linkPath;
96+
} else {
97+
return false;
98+
}
99+
}
100+
101+
$prevReadable = is_readable($tmpPath);
102+
$prevWritable = is_writable($tmpPath);
103+
} else {
104+
return ($prevReadable && $prevWritable);
105+
}
106+
}
107+
108+
return true;
78109
}
79110

80111
/**

0 commit comments

Comments
 (0)