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

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 port. 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..b1645bf7011c9753208715af59fef9a1c8cb76f9 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_posix.cc
@@ -87,6 +87,24 @@ static void HandleFile(char* file_name,
}
+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,
@@ -95,7 +113,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);
Søren Gjesse 2011/11/08 16:56:16 This does not say anything about the actual error.
Mads Ager (google) 2011/11/09 08:07:30 Yes. Refactored so PostError always extracts the e
return false;
}
@@ -112,7 +130,8 @@ static bool ListRecursively(const char* dir_name,
dirent entry;
dirent* result;
while ((success = readdir_r(dir_pointer, &entry, &result)) == 0 &&
- result != NULL) {
+ result != NULL &&
+ completed) {
Søren Gjesse 2011/11/08 16:56:16 Maybe it is just the naming, but "while (completed
Mads Ager (google) 2011/11/09 08:07:30 I agree. Renamed to listing_error and updated the
switch (entry.d_type) {
case DT_DIR:
completed = completed && HandleDir(entry.d_name,
@@ -140,6 +159,7 @@ static bool ListRecursively(const char* dir_name,
int lstat_success = lstat(path, &entry_info);
if (lstat_success != 0) {
completed = false;
+ PostError(error_port, "Directory listing failed for: ", path);
break;
}
if ((entry_info.st_mode & S_IFMT) == S_IFDIR) {
@@ -160,10 +180,20 @@ 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) {
+ completed = false;
+ PostError(error_port, "Directory listing failed", "");
+ }
+
+ if (closedir(dir_pointer) == -1) {
+ static int kBufferSize = 1024;
+ char* buffer = static_cast<char*>(malloc(kBufferSize));
+ buffer[0] = '\0';
+ strerror_r(errno, buffer, kBufferSize);
+ PostError(error_port, "Failed to close directory: ", buffer);
+ free(buffer);
+ }
free(path);
return completed;
« 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