| Index: runtime/bin/directory_posix.cc
|
| diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_posix.cc
|
| index 7bf78f944522d1b4e25ee4f44c5120586a566fde..dfcab6992445e6a24658bcf5ffc41ebc772af2c1 100644
|
| --- a/runtime/bin/directory_posix.cc
|
| +++ b/runtime/bin/directory_posix.cc
|
| @@ -87,34 +87,6 @@ static void HandleFile(char* file_name,
|
| }
|
|
|
|
|
| -static void PostError(Dart_Port error_port,
|
| - const char* prefix,
|
| - const char* suffix,
|
| - int error_code) {
|
| - if (error_port != 0) {
|
| - // Extract the errno string.
|
| - static int kBufferSize = 1024;
|
| - char* error_buffer = static_cast<char*>(malloc(kBufferSize));
|
| - error_buffer[0] = '\0';
|
| - char* error_str = strerror_r(error_code, error_buffer, kBufferSize);
|
| - // Compose the error message from the parts.
|
| - int error_message_size =
|
| - strlen(prefix) + strlen(suffix) + strlen(error_str) + 3;
|
| - char* message = static_cast<char*>(malloc(error_message_size + 1));
|
| - int written = snprintf(message,
|
| - error_message_size + 1,
|
| - "%s%s (%s)",
|
| - prefix,
|
| - suffix,
|
| - error_str);
|
| - ASSERT(written == error_message_size);
|
| - free(error_buffer);
|
| - Dart_Post(error_port, Dart_NewString(message));
|
| - free(message);
|
| - }
|
| -}
|
| -
|
| -
|
| static bool ListRecursively(const char* dir_name,
|
| bool recursive,
|
| Dart_Port dir_port,
|
| @@ -123,7 +95,7 @@ static bool ListRecursively(const char* dir_name,
|
| Dart_Port error_port) {
|
| DIR* dir_pointer = opendir(dir_name);
|
| if (dir_pointer == NULL) {
|
| - PostError(error_port, "Directory listing failed for: ", dir_name, errno);
|
| + // TODO(ager): post something on the error port.
|
| return false;
|
| }
|
|
|
| @@ -136,22 +108,21 @@ static bool ListRecursively(const char* dir_name,
|
| // Iterated the directory and post the directories and files to the
|
| // ports.
|
| int success = 0;
|
| - bool listing_error = false;
|
| + bool completed = true;
|
| dirent entry;
|
| dirent* result;
|
| while ((success = readdir_r(dir_pointer, &entry, &result)) == 0 &&
|
| - result != NULL &&
|
| - !listing_error) {
|
| + result != NULL) {
|
| switch (entry.d_type) {
|
| case DT_DIR:
|
| - listing_error = listing_error || !HandleDir(entry.d_name,
|
| - path,
|
| - path_length,
|
| - recursive,
|
| - dir_port,
|
| - file_port,
|
| - done_port,
|
| - error_port);
|
| + completed = completed && HandleDir(entry.d_name,
|
| + path,
|
| + path_length,
|
| + recursive,
|
| + dir_port,
|
| + file_port,
|
| + done_port,
|
| + error_port);
|
| break;
|
| case DT_REG:
|
| HandleFile(entry.d_name, path, path_length, file_port);
|
| @@ -167,20 +138,19 @@ static bool ListRecursively(const char* dir_name,
|
| entry.d_name);
|
| ASSERT(written == strlen(entry.d_name));
|
| int lstat_success = lstat(path, &entry_info);
|
| - if (lstat_success == -1) {
|
| - listing_error = true;
|
| - PostError(error_port, "Directory listing failed for: ", path, errno);
|
| + if (lstat_success != 0) {
|
| + completed = false;
|
| break;
|
| }
|
| if ((entry_info.st_mode & S_IFMT) == S_IFDIR) {
|
| - listing_error = listing_error || !HandleDir(entry.d_name,
|
| - path,
|
| - path_length,
|
| - recursive,
|
| - dir_port,
|
| - file_port,
|
| - done_port,
|
| - error_port);
|
| + HandleDir(entry.d_name,
|
| + path,
|
| + path_length,
|
| + recursive,
|
| + dir_port,
|
| + file_port,
|
| + done_port,
|
| + error_port);
|
| } else if ((entry_info.st_mode & S_IFMT) == S_IFREG) {
|
| HandleFile(entry.d_name, path, path_length, file_port);
|
| }
|
| @@ -190,18 +160,13 @@ static bool ListRecursively(const char* dir_name,
|
| break;
|
| }
|
| }
|
| + completed = completed && (success == 0);
|
|
|
| - if (success != 0) {
|
| - listing_error = true;
|
| - PostError(error_port, "Directory listing failed", "", success);
|
| - }
|
| -
|
| - if (closedir(dir_pointer) == -1) {
|
| - PostError(error_port, "Failed to close directory", "", errno);
|
| - }
|
| + // TODO(ager): Post on error port if closing fails.
|
| + closedir(dir_pointer);
|
| free(path);
|
|
|
| - return !listing_error;
|
| + return completed;
|
| }
|
|
|
|
|
|
|