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

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

Issue 25279003: dart:io | Add Directory.CreateSystemTemp(template) and change Directory.CreateTemp(template). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add check of "TMP" environment variable if "TMPDIR" is missing. Created 7 years, 2 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 | Annotate | Revision Log
« 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/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } else { 71 } else {
72 Dart_Handle err = DartUtils::NewDartOSError(); 72 Dart_Handle err = DartUtils::NewDartOSError();
73 if (Dart_IsError(err)) Dart_PropagateError(err); 73 if (Dart_IsError(err)) Dart_PropagateError(err);
74 Dart_SetReturnValue(args, err); 74 Dart_SetReturnValue(args, err);
75 } 75 }
76 } 76 }
77 77
78 78
79 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { 79 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) {
80 Dart_Handle path = Dart_GetNativeArgument(args, 0); 80 Dart_Handle path = Dart_GetNativeArgument(args, 0);
81 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); 81 Dart_Handle system = Dart_GetNativeArgument(args, 1);
82 if (!Dart_IsString(path)) {
83 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(
84 "Template argument of CreateSystemTempSync is not a String"));
85 return;
86 }
87 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path),
88 DartUtils::GetBooleanValue(system));
82 if (result != NULL) { 89 if (result != NULL) {
83 Dart_SetReturnValue(args, DartUtils::NewString(result)); 90 Dart_SetReturnValue(args, DartUtils::NewString(result));
84 free(result); 91 free(result);
85 } else { 92 } else {
86 Dart_Handle err = DartUtils::NewDartOSError(); 93 Dart_Handle err = DartUtils::NewDartOSError();
87 if (Dart_IsError(err)) Dart_PropagateError(err); 94 if (Dart_IsError(err)) Dart_PropagateError(err);
88 Dart_SetReturnValue(args, err); 95 Dart_SetReturnValue(args, err);
89 } 96 }
90 } 97 }
91 98
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return CObject::NewOSError(); 188 return CObject::NewOSError();
182 } 189 }
183 } 190 }
184 return CObject::IllegalArgumentError(); 191 return CObject::IllegalArgumentError();
185 } 192 }
186 193
187 194
188 CObject* Directory::CreateTempRequest(const CObjectArray& request) { 195 CObject* Directory::CreateTempRequest(const CObjectArray& request) {
189 if (request.Length() == 1 && request[0]->IsString()) { 196 if (request.Length() == 1 && request[0]->IsString()) {
190 CObjectString path(request[0]); 197 CObjectString path(request[0]);
191 char* result = Directory::CreateTemp(path.CString()); 198 char* result = Directory::CreateTemp(path.CString(), false);
192 if (result != NULL) { 199 if (result != NULL) {
193 CObject* temp_dir = new CObjectString(CObject::NewString(result)); 200 CObject* temp_dir = new CObjectString(CObject::NewString(result));
194 free(result); 201 free(result);
195 return temp_dir; 202 return temp_dir;
196 } else { 203 } else {
197 return CObject::NewOSError(); 204 return CObject::NewOSError();
198 } 205 }
199 } 206 }
200 return CObject::IllegalArgumentError(); 207 return CObject::IllegalArgumentError();
201 } 208 }
202 209
210
211 CObject* Directory::CreateSystemTempRequest(const CObjectArray& request) {
212 if (request.Length() == 1 && request[0]->IsString()) {
213 CObjectString path(request[0]);
214 char* result = Directory::CreateTemp(path.CString(), true);
215 if (result != NULL) {
216 CObject* temp_dir = new CObjectString(CObject::NewString(result));
217 free(result);
218 return temp_dir;
219 } else {
220 return CObject::NewOSError();
221 }
222 }
223 return CObject::IllegalArgumentError();
224 }
225
226
203 static CObject* CreateIllegalArgumentError() { 227 static CObject* CreateIllegalArgumentError() {
204 // Respond with an illegal argument list error message. 228 // Respond with an illegal argument list error message.
205 CObjectArray* error = new CObjectArray(CObject::NewArray(3)); 229 CObjectArray* error = new CObjectArray(CObject::NewArray(3));
206 error->SetAt(0, new CObjectInt32( 230 error->SetAt(0, new CObjectInt32(
207 CObject::NewInt32(AsyncDirectoryListing::kListError))); 231 CObject::NewInt32(AsyncDirectoryListing::kListError)));
208 error->SetAt(1, CObject::Null()); 232 error->SetAt(1, CObject::Null());
209 error->SetAt(2, CObject::IllegalArgumentError()); 233 error->SetAt(2, CObject::IllegalArgumentError());
210 return error; 234 return error;
211 } 235 }
212 236
237
213 CObject* Directory::ListStartRequest(const CObjectArray& request) { 238 CObject* Directory::ListStartRequest(const CObjectArray& request) {
214 if (request.Length() == 3 && 239 if (request.Length() == 3 &&
215 request[0]->IsString() && 240 request[0]->IsString() &&
216 request[1]->IsBool() && 241 request[1]->IsBool() &&
217 request[2]->IsBool()) { 242 request[2]->IsBool()) {
218 CObjectString path(request[0]); 243 CObjectString path(request[0]);
219 CObjectBool recursive(request[1]); 244 CObjectBool recursive(request[1]);
220 CObjectBool follow_links(request[2]); 245 CObjectBool follow_links(request[2]);
221 AsyncDirectoryListing* dir_listing = 246 AsyncDirectoryListing* dir_listing =
222 new AsyncDirectoryListing(path.CString(), 247 new AsyncDirectoryListing(path.CString(),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (listing->error()) { 428 if (listing->error()) {
404 listing->HandleError("Invalid path"); 429 listing->HandleError("Invalid path");
405 listing->HandleDone(); 430 listing->HandleDone();
406 } else { 431 } else {
407 while (ListNext(listing)) {} 432 while (ListNext(listing)) {}
408 } 433 }
409 } 434 }
410 435
411 } // namespace bin 436 } // namespace bin
412 } // namespace dart 437 } // 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