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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } else { | 58 } else { |
59 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 59 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
60 } | 60 } |
61 Dart_ExitScope(); | 61 Dart_ExitScope(); |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { | 65 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { |
66 Dart_EnterScope(); | 66 Dart_EnterScope(); |
67 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 67 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
68 Dart_Handle status_handle = Dart_GetNativeArgument(args, 1); | 68 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); |
69 static const int kMaxChildOsErrorMessageLength = 256; | 69 if (result != NULL) { |
70 char os_error_message[kMaxChildOsErrorMessageLength]; | |
71 if (!Dart_IsString(path)) { | |
72 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | |
73 DartUtils::SetStringField( | |
74 status_handle, "_errorMessage", "Invalid arguments"); | |
75 Dart_SetReturnValue(args, Dart_Null()); | |
76 Dart_ExitScope(); | |
77 return; | |
78 } | |
79 | |
80 char* result = NULL; | |
81 int error_code = Directory::CreateTemp(DartUtils::GetStringValue(path), | |
82 &result, | |
83 os_error_message, | |
84 kMaxChildOsErrorMessageLength); | |
85 if (error_code == 0) { | |
86 Dart_SetReturnValue(args, Dart_NewString(result)); | 70 Dart_SetReturnValue(args, Dart_NewString(result)); |
87 free(result); | 71 free(result); |
88 } else { | 72 } else { |
89 ASSERT(result == NULL); | 73 Dart_Handle err = DartUtils::NewDartOSError(); |
90 if (error_code == -1) { | 74 if (Dart_IsError(err)) { |
91 DartUtils::SetIntegerField(status_handle, "_errorCode", 0); | 75 Dart_PropagateError(err); |
92 DartUtils::SetStringField( | |
93 status_handle, "_errorMessage", "Invalid arguments"); | |
94 } else { | |
95 DartUtils::SetIntegerField( | |
96 status_handle, "_errorCode", error_code); | |
97 DartUtils::SetStringField( | |
98 status_handle, "_errorMessage", os_error_message); | |
99 } | 76 } |
100 Dart_SetReturnValue(args, Dart_Null()); | 77 Dart_SetReturnValue(args, err); |
101 } | 78 } |
102 Dart_ExitScope(); | 79 Dart_ExitScope(); |
103 } | 80 } |
104 | 81 |
105 | 82 |
106 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | 83 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
107 Dart_EnterScope(); | 84 Dart_EnterScope(); |
108 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 85 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
109 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 86 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
110 if (Dart_IsString(path) && Dart_IsBoolean(recursive)) { | 87 if (Dart_IsString(path) && Dart_IsBoolean(recursive)) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 132 } |
156 return new CObjectInt32(CObject::NewInt32(return_value)); | 133 return new CObjectInt32(CObject::NewInt32(return_value)); |
157 } | 134 } |
158 return new CObjectInt32(CObject::NewInt32(kDoesNotExist)); | 135 return new CObjectInt32(CObject::NewInt32(kDoesNotExist)); |
159 } | 136 } |
160 | 137 |
161 | 138 |
162 static CObject* DirectoryCreateTempRequest(const CObjectArray& request) { | 139 static CObject* DirectoryCreateTempRequest(const CObjectArray& request) { |
163 if (request.Length() == 2 && request[1]->IsString()) { | 140 if (request.Length() == 2 && request[1]->IsString()) { |
164 CObjectString path(request[1]); | 141 CObjectString path(request[1]); |
165 | 142 char* result = Directory::CreateTemp(path.CString()); |
166 static const int kMaxChildOsErrorMessageLength = 256; | 143 if (result != NULL) { |
167 char os_error_message[kMaxChildOsErrorMessageLength]; | |
168 char* result = NULL; | |
169 int error_code = Directory::CreateTemp(path.CString(), | |
170 &result, | |
171 os_error_message, | |
172 kMaxChildOsErrorMessageLength); | |
173 if (error_code == 0) { | |
174 CObject* temp_dir = new CObjectString(CObject::NewString(result)); | 144 CObject* temp_dir = new CObjectString(CObject::NewString(result)); |
175 free(result); | 145 free(result); |
176 return temp_dir; | 146 return temp_dir; |
177 } else { | 147 } else { |
178 ASSERT(result == NULL); | 148 return CObject::NewOSError(); |
179 CObjectArray* error_response = new CObjectArray(CObject::NewArray(2)); | |
180 if (error_code == -1) { | |
181 error_response->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); | |
182 error_response->SetAt( | |
183 1, new CObjectString(CObject::NewString("Invalid arguments"))); | |
184 } else { | |
185 error_response->SetAt( | |
186 0, new CObjectInt32(CObject::NewInt32(error_code))); | |
187 error_response->SetAt( | |
188 1, new CObjectString(CObject::NewString(os_error_message))); | |
189 } | |
190 return error_response; | |
191 } | 149 } |
192 } | 150 } |
193 return CObject::False(); | 151 return CObject::False(); |
194 } | 152 } |
195 | 153 |
196 | 154 |
197 static CObject* DirectoryListRequest(const CObjectArray& request, | 155 static CObject* DirectoryListRequest(const CObjectArray& request, |
198 Dart_Port response_port) { | 156 Dart_Port response_port) { |
199 if (request.Length() == 3 && request[1]->IsString() && request[2]->IsBool()) { | 157 if (request.Length() == 3 && request[1]->IsString() && request[2]->IsBool()) { |
200 DirectoryListing* dir_listing = new DirectoryListing(response_port); | 158 DirectoryListing* dir_listing = new DirectoryListing(response_port); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return Dart_PostCObject(response_port_, response->AsApiCObject()); | 266 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
309 } | 267 } |
310 | 268 |
311 | 269 |
312 bool DirectoryListing::HandleError(char* message) { | 270 bool DirectoryListing::HandleError(char* message) { |
313 // TODO(sgjesse): Pass flags to indicate whether error | 271 // TODO(sgjesse): Pass flags to indicate whether error |
314 // responses are needed. | 272 // responses are needed. |
315 CObjectArray* response = NewResponse(kListError, message); | 273 CObjectArray* response = NewResponse(kListError, message); |
316 return Dart_PostCObject(response_port_, response->AsApiCObject()); | 274 return Dart_PostCObject(response_port_, response->AsApiCObject()); |
317 } | 275 } |
OLD | NEW |