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

Side by Side Diff: sdk/lib/vmservice/devfs.dart

Issue 2733413003: Support DevFS paths encoded as URIs (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « runtime/observatory/tests/service/dev_fs_uri_test.dart ('k') | no next file » | 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) 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 24 matching lines...) Expand all
35 if (path.isEmpty) { 35 if (path.isEmpty) {
36 return null; 36 return null;
37 } 37 }
38 Uri pathUri; 38 Uri pathUri;
39 try { 39 try {
40 pathUri = new Uri.file(path); 40 pathUri = new Uri.file(path);
41 } on FormatException catch(e) { 41 } on FormatException catch(e) {
42 return null; 42 return null;
43 } 43 }
44 44
45 return resolve(pathUri);
46 }
47
48 Uri resolve(Uri pathUri) {
45 try { 49 try {
46 // Make sure that this pathUri can be converted to a file path. 50 // Make sure that this pathUri can be converted to a file path.
47 pathUri.toFilePath(); 51 pathUri.toFilePath();
48 } on UnsupportedError catch (e) { 52 } on UnsupportedError catch (e) {
49 return null; 53 return null;
50 } 54 }
51 55
52 Uri resolvedUri = uri.resolveUri(pathUri); 56 Uri resolvedUri = uri.resolveUri(pathUri);
53 if (!resolvedUri.toString().startsWith(uri.toString())) { 57 if (!resolvedUri.toString().startsWith(uri.toString())) {
54 // Resolved uri must be within the filesystem's base uri. 58 // Resolved uri must be within the filesystem's base uri.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return _listDevFSFiles(message); 120 return _listDevFSFiles(message);
117 default: 121 default:
118 return encodeRpcError( 122 return encodeRpcError(
119 message, kInternalError, 123 message, kInternalError,
120 details: 'Unexpected rpc ${message.method}'); 124 details: 'Unexpected rpc ${message.method}');
121 } 125 }
122 } 126 }
123 127
124 Future<String> handlePutStream(Object fsName, 128 Future<String> handlePutStream(Object fsName,
125 Object path, 129 Object path,
130 Uri fsUri,
126 Stream<List<int>> bytes) async { 131 Stream<List<int>> bytes) async {
127 // A dummy Message for error message construction. 132 // A dummy Message for error message construction.
128 Message message = new Message.forMethod('_writeDevFSFile'); 133 Message message = new Message.forMethod('_writeDevFSFile');
129 var writeStreamFile = VMServiceEmbedderHooks.writeStreamFile; 134 var writeStreamFile = VMServiceEmbedderHooks.writeStreamFile;
130 if (writeStreamFile == null) { 135 if (writeStreamFile == null) {
131 return _encodeDevFSDisabledError(message); 136 return _encodeDevFSDisabledError(message);
132 } 137 }
133 if (fsName == null) { 138 if (fsName == null) {
134 return encodeMissingParamError(message, 'fsName'); 139 return encodeMissingParamError(message, 'fsName');
135 } 140 }
136 if (fsName is! String) { 141 if (fsName is! String) {
137 return encodeInvalidParamError(message, 'fsName'); 142 return encodeInvalidParamError(message, 'fsName');
138 } 143 }
139 var fs = _fsMap[fsName]; 144 var fs = _fsMap[fsName];
140 if (fs == null) { 145 if (fs == null) {
141 return _encodeFileSystemDoesNotExistError(message, fsName); 146 return _encodeFileSystemDoesNotExistError(message, fsName);
142 } 147 }
143 if (path == null) { 148 Uri uri = fsUri;
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) { 149 if (uri == null) {
151 return encodeInvalidParamError(message, 'path'); 150 if (path == null) {
151 return encodeMissingParamError(message, 'path');
152 }
153 if (path is! String) {
154 return encodeInvalidParamError(message, 'path');
155 }
156 uri = fs.resolvePath(path);
157 if (uri == null) {
158 return encodeInvalidParamError(message, 'path');
159 }
160 } else {
161 uri = fs.resolve(uri);
162 if (uri == null) {
163 return encodeInvalidParamError(message, 'uri');
164 }
152 } 165 }
153 await writeStreamFile(uri, bytes); 166 await writeStreamFile(uri, bytes);
154 return encodeSuccess(message); 167 return encodeSuccess(message);
155 } 168 }
156 169
157 Future<String> _listDevFS(Message message) async { 170 Future<String> _listDevFS(Message message) async {
158 var result = {}; 171 var result = {};
159 result['type'] = 'FileSystemList'; 172 result['type'] = 'FileSystemList';
160 result['fsNames'] = _fsMap.keys.toList(); 173 result['fsNames'] = _fsMap.keys.toList();
161 return encodeResult(message, result); 174 return encodeResult(message, result);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (fsName == null) { 225 if (fsName == null) {
213 return encodeMissingParamError(message, 'fsName'); 226 return encodeMissingParamError(message, 'fsName');
214 } 227 }
215 if (fsName is! String) { 228 if (fsName is! String) {
216 return encodeInvalidParamError(message, 'fsName'); 229 return encodeInvalidParamError(message, 'fsName');
217 } 230 }
218 var fs = _fsMap[fsName]; 231 var fs = _fsMap[fsName];
219 if (fs == null) { 232 if (fs == null) {
220 return _encodeFileSystemDoesNotExistError(message, fsName); 233 return _encodeFileSystemDoesNotExistError(message, fsName);
221 } 234 }
222 var path = message.params['path']; 235 Uri uri;
223 if (path == null) { 236 if (message.params['uri'] != null) {
224 return encodeMissingParamError(message, 'path'); 237 try {
238 var uriParam = message.params['uri'];
239 if (uriParam is! String) {
240 return encodeInvalidParamError(message, 'uri');
241 }
242 Uri parsedUri = Uri.parse(uriParam);
243 uri = fs.resolve(parsedUri);
244 if (uri == null) {
245 return encodeInvalidParamError(message, 'uri');
246 }
247 } catch (e) {
248 return encodeInvalidParamError(message, 'uri');
249 }
250 } else {
251 var path = message.params['path'];
252 if (path == null) {
253 return encodeMissingParamError(message, 'path');
254 }
255 if (path is! String) {
256 return encodeInvalidParamError(message, 'path');
257 }
258 uri = fs.resolvePath(path);
259 if (uri == null) {
260 return encodeInvalidParamError(message, 'path');
261 }
225 } 262 }
226 if (path is! String) {
227 return encodeInvalidParamError(message, 'path');
228 }
229 Uri uri = fs.resolvePath(path);
230 if (uri == null) {
231 return encodeInvalidParamError(message, 'path');
232 }
233
234 try { 263 try {
235 List<int> bytes = await readFile(uri); 264 List<int> bytes = await readFile(uri);
236 var result = { 265 var result = {
237 'type': 'FSFile', 266 'type': 'FSFile',
238 'fileContents': BASE64.encode(bytes) 267 'fileContents': BASE64.encode(bytes)
239 }; 268 };
240 return encodeResult(message, result); 269 return encodeResult(message, result);
241 } catch (e) { 270 } catch (e) {
242 return encodeRpcError( 271 return encodeRpcError(
243 message, kFileDoesNotExist, 272 message, kFileDoesNotExist,
(...skipping 10 matching lines...) Expand all
254 if (fsName == null) { 283 if (fsName == null) {
255 return encodeMissingParamError(message, 'fsName'); 284 return encodeMissingParamError(message, 'fsName');
256 } 285 }
257 if (fsName is! String) { 286 if (fsName is! String) {
258 return encodeInvalidParamError(message, 'fsName'); 287 return encodeInvalidParamError(message, 'fsName');
259 } 288 }
260 var fs = _fsMap[fsName]; 289 var fs = _fsMap[fsName];
261 if (fs == null) { 290 if (fs == null) {
262 return _encodeFileSystemDoesNotExistError(message, fsName); 291 return _encodeFileSystemDoesNotExistError(message, fsName);
263 } 292 }
264 var path = message.params['path']; 293 Uri uri;
265 if (path == null) { 294 if (message.params['uri'] != null) {
266 return encodeMissingParamError(message, 'path'); 295 try {
267 } 296 var uriParam = message.params['uri'];
268 if (path is! String) { 297 if (uriParam is! String) {
269 return encodeInvalidParamError(message, 'path'); 298 return encodeInvalidParamError(message, 'uri');
270 } 299 }
271 Uri uri = fs.resolvePath(path); 300 Uri parsedUri = Uri.parse(uriParam);
272 if (uri == null) { 301 uri = fs.resolve(parsedUri);
273 return encodeInvalidParamError(message, 'path'); 302 if (uri == null) {
303 return encodeInvalidParamError(message, 'uri');
304 }
305 } catch (e) {
306 return encodeInvalidParamError(message, 'uri');
307 }
308 } else {
309 var path = message.params['path'];
310 if (path == null) {
311 return encodeMissingParamError(message, 'path');
312 }
313 if (path is! String) {
314 return encodeInvalidParamError(message, 'path');
315 }
316 uri = fs.resolvePath(path);
317 if (uri == null) {
318 return encodeInvalidParamError(message, 'path');
319 }
turnidge 2017/03/08 21:13:51 Does this code duplicate the code above? Can ther
Cutch 2017/03/08 23:41:07 A helper function is awkward here (see other DevFS
274 } 320 }
275 var fileContents = message.params['fileContents']; 321 var fileContents = message.params['fileContents'];
276 if (fileContents == null) { 322 if (fileContents == null) {
277 return encodeMissingParamError(message, 'fileContents'); 323 return encodeMissingParamError(message, 'fileContents');
278 } 324 }
279 if (fileContents is! String) { 325 if (fileContents is! String) {
280 return encodeInvalidParamError(message, 'fileContents'); 326 return encodeInvalidParamError(message, 'fileContents');
281 } 327 }
282 List<int> decodedFileContents = BASE64.decode(fileContents); 328 List<int> decodedFileContents = BASE64.decode(fileContents);
283 329
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 401 }
356 var fileList = await listFiles(fs.uri); 402 var fileList = await listFiles(fs.uri);
357 // Remove any url-encoding in the filenames. 403 // Remove any url-encoding in the filenames.
358 for (int i = 0; i < fileList.length; i++) { 404 for (int i = 0; i < fileList.length; i++) {
359 fileList[i]['name'] = Uri.decodeFull(fileList[i]['name']); 405 fileList[i]['name'] = Uri.decodeFull(fileList[i]['name']);
360 } 406 }
361 var result = { 'type': 'FSFileList', 'files': fileList }; 407 var result = { 'type': 'FSFileList', 'files': fileList };
362 return encodeResult(message, result); 408 return encodeResult(message, result);
363 } 409 }
364 } 410 }
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/dev_fs_uri_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698