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 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 if (File::CreateLink(link_name.CString(), target_name.CString())) { | 1054 if (File::CreateLink(link_name.CString(), target_name.CString())) { |
1055 return CObject::True(); | 1055 return CObject::True(); |
1056 } else { | 1056 } else { |
1057 return CObject::NewOSError(); | 1057 return CObject::NewOSError(); |
1058 } | 1058 } |
1059 } | 1059 } |
1060 | 1060 |
1061 | 1061 |
1062 static CObject* FileDeleteLinkRequest(const CObjectArray& request) { | 1062 static CObject* FileDeleteLinkRequest(const CObjectArray& request) { |
1063 if (request.Length() == 2 && request[1]->IsString()) { | 1063 if (request.Length() == 2 && request[1]->IsString()) { |
1064 CObjectString filename(request[1]); | 1064 CObjectString link_path(request[1]); |
1065 bool result = File::DeleteLink(filename.CString()); | 1065 bool result = File::DeleteLink(link_path.CString()); |
1066 if (result) { | 1066 if (result) { |
1067 return CObject::True(); | 1067 return CObject::True(); |
1068 } else { | 1068 } else { |
1069 return CObject::NewOSError(); | 1069 return CObject::NewOSError(); |
1070 } | 1070 } |
1071 } | 1071 } |
1072 return CObject::IllegalArgumentError(); | 1072 return CObject::IllegalArgumentError(); |
1073 } | 1073 } |
1074 | 1074 |
1075 | 1075 |
| 1076 static CObject* FileLinkTargetRequest(const CObjectArray& request) { |
| 1077 if (request.Length() == 2 && request[1]->IsString()) { |
| 1078 CObjectString link_path(request[1]); |
| 1079 char* target = File::LinkTarget(link_path.CString()); |
| 1080 if (target != NULL) { |
| 1081 CObject* result = new CObjectString(CObject::NewString(target)); |
| 1082 free(target); |
| 1083 return result; |
| 1084 } else { |
| 1085 return CObject::NewOSError(); |
| 1086 } |
| 1087 } |
| 1088 return CObject::IllegalArgumentError(); |
| 1089 } |
| 1090 |
| 1091 |
1076 static void FileService(Dart_Port dest_port_id, | 1092 static void FileService(Dart_Port dest_port_id, |
1077 Dart_Port reply_port_id, | 1093 Dart_Port reply_port_id, |
1078 Dart_CObject* message) { | 1094 Dart_CObject* message) { |
1079 CObject* response = CObject::IllegalArgumentError(); | 1095 CObject* response = CObject::IllegalArgumentError(); |
1080 CObjectArray request(message); | 1096 CObjectArray request(message); |
1081 if (message->type == Dart_CObject::kArray) { | 1097 if (message->type == Dart_CObject::kArray) { |
1082 if (request.Length() > 1 && request[0]->IsInt32()) { | 1098 if (request.Length() > 1 && request[0]->IsInt32()) { |
1083 CObjectInt32 requestType(request[0]); | 1099 CObjectInt32 requestType(request[0]); |
1084 switch (requestType.Value()) { | 1100 switch (requestType.Value()) { |
1085 case File::kExistsRequest: | 1101 case File::kExistsRequest: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 break; | 1154 break; |
1139 case File::kWriteFromRequest: | 1155 case File::kWriteFromRequest: |
1140 response = FileWriteFromRequest(request); | 1156 response = FileWriteFromRequest(request); |
1141 break; | 1157 break; |
1142 case File::kDeleteLinkRequest: | 1158 case File::kDeleteLinkRequest: |
1143 response = FileDeleteLinkRequest(request); | 1159 response = FileDeleteLinkRequest(request); |
1144 break; | 1160 break; |
1145 case File::kCreateLinkRequest: | 1161 case File::kCreateLinkRequest: |
1146 response = FileCreateLinkRequest(request); | 1162 response = FileCreateLinkRequest(request); |
1147 break; | 1163 break; |
| 1164 case File::kLinkTargetRequest: |
| 1165 response = FileLinkTargetRequest(request); |
| 1166 break; |
1148 default: | 1167 default: |
1149 UNREACHABLE(); | 1168 UNREACHABLE(); |
1150 } | 1169 } |
1151 } | 1170 } |
1152 } | 1171 } |
1153 | 1172 |
1154 Dart_PostCObject(reply_port_id, response->AsApiCObject()); | 1173 Dart_PostCObject(reply_port_id, response->AsApiCObject()); |
1155 } | 1174 } |
1156 | 1175 |
1157 | 1176 |
1158 Dart_Port File::GetServicePort() { | 1177 Dart_Port File::GetServicePort() { |
1159 return file_service_.GetServicePort(); | 1178 return file_service_.GetServicePort(); |
1160 } | 1179 } |
1161 | 1180 |
1162 | 1181 |
1163 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { | 1182 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { |
1164 Dart_EnterScope(); | 1183 Dart_EnterScope(); |
1165 Dart_SetReturnValue(args, Dart_Null()); | 1184 Dart_SetReturnValue(args, Dart_Null()); |
1166 Dart_Port service_port = File::GetServicePort(); | 1185 Dart_Port service_port = File::GetServicePort(); |
1167 if (service_port != ILLEGAL_PORT) { | 1186 if (service_port != ILLEGAL_PORT) { |
1168 // Return a send port for the service port. | 1187 // Return a send port for the service port. |
1169 Dart_Handle send_port = Dart_NewSendPort(service_port); | 1188 Dart_Handle send_port = Dart_NewSendPort(service_port); |
1170 Dart_SetReturnValue(args, send_port); | 1189 Dart_SetReturnValue(args, send_port); |
1171 } | 1190 } |
1172 Dart_ExitScope(); | 1191 Dart_ExitScope(); |
1173 } | 1192 } |
1174 | 1193 |
1175 } // namespace bin | 1194 } // namespace bin |
1176 } // namespace dart | 1195 } // namespace dart |
OLD | NEW |