Use PHP_MAXPATHLEN in Filesystem.
This commit is contained in:
parent
4129fd2a83
commit
7a475595e2
|
@ -117,9 +117,11 @@ class Filesystem
|
|||
*/
|
||||
public function exists($files)
|
||||
{
|
||||
$maxPathLength = PHP_MAXPATHLEN - 2;
|
||||
|
||||
foreach ($this->toIterator($files) as $file) {
|
||||
if ('\\' === DIRECTORY_SEPARATOR && strlen($file) > 258) {
|
||||
throw new IOException('Could not check if file exist because path length exceeds 258 characters.', 0, null, $file);
|
||||
if (strlen($file) > $maxPathLength) {
|
||||
throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
|
||||
}
|
||||
|
||||
if (!file_exists($file)) {
|
||||
|
@ -301,8 +303,10 @@ class Filesystem
|
|||
*/
|
||||
private function isReadable($filename)
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR && strlen($filename) > 258) {
|
||||
throw new IOException('Could not check if file is readable because path length exceeds 258 characters.', 0, null, $filename);
|
||||
$maxPathLength = PHP_MAXPATHLEN - 2;
|
||||
|
||||
if (strlen($filename) > $maxPathLength) {
|
||||
throw new IOException(sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
|
||||
}
|
||||
|
||||
return is_readable($filename);
|
||||
|
|
|
@ -374,16 +374,13 @@ class FilesystemTest extends FilesystemTestCase
|
|||
*/
|
||||
public function testFilesExistsFails()
|
||||
{
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Test covers edge case on Windows only.');
|
||||
}
|
||||
|
||||
$basePath = $this->workspace.'\\directory\\';
|
||||
$maxPathLength = PHP_MAXPATHLEN - 2;
|
||||
|
||||
$oldPath = getcwd();
|
||||
mkdir($basePath);
|
||||
chdir($basePath);
|
||||
$file = str_repeat('T', 259 - strlen($basePath));
|
||||
$file = str_repeat('T', $maxPathLength - strlen($basePath) + 1);
|
||||
$path = $basePath.$file;
|
||||
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
|
||||
$this->longPathNamesWindows[] = $path; // save this so we can clean up later
|
||||
|
|
Reference in New Issue