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

Unified Diff: runtime/bin/directory_win.cc

Issue 8511001: Reapply directory error handling change. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cut down on includes in posix version. 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_posix.cc ('k') | runtime/bin/platform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index d3adfb83e46e3fbc19e026017d6b1a8249f4314c..0f48408adc3cc71788df0c547de0dc2c7fb1ebc4 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -2,10 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+#include "bin/directory.h"
+
#include <errno.h>
#include <sys/stat.h>
-#include "bin/directory.h"
+#include "bin/platform.h"
// Forward declaration.
static bool ListRecursively(const char* dir_name,
@@ -95,7 +97,7 @@ static void ComputeFullSearchPath(const char* dir_name,
// GetFullPathName only works in a multi-threaded environment if
// SetCurrentDirectory is not used. We currently have no plan for
// exposing SetCurrentDirectory.
- int written =
+ size_t written =
GetFullPathName(dir_name, MAX_PATH - *path_length, path, NULL);
*path_length += written;
written = snprintf(path + *path_length,
@@ -106,6 +108,28 @@ 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) {
+ char* error_str = Platform::StrError(GetLastError());
+ int error_message_size =
+ strlen(prefix) + strlen(suffix) + strlen(error_str) + 3;
+ char* message = static_cast<char*>(malloc(error_message_size + 1));
+ size_t written = snprintf(message,
+ error_message_size + 1,
+ "%s%s (%s)",
+ prefix,
+ suffix,
+ error_str);
+ ASSERT(written == error_message_size);
+ free(error_str);
+ Dart_Post(error_port, Dart_NewString(message));
+ free(message);
+ }
+}
+
+
static bool ListRecursively(const char* dir_name,
bool recursive,
Dart_Port dir_port,
@@ -124,38 +148,42 @@ 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;
}
- bool completed = HandleEntry(&find_file_data,
- path,
- path_length,
- recursive,
- dir_port,
- file_port,
- done_port,
- error_port);
-
- while (FindNextFile(find_handle, &find_file_data) != 0) {
- completed = completed && HandleEntry(&find_file_data,
- path,
- path_length,
- recursive,
- dir_port,
- file_port,
- done_port,
- error_port);
+ bool listing_error = !HandleEntry(&find_file_data,
+ path,
+ path_length,
+ recursive,
+ dir_port,
+ file_port,
+ done_port,
+ error_port);
+
+ while ((FindNextFile(find_handle, &find_file_data) != 0) && !listing_error) {
+ listing_error = listing_error || !HandleEntry(&find_file_data,
+ path,
+ path_length,
+ recursive,
+ dir_port,
+ file_port,
+ done_port,
+ error_port);
}
- completed = completed && (GetLastError() == ERROR_NO_MORE_FILES);
+ if (GetLastError() != ERROR_NO_MORE_FILES) {
+ listing_error = true;
+ PostError(error_port, "Directory listing failed", "");
+ }
- // TODO(ager): Post on error port if close fails.
- FindClose(find_handle);
+ if (FindClose(find_handle) == 0) {
+ PostError(error_port, "Failed to close directory", "");
+ }
free(path);
- return completed;
+ return !listing_error;
}
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698