| 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 "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| 11 | |
| 12 namespace dart { | 11 namespace dart { |
| 13 namespace bin { | 12 namespace bin { |
| 14 | 13 |
| 15 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { | 14 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { |
| 16 const char* current = Directory::Current(); | 15 const char* current = Directory::Current(); |
| 17 if (current != NULL) { | 16 if (current != NULL) { |
| 18 Dart_SetReturnValue(args, DartUtils::NewString(current)); | 17 Dart_SetReturnValue(args, DartUtils::NewString(current)); |
| 19 } else { | 18 } else { |
| 20 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 19 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 21 } | 20 } |
| 22 } | 21 } |
| 23 | 22 |
| 24 | 23 |
| 25 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { | 24 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { |
| 26 int argc = Dart_GetNativeArgumentCount(args); | 25 int argc = Dart_GetNativeArgumentCount(args); |
| 27 Dart_Handle path; | 26 Dart_Handle path; |
| 28 if (argc == 1) { | 27 if (argc == 1) { |
| 29 path = Dart_GetNativeArgument(args, 0); | 28 path = Dart_GetNativeArgument(args, 0); |
| 30 } | 29 } |
| 31 if (argc != 1 || !Dart_IsString(path)) { | 30 if ((argc != 1) || !Dart_IsString(path)) { |
| 32 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); | 31 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); |
| 33 } else { | 32 } else { |
| 34 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { | 33 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { |
| 35 Dart_SetReturnValue(args, Dart_True()); | 34 Dart_SetReturnValue(args, Dart_True()); |
| 36 } else { | 35 } else { |
| 37 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 36 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 | 40 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { | 58 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { |
| 60 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 59 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 61 if (Directory::Create(DartUtils::GetStringValue(path))) { | 60 if (Directory::Create(DartUtils::GetStringValue(path))) { |
| 62 Dart_SetReturnValue(args, Dart_True()); | 61 Dart_SetReturnValue(args, Dart_True()); |
| 63 } else { | 62 } else { |
| 64 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 63 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 | 66 |
| 68 | 67 |
| 69 void FUNCTION_NAME(Directory_SystemTemp)( | 68 void FUNCTION_NAME(Directory_SystemTemp)(Dart_NativeArguments args) { |
| 70 Dart_NativeArguments args) { | |
| 71 const char* result = Directory::SystemTemp(); | 69 const char* result = Directory::SystemTemp(); |
| 72 Dart_SetReturnValue(args, DartUtils::NewString(result)); | 70 Dart_SetReturnValue(args, DartUtils::NewString(result)); |
| 73 } | 71 } |
| 74 | 72 |
| 75 | 73 |
| 76 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { | 74 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { |
| 77 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 75 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 78 if (!Dart_IsString(path)) { | 76 if (!Dart_IsString(path)) { |
| 79 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError( | 77 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError( |
| 80 "Prefix argument of CreateSystemTempSync is not a String")); | 78 "Prefix argument of CreateSystemTempSync is not a String")); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // 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 |
| 121 // SyncDirectoryListing object, which adds elements to it. | 119 // SyncDirectoryListing object, which adds elements to it. |
| 122 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); | 120 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); |
| 123 // Create the list to hold the directory listing here, and pass it to the | 121 // Create the list to hold the directory listing here, and pass it to the |
| 124 // SyncDirectoryListing object, which adds elements to it. | 122 // SyncDirectoryListing object, which adds elements to it. |
| 125 Dart_Handle results = | 123 Dart_Handle results = |
| 126 Dart_New(DartUtils::GetDartType(DartUtils::kCoreLibURL, "List"), | 124 Dart_New(DartUtils::GetDartType(DartUtils::kCoreLibURL, "List"), |
| 127 Dart_Null(), | 125 Dart_Null(), |
| 128 0, | 126 0, |
| 129 NULL); | 127 NULL); |
| 130 if (Dart_IsError(results)) Dart_PropagateError(results); | 128 if (Dart_IsError(results)) { |
| 129 Dart_PropagateError(results); |
| 130 } |
| 131 SyncDirectoryListing sync_listing(results, | 131 SyncDirectoryListing sync_listing(results, |
| 132 DartUtils::GetStringValue(path), | 132 DartUtils::GetStringValue(path), |
| 133 DartUtils::GetBooleanValue(recursive), | 133 DartUtils::GetBooleanValue(recursive), |
| 134 DartUtils::GetBooleanValue(follow_links)); | 134 DartUtils::GetBooleanValue(follow_links)); |
| 135 Directory::List(&sync_listing); | 135 Directory::List(&sync_listing); |
| 136 Dart_SetReturnValue(args, results); | 136 Dart_SetReturnValue(args, results); |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 |
| 140 CObject* Directory::CreateRequest(const CObjectArray& request) { | 140 CObject* Directory::CreateRequest(const CObjectArray& request) { |
| 141 if (request.Length() == 1 && request[0]->IsString()) { | 141 if ((request.Length() == 1) && request[0]->IsString()) { |
| 142 CObjectString path(request[0]); | 142 CObjectString path(request[0]); |
| 143 if (Directory::Create(path.CString())) { | 143 if (Directory::Create(path.CString())) { |
| 144 return CObject::True(); | 144 return CObject::True(); |
| 145 } else { | 145 } else { |
| 146 return CObject::NewOSError(); | 146 return CObject::NewOSError(); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 return CObject::IllegalArgumentError(); | 149 return CObject::IllegalArgumentError(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 | 152 |
| 153 CObject* Directory::DeleteRequest(const CObjectArray& request) { | 153 CObject* Directory::DeleteRequest(const CObjectArray& request) { |
| 154 if (request.Length() == 2 && request[0]->IsString() && request[1]->IsBool()) { | 154 if ((request.Length() == 2) && |
| 155 request[0]->IsString() && request[1]->IsBool()) { |
| 155 CObjectString path(request[0]); | 156 CObjectString path(request[0]); |
| 156 CObjectBool recursive(request[1]); | 157 CObjectBool recursive(request[1]); |
| 157 if (Directory::Delete(path.CString(), recursive.Value())) { | 158 if (Directory::Delete(path.CString(), recursive.Value())) { |
| 158 return CObject::True(); | 159 return CObject::True(); |
| 159 } else { | 160 } else { |
| 160 return CObject::NewOSError(); | 161 return CObject::NewOSError(); |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 return CObject::IllegalArgumentError(); | 164 return CObject::IllegalArgumentError(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 | 167 |
| 167 CObject* Directory::ExistsRequest(const CObjectArray& request) { | 168 CObject* Directory::ExistsRequest(const CObjectArray& request) { |
| 168 static const int kExists = 1; | 169 static const int kExists = 1; |
| 169 static const int kDoesNotExist = 0; | 170 static const int kDoesNotExist = 0; |
| 170 if (request.Length() == 1 && request[0]->IsString()) { | 171 if ((request.Length() == 1) && request[0]->IsString()) { |
| 171 CObjectString path(request[0]); | 172 CObjectString path(request[0]); |
| 172 Directory::ExistsResult result = Directory::Exists(path.CString()); | 173 Directory::ExistsResult result = Directory::Exists(path.CString()); |
| 173 if (result == Directory::EXISTS) { | 174 if (result == Directory::EXISTS) { |
| 174 return new CObjectInt32(CObject::NewInt32(kExists)); | 175 return new CObjectInt32(CObject::NewInt32(kExists)); |
| 175 } else if (result == Directory::DOES_NOT_EXIST) { | 176 } else if (result == Directory::DOES_NOT_EXIST) { |
| 176 return new CObjectInt32(CObject::NewInt32(kDoesNotExist)); | 177 return new CObjectInt32(CObject::NewInt32(kDoesNotExist)); |
| 177 } else { | 178 } else { |
| 178 return CObject::NewOSError(); | 179 return CObject::NewOSError(); |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 return CObject::IllegalArgumentError(); | 182 return CObject::IllegalArgumentError(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 | 185 |
| 185 CObject* Directory::CreateTempRequest(const CObjectArray& request) { | 186 CObject* Directory::CreateTempRequest(const CObjectArray& request) { |
| 186 if (request.Length() == 1 && request[0]->IsString()) { | 187 if ((request.Length() == 1) && request[0]->IsString()) { |
| 187 CObjectString path(request[0]); | 188 CObjectString path(request[0]); |
| 188 const char* result = Directory::CreateTemp(path.CString()); | 189 const char* result = Directory::CreateTemp(path.CString()); |
| 189 if (result != NULL) { | 190 if (result != NULL) { |
| 190 CObject* temp_dir = new CObjectString(CObject::NewString(result)); | 191 CObject* temp_dir = new CObjectString(CObject::NewString(result)); |
| 191 return temp_dir; | 192 return temp_dir; |
| 192 } else { | 193 } else { |
| 193 return CObject::NewOSError(); | 194 return CObject::NewOSError(); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 return CObject::IllegalArgumentError(); | 197 return CObject::IllegalArgumentError(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 | 200 |
| 200 static CObject* CreateIllegalArgumentError() { | 201 static CObject* CreateIllegalArgumentError() { |
| 201 // Respond with an illegal argument list error message. | 202 // Respond with an illegal argument list error message. |
| 202 CObjectArray* error = new CObjectArray(CObject::NewArray(3)); | 203 CObjectArray* error = new CObjectArray(CObject::NewArray(3)); |
| 203 error->SetAt(0, new CObjectInt32( | 204 error->SetAt(0, new CObjectInt32( |
| 204 CObject::NewInt32(AsyncDirectoryListing::kListError))); | 205 CObject::NewInt32(AsyncDirectoryListing::kListError))); |
| 205 error->SetAt(1, CObject::Null()); | 206 error->SetAt(1, CObject::Null()); |
| 206 error->SetAt(2, CObject::IllegalArgumentError()); | 207 error->SetAt(2, CObject::IllegalArgumentError()); |
| 207 return error; | 208 return error; |
| 208 } | 209 } |
| 209 | 210 |
| 210 | 211 |
| 211 CObject* Directory::ListStartRequest(const CObjectArray& request) { | 212 CObject* Directory::ListStartRequest(const CObjectArray& request) { |
| 212 if (request.Length() == 3 && | 213 if ((request.Length() == 3) && |
| 213 request[0]->IsString() && | 214 request[0]->IsString() && |
| 214 request[1]->IsBool() && | 215 request[1]->IsBool() && |
| 215 request[2]->IsBool()) { | 216 request[2]->IsBool()) { |
| 216 CObjectString path(request[0]); | 217 CObjectString path(request[0]); |
| 217 CObjectBool recursive(request[1]); | 218 CObjectBool recursive(request[1]); |
| 218 CObjectBool follow_links(request[2]); | 219 CObjectBool follow_links(request[2]); |
| 219 AsyncDirectoryListing* dir_listing = | 220 AsyncDirectoryListing* dir_listing = |
| 220 new AsyncDirectoryListing(path.CString(), | 221 new AsyncDirectoryListing(path.CString(), |
| 221 recursive.Value(), | 222 recursive.Value(), |
| 222 follow_links.Value()); | 223 follow_links.Value()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 AsyncDirectoryListing* dir_listing = | 267 AsyncDirectoryListing* dir_listing = |
| 267 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value()); | 268 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value()); |
| 268 delete dir_listing; | 269 delete dir_listing; |
| 269 return new CObjectBool(CObject::Bool(true)); | 270 return new CObjectBool(CObject::Bool(true)); |
| 270 } | 271 } |
| 271 return CreateIllegalArgumentError(); | 272 return CreateIllegalArgumentError(); |
| 272 } | 273 } |
| 273 | 274 |
| 274 | 275 |
| 275 CObject* Directory::RenameRequest(const CObjectArray& request) { | 276 CObject* Directory::RenameRequest(const CObjectArray& request) { |
| 276 if (request.Length() == 2 && | 277 if ((request.Length() == 2) && |
| 277 request[0]->IsString() && | 278 request[0]->IsString() && |
| 278 request[1]->IsString()) { | 279 request[1]->IsString()) { |
| 279 CObjectString path(request[0]); | 280 CObjectString path(request[0]); |
| 280 CObjectString new_path(request[1]); | 281 CObjectString new_path(request[1]); |
| 281 bool completed = Directory::Rename(path.CString(), new_path.CString()); | 282 bool completed = Directory::Rename(path.CString(), new_path.CString()); |
| 282 if (completed) { | 283 if (completed) { |
| 283 return CObject::True(); | 284 return CObject::True(); |
| 284 } | 285 } |
| 285 return CObject::NewOSError(); | 286 return CObject::NewOSError(); |
| 286 } | 287 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 if (listing->error()) { | 415 if (listing->error()) { |
| 415 listing->HandleError(); | 416 listing->HandleError(); |
| 416 listing->HandleDone(); | 417 listing->HandleDone(); |
| 417 } else { | 418 } else { |
| 418 while (ListNext(listing)) {} | 419 while (ListNext(listing)) {} |
| 419 } | 420 } |
| 420 } | 421 } |
| 421 | 422 |
| 422 } // namespace bin | 423 } // namespace bin |
| 423 } // namespace dart | 424 } // namespace dart |
| OLD | NEW |