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:
parent
2f42596ac7
commit
9a375918ae
@ -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"
|
||||||
));
|
));
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user