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

Side by Side Diff: runtime/bin/directory_win.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 7
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 9
10 // Forward declaration. 10 // Forward declaration.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 GetFullPathName(dir_name, MAX_PATH - *path_length, path, NULL); 99 GetFullPathName(dir_name, MAX_PATH - *path_length, path, NULL);
100 *path_length += written; 100 *path_length += written;
101 written = snprintf(path + *path_length, 101 written = snprintf(path + *path_length,
102 MAX_PATH - *path_length, 102 MAX_PATH - *path_length,
103 "%s", 103 "%s",
104 "\\*"); 104 "\\*");
105 ASSERT(written == 2); 105 ASSERT(written == 2);
106 *path_length += written; 106 *path_length += written;
107 } 107 }
108 108
109 static void PostError(Dart_Port error_port,
110 const char* prefix,
111 const char* suffix) {
112 if (error_port != 0) {
113 int error_message_size = strlen(prefix) + strlen(suffix);
114 char* buffer = static_cast<char*>(malloc(error_message_size + 1));
115 int written = snprintf(buffer,
116 error_message_size + 1,
117 "%s%s",
118 prefix,
119 suffix);
120 ASSERT(written == error_message_size);
121 Dart_Post(error_port, Dart_NewString(buffer));
122 free(buffer);
123 }
124 }
125
126
109 static bool ListRecursively(const char* dir_name, 127 static bool ListRecursively(const char* dir_name,
110 bool recursive, 128 bool recursive,
111 Dart_Port dir_port, 129 Dart_Port dir_port,
112 Dart_Port file_port, 130 Dart_Port file_port,
113 Dart_Port done_port, 131 Dart_Port done_port,
114 Dart_Port error_port) { 132 Dart_Port error_port) {
115 char* path = static_cast<char*>(malloc(MAX_PATH)); 133 char* path = static_cast<char*>(malloc(MAX_PATH));
116 int path_length = 0; 134 int path_length = 0;
117 ComputeFullSearchPath(dir_name, path, &path_length); 135 ComputeFullSearchPath(dir_name, path, &path_length);
118 136
119 WIN32_FIND_DATA find_file_data; 137 WIN32_FIND_DATA find_file_data;
120 HANDLE find_handle = FindFirstFile(path, &find_file_data); 138 HANDLE find_handle = FindFirstFile(path, &find_file_data);
121 139
122 // Adjust the path by removing the '*' used for the search. 140 // Adjust the path by removing the '*' used for the search.
123 path_length -= 1; 141 path_length -= 1;
124 path[path_length] = '\0'; 142 path[path_length] = '\0';
125 143
126 if (find_handle == INVALID_HANDLE_VALUE) { 144 if (find_handle == INVALID_HANDLE_VALUE) {
127 // TODO(ager): Post on error port. 145 PostError(error_port, "Directory listing failed for: ", path);
128 free(path); 146 free(path);
129 return false; 147 return false;
130 } 148 }
131 149
132 bool completed = HandleEntry(&find_file_data, 150 bool completed = HandleEntry(&find_file_data,
133 path, 151 path,
134 path_length, 152 path_length,
135 recursive, 153 recursive,
136 dir_port, 154 dir_port,
137 file_port, 155 file_port,
138 done_port, 156 done_port,
139 error_port); 157 error_port);
140 158
141 while (FindNextFile(find_handle, &find_file_data) != 0) { 159 while ((FindNextFile(find_handle, &find_file_data) != 0) && completed) {
142 completed = completed && HandleEntry(&find_file_data, 160 completed = completed && HandleEntry(&find_file_data,
143 path, 161 path,
144 path_length, 162 path_length,
145 recursive, 163 recursive,
146 dir_port, 164 dir_port,
147 file_port, 165 file_port,
148 done_port, 166 done_port,
149 error_port); 167 error_port);
150 } 168 }
151 169
152 completed = completed && (GetLastError() == ERROR_NO_MORE_FILES); 170 if (GetLastError() != ERROR_NO_MORE_FILES) {
171 completed = false;
172 PostError(error_port, "Directory listing failed", "");
173 }
153 174
154 // TODO(ager): Post on error port if close fails. 175 if (FindClose(find_handle) != 0) {
155 FindClose(find_handle); 176 static const int kBufferSize = 10;
177 char error_str[kBufferSize];
178 int written = snprintf(error_str, kBufferSize, "%d", GetLastError());
179 ASSERT(written < kBufferSize);
180 PostError(error_port, "Failed to close directory. ErrorCode: ", error_str);
181 }
156 free(path); 182 free(path);
157 183
158 return completed; 184 return completed;
159 } 185 }
160 186
161 187
162 void Directory::List(const char* dir_name, 188 void Directory::List(const char* dir_name,
163 bool recursive, 189 bool recursive,
164 Dart_Port dir_port, 190 Dart_Port dir_port,
165 Dart_Port file_port, 191 Dart_Port file_port,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 232
207 233
208 bool Directory::Create(const char* dir_name) { 234 bool Directory::Create(const char* dir_name) {
209 return (CreateDirectory(dir_name, NULL) != 0); 235 return (CreateDirectory(dir_name, NULL) != 0);
210 } 236 }
211 237
212 238
213 bool Directory::Delete(const char* dir_name) { 239 bool Directory::Delete(const char* dir_name) {
214 return (RemoveDirectory(dir_name) != 0); 240 return (RemoveDirectory(dir_name) != 0);
215 } 241 }
OLDNEW
« runtime/bin/directory_posix.cc ('K') | « runtime/bin/directory_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698