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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "bin/directory.h" | 7 #include "bin/directory.h" |
8 | 8 |
9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
10 #include "bin/log.h" | 10 #include "bin/log.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 void FUNCTION_NAME(Directory_FillWithDirectoryListing)( | 120 void FUNCTION_NAME(Directory_FillWithDirectoryListing)( |
121 Dart_NativeArguments args) { | 121 Dart_NativeArguments args) { |
122 // The list that we should fill. | 122 // The list that we should fill. |
123 Dart_Handle results = Dart_GetNativeArgument(args, 0); | 123 Dart_Handle results = Dart_GetNativeArgument(args, 0); |
124 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 124 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
125 Dart_Handle recursive = Dart_GetNativeArgument(args, 2); | 125 Dart_Handle recursive = Dart_GetNativeArgument(args, 2); |
126 Dart_Handle follow_links = Dart_GetNativeArgument(args, 3); | 126 Dart_Handle follow_links = Dart_GetNativeArgument(args, 3); |
127 // Pass the list that should hold the directory listing to the | 127 |
128 // SyncDirectoryListing object, which adds elements to it. | 128 Dart_Handle dart_error; |
129 SyncDirectoryListing sync_listing(results, DartUtils::GetStringValue(path), | 129 { |
130 DartUtils::GetBooleanValue(recursive), | 130 // Pass the list that should hold the directory listing to the |
131 DartUtils::GetBooleanValue(follow_links)); | 131 // SyncDirectoryListing object, which adds elements to it. |
132 Directory::List(&sync_listing); | 132 SyncDirectoryListing sync_listing(results, DartUtils::GetStringValue(path), |
| 133 DartUtils::GetBooleanValue(recursive), |
| 134 DartUtils::GetBooleanValue(follow_links)); |
| 135 Directory::List(&sync_listing); |
| 136 dart_error = sync_listing.dart_error(); |
| 137 } |
| 138 if (Dart_IsError(dart_error)) { |
| 139 Dart_PropagateError(dart_error); |
| 140 } else if (!Dart_IsNull(dart_error)) { |
| 141 Dart_ThrowException(dart_error); |
| 142 } |
133 } | 143 } |
134 | 144 |
135 | 145 |
136 static const int kAsyncDirectoryListerFieldIndex = 0; | 146 static const int kAsyncDirectoryListerFieldIndex = 0; |
137 | 147 |
138 | 148 |
139 void FUNCTION_NAME(Directory_GetAsyncDirectoryListerPointer)( | 149 void FUNCTION_NAME(Directory_GetAsyncDirectoryListerPointer)( |
140 Dart_NativeArguments args) { | 150 Dart_NativeArguments args) { |
141 AsyncDirectoryListing* listing; | 151 AsyncDirectoryListing* listing; |
142 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); | 152 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 array_->SetAt(index_++, response); | 404 array_->SetAt(index_++, response); |
395 return index_ < length_; | 405 return index_ < length_; |
396 } | 406 } |
397 | 407 |
398 | 408 |
399 bool SyncDirectoryListing::HandleDirectory(const char* dir_name) { | 409 bool SyncDirectoryListing::HandleDirectory(const char* dir_name) { |
400 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); | 410 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); |
401 Dart_Handle dir = Dart_New(directory_type_, Dart_Null(), 1, &dir_name_dart); | 411 Dart_Handle dir = Dart_New(directory_type_, Dart_Null(), 1, &dir_name_dart); |
402 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &dir); | 412 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &dir); |
403 if (Dart_IsError(result)) { | 413 if (Dart_IsError(result)) { |
404 Dart_PropagateError(result); | 414 dart_error_ = result; |
| 415 return false; |
405 } | 416 } |
406 return true; | 417 return true; |
407 } | 418 } |
408 | 419 |
409 | 420 |
410 bool SyncDirectoryListing::HandleLink(const char* link_name) { | 421 bool SyncDirectoryListing::HandleLink(const char* link_name) { |
411 Dart_Handle link_name_dart = DartUtils::NewString(link_name); | 422 Dart_Handle link_name_dart = DartUtils::NewString(link_name); |
412 Dart_Handle link = Dart_New(link_type_, Dart_Null(), 1, &link_name_dart); | 423 Dart_Handle link = Dart_New(link_type_, Dart_Null(), 1, &link_name_dart); |
413 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &link); | 424 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &link); |
414 if (Dart_IsError(result)) { | 425 if (Dart_IsError(result)) { |
415 Dart_PropagateError(result); | 426 dart_error_ = result; |
| 427 return false; |
416 } | 428 } |
417 return true; | 429 return true; |
418 } | 430 } |
419 | 431 |
420 | 432 |
421 bool SyncDirectoryListing::HandleFile(const char* file_name) { | 433 bool SyncDirectoryListing::HandleFile(const char* file_name) { |
422 Dart_Handle file_name_dart = DartUtils::NewString(file_name); | 434 Dart_Handle file_name_dart = DartUtils::NewString(file_name); |
423 Dart_Handle file = Dart_New(file_type_, Dart_Null(), 1, &file_name_dart); | 435 Dart_Handle file = Dart_New(file_type_, Dart_Null(), 1, &file_name_dart); |
424 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &file); | 436 Dart_Handle result = Dart_Invoke(results_, add_string_, 1, &file); |
425 if (Dart_IsError(result)) { | 437 if (Dart_IsError(result)) { |
426 Dart_PropagateError(result); | 438 dart_error_ = result; |
| 439 return false; |
427 } | 440 } |
428 return true; | 441 return true; |
429 } | 442 } |
430 | 443 |
431 | 444 |
432 bool SyncDirectoryListing::HandleError() { | 445 bool SyncDirectoryListing::HandleError() { |
433 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); | 446 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); |
434 Dart_Handle args[3]; | 447 Dart_Handle args[3]; |
435 args[0] = DartUtils::NewString("Directory listing failed"); | 448 args[0] = DartUtils::NewString("Directory listing failed"); |
436 args[1] = DartUtils::NewString(error() ? "Invalid path" : CurrentPath()); | 449 args[1] = DartUtils::NewString(error() ? "Invalid path" : CurrentPath()); |
437 args[2] = dart_os_error; | 450 args[2] = dart_os_error; |
438 Dart_ThrowException(Dart_New( | 451 |
| 452 dart_error_ = Dart_New( |
439 DartUtils::GetDartType(DartUtils::kIOLibURL, "FileSystemException"), | 453 DartUtils::GetDartType(DartUtils::kIOLibURL, "FileSystemException"), |
440 Dart_Null(), 3, args)); | 454 Dart_Null(), 3, args); |
441 return true; | 455 return false; |
442 } | 456 } |
443 | 457 |
444 | 458 |
445 static bool ListNext(DirectoryListing* listing) { | 459 static bool ListNext(DirectoryListing* listing) { |
446 switch (listing->top()->Next(listing)) { | 460 switch (listing->top()->Next(listing)) { |
447 case kListFile: | 461 case kListFile: |
448 return listing->HandleFile(listing->CurrentPath()); | 462 return listing->HandleFile(listing->CurrentPath()); |
449 | 463 |
450 case kListLink: | 464 case kListLink: |
451 return listing->HandleLink(listing->CurrentPath()); | 465 return listing->HandleLink(listing->CurrentPath()); |
(...skipping 30 matching lines...) Expand all Loading... |
482 } else { | 496 } else { |
483 while (ListNext(listing)) { | 497 while (ListNext(listing)) { |
484 } | 498 } |
485 } | 499 } |
486 } | 500 } |
487 | 501 |
488 } // namespace bin | 502 } // namespace bin |
489 } // namespace dart | 503 } // namespace dart |
490 | 504 |
491 #endif // !defined(DART_IO_DISABLED) | 505 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |