1
0
mirror of https://github.com/danog/file.git synced 2024-11-26 11:54:54 +01:00

Reflect "e" flag changes and mode validation to BlockingDriver

This commit is contained in:
Aaron Piotrowski 2017-10-29 23:10:35 -05:00
parent 2f42596ac7
commit 9a375918ae
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 22 additions and 3 deletions

View File

@ -11,7 +11,26 @@ class BlockingDriver implements Driver {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function open(string $path, string $mode): Promise { public function open(string $path, string $mode): Promise {
if (!$fh = \fopen($path, $mode)) { $mode = \str_replace(['b', 't', 'e'], '', $mode);
switch ($mode) {
case "r":
case "r+":
case "w":
case "w+":
case "a":
case "a+":
case "x":
case "x+":
case "c":
case "c+":
break;
default:
throw new \Error("Invalid file mode");
}
if (!$fh = \fopen($path, $mode . 'be')) {
return new Failure(new FilesystemException( return new Failure(new FilesystemException(
"Failed opening file handle" "Failed opening file handle"
)); ));

View File

@ -31,7 +31,7 @@ class EioDriver implements Driver {
} }
private function parseMode(string $mode): int { private function parseMode(string $mode): int {
$mode = \str_replace(['b', 't'], '', $mode); $mode = \str_replace(['b', 't', 'e'], '', $mode);
switch ($mode) { switch ($mode) {
case 'r': return \EIO_O_RDONLY; case 'r': return \EIO_O_RDONLY;

View File

@ -54,7 +54,7 @@ class UvDriver implements Driver {
} }
private function parseMode(string $mode): int { private function parseMode(string $mode): int {
$mode = \str_replace(['b', 't'], '', $mode); $mode = \str_replace(['b', 't', 'e'], '', $mode);
switch ($mode) { switch ($mode) {
case "r": return \UV::O_RDONLY; case "r": return \UV::O_RDONLY;