| Index: runtime/bin/directory_win.cc
|
| diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
|
| index d3adfb83e46e3fbc19e026017d6b1a8249f4314c..8fc4cc0aec17daa48abbc7408086891137607de8 100644
|
| --- a/runtime/bin/directory_win.cc
|
| +++ b/runtime/bin/directory_win.cc
|
| @@ -106,6 +106,24 @@ static void ComputeFullSearchPath(const char* dir_name,
|
| *path_length += written;
|
| }
|
|
|
| +static void PostError(Dart_Port error_port,
|
| + const char* prefix,
|
| + const char* suffix) {
|
| + if (error_port != 0) {
|
| + int error_message_size = strlen(prefix) + strlen(suffix);
|
| + char* buffer = static_cast<char*>(malloc(error_message_size + 1));
|
| + int written = snprintf(buffer,
|
| + error_message_size + 1,
|
| + "%s%s",
|
| + prefix,
|
| + suffix);
|
| + ASSERT(written == error_message_size);
|
| + Dart_Post(error_port, Dart_NewString(buffer));
|
| + free(buffer);
|
| + }
|
| +}
|
| +
|
| +
|
| static bool ListRecursively(const char* dir_name,
|
| bool recursive,
|
| Dart_Port dir_port,
|
| @@ -124,7 +142,7 @@ static bool ListRecursively(const char* dir_name,
|
| path[path_length] = '\0';
|
|
|
| if (find_handle == INVALID_HANDLE_VALUE) {
|
| - // TODO(ager): Post on error port.
|
| + PostError(error_port, "Directory listing failed for: ", path);
|
| free(path);
|
| return false;
|
| }
|
| @@ -138,7 +156,7 @@ static bool ListRecursively(const char* dir_name,
|
| done_port,
|
| error_port);
|
|
|
| - while (FindNextFile(find_handle, &find_file_data) != 0) {
|
| + while ((FindNextFile(find_handle, &find_file_data) != 0) && completed) {
|
| completed = completed && HandleEntry(&find_file_data,
|
| path,
|
| path_length,
|
| @@ -149,10 +167,18 @@ static bool ListRecursively(const char* dir_name,
|
| error_port);
|
| }
|
|
|
| - completed = completed && (GetLastError() == ERROR_NO_MORE_FILES);
|
| + if (GetLastError() != ERROR_NO_MORE_FILES) {
|
| + completed = false;
|
| + PostError(error_port, "Directory listing failed", "");
|
| + }
|
|
|
| - // TODO(ager): Post on error port if close fails.
|
| - FindClose(find_handle);
|
| + if (FindClose(find_handle) != 0) {
|
| + static const int kBufferSize = 10;
|
| + char error_str[kBufferSize];
|
| + int written = snprintf(error_str, kBufferSize, "%d", GetLastError());
|
| + ASSERT(written < kBufferSize);
|
| + PostError(error_port, "Failed to close directory. ErrorCode: ", error_str);
|
| + }
|
| free(path);
|
|
|
| return completed;
|
|
|