OLD | NEW |
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 Dart_SetReturnValue(args, Dart_NewBoolean(result)); | 481 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
482 } else { | 482 } else { |
483 Dart_Handle err = DartUtils::NewDartOSError(); | 483 Dart_Handle err = DartUtils::NewDartOSError(); |
484 if (Dart_IsError(err)) Dart_PropagateError(err); | 484 if (Dart_IsError(err)) Dart_PropagateError(err); |
485 Dart_SetReturnValue(args, err); | 485 Dart_SetReturnValue(args, err); |
486 } | 486 } |
487 Dart_ExitScope(); | 487 Dart_ExitScope(); |
488 } | 488 } |
489 | 489 |
490 | 490 |
| 491 void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) { |
| 492 Dart_EnterScope(); |
| 493 const char* str = |
| 494 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
| 495 bool result = File::DeleteLink(str); |
| 496 if (result) { |
| 497 Dart_SetReturnValue(args, Dart_NewBoolean(result)); |
| 498 } else { |
| 499 Dart_Handle err = DartUtils::NewDartOSError(); |
| 500 if (Dart_IsError(err)) Dart_PropagateError(err); |
| 501 Dart_SetReturnValue(args, err); |
| 502 } |
| 503 Dart_ExitScope(); |
| 504 } |
| 505 |
| 506 |
491 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { | 507 void FUNCTION_NAME(File_Directory)(Dart_NativeArguments args) { |
492 Dart_EnterScope(); | 508 Dart_EnterScope(); |
493 const char* str = | 509 const char* str = |
494 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | 510 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); |
495 char* str_copy = strdup(str); | 511 char* str_copy = strdup(str); |
496 char* path = File::GetContainingDirectory(str_copy); | 512 char* path = File::GetContainingDirectory(str_copy); |
497 free(str_copy); | 513 free(str_copy); |
498 if (path != NULL) { | 514 if (path != NULL) { |
499 Dart_SetReturnValue(args, DartUtils::NewString(path)); | 515 Dart_SetReturnValue(args, DartUtils::NewString(path)); |
500 free(path); | 516 free(path); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 return CObject::NewOSError(); | 1006 return CObject::NewOSError(); |
991 } | 1007 } |
992 } else { | 1008 } else { |
993 return CObject::FileClosedError(); | 1009 return CObject::FileClosedError(); |
994 } | 1010 } |
995 } | 1011 } |
996 return CObject::IllegalArgumentError(); | 1012 return CObject::IllegalArgumentError(); |
997 } | 1013 } |
998 | 1014 |
999 | 1015 |
| 1016 static CObject* FileDeleteLinkRequest(const CObjectArray& request) { |
| 1017 if (request.Length() == 2 && request[1]->IsString()) { |
| 1018 CObjectString filename(request[1]); |
| 1019 bool result = File::DeleteLink(filename.CString()); |
| 1020 if (result) { |
| 1021 return CObject::True(); |
| 1022 } else { |
| 1023 return CObject::NewOSError(); |
| 1024 } |
| 1025 } |
| 1026 return CObject::False(); |
| 1027 } |
| 1028 |
| 1029 |
1000 static void FileService(Dart_Port dest_port_id, | 1030 static void FileService(Dart_Port dest_port_id, |
1001 Dart_Port reply_port_id, | 1031 Dart_Port reply_port_id, |
1002 Dart_CObject* message) { | 1032 Dart_CObject* message) { |
1003 CObject* response = CObject::IllegalArgumentError(); | 1033 CObject* response = CObject::IllegalArgumentError(); |
1004 CObjectArray request(message); | 1034 CObjectArray request(message); |
1005 if (message->type == Dart_CObject::kArray) { | 1035 if (message->type == Dart_CObject::kArray) { |
1006 if (request.Length() > 1 && request[0]->IsInt32()) { | 1036 if (request.Length() > 1 && request[0]->IsInt32()) { |
1007 CObjectInt32 requestType(request[0]); | 1037 CObjectInt32 requestType(request[0]); |
1008 switch (requestType.Value()) { | 1038 switch (requestType.Value()) { |
1009 case File::kExistsRequest: | 1039 case File::kExistsRequest: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 break; | 1086 break; |
1057 case File::kReadRequest: | 1087 case File::kReadRequest: |
1058 response = FileReadRequest(request); | 1088 response = FileReadRequest(request); |
1059 break; | 1089 break; |
1060 case File::kReadListRequest: | 1090 case File::kReadListRequest: |
1061 response = FileReadListRequest(request); | 1091 response = FileReadListRequest(request); |
1062 break; | 1092 break; |
1063 case File::kWriteListRequest: | 1093 case File::kWriteListRequest: |
1064 response = FileWriteListRequest(request); | 1094 response = FileWriteListRequest(request); |
1065 break; | 1095 break; |
| 1096 case File::kDeleteLinkRequest: |
| 1097 response = FileDeleteLinkRequest(request); |
| 1098 break; |
1066 default: | 1099 default: |
1067 UNREACHABLE(); | 1100 UNREACHABLE(); |
1068 } | 1101 } |
1069 } | 1102 } |
1070 } | 1103 } |
1071 | 1104 |
1072 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 1105 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
1073 } | 1106 } |
1074 | 1107 |
1075 | 1108 |
1076 Dart_Port File::GetServicePort() { | 1109 Dart_Port File::GetServicePort() { |
1077 return file_service_.GetServicePort(); | 1110 return file_service_.GetServicePort(); |
1078 } | 1111 } |
1079 | 1112 |
1080 | 1113 |
1081 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { | 1114 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { |
1082 Dart_EnterScope(); | 1115 Dart_EnterScope(); |
1083 Dart_SetReturnValue(args, Dart_Null()); | 1116 Dart_SetReturnValue(args, Dart_Null()); |
1084 Dart_Port service_port = File::GetServicePort(); | 1117 Dart_Port service_port = File::GetServicePort(); |
1085 if (service_port != ILLEGAL_PORT) { | 1118 if (service_port != ILLEGAL_PORT) { |
1086 // Return a send port for the service port. | 1119 // Return a send port for the service port. |
1087 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1120 Dart_Handle send_port = Dart_NewSendPort(service_port); |
1088 Dart_SetReturnValue(args, send_port); | 1121 Dart_SetReturnValue(args, send_port); |
1089 } | 1122 } |
1090 Dart_ExitScope(); | 1123 Dart_ExitScope(); |
1091 } | 1124 } |
OLD | NEW |