| 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" |
| 11 | 11 |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 namespace bin { | 14 namespace bin { |
| 15 | 15 |
| 16 // Forward declaration. | 16 // Forward declaration. |
| 17 static void DirectoryService(Dart_Port, Dart_Port, Dart_CObject*); | 17 static void DirectoryService(Dart_Port, Dart_Port, Dart_CObject*); |
| 18 | 18 |
| 19 NativeService Directory::directory_service_("DirectoryService", | 19 NativeService Directory::directory_service_("DirectoryService", |
| 20 DirectoryService, | 20 DirectoryService, |
| 21 16); | 21 16); |
| 22 | 22 |
| 23 | 23 |
| 24 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { | 24 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { |
| 25 Dart_EnterScope(); | |
| 26 char* current = Directory::Current(); | 25 char* current = Directory::Current(); |
| 27 if (current != NULL) { | 26 if (current != NULL) { |
| 28 Dart_SetReturnValue(args, DartUtils::NewString(current)); | 27 Dart_SetReturnValue(args, DartUtils::NewString(current)); |
| 29 free(current); | 28 free(current); |
| 30 } | 29 } |
| 31 Dart_ExitScope(); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 | 32 |
| 35 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { | 33 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { |
| 36 Dart_EnterScope(); | |
| 37 int argc = Dart_GetNativeArgumentCount(args); | 34 int argc = Dart_GetNativeArgumentCount(args); |
| 38 Dart_Handle path; | 35 Dart_Handle path; |
| 39 if (argc == 1) { | 36 if (argc == 1) { |
| 40 path = Dart_GetNativeArgument(args, 0); | 37 path = Dart_GetNativeArgument(args, 0); |
| 41 } | 38 } |
| 42 if (argc != 1 || !Dart_IsString(path)) { | 39 if (argc != 1 || !Dart_IsString(path)) { |
| 43 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); | 40 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); |
| 44 } else { | 41 } else { |
| 45 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { | 42 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { |
| 46 Dart_SetReturnValue(args, Dart_True()); | 43 Dart_SetReturnValue(args, Dart_True()); |
| 47 } else { | 44 } else { |
| 48 Dart_Handle err = DartUtils::NewDartOSError(); | 45 Dart_Handle err = DartUtils::NewDartOSError(); |
| 49 if (Dart_IsError(err)) Dart_PropagateError(err); | 46 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 50 Dart_SetReturnValue(args, err); | 47 Dart_SetReturnValue(args, err); |
| 51 } | 48 } |
| 52 } | 49 } |
| 53 Dart_ExitScope(); | |
| 54 } | 50 } |
| 55 | 51 |
| 56 | 52 |
| 57 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { | 53 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { |
| 58 static const int kExists = 1; | 54 static const int kExists = 1; |
| 59 static const int kDoesNotExist = 0; | 55 static const int kDoesNotExist = 0; |
| 60 Dart_EnterScope(); | |
| 61 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 56 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 62 Directory::ExistsResult result = | 57 Directory::ExistsResult result = |
| 63 Directory::Exists(DartUtils::GetStringValue(path)); | 58 Directory::Exists(DartUtils::GetStringValue(path)); |
| 64 if (result == Directory::EXISTS) { | 59 if (result == Directory::EXISTS) { |
| 65 Dart_SetReturnValue(args, Dart_NewInteger(kExists)); | 60 Dart_SetReturnValue(args, Dart_NewInteger(kExists)); |
| 66 } else if (result == Directory::DOES_NOT_EXIST) { | 61 } else if (result == Directory::DOES_NOT_EXIST) { |
| 67 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); | 62 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); |
| 68 } else { | 63 } else { |
| 69 Dart_Handle err = DartUtils::NewDartOSError(); | 64 Dart_Handle err = DartUtils::NewDartOSError(); |
| 70 if (Dart_IsError(err)) Dart_PropagateError(err); | 65 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 71 Dart_SetReturnValue(args, err); | 66 Dart_SetReturnValue(args, err); |
| 72 } | 67 } |
| 73 Dart_ExitScope(); | |
| 74 } | 68 } |
| 75 | 69 |
| 76 | 70 |
| 77 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { | 71 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { |
| 78 Dart_EnterScope(); | |
| 79 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 72 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 80 if (Directory::Create(DartUtils::GetStringValue(path))) { | 73 if (Directory::Create(DartUtils::GetStringValue(path))) { |
| 81 Dart_SetReturnValue(args, Dart_True()); | 74 Dart_SetReturnValue(args, Dart_True()); |
| 82 } else { | 75 } else { |
| 83 Dart_Handle err = DartUtils::NewDartOSError(); | 76 Dart_Handle err = DartUtils::NewDartOSError(); |
| 84 if (Dart_IsError(err)) Dart_PropagateError(err); | 77 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 85 Dart_SetReturnValue(args, err); | 78 Dart_SetReturnValue(args, err); |
| 86 } | 79 } |
| 87 Dart_ExitScope(); | |
| 88 } | 80 } |
| 89 | 81 |
| 90 | 82 |
| 91 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { | 83 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { |
| 92 Dart_EnterScope(); | |
| 93 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 84 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 94 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); | 85 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); |
| 95 if (result != NULL) { | 86 if (result != NULL) { |
| 96 Dart_SetReturnValue(args, DartUtils::NewString(result)); | 87 Dart_SetReturnValue(args, DartUtils::NewString(result)); |
| 97 free(result); | 88 free(result); |
| 98 } else { | 89 } else { |
| 99 Dart_Handle err = DartUtils::NewDartOSError(); | 90 Dart_Handle err = DartUtils::NewDartOSError(); |
| 100 if (Dart_IsError(err)) Dart_PropagateError(err); | 91 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 101 Dart_SetReturnValue(args, err); | 92 Dart_SetReturnValue(args, err); |
| 102 } | 93 } |
| 103 Dart_ExitScope(); | |
| 104 } | 94 } |
| 105 | 95 |
| 106 | 96 |
| 107 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | 97 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
| 108 Dart_EnterScope(); | |
| 109 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 98 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 110 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 99 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
| 111 if (Directory::Delete(DartUtils::GetStringValue(path), | 100 if (Directory::Delete(DartUtils::GetStringValue(path), |
| 112 DartUtils::GetBooleanValue(recursive))) { | 101 DartUtils::GetBooleanValue(recursive))) { |
| 113 Dart_SetReturnValue(args, Dart_True()); | 102 Dart_SetReturnValue(args, Dart_True()); |
| 114 } else { | 103 } else { |
| 115 Dart_Handle err = DartUtils::NewDartOSError(); | 104 Dart_Handle err = DartUtils::NewDartOSError(); |
| 116 if (Dart_IsError(err)) Dart_PropagateError(err); | 105 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 117 Dart_SetReturnValue(args, err); | 106 Dart_SetReturnValue(args, err); |
| 118 } | 107 } |
| 119 Dart_ExitScope(); | |
| 120 } | 108 } |
| 121 | 109 |
| 122 | 110 |
| 123 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) { | 111 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) { |
| 124 Dart_EnterScope(); | |
| 125 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 112 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 126 Dart_Handle newPath = Dart_GetNativeArgument(args, 1); | 113 Dart_Handle newPath = Dart_GetNativeArgument(args, 1); |
| 127 if (Directory::Rename(DartUtils::GetStringValue(path), | 114 if (Directory::Rename(DartUtils::GetStringValue(path), |
| 128 DartUtils::GetStringValue(newPath))) { | 115 DartUtils::GetStringValue(newPath))) { |
| 129 Dart_SetReturnValue(args, Dart_True()); | 116 Dart_SetReturnValue(args, Dart_True()); |
| 130 } else { | 117 } else { |
| 131 Dart_Handle err = DartUtils::NewDartOSError(); | 118 Dart_Handle err = DartUtils::NewDartOSError(); |
| 132 if (Dart_IsError(err)) Dart_PropagateError(err); | 119 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 133 Dart_SetReturnValue(args, err); | 120 Dart_SetReturnValue(args, err); |
| 134 } | 121 } |
| 135 Dart_ExitScope(); | |
| 136 } | 122 } |
| 137 | 123 |
| 138 | 124 |
| 139 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 125 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
| 140 Dart_EnterScope(); | |
| 141 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 126 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 142 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 127 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
| 143 // Create the list to hold the directory listing here, and pass it to the | 128 // Create the list to hold the directory listing here, and pass it to the |
| 144 // SyncDirectoryListing object, which adds elements to it. | 129 // SyncDirectoryListing object, which adds elements to it. |
| 145 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); | 130 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); |
| 146 // Create the list to hold the directory listing here, and pass it to the | 131 // Create the list to hold the directory listing here, and pass it to the |
| 147 // SyncDirectoryListing object, which adds elements to it. | 132 // SyncDirectoryListing object, which adds elements to it. |
| 148 Dart_Handle results = | 133 Dart_Handle results = |
| 149 Dart_New(DartUtils::GetDartType(DartUtils::kCoreLibURL, "List"), | 134 Dart_New(DartUtils::GetDartType(DartUtils::kCoreLibURL, "List"), |
| 150 Dart_Null(), | 135 Dart_Null(), |
| 151 0, | 136 0, |
| 152 NULL); | 137 NULL); |
| 153 SyncDirectoryListing sync_listing(results, | 138 SyncDirectoryListing sync_listing(results, |
| 154 DartUtils::GetStringValue(path), | 139 DartUtils::GetStringValue(path), |
| 155 DartUtils::GetBooleanValue(recursive), | 140 DartUtils::GetBooleanValue(recursive), |
| 156 DartUtils::GetBooleanValue(follow_links)); | 141 DartUtils::GetBooleanValue(follow_links)); |
| 157 Directory::List(&sync_listing); | 142 Directory::List(&sync_listing); |
| 158 Dart_SetReturnValue(args, results); | 143 Dart_SetReturnValue(args, results); |
| 159 Dart_ExitScope(); | |
| 160 } | 144 } |
| 161 | 145 |
| 162 | 146 |
| 163 static CObject* DirectoryCreateRequest(const CObjectArray& request) { | 147 static CObject* DirectoryCreateRequest(const CObjectArray& request) { |
| 164 if (request.Length() == 2 && request[1]->IsString()) { | 148 if (request.Length() == 2 && request[1]->IsString()) { |
| 165 CObjectString path(request[1]); | 149 CObjectString path(request[1]); |
| 166 if (Directory::Create(path.CString())) { | 150 if (Directory::Create(path.CString())) { |
| 167 return CObject::True(); | 151 return CObject::True(); |
| 168 } else { | 152 } else { |
| 169 return CObject::NewOSError(); | 153 return CObject::NewOSError(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 333 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
| 350 } | 334 } |
| 351 | 335 |
| 352 | 336 |
| 353 Dart_Port Directory::GetServicePort() { | 337 Dart_Port Directory::GetServicePort() { |
| 354 return directory_service_.GetServicePort(); | 338 return directory_service_.GetServicePort(); |
| 355 } | 339 } |
| 356 | 340 |
| 357 | 341 |
| 358 void FUNCTION_NAME(Directory_NewServicePort)(Dart_NativeArguments args) { | 342 void FUNCTION_NAME(Directory_NewServicePort)(Dart_NativeArguments args) { |
| 359 Dart_EnterScope(); | |
| 360 Dart_SetReturnValue(args, Dart_Null()); | 343 Dart_SetReturnValue(args, Dart_Null()); |
| 361 Dart_Port service_port = Directory::GetServicePort(); | 344 Dart_Port service_port = Directory::GetServicePort(); |
| 362 if (service_port != ILLEGAL_PORT) { | 345 if (service_port != ILLEGAL_PORT) { |
| 363 // Return a send port for the service port. | 346 // Return a send port for the service port. |
| 364 Dart_Handle send_port = Dart_NewSendPort(service_port); | 347 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 365 Dart_SetReturnValue(args, send_port); | 348 Dart_SetReturnValue(args, send_port); |
| 366 } | 349 } |
| 367 Dart_ExitScope(); | |
| 368 } | 350 } |
| 369 | 351 |
| 370 | 352 |
| 371 bool AsyncDirectoryListing::AddFileSystemEntityToResponse(Response type, | 353 bool AsyncDirectoryListing::AddFileSystemEntityToResponse(Response type, |
| 372 char* arg) { | 354 char* arg) { |
| 373 array_->SetAt(index_++, new CObjectInt32(CObject::NewInt32(type))); | 355 array_->SetAt(index_++, new CObjectInt32(CObject::NewInt32(type))); |
| 374 if (arg != NULL) { | 356 if (arg != NULL) { |
| 375 array_->SetAt(index_++, new CObjectString(CObject::NewString(arg))); | 357 array_->SetAt(index_++, new CObjectString(CObject::NewString(arg))); |
| 376 } else { | 358 } else { |
| 377 array_->SetAt(index_++, CObject::Null()); | 359 array_->SetAt(index_++, CObject::Null()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 if (listing->error()) { | 467 if (listing->error()) { |
| 486 listing->HandleError("Invalid path"); | 468 listing->HandleError("Invalid path"); |
| 487 listing->HandleDone(); | 469 listing->HandleDone(); |
| 488 } else { | 470 } else { |
| 489 while (ListNext(listing)) {} | 471 while (ListNext(listing)) {} |
| 490 } | 472 } |
| 491 } | 473 } |
| 492 | 474 |
| 493 } // namespace bin | 475 } // namespace bin |
| 494 } // namespace dart | 476 } // namespace dart |
| OLD | NEW |