OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 part of dart._vmservice; | 5 part of dart._vmservice; |
6 | 6 |
7 String _encodeDevFSDisabledError(Message message) { | 7 String _encodeDevFSDisabledError(Message message) { |
8 return encodeRpcError( | 8 return encodeRpcError( |
9 message, kFeatureDisabled, | 9 message, kFeatureDisabled, |
10 details: "DevFS is not supported by this Dart implementation"); | 10 details: "DevFS is not supported by this Dart implementation"); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return _writeDevFSFiles(message); | 114 return _writeDevFSFiles(message); |
115 case '_listDevFSFiles': | 115 case '_listDevFSFiles': |
116 return _listDevFSFiles(message); | 116 return _listDevFSFiles(message); |
117 default: | 117 default: |
118 return encodeRpcError( | 118 return encodeRpcError( |
119 message, kInternalError, | 119 message, kInternalError, |
120 details: 'Unexpected rpc ${message.method}'); | 120 details: 'Unexpected rpc ${message.method}'); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
| 124 Future<String> handlePutStream(Object fsName, |
| 125 Object path, |
| 126 Stream<List<int>> bytes) async { |
| 127 // A dummy Message for error message construction. |
| 128 Message message = new Message.forMethod('_writeDevFSFile'); |
| 129 var writeStreamFile = VMServiceEmbedderHooks.writeStreamFile; |
| 130 if (writeStreamFile == null) { |
| 131 return _encodeDevFSDisabledError(message); |
| 132 } |
| 133 if (fsName == null) { |
| 134 return encodeMissingParamError(message, 'fsName'); |
| 135 } |
| 136 if (fsName is! String) { |
| 137 return encodeInvalidParamError(message, 'fsName'); |
| 138 } |
| 139 var fs = _fsMap[fsName]; |
| 140 if (fs == null) { |
| 141 return _encodeFileSystemDoesNotExistError(message, fsName); |
| 142 } |
| 143 if (path == null) { |
| 144 return encodeMissingParamError(message, 'path'); |
| 145 } |
| 146 if (path is! String) { |
| 147 return encodeInvalidParamError(message, 'path'); |
| 148 } |
| 149 Uri uri = fs.resolvePath(path); |
| 150 if (uri == null) { |
| 151 return encodeInvalidParamError(message, 'path'); |
| 152 } |
| 153 await writeStreamFile(uri, bytes); |
| 154 return encodeSuccess(message); |
| 155 } |
| 156 |
124 Future<String> _listDevFS(Message message) async { | 157 Future<String> _listDevFS(Message message) async { |
125 var result = {}; | 158 var result = {}; |
126 result['type'] = 'FileSystemList'; | 159 result['type'] = 'FileSystemList'; |
127 result['fsNames'] = _fsMap.keys.toList(); | 160 result['fsNames'] = _fsMap.keys.toList(); |
128 return encodeResult(message, result); | 161 return encodeResult(message, result); |
129 } | 162 } |
130 | 163 |
131 Future<String> _createDevFS(Message message) async { | 164 Future<String> _createDevFS(Message message) async { |
132 var createTempDir = VMServiceEmbedderHooks.createTempDir; | 165 var createTempDir = VMServiceEmbedderHooks.createTempDir; |
133 if (createTempDir == null) { | 166 if (createTempDir == null) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 355 } |
323 var fileList = await listFiles(fs.uri); | 356 var fileList = await listFiles(fs.uri); |
324 // Remove any url-encoding in the filenames. | 357 // Remove any url-encoding in the filenames. |
325 for (int i = 0; i < fileList.length; i++) { | 358 for (int i = 0; i < fileList.length; i++) { |
326 fileList[i]['name'] = Uri.decodeFull(fileList[i]['name']); | 359 fileList[i]['name'] = Uri.decodeFull(fileList[i]['name']); |
327 } | 360 } |
328 var result = { 'type': 'FSFileList', 'files': fileList }; | 361 var result = { 'type': 'FSFileList', 'files': fileList }; |
329 return encodeResult(message, result); | 362 return encodeResult(message, result); |
330 } | 363 } |
331 } | 364 } |
OLD | NEW |