| Index: runtime/bin/file.cc
|
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
|
| index 9eedc8579206a092f6931360747e25c844317c87..ed86895d24a95f229ebbbc07ee1a5e0e2b2d285b 100644
|
| --- a/runtime/bin/file.cc
|
| +++ b/runtime/bin/file.cc
|
| @@ -59,7 +59,14 @@ void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
|
| if (mode == kAppend) {
|
| file_mode = File::kWrite;
|
| }
|
| - File* file = File::Open(filename, file_mode);
|
| + // Check that the file exists before opening it only for
|
| + // reading. This is to prevent the opening of directories as
|
| + // files. Directories can be opened for reading using the posix
|
| + // 'open' call.
|
| + File* file = NULL;
|
| + if (((file_mode & File::kWrite) != 0) || File::Exists(filename)) {
|
| + file = File::Open(filename, file_mode);
|
| + }
|
| Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
|
| Dart_ExitScope();
|
| }
|
|
|