OLD | NEW |
---|---|
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 memory_file_system; | 5 library memory_file_system; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
(...skipping 29 matching lines...) Expand all Loading... | |
40 new HashMap<String, _MemoryResource>(); | 40 new HashMap<String, _MemoryResource>(); |
41 final Map<String, String> _pathToContent = new HashMap<String, String>(); | 41 final Map<String, String> _pathToContent = new HashMap<String, String>(); |
42 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); | 42 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); |
43 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = | 43 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = |
44 new HashMap<String, List<StreamController<WatchEvent>>>(); | 44 new HashMap<String, List<StreamController<WatchEvent>>>(); |
45 int nextStamp = 0; | 45 int nextStamp = 0; |
46 | 46 |
47 @override | 47 @override |
48 Context get pathContext => posix; | 48 Context get pathContext => posix; |
49 | 49 |
50 /** | |
51 * Simulate revoked file access | |
52 * and return an object that can be passed to [restore]. | |
53 */ | |
54 clear() { | |
55 var restorePoint = new _MemoryRestorePoint(this); | |
56 _pathToResource.clear(); | |
57 _pathToContent.clear(); | |
58 _pathToTimestamp.clear(); | |
59 // TODO(danrubel) notify watchers | |
60 return restorePoint; | |
61 } | |
62 | |
63 /** | |
64 * Simulate restored file access based upon some earlier call to [clear]. | |
65 */ | |
66 void restore(var restorePoint) { | |
67 _pathToResource.clear(); | |
68 _pathToContent.clear(); | |
69 _pathToTimestamp.clear(); | |
70 (restorePoint as _MemoryRestorePoint).restore(this); | |
71 // TODO(danrubel) notify watchers | |
72 } | |
73 | |
50 void deleteFile(String path) { | 74 void deleteFile(String path) { |
51 _checkFileAtPath(path); | 75 _checkFileAtPath(path); |
52 _pathToResource.remove(path); | 76 _pathToResource.remove(path); |
53 _pathToContent.remove(path); | 77 _pathToContent.remove(path); |
54 _pathToTimestamp.remove(path); | 78 _pathToTimestamp.remove(path); |
55 _notifyWatchers(path, ChangeType.REMOVE); | 79 _notifyWatchers(path, ChangeType.REMOVE); |
56 } | 80 } |
57 | 81 |
58 @override | 82 @override |
59 Resource getResource(String path) { | 83 Resource getResource(String path) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 { | 166 { |
143 streamController.add(new WatchEvent(changeType, path)); | 167 streamController.add(new WatchEvent(changeType, path)); |
144 } | 168 } |
145 } | 169 } |
146 }); | 170 }); |
147 } | 171 } |
148 } | 172 } |
149 | 173 |
150 | 174 |
151 /** | 175 /** |
176 * A restore point captures the [MemoryResourceProvider] state | |
177 * so that it can be restored at later point. | |
178 */ | |
179 class _MemoryRestorePoint { | |
Paul Berry
2015/02/20 22:00:26
I'm not really comfortable adding this level of tr
danrubel
2015/02/21 03:09:30
How do we simulate revoked and restored access? Th
Paul Berry
2015/02/23 18:54:58
I was imagining that in the 'project removed then
danrubel
2015/02/24 02:29:45
I have moved this functionality into the test itse
| |
180 final Map<String, _MemoryResource> _pathToResource = | |
181 new HashMap<String, _MemoryResource>(); | |
182 final Map<String, String> _pathToContent = new HashMap<String, String>(); | |
183 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); | |
184 | |
185 _MemoryRestorePoint(MemoryResourceProvider provider) { | |
186 _pathToResource.addAll(provider._pathToResource); | |
187 _pathToContent.addAll(provider._pathToContent); | |
188 _pathToTimestamp.addAll(provider._pathToTimestamp); | |
189 } | |
190 | |
191 void restore(MemoryResourceProvider provider) { | |
192 provider._pathToResource.addAll(_pathToResource); | |
193 provider._pathToContent.addAll(_pathToContent); | |
194 provider._pathToTimestamp.addAll(_pathToTimestamp); | |
195 } | |
196 } | |
197 | |
198 | |
199 /** | |
152 * An in-memory implementation of [File] which acts like a symbolic link to a | 200 * An in-memory implementation of [File] which acts like a symbolic link to a |
153 * non-existent file. | 201 * non-existent file. |
154 */ | 202 */ |
155 class _MemoryDummyLink extends _MemoryResource implements File { | 203 class _MemoryDummyLink extends _MemoryResource implements File { |
156 _MemoryDummyLink(MemoryResourceProvider provider, String path) | 204 _MemoryDummyLink(MemoryResourceProvider provider, String path) |
157 : super(provider, path); | 205 : super(provider, path); |
158 | 206 |
159 @override | 207 @override |
160 bool get exists => false; | 208 bool get exists => false; |
161 | 209 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 bool operator ==(other) { | 424 bool operator ==(other) { |
377 if (runtimeType != other.runtimeType) { | 425 if (runtimeType != other.runtimeType) { |
378 return false; | 426 return false; |
379 } | 427 } |
380 return path == other.path; | 428 return path == other.path; |
381 } | 429 } |
382 | 430 |
383 @override | 431 @override |
384 String toString() => path; | 432 String toString() => path; |
385 } | 433 } |
OLD | NEW |