Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: runtime/bin/directory_posix.cc

Issue 8499018: Post on the error handler in the Directory API when errors are encountered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows build Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | runtime/bin/directory_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_posix.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_posix.cc
index dfcab6992445e6a24658bcf5ffc41ebc772af2c1..7bf78f944522d1b4e25ee4f44c5120586a566fde 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_posix.cc
@@ -87,6 +87,34 @@ 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,
@@ -95,7 +123,7 @@ static bool ListRecursively(const char* dir_name,
Dart_Port error_port) {
DIR* dir_pointer = opendir(dir_name);
if (dir_pointer == NULL) {
- // TODO(ager): post something on the error port.
+ PostError(error_port, "Directory listing failed for: ", dir_name, errno);
return false;
}
@@ -108,21 +136,22 @@ static bool ListRecursively(const char* dir_name,
// Iterated the directory and post the directories and files to the
// ports.
int success = 0;
- bool completed = true;
+ bool listing_error = false;
dirent entry;
dirent* result;
while ((success = readdir_r(dir_pointer, &entry, &result)) == 0 &&
- result != NULL) {
+ result != NULL &&
+ !listing_error) {
switch (entry.d_type) {
case DT_DIR:
- completed = completed && HandleDir(entry.d_name,
- path,
- path_length,
- recursive,
- dir_port,
- file_port,
- done_port,
- error_port);
+ listing_error = listing_error || !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);
@@ -138,19 +167,20 @@ 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 != 0) {
- completed = false;
+ if (lstat_success == -1) {
+ listing_error = true;
+ PostError(error_port, "Directory listing failed for: ", path, errno);
break;
}
if ((entry_info.st_mode & S_IFMT) == S_IFDIR) {
- HandleDir(entry.d_name,
- path,
- path_length,
- recursive,
- dir_port,
- file_port,
- done_port,
- error_port);
+ listing_error = listing_error || !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);
}
@@ -160,13 +190,18 @@ static bool ListRecursively(const char* dir_name,
break;
}
}
- completed = completed && (success == 0);
- // TODO(ager): Post on error port if closing fails.
- closedir(dir_pointer);
+ 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);
+ }
free(path);
- return completed;
+ return !listing_error;
}
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | runtime/bin/directory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698