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

Side by Side Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 1808213004: Add File.renameSync() to virtual file system. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.file_system.memory_file_system; 5 library analyzer.file_system.memory_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:core' hide Resource; 9 import 'dart:core' hide Resource;
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } else if (resource is _MemoryFolder) { 152 } else if (resource is _MemoryFolder) {
153 _notifyWatchers(path, ChangeType.ADD); 153 _notifyWatchers(path, ChangeType.ADD);
154 return resource; 154 return resource;
155 } else { 155 } else {
156 String message = 156 String message =
157 'Folder expected at ' "'$path'" 'but ${resource.runtimeType} found'; 157 'Folder expected at ' "'$path'" 'but ${resource.runtimeType} found';
158 throw new ArgumentError(message); 158 throw new ArgumentError(message);
159 } 159 }
160 } 160 }
161 161
162 void renameFileSync(String path, String newPath) {
163 if (newPath == path) {
164 return;
165 }
166 if (_pathToResource[newPath] is _MemoryFolder) {
167 throw new FileSystemException(
168 path, 'Could not be renamed: $newPath is a folder.');
169 }
170 _pathToResource.remove(path);
171 _pathToContent[newPath] = _pathToContent.remove(path);
172 _pathToBytes[newPath] = _pathToBytes.remove(path);
173 _pathToTimestamp[newPath] = _pathToTimestamp.remove(path);
174 _pathToWatchers[newPath] = _pathToWatchers.remove(path);
Brian Wilkerson 2016/03/17 19:31:00 Does this need to call _notifyWatchers?
175 }
176
162 File updateFile(String path, String content, [int stamp]) { 177 File updateFile(String path, String content, [int stamp]) {
163 path = pathContext.normalize(path); 178 path = pathContext.normalize(path);
164 newFolder(pathContext.dirname(path)); 179 newFolder(pathContext.dirname(path));
165 _MemoryFile file = new _MemoryFile(this, path); 180 _MemoryFile file = new _MemoryFile(this, path);
166 _pathToResource[path] = file; 181 _pathToResource[path] = file;
167 _pathToContent[path] = content; 182 _pathToContent[path] = content;
168 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++; 183 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++;
169 _notifyWatchers(path, ChangeType.MODIFY); 184 _notifyWatchers(path, ChangeType.MODIFY);
170 return file; 185 return file;
171 } 186 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 List<StreamController<WatchEvent>> streamControllers) { 222 List<StreamController<WatchEvent>> streamControllers) {
208 if (watcherPath == path || pathContext.isWithin(watcherPath, path)) { 223 if (watcherPath == path || pathContext.isWithin(watcherPath, path)) {
209 for (StreamController<WatchEvent> streamController 224 for (StreamController<WatchEvent> streamController
210 in streamControllers) { 225 in streamControllers) {
211 streamController.add(new WatchEvent(changeType, path)); 226 streamController.add(new WatchEvent(changeType, path));
212 } 227 }
213 } 228 }
214 }); 229 });
215 } 230 }
216 231
217 void _setFileBytes(String path, List<int> bytes) { 232 void _setFileBytes(_MemoryFile file, List<int> bytes) {
233 String path = file.path;
234 _pathToResource[path] = file;
218 _pathToBytes[path] = bytes; 235 _pathToBytes[path] = bytes;
219 _pathToTimestamp[path] = nextStamp++; 236 _pathToTimestamp[path] = nextStamp++;
220 _notifyWatchers(path, ChangeType.MODIFY); 237 _notifyWatchers(path, ChangeType.MODIFY);
221 } 238 }
222 } 239 }
223 240
224 /** 241 /**
225 * An in-memory implementation of [File] which acts like a symbolic link to a 242 * An in-memory implementation of [File] which acts like a symbolic link to a
226 * non-existent file. 243 * non-existent file.
227 */ 244 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 List<int> readAsBytesSync() { 281 List<int> readAsBytesSync() {
265 throw new FileSystemException(path, 'File could not be read'); 282 throw new FileSystemException(path, 'File could not be read');
266 } 283 }
267 284
268 @override 285 @override
269 String readAsStringSync() { 286 String readAsStringSync() {
270 throw new FileSystemException(path, 'File could not be read'); 287 throw new FileSystemException(path, 'File could not be read');
271 } 288 }
272 289
273 @override 290 @override
291 Resource renameSync(String newPath) {
292 throw new FileSystemException(path, 'File could not be renamed');
293 }
294
295 @override
274 void writeAsBytesSync(List<int> bytes) { 296 void writeAsBytesSync(List<int> bytes) {
275 throw new FileSystemException(path, 'File could not be written'); 297 throw new FileSystemException(path, 'File could not be written');
276 } 298 }
277 } 299 }
278 300
279 /** 301 /**
280 * An in-memory implementation of [File]. 302 * An in-memory implementation of [File].
281 */ 303 */
282 class _MemoryFile extends _MemoryResource implements File { 304 class _MemoryFile extends _MemoryResource implements File {
283 _MemoryFile(MemoryResourceProvider provider, String path) 305 _MemoryFile(MemoryResourceProvider provider, String path)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 @override 350 @override
329 String readAsStringSync() { 351 String readAsStringSync() {
330 String content = _provider._pathToContent[path]; 352 String content = _provider._pathToContent[path];
331 if (content == null) { 353 if (content == null) {
332 throw new FileSystemException(path, 'File "$path" does not exist.'); 354 throw new FileSystemException(path, 'File "$path" does not exist.');
333 } 355 }
334 return content; 356 return content;
335 } 357 }
336 358
337 @override 359 @override
360 File renameSync(String newPath) {
361 _provider.renameFileSync(path, newPath);
362 return _provider._newFile(newPath);
363 }
364
365 @override
338 void writeAsBytesSync(List<int> bytes) { 366 void writeAsBytesSync(List<int> bytes) {
339 _provider._setFileBytes(path, bytes); 367 _provider._setFileBytes(this, bytes);
340 } 368 }
341 } 369 }
342 370
343 /** 371 /**
344 * An in-memory implementation of [Source]. 372 * An in-memory implementation of [Source].
345 */ 373 */
346 class _MemoryFileSource extends Source { 374 class _MemoryFileSource extends Source {
347 /** 375 /**
348 * Map from encoded URI/filepath pair to a unique integer identifier. This 376 * Map from encoded URI/filepath pair to a unique integer identifier. This
349 * identifier is used for equality tests and hash codes. 377 * identifier is used for equality tests and hash codes.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 bool operator ==(other) { 574 bool operator ==(other) {
547 if (runtimeType != other.runtimeType) { 575 if (runtimeType != other.runtimeType) {
548 return false; 576 return false;
549 } 577 }
550 return path == other.path; 578 return path == other.path;
551 } 579 }
552 580
553 @override 581 @override
554 String toString() => path; 582 String toString() => path;
555 } 583 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/file_system.dart ('k') | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698