-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FileSystem] Windows fix #16987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FileSystem] Windows fix #16987
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,10 @@ public function mkdir($dirs, $mode = 0777) | |
public function exists($files) | ||
{ | ||
foreach ($this->toIterator($files) as $file) { | ||
if ('\\' === DIRECTORY_SEPARATOR AND strlen($file) > 258) { | ||
throw new IOException(sprintf('Could not check if file exist because path length exceeds 258 characters for file "%s"', $file)); | ||
} | ||
|
||
if (!file_exists($file)) { | ||
return false; | ||
} | ||
|
@@ -139,7 +143,7 @@ public function remove($files) | |
$files = iterator_to_array($this->toIterator($files)); | ||
$files = array_reverse($files); | ||
foreach ($files as $file) { | ||
if (!file_exists($file) && !is_link($file)) { | ||
if (!$this->exists($file) && !is_link($file)) { | ||
continue; | ||
} | ||
|
||
|
@@ -157,7 +161,8 @@ public function remove($files) | |
} | ||
} else { | ||
if (true !== @unlink($file)) { | ||
throw new IOException(sprintf('Failed to remove file %s', $file)); | ||
$error = error_get_last(); | ||
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message'])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, this kind of changes are considered as new features, to me moved to a PR on the master branch IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really, we do improve exception messages in patch releases. |
||
} | ||
} | ||
} | ||
|
@@ -253,7 +258,7 @@ public function chgrp($files, $group, $recursive = false) | |
public function rename($origin, $target, $overwrite = false) | ||
{ | ||
// we check that target does not exist | ||
if (!$overwrite && is_readable($target)) { | ||
if (!$overwrite && $this->isReadable($target)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use file_exists here ? Is is_readable really required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well your question would be best addressed to fabpot, since he put this in at 17 Feb 2010. But my guess is that |
||
throw new IOException(sprintf('Cannot rename because the target "%s" already exist.', $target)); | ||
} | ||
|
||
|
@@ -262,6 +267,22 @@ public function rename($origin, $target, $overwrite = false) | |
} | ||
} | ||
|
||
/** | ||
* Tells whether a file exists and is readable. | ||
* | ||
* @param string $filename Path to the file. | ||
* | ||
* @throws IOException When windows path is longer than 258 characters | ||
*/ | ||
private function isReadable($filename) | ||
{ | ||
if ('\\' === DIRECTORY_SEPARATOR AND strlen($filename) > 258) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe better use && here? Any reason why AND needed? |
||
throw new IOException(sprintf('Could not check if file is readable because path length exceeds 258 characters for file "%s"', $filename)); | ||
} | ||
|
||
return is_readable($filename); | ||
} | ||
|
||
/** | ||
* Creates a symbolic link or copy a directory. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better use && here? Any reason why AND needed?