Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: runtime/bin/directory.cc

Issue 3007703002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Remove namespace_unsupported.cc Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/directory.h ('k') | runtime/bin/directory_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/log.h" 8 #include "bin/log.h"
9 #include "bin/namespace.h"
9 #include "include/dart_api.h" 10 #include "include/dart_api.h"
10 #include "platform/assert.h" 11 #include "platform/assert.h"
11 12
12 namespace dart { 13 namespace dart {
13 namespace bin { 14 namespace bin {
14 15
15 char* Directory::system_temp_path_override_ = NULL; 16 char* Directory::system_temp_path_override_ = NULL;
16 17
17 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { 18 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) {
18 const char* current = Directory::Current(); 19 Namespace* namespc = Namespace::GetNamespace(args, 0);
20 const char* current = Directory::Current(namespc);
19 if (current != NULL) { 21 if (current != NULL) {
20 Dart_SetReturnValue(args, DartUtils::NewString(current)); 22 Dart_SetReturnValue(args, DartUtils::NewString(current));
21 } else { 23 } else {
22 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 24 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
23 } 25 }
24 } 26 }
25 27
26 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { 28 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) {
27 int argc = Dart_GetNativeArgumentCount(args); 29 Namespace* namespc = Namespace::GetNamespace(args, 0);
28 Dart_Handle path; 30 Dart_Handle path = Dart_GetNativeArgument(args, 1);
29 if (argc == 1) { 31 if (Dart_IsError(path) || !Dart_IsString(path)) {
30 path = Dart_GetNativeArgument(args, 0); 32 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL));
33 return;
31 } 34 }
32 if ((argc != 1) || !Dart_IsString(path)) { 35 if (Directory::SetCurrent(namespc, DartUtils::GetStringValue(path))) {
33 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); 36 Dart_SetBooleanReturnValue(args, true);
34 } else { 37 } else {
35 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { 38 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
36 Dart_SetReturnValue(args, Dart_True());
37 } else {
38 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
39 }
40 } 39 }
41 } 40 }
42 41
43 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { 42 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) {
44 static const int kExists = 1; 43 static const int kExists = 1;
45 static const int kDoesNotExist = 0; 44 static const int kDoesNotExist = 0;
46 Dart_Handle path = Dart_GetNativeArgument(args, 0); 45 Namespace* namespc = Namespace::GetNamespace(args, 0);
46 Dart_Handle path = Dart_GetNativeArgument(args, 1);
47 Directory::ExistsResult result = 47 Directory::ExistsResult result =
48 Directory::Exists(DartUtils::GetStringValue(path)); 48 Directory::Exists(namespc, DartUtils::GetStringValue(path));
49 if (result == Directory::EXISTS) { 49 if (result == Directory::EXISTS) {
50 Dart_SetReturnValue(args, Dart_NewInteger(kExists)); 50 Dart_SetIntegerReturnValue(args, kExists);
51 } else if (result == Directory::DOES_NOT_EXIST) { 51 } else if (result == Directory::DOES_NOT_EXIST) {
52 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); 52 Dart_SetIntegerReturnValue(args, kDoesNotExist);
53 } else { 53 } else {
54 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 54 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
55 } 55 }
56 } 56 }
57 57
58 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { 58 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) {
59 Dart_Handle path = Dart_GetNativeArgument(args, 0); 59 Namespace* namespc = Namespace::GetNamespace(args, 0);
60 if (Directory::Create(DartUtils::GetStringValue(path))) { 60 Dart_Handle path = Dart_GetNativeArgument(args, 1);
61 Dart_SetReturnValue(args, Dart_True()); 61 if (Directory::Create(namespc, DartUtils::GetStringValue(path))) {
62 Dart_SetBooleanReturnValue(args, true);
62 } else { 63 } else {
63 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 64 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
64 } 65 }
65 } 66 }
66 67
67 void FUNCTION_NAME(Directory_SystemTemp)(Dart_NativeArguments args) { 68 void FUNCTION_NAME(Directory_SystemTemp)(Dart_NativeArguments args) {
68 const char* result = Directory::SystemTemp(); 69 Namespace* namespc = Namespace::GetNamespace(args, 0);
70 const char* result = Directory::SystemTemp(namespc);
69 Dart_SetReturnValue(args, DartUtils::NewString(result)); 71 Dart_SetReturnValue(args, DartUtils::NewString(result));
70 } 72 }
71 73
72 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { 74 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) {
73 Dart_Handle path = Dart_GetNativeArgument(args, 0); 75 Namespace* namespc = Namespace::GetNamespace(args, 0);
76 Dart_Handle path = Dart_GetNativeArgument(args, 1);
74 if (!Dart_IsString(path)) { 77 if (!Dart_IsString(path)) {
75 Dart_SetReturnValue( 78 Dart_SetReturnValue(
76 args, DartUtils::NewDartArgumentError( 79 args, DartUtils::NewDartArgumentError(
77 "Prefix argument of CreateSystemTempSync is not a String")); 80 "Prefix argument of CreateSystemTempSync is not a String"));
78 return; 81 return;
79 } 82 }
80 const char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); 83 const char* result =
84 Directory::CreateTemp(namespc, DartUtils::GetStringValue(path));
81 if (result != NULL) { 85 if (result != NULL) {
82 Dart_SetReturnValue(args, DartUtils::NewString(result)); 86 Dart_SetReturnValue(args, DartUtils::NewString(result));
83 } else { 87 } else {
84 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 88 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
85 } 89 }
86 } 90 }
87 91
88 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { 92 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) {
89 Dart_Handle path = Dart_GetNativeArgument(args, 0); 93 Namespace* namespc = Namespace::GetNamespace(args, 0);
90 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); 94 Dart_Handle path = Dart_GetNativeArgument(args, 1);
91 if (Directory::Delete(DartUtils::GetStringValue(path), 95 Dart_Handle recursive = Dart_GetNativeArgument(args, 2);
96 if (Directory::Delete(namespc, DartUtils::GetStringValue(path),
92 DartUtils::GetBooleanValue(recursive))) { 97 DartUtils::GetBooleanValue(recursive))) {
93 Dart_SetReturnValue(args, Dart_True()); 98 Dart_SetBooleanReturnValue(args, true);
94 } else { 99 } else {
95 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 100 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
96 } 101 }
97 } 102 }
98 103
99 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) { 104 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) {
100 Dart_Handle path = Dart_GetNativeArgument(args, 0); 105 Namespace* namespc = Namespace::GetNamespace(args, 0);
101 Dart_Handle newPath = Dart_GetNativeArgument(args, 1); 106 Dart_Handle path = Dart_GetNativeArgument(args, 1);
102 if (Directory::Rename(DartUtils::GetStringValue(path), 107 Dart_Handle newPath = Dart_GetNativeArgument(args, 2);
108 if (Directory::Rename(namespc, DartUtils::GetStringValue(path),
103 DartUtils::GetStringValue(newPath))) { 109 DartUtils::GetStringValue(newPath))) {
104 Dart_SetReturnValue(args, Dart_True()); 110 Dart_SetBooleanReturnValue(args, true);
105 } else { 111 } else {
106 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 112 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
107 } 113 }
108 } 114 }
109 115
110 void FUNCTION_NAME(Directory_FillWithDirectoryListing)( 116 void FUNCTION_NAME(Directory_FillWithDirectoryListing)(
111 Dart_NativeArguments args) { 117 Dart_NativeArguments args) {
118 Namespace* namespc = Namespace::GetNamespace(args, 0);
112 // The list that we should fill. 119 // The list that we should fill.
113 Dart_Handle results = Dart_GetNativeArgument(args, 0); 120 Dart_Handle results = Dart_GetNativeArgument(args, 1);
114 Dart_Handle path = Dart_GetNativeArgument(args, 1); 121 Dart_Handle path = Dart_GetNativeArgument(args, 2);
115 Dart_Handle recursive = Dart_GetNativeArgument(args, 2); 122 Dart_Handle recursive = Dart_GetNativeArgument(args, 3);
116 Dart_Handle follow_links = Dart_GetNativeArgument(args, 3); 123 Dart_Handle follow_links = Dart_GetNativeArgument(args, 4);
117 124
118 Dart_Handle dart_error; 125 Dart_Handle dart_error;
119 { 126 {
120 // Pass the list that should hold the directory listing to the 127 // Pass the list that should hold the directory listing to the
121 // SyncDirectoryListing object, which adds elements to it. 128 // SyncDirectoryListing object, which adds elements to it.
122 SyncDirectoryListing sync_listing(results, DartUtils::GetStringValue(path), 129 SyncDirectoryListing sync_listing(results, namespc,
130 DartUtils::GetStringValue(path),
123 DartUtils::GetBooleanValue(recursive), 131 DartUtils::GetBooleanValue(recursive),
124 DartUtils::GetBooleanValue(follow_links)); 132 DartUtils::GetBooleanValue(follow_links));
125 Directory::List(&sync_listing); 133 Directory::List(&sync_listing);
126 dart_error = sync_listing.dart_error(); 134 dart_error = sync_listing.dart_error();
127 } 135 }
128 if (Dart_IsError(dart_error)) { 136 if (Dart_IsError(dart_error)) {
129 Dart_PropagateError(dart_error); 137 Dart_PropagateError(dart_error);
130 } else if (!Dart_IsNull(dart_error)) { 138 } else if (!Dart_IsNull(dart_error)) {
131 Dart_ThrowException(dart_error); 139 Dart_ThrowException(dart_error);
132 } 140 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void Directory::SetSystemTemp(const char* path) { 188 void Directory::SetSystemTemp(const char* path) {
181 if (system_temp_path_override_ != NULL) { 189 if (system_temp_path_override_ != NULL) {
182 free(system_temp_path_override_); 190 free(system_temp_path_override_);
183 system_temp_path_override_ = NULL; 191 system_temp_path_override_ = NULL;
184 } 192 }
185 if (path != NULL) { 193 if (path != NULL) {
186 system_temp_path_override_ = strdup(path); 194 system_temp_path_override_ = strdup(path);
187 } 195 }
188 } 196 }
189 197
198 static Namespace* CObjectToNamespacePointer(CObject* cobject) {
199 CObjectIntptr value(cobject);
200 return reinterpret_cast<Namespace*>(value.Value());
201 }
202
190 CObject* Directory::CreateRequest(const CObjectArray& request) { 203 CObject* Directory::CreateRequest(const CObjectArray& request) {
191 if ((request.Length() == 1) && request[0]->IsString()) { 204 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
192 CObjectString path(request[0]); 205 return CObject::IllegalArgumentError();
193 if (Directory::Create(path.CString())) {
194 return CObject::True();
195 } else {
196 return CObject::NewOSError();
197 }
198 } 206 }
199 return CObject::IllegalArgumentError(); 207 Namespace* namespc = CObjectToNamespacePointer(request[0]);
208 RefCntReleaseScope<Namespace> rs(namespc);
209 if ((request.Length() != 2) || !request[1]->IsString()) {
210 return CObject::IllegalArgumentError();
211 }
212 CObjectString path(request[1]);
213 return Directory::Create(namespc, path.CString()) ? CObject::True()
214 : CObject::NewOSError();
200 } 215 }
201 216
202 CObject* Directory::DeleteRequest(const CObjectArray& request) { 217 CObject* Directory::DeleteRequest(const CObjectArray& request) {
203 if ((request.Length() == 2) && request[0]->IsString() && 218 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
204 request[1]->IsBool()) { 219 return CObject::IllegalArgumentError();
205 CObjectString path(request[0]);
206 CObjectBool recursive(request[1]);
207 if (Directory::Delete(path.CString(), recursive.Value())) {
208 return CObject::True();
209 } else {
210 return CObject::NewOSError();
211 }
212 } 220 }
213 return CObject::IllegalArgumentError(); 221 Namespace* namespc = CObjectToNamespacePointer(request[0]);
222 RefCntReleaseScope<Namespace> rs(namespc);
223 if ((request.Length() != 3) || !request[1]->IsString() ||
224 !request[2]->IsBool()) {
225 return CObject::IllegalArgumentError();
226 }
227 CObjectString path(request[1]);
228 CObjectBool recursive(request[2]);
229 return Directory::Delete(namespc, path.CString(), recursive.Value())
230 ? CObject::True()
231 : CObject::NewOSError();
214 } 232 }
215 233
216 CObject* Directory::ExistsRequest(const CObjectArray& request) { 234 CObject* Directory::ExistsRequest(const CObjectArray& request) {
217 static const int kExists = 1; 235 static const int kExists = 1;
218 static const int kDoesNotExist = 0; 236 static const int kDoesNotExist = 0;
219 if ((request.Length() == 1) && request[0]->IsString()) { 237 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
220 CObjectString path(request[0]); 238 return CObject::IllegalArgumentError();
221 Directory::ExistsResult result = Directory::Exists(path.CString());
222 if (result == Directory::EXISTS) {
223 return new CObjectInt32(CObject::NewInt32(kExists));
224 } else if (result == Directory::DOES_NOT_EXIST) {
225 return new CObjectInt32(CObject::NewInt32(kDoesNotExist));
226 } else {
227 return CObject::NewOSError();
228 }
229 } 239 }
230 return CObject::IllegalArgumentError(); 240 Namespace* namespc = CObjectToNamespacePointer(request[0]);
241 RefCntReleaseScope<Namespace> rs(namespc);
242 if ((request.Length() != 2) || !request[1]->IsString()) {
243 return CObject::IllegalArgumentError();
244 }
245 CObjectString path(request[1]);
246 Directory::ExistsResult result = Directory::Exists(namespc, path.CString());
247 if (result == Directory::EXISTS) {
248 return new CObjectInt32(CObject::NewInt32(kExists));
249 } else if (result == Directory::DOES_NOT_EXIST) {
250 return new CObjectInt32(CObject::NewInt32(kDoesNotExist));
251 } else {
252 return CObject::NewOSError();
253 }
231 } 254 }
232 255
233 CObject* Directory::CreateTempRequest(const CObjectArray& request) { 256 CObject* Directory::CreateTempRequest(const CObjectArray& request) {
234 if ((request.Length() == 1) && request[0]->IsString()) { 257 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
235 CObjectString path(request[0]); 258 return CObject::IllegalArgumentError();
236 const char* result = Directory::CreateTemp(path.CString());
237 if (result != NULL) {
238 CObject* temp_dir = new CObjectString(CObject::NewString(result));
239 return temp_dir;
240 } else {
241 return CObject::NewOSError();
242 }
243 } 259 }
244 return CObject::IllegalArgumentError(); 260 Namespace* namespc = CObjectToNamespacePointer(request[0]);
261 RefCntReleaseScope<Namespace> rs(namespc);
262 if ((request.Length() != 2) || !request[1]->IsString()) {
263 return CObject::IllegalArgumentError();
264 }
265 CObjectString path(request[1]);
266 const char* result = Directory::CreateTemp(namespc, path.CString());
267 if (result == NULL) {
268 return CObject::NewOSError();
269 }
270 return new CObjectString(CObject::NewString(result));
245 } 271 }
246 272
247 static CObject* CreateIllegalArgumentError() { 273 static CObject* CreateIllegalArgumentError() {
248 // Respond with an illegal argument list error message. 274 // Respond with an illegal argument list error message.
249 CObjectArray* error = new CObjectArray(CObject::NewArray(3)); 275 CObjectArray* error = new CObjectArray(CObject::NewArray(3));
250 error->SetAt(0, new CObjectInt32( 276 error->SetAt(0, new CObjectInt32(
251 CObject::NewInt32(AsyncDirectoryListing::kListError))); 277 CObject::NewInt32(AsyncDirectoryListing::kListError)));
252 error->SetAt(1, CObject::Null()); 278 error->SetAt(1, CObject::Null());
253 error->SetAt(2, CObject::IllegalArgumentError()); 279 error->SetAt(2, CObject::IllegalArgumentError());
254 return error; 280 return error;
255 } 281 }
256 282
257 CObject* Directory::ListStartRequest(const CObjectArray& request) { 283 CObject* Directory::ListStartRequest(const CObjectArray& request) {
258 if ((request.Length() == 3) && request[0]->IsString() && 284 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
259 request[1]->IsBool() && request[2]->IsBool()) { 285 return CreateIllegalArgumentError();
260 CObjectString path(request[0]);
261 CObjectBool recursive(request[1]);
262 CObjectBool follow_links(request[2]);
263 AsyncDirectoryListing* dir_listing = new AsyncDirectoryListing(
264 path.CString(), recursive.Value(), follow_links.Value());
265 if (dir_listing->error()) {
266 // Report error now, so we capture the correct OSError.
267 CObject* err = CObject::NewOSError();
268 dir_listing->Release();
269 CObjectArray* error = new CObjectArray(CObject::NewArray(3));
270 error->SetAt(0, new CObjectInt32(CObject::NewInt32(
271 AsyncDirectoryListing::kListError)));
272 error->SetAt(1, request[0]);
273 error->SetAt(2, err);
274 return error;
275 }
276 // TODO(ajohnsen): Consider returning the first few results.
277 return new CObjectIntptr(
278 CObject::NewIntptr(reinterpret_cast<intptr_t>(dir_listing)));
279 } 286 }
280 return CreateIllegalArgumentError(); 287 Namespace* namespc = CObjectToNamespacePointer(request[0]);
288 RefCntReleaseScope<Namespace> rs(namespc);
289 if ((request.Length() != 4) || !request[1]->IsString() ||
290 !request[2]->IsBool() || !request[3]->IsBool()) {
291 return CreateIllegalArgumentError();
292 }
293 CObjectString path(request[1]);
294 CObjectBool recursive(request[2]);
295 CObjectBool follow_links(request[3]);
296 AsyncDirectoryListing* dir_listing = new AsyncDirectoryListing(
297 namespc, path.CString(), recursive.Value(), follow_links.Value());
298 if (dir_listing->error()) {
299 // Report error now, so we capture the correct OSError.
300 CObject* err = CObject::NewOSError();
301 dir_listing->Release();
302 CObjectArray* error = new CObjectArray(CObject::NewArray(3));
303 error->SetAt(0, new CObjectInt32(
304 CObject::NewInt32(AsyncDirectoryListing::kListError)));
305 error->SetAt(1, request[1]);
306 error->SetAt(2, err);
307 return error;
308 }
309 // TODO(ajohnsen): Consider returning the first few results.
310 return new CObjectIntptr(
311 CObject::NewIntptr(reinterpret_cast<intptr_t>(dir_listing)));
281 } 312 }
282 313
283 CObject* Directory::ListNextRequest(const CObjectArray& request) { 314 CObject* Directory::ListNextRequest(const CObjectArray& request) {
284 if ((request.Length() == 1) && request[0]->IsIntptr()) { 315 if ((request.Length() != 1) || !request[0]->IsIntptr()) {
285 CObjectIntptr ptr(request[0]); 316 return CreateIllegalArgumentError();
286 AsyncDirectoryListing* dir_listing =
287 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value());
288 RefCntReleaseScope<AsyncDirectoryListing> rs(dir_listing);
289 if (dir_listing->IsEmpty()) {
290 return new CObjectArray(CObject::NewArray(0));
291 }
292 const int kArraySize = 128;
293 CObjectArray* response = new CObjectArray(CObject::NewArray(kArraySize));
294 dir_listing->SetArray(response, kArraySize);
295 Directory::List(dir_listing);
296 // In case the listing ended before it hit the buffer length, we need to
297 // override the array length.
298 response->AsApiCObject()->value.as_array.length = dir_listing->index();
299 return response;
300 } 317 }
301 return CreateIllegalArgumentError(); 318 CObjectIntptr ptr(request[0]);
319 AsyncDirectoryListing* dir_listing =
320 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value());
321 RefCntReleaseScope<AsyncDirectoryListing> rs(dir_listing);
322 if (dir_listing->IsEmpty()) {
323 return new CObjectArray(CObject::NewArray(0));
324 }
325 const int kArraySize = 128;
326 CObjectArray* response = new CObjectArray(CObject::NewArray(kArraySize));
327 dir_listing->SetArray(response, kArraySize);
328 Directory::List(dir_listing);
329 // In case the listing ended before it hit the buffer length, we need to
330 // override the array length.
331 response->AsApiCObject()->value.as_array.length = dir_listing->index();
332 return response;
302 } 333 }
303 334
304 CObject* Directory::ListStopRequest(const CObjectArray& request) { 335 CObject* Directory::ListStopRequest(const CObjectArray& request) {
305 if ((request.Length() == 1) && request[0]->IsIntptr()) { 336 if ((request.Length() != 1) || !request[0]->IsIntptr()) {
306 CObjectIntptr ptr(request[0]); 337 return CreateIllegalArgumentError();
307 AsyncDirectoryListing* dir_listing = 338 }
308 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value()); 339 CObjectIntptr ptr(request[0]);
309 RefCntReleaseScope<AsyncDirectoryListing> rs(dir_listing); 340 AsyncDirectoryListing* dir_listing =
341 reinterpret_cast<AsyncDirectoryListing*>(ptr.Value());
342 RefCntReleaseScope<AsyncDirectoryListing> rs(dir_listing);
310 343
311 // We have retained a reference to the listing here. Therefore the listing's 344 // We have retained a reference to the listing here. Therefore the listing's
312 // destructor can't be running. Since no further requests are dispatched by 345 // destructor can't be running. Since no further requests are dispatched by
313 // the Dart code after an async stop call, this PopAll() can't be racing 346 // the Dart code after an async stop call, this PopAll() can't be racing
314 // with any other call on the listing. We don't do an extra Release(), and 347 // with any other call on the listing. We don't do an extra Release(), and
315 // we don't delete the weak persistent handle. The file is closed here, but 348 // we don't delete the weak persistent handle. The file is closed here, but
316 // the memory for the listing will be cleaned up when the finalizer runs. 349 // the memory for the listing will be cleaned up when the finalizer runs.
317 dir_listing->PopAll(); 350 dir_listing->PopAll();
318 return new CObjectBool(CObject::Bool(true)); 351 return new CObjectBool(CObject::Bool(true));
319 }
320 return CreateIllegalArgumentError();
321 } 352 }
322 353
323 CObject* Directory::RenameRequest(const CObjectArray& request) { 354 CObject* Directory::RenameRequest(const CObjectArray& request) {
324 if ((request.Length() == 2) && request[0]->IsString() && 355 if ((request.Length() < 1) || !request[0]->IsIntptr()) {
325 request[1]->IsString()) { 356 return CObject::IllegalArgumentError();
326 CObjectString path(request[0]);
327 CObjectString new_path(request[1]);
328 bool completed = Directory::Rename(path.CString(), new_path.CString());
329 if (completed) {
330 return CObject::True();
331 }
332 return CObject::NewOSError();
333 } 357 }
334 return CObject::IllegalArgumentError(); 358 Namespace* namespc = CObjectToNamespacePointer(request[0]);
359 RefCntReleaseScope<Namespace> rs(namespc);
360 if ((request.Length() != 3) || !request[1]->IsString() ||
361 !request[2]->IsString()) {
362 return CObject::IllegalArgumentError();
363 }
364 CObjectString path(request[1]);
365 CObjectString new_path(request[2]);
366 return Directory::Rename(namespc, path.CString(), new_path.CString())
367 ? CObject::True()
368 : CObject::NewOSError();
335 } 369 }
336 370
337 bool AsyncDirectoryListing::AddFileSystemEntityToResponse(Response type, 371 bool AsyncDirectoryListing::AddFileSystemEntityToResponse(Response type,
338 const char* arg) { 372 const char* arg) {
339 array_->SetAt(index_++, new CObjectInt32(CObject::NewInt32(type))); 373 array_->SetAt(index_++, new CObjectInt32(CObject::NewInt32(type)));
340 if (arg != NULL) { 374 if (arg != NULL) {
341 array_->SetAt(index_++, new CObjectString(CObject::NewString(arg))); 375 array_->SetAt(index_++, new CObjectString(CObject::NewString(arg)));
342 } else { 376 } else {
343 array_->SetAt(index_++, CObject::Null()); 377 array_->SetAt(index_++, CObject::Null());
344 } 378 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 void Directory::List(DirectoryListing* listing) { 490 void Directory::List(DirectoryListing* listing) {
457 if (listing->error()) { 491 if (listing->error()) {
458 listing->HandleError(); 492 listing->HandleError();
459 listing->HandleDone(); 493 listing->HandleDone();
460 } else { 494 } else {
461 while (ListNext(listing)) { 495 while (ListNext(listing)) {
462 } 496 }
463 } 497 }
464 } 498 }
465 499
500 const char* Directory::Current(Namespace* namespc) {
501 return Namespace::GetCurrent(namespc);
502 }
503
504 bool Directory::SetCurrent(Namespace* namespc, const char* name) {
505 return Namespace::SetCurrent(namespc, name);
506 }
507
466 } // namespace bin 508 } // namespace bin
467 } // namespace dart 509 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/directory.h ('k') | runtime/bin/directory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698