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

Side by Side Diff: runtime/bin/directory_win.cc

Issue 8509002: Revert "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: 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
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 static const int kBufferSize = 10;
114 char error_str[kBufferSize];
115 int written = snprintf(error_str, kBufferSize, "%d", GetLastError());
116 ASSERT(written < kBufferSize);
117 int error_message_size =
118 strlen(prefix) + strlen(suffix) + strlen(error_str) + 3;
119 char* message = static_cast<char*>(malloc(error_message_size + 1));
120 written = snprintf(message,
121 error_message_size + 1,
122 "%s%s (%s)",
123 prefix,
124 suffix,
125 error_str);
126 ASSERT(written == error_message_size);
127 Dart_Post(error_port, Dart_NewString(message));
128 free(message);
129 }
130 }
131
132
133 static bool ListRecursively(const char* dir_name, 109 static bool ListRecursively(const char* dir_name,
134 bool recursive, 110 bool recursive,
135 Dart_Port dir_port, 111 Dart_Port dir_port,
136 Dart_Port file_port, 112 Dart_Port file_port,
137 Dart_Port done_port, 113 Dart_Port done_port,
138 Dart_Port error_port) { 114 Dart_Port error_port) {
139 char* path = static_cast<char*>(malloc(MAX_PATH)); 115 char* path = static_cast<char*>(malloc(MAX_PATH));
140 int path_length = 0; 116 int path_length = 0;
141 ComputeFullSearchPath(dir_name, path, &path_length); 117 ComputeFullSearchPath(dir_name, path, &path_length);
142 118
143 WIN32_FIND_DATA find_file_data; 119 WIN32_FIND_DATA find_file_data;
144 HANDLE find_handle = FindFirstFile(path, &find_file_data); 120 HANDLE find_handle = FindFirstFile(path, &find_file_data);
145 121
146 // Adjust the path by removing the '*' used for the search. 122 // Adjust the path by removing the '*' used for the search.
147 path_length -= 1; 123 path_length -= 1;
148 path[path_length] = '\0'; 124 path[path_length] = '\0';
149 125
150 if (find_handle == INVALID_HANDLE_VALUE) { 126 if (find_handle == INVALID_HANDLE_VALUE) {
151 PostError(error_port, "Directory listing failed for: ", path); 127 // TODO(ager): Post on error port.
152 free(path); 128 free(path);
153 return false; 129 return false;
154 } 130 }
155 131
156 bool listing_error = !HandleEntry(&find_file_data, 132 bool completed = HandleEntry(&find_file_data,
157 path, 133 path,
158 path_length, 134 path_length,
159 recursive, 135 recursive,
160 dir_port, 136 dir_port,
161 file_port, 137 file_port,
162 done_port, 138 done_port,
163 error_port); 139 error_port);
164 140
165 while ((FindNextFile(find_handle, &find_file_data) != 0) && !listing_error) { 141 while (FindNextFile(find_handle, &find_file_data) != 0) {
166 listing_error = listing_error || !HandleEntry(&find_file_data, 142 completed = completed && HandleEntry(&find_file_data,
167 path, 143 path,
168 path_length, 144 path_length,
169 recursive, 145 recursive,
170 dir_port, 146 dir_port,
171 file_port, 147 file_port,
172 done_port, 148 done_port,
173 error_port); 149 error_port);
174 } 150 }
175 151
176 if (GetLastError() != ERROR_NO_MORE_FILES) { 152 completed = completed && (GetLastError() == ERROR_NO_MORE_FILES);
177 listing_error = true;
178 PostError(error_port, "Directory listing failed", "");
179 }
180 153
181 if (FindClose(find_handle) == 0) { 154 // TODO(ager): Post on error port if close fails.
182 PostError(error_port, "Failed to close directory", ""); 155 FindClose(find_handle);
183 }
184 free(path); 156 free(path);
185 157
186 return !listing_error; 158 return completed;
187 } 159 }
188 160
189 161
190 void Directory::List(const char* dir_name, 162 void Directory::List(const char* dir_name,
191 bool recursive, 163 bool recursive,
192 Dart_Port dir_port, 164 Dart_Port dir_port,
193 Dart_Port file_port, 165 Dart_Port file_port,
194 Dart_Port done_port, 166 Dart_Port done_port,
195 Dart_Port error_port) { 167 Dart_Port error_port) {
196 bool result = ListRecursively(dir_name, 168 bool result = ListRecursively(dir_name,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 206
235 207
236 bool Directory::Create(const char* dir_name) { 208 bool Directory::Create(const char* dir_name) {
237 return (CreateDirectory(dir_name, NULL) != 0); 209 return (CreateDirectory(dir_name, NULL) != 0);
238 } 210 }
239 211
240 212
241 bool Directory::Delete(const char* dir_name) { 213 bool Directory::Delete(const char* dir_name) {
242 return (RemoveDirectory(dir_name) != 0); 214 return (RemoveDirectory(dir_name) != 0);
243 } 215 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698