OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "bin/directory.h" | 5 #include "bin/directory.h" |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/thread.h" | 8 #include "bin/thread.h" |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Dart_ExitScope(); | 110 Dart_ExitScope(); |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 114 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
115 Dart_EnterScope(); | 115 Dart_EnterScope(); |
116 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 116 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
117 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 117 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
118 // Create the list to hold the directory listing here, and pass it to the | 118 // Create the list to hold the directory listing here, and pass it to the |
119 // SyncDirectoryListing object, which adds elements to it. | 119 // SyncDirectoryListing object, which adds elements to it. |
| 120 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); |
| 121 // Create the list to hold the directory listing here, and pass it to the |
| 122 // SyncDirectoryListing object, which adds elements to it. |
120 Dart_Handle results = | 123 Dart_Handle results = |
121 Dart_New(DartUtils::GetDartClass(DartUtils::kCoreLibURL, "List"), | 124 Dart_New(DartUtils::GetDartClass(DartUtils::kCoreLibURL, "List"), |
122 Dart_Null(), | 125 Dart_Null(), |
123 0, | 126 0, |
124 NULL); | 127 NULL); |
125 SyncDirectoryListing sync_listing(results); | 128 SyncDirectoryListing sync_listing(results); |
126 Directory::List(DartUtils::GetStringValue(path), | 129 Directory::List(DartUtils::GetStringValue(path), |
127 DartUtils::GetBooleanValue(recursive), | 130 DartUtils::GetBooleanValue(recursive), |
| 131 DartUtils::GetBooleanValue(follow_links), |
128 &sync_listing); | 132 &sync_listing); |
129 Dart_SetReturnValue(args, results); | 133 Dart_SetReturnValue(args, results); |
130 Dart_ExitScope(); | 134 Dart_ExitScope(); |
131 } | 135 } |
132 | 136 |
133 | 137 |
134 static CObject* DirectoryCreateRequest(const CObjectArray& request) { | 138 static CObject* DirectoryCreateRequest(const CObjectArray& request) { |
135 if (request.Length() == 2 && request[1]->IsString()) { | 139 if (request.Length() == 2 && request[1]->IsString()) { |
136 CObjectString path(request[1]); | 140 CObjectString path(request[1]); |
137 if (Directory::Create(path.CString())) { | 141 if (Directory::Create(path.CString())) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } else { | 191 } else { |
188 return CObject::NewOSError(); | 192 return CObject::NewOSError(); |
189 } | 193 } |
190 } | 194 } |
191 return CObject::IllegalArgumentError(); | 195 return CObject::IllegalArgumentError(); |
192 } | 196 } |
193 | 197 |
194 | 198 |
195 static CObject* DirectoryListRequest(const CObjectArray& request, | 199 static CObject* DirectoryListRequest(const CObjectArray& request, |
196 Dart_Port response_port) { | 200 Dart_Port response_port) { |
197 if (request.Length() == 3 && request[1]->IsString() && request[2]->IsBool()) { | 201 if (request.Length() == 4 && |
| 202 request[1]->IsString() && |
| 203 request[2]->IsBool() && |
| 204 request[3]->IsBool()) { |
198 AsyncDirectoryListing* dir_listing = | 205 AsyncDirectoryListing* dir_listing = |
199 new AsyncDirectoryListing(response_port); | 206 new AsyncDirectoryListing(response_port); |
200 CObjectString path(request[1]); | 207 CObjectString path(request[1]); |
201 CObjectBool recursive(request[2]); | 208 CObjectBool recursive(request[2]); |
| 209 CObjectBool follow_links(request[3]); |
202 bool completed = Directory::List( | 210 bool completed = Directory::List( |
203 path.CString(), recursive.Value(), dir_listing); | 211 path.CString(), recursive.Value(), follow_links.Value(), dir_listing); |
204 delete dir_listing; | 212 delete dir_listing; |
205 CObjectArray* response = new CObjectArray(CObject::NewArray(2)); | 213 CObjectArray* response = new CObjectArray(CObject::NewArray(2)); |
206 response->SetAt( | 214 response->SetAt( |
207 0, | 215 0, |
208 new CObjectInt32(CObject::NewInt32(AsyncDirectoryListing::kListDone))); | 216 new CObjectInt32(CObject::NewInt32(AsyncDirectoryListing::kListDone))); |
209 response->SetAt(1, CObject::Bool(completed)); | 217 response->SetAt(1, CObject::Bool(completed)); |
210 return response; | 218 return response; |
211 } | 219 } |
212 // Respond with an illegal argument list error message. | 220 // Respond with an illegal argument list error message. |
213 CObjectArray* response = new CObjectArray(CObject::NewArray(3)); | 221 CObjectArray* response = new CObjectArray(CObject::NewArray(3)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return Dart_PostCObject(response_port_, response->AsApiCObject()); | 316 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
309 } | 317 } |
310 | 318 |
311 | 319 |
312 bool AsyncDirectoryListing::HandleFile(char* file_name) { | 320 bool AsyncDirectoryListing::HandleFile(char* file_name) { |
313 CObjectArray* response = NewResponse(kListFile, file_name); | 321 CObjectArray* response = NewResponse(kListFile, file_name); |
314 return Dart_PostCObject(response_port_, response->AsApiCObject()); | 322 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
315 } | 323 } |
316 | 324 |
317 | 325 |
| 326 bool AsyncDirectoryListing::HandleLink(char* link_name) { |
| 327 CObjectArray* response = NewResponse(kListLink, link_name); |
| 328 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
| 329 } |
| 330 |
| 331 |
318 bool AsyncDirectoryListing::HandleError(const char* dir_name) { | 332 bool AsyncDirectoryListing::HandleError(const char* dir_name) { |
319 CObject* err = CObject::NewOSError(); | 333 CObject* err = CObject::NewOSError(); |
320 CObjectArray* response = new CObjectArray(CObject::NewArray(3)); | 334 CObjectArray* response = new CObjectArray(CObject::NewArray(3)); |
321 response->SetAt(0, new CObjectInt32(CObject::NewInt32(kListError))); | 335 response->SetAt(0, new CObjectInt32(CObject::NewInt32(kListError))); |
322 response->SetAt(1, new CObjectString(CObject::NewString(dir_name))); | 336 response->SetAt(1, new CObjectString(CObject::NewString(dir_name))); |
323 response->SetAt(2, err); | 337 response->SetAt(2, err); |
324 return Dart_PostCObject(response_port_, response->AsApiCObject()); | 338 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
325 } | 339 } |
326 | 340 |
327 bool SyncDirectoryListing::HandleDirectory(char* dir_name) { | 341 bool SyncDirectoryListing::HandleDirectory(char* dir_name) { |
328 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); | 342 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); |
329 Dart_Handle dir = | 343 Dart_Handle dir = |
330 Dart_New(directory_class_, Dart_Null(), 1, &dir_name_dart); | 344 Dart_New(directory_class_, Dart_Null(), 1, &dir_name_dart); |
331 Dart_Invoke(results_, add_string_, 1, &dir); | 345 Dart_Invoke(results_, add_string_, 1, &dir); |
332 return true; | 346 return true; |
333 } | 347 } |
334 | 348 |
| 349 bool SyncDirectoryListing::HandleLink(char* link_name) { |
| 350 Dart_Handle link_name_dart = DartUtils::NewString(link_name); |
| 351 Dart_Handle link = |
| 352 Dart_New(link_class_, Dart_Null(), 1, &link_name_dart); |
| 353 Dart_Invoke(results_, add_string_, 1, &link); |
| 354 return true; |
| 355 } |
| 356 |
335 bool SyncDirectoryListing::HandleFile(char* file_name) { | 357 bool SyncDirectoryListing::HandleFile(char* file_name) { |
336 Dart_Handle file_name_dart = DartUtils::NewString(file_name); | 358 Dart_Handle file_name_dart = DartUtils::NewString(file_name); |
337 Dart_Handle file = | 359 Dart_Handle file = |
338 Dart_New(file_class_, Dart_Null(), 1, &file_name_dart); | 360 Dart_New(file_class_, Dart_Null(), 1, &file_name_dart); |
339 Dart_Invoke(results_, add_string_, 1, &file); | 361 Dart_Invoke(results_, add_string_, 1, &file); |
340 return true; | 362 return true; |
341 } | 363 } |
342 | 364 |
343 bool SyncDirectoryListing::HandleError(const char* dir_name) { | 365 bool SyncDirectoryListing::HandleError(const char* dir_name) { |
344 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); | 366 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); |
345 Dart_Handle args[3]; | 367 Dart_Handle args[3]; |
346 args[0] = DartUtils::NewString("Directory listing failed"); | 368 args[0] = DartUtils::NewString("Directory listing failed"); |
347 args[1] = DartUtils::NewString(dir_name); | 369 args[1] = DartUtils::NewString(dir_name); |
348 args[2] = dart_os_error; | 370 args[2] = dart_os_error; |
349 Dart_ThrowException(Dart_New( | 371 Dart_ThrowException(Dart_New( |
350 DartUtils::GetDartClass(DartUtils::kIOLibURL, "DirectoryIOException"), | 372 DartUtils::GetDartClass(DartUtils::kIOLibURL, "DirectoryIOException"), |
351 Dart_Null(), | 373 Dart_Null(), |
352 3, | 374 3, |
353 args)); | 375 args)); |
354 return true; | 376 return true; |
355 } | 377 } |
OLD | NEW |