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

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

Issue 105133004: Add File.copy(Sync) to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix permissions. Created 7 years 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/file.h ('k') | runtime/bin/file_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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 if (result) { 496 if (result) {
497 Dart_SetReturnValue(args, Dart_NewBoolean(result)); 497 Dart_SetReturnValue(args, Dart_NewBoolean(result));
498 } else { 498 } else {
499 Dart_Handle err = DartUtils::NewDartOSError(); 499 Dart_Handle err = DartUtils::NewDartOSError();
500 if (Dart_IsError(err)) Dart_PropagateError(err); 500 if (Dart_IsError(err)) Dart_PropagateError(err);
501 Dart_SetReturnValue(args, err); 501 Dart_SetReturnValue(args, err);
502 } 502 }
503 } 503 }
504 504
505 505
506 void FUNCTION_NAME(File_Copy)(Dart_NativeArguments args) {
507 const char* old_path =
508 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
509 const char* new_path =
510 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
511 bool result = File::Copy(old_path, new_path);
512 if (result) {
513 Dart_SetReturnValue(args, Dart_NewBoolean(result));
514 } else {
515 Dart_Handle err = DartUtils::NewDartOSError();
516 if (Dart_IsError(err)) Dart_PropagateError(err);
517 Dart_SetReturnValue(args, err);
518 }
519 }
520
521
506 void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) { 522 void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) {
507 const char* str = 523 const char* str =
508 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 524 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
509 char* path = File::GetCanonicalPath(str); 525 char* path = File::GetCanonicalPath(str);
510 if (path != NULL) { 526 if (path != NULL) {
511 Dart_SetReturnValue(args, DartUtils::NewString(path)); 527 Dart_SetReturnValue(args, DartUtils::NewString(path));
512 free(path); 528 free(path);
513 } else { 529 } else {
514 Dart_Handle err = DartUtils::NewDartOSError(); 530 Dart_Handle err = DartUtils::NewDartOSError();
515 if (Dart_IsError(err)) Dart_PropagateError(err); 531 if (Dart_IsError(err)) Dart_PropagateError(err);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 CObjectString old_path(request[0]); 715 CObjectString old_path(request[0]);
700 CObjectString new_path(request[1]); 716 CObjectString new_path(request[1]);
701 bool completed = File::Rename(old_path.CString(), new_path.CString()); 717 bool completed = File::Rename(old_path.CString(), new_path.CString());
702 if (completed) return CObject::True(); 718 if (completed) return CObject::True();
703 return CObject::NewOSError(); 719 return CObject::NewOSError();
704 } 720 }
705 return CObject::IllegalArgumentError(); 721 return CObject::IllegalArgumentError();
706 } 722 }
707 723
708 724
725 CObject* File::CopyRequest(const CObjectArray& request) {
726 if (request.Length() == 2 &&
727 request[0]->IsString() &&
728 request[1]->IsString()) {
729 CObjectString old_path(request[0]);
730 CObjectString new_path(request[1]);
731 bool completed = File::Copy(old_path.CString(), new_path.CString());
732 if (completed) return CObject::True();
733 return CObject::NewOSError();
734 }
735 return CObject::IllegalArgumentError();
736 }
737
738
709 CObject* File::ResolveSymbolicLinksRequest(const CObjectArray& request) { 739 CObject* File::ResolveSymbolicLinksRequest(const CObjectArray& request) {
710 if (request.Length() == 1 && request[0]->IsString()) { 740 if (request.Length() == 1 && request[0]->IsString()) {
711 CObjectString filename(request[0]); 741 CObjectString filename(request[0]);
712 char* result = File::GetCanonicalPath(filename.CString()); 742 char* result = File::GetCanonicalPath(filename.CString());
713 if (result != NULL) { 743 if (result != NULL) {
714 CObject* path = new CObjectString(CObject::NewString(result)); 744 CObject* path = new CObjectString(CObject::NewString(result));
715 free(result); 745 free(result);
716 return path; 746 return path;
717 } else { 747 } else {
718 return CObject::NewOSError(); 748 return CObject::NewOSError();
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); 1186 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2));
1157 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); 1187 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess)));
1158 wrapper->SetAt(1, result); 1188 wrapper->SetAt(1, result);
1159 return wrapper; 1189 return wrapper;
1160 } 1190 }
1161 return CObject::IllegalArgumentError(); 1191 return CObject::IllegalArgumentError();
1162 } 1192 }
1163 1193
1164 } // namespace bin 1194 } // namespace bin
1165 } // namespace dart 1195 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/file_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698