@@ -14,50 +14,53 @@ import 'memory_file.dart';
1414import 'memory_file_stat.dart' ;
1515import 'memory_link.dart' ;
1616import 'node.dart' ;
17+ import 'style.dart' ;
1718import 'utils.dart' as utils;
1819
1920const String _thisDir = '.' ;
2021const String _parentDir = '..' ;
2122
2223/// An implementation of [FileSystem] that exists entirely in memory with an
2324/// internal representation loosely based on the Filesystem Hierarchy Standard.
24- /// Notably, this means that this implementation will not look like a Windows
25- /// file system even if it's being run on a Windows host operating system.
2625///
2726/// [MemoryFileSystem] is suitable for mocking and tests, as well as for
2827/// caching or staging before writing or reading to a live system.
2928///
3029/// This implementation of the [FileSystem] interface does not directly use
3130/// any `dart:io` APIs; it merely uses the library's enum values and interfaces.
3231/// As such, it is suitable for use in the browser.
33- abstract class MemoryFileSystem implements FileSystem {
32+ abstract class MemoryFileSystem implements StyleableFileSystem {
3433 /// Creates a new `MemoryFileSystem` .
3534 ///
3635 /// The file system will be empty, and the current directory will be the
3736 /// root directory.
38- factory MemoryFileSystem () = _MemoryFileSystem ;
37+ ///
38+ /// If [style] is specified, the file system will use the specified path
39+ /// style. The default is [FileSystemStyle.posix] .
40+ factory MemoryFileSystem ({FileSystemStyle style}) = _MemoryFileSystem ;
3941}
4042
4143/// Internal implementation of [MemoryFileSystem] .
4244class _MemoryFileSystem extends FileSystem
4345 implements MemoryFileSystem , NodeBasedFileSystem {
4446 RootNode _root;
4547 String _systemTemp;
46- String _cwd = separator ;
48+ p. Context _context ;
4749
48- /// Creates a new `MemoryFileSystem` .
49- ///
50- /// The file system will be empty, and the current directory will be the
51- /// root directory.
52- _MemoryFileSystem () {
50+ _MemoryFileSystem ({this .style: FileSystemStyle .posix})
51+ : assert (style != null ) {
5352 _root = new RootNode (this );
53+ _context = style.contextFor (style.root);
5454 }
5555
56+ @override
57+ final FileSystemStyle style;
58+
5659 @override
5760 RootNode get root => _root;
5861
5962 @override
60- String get cwd => _cwd ;
63+ String get cwd => _context.current ;
6164
6265 @override
6366 Directory directory (dynamic path) => new MemoryDirectory (this , getPath (path));
@@ -69,19 +72,19 @@ class _MemoryFileSystem extends FileSystem
6972 Link link (dynamic path) => new MemoryLink (this , getPath (path));
7073
7174 @override
72- p.Context get path => new p. Context (style : p. Style .posix, current : _cwd) ;
75+ p.Context get path => _context ;
7376
7477 /// Gets the system temp directory. This directory will be created on-demand
7578 /// in the root of the file system. Once created, its location is fixed for
7679 /// the life of the process.
7780 @override
7881 Directory get systemTempDirectory {
79- _systemTemp ?? = directory (separator ).createTempSync ('.tmp_' ).path;
82+ _systemTemp ?? = directory (style.root ).createTempSync ('.tmp_' ).path;
8083 return directory (_systemTemp)..createSync ();
8184 }
8285
8386 @override
84- Directory get currentDirectory => directory (_cwd );
87+ Directory get currentDirectory => directory (cwd );
8588
8689 @override
8790 set currentDirectory (dynamic path) {
@@ -98,8 +101,8 @@ class _MemoryFileSystem extends FileSystem
98101 Node node = findNode (value);
99102 checkExists (node, () => value);
100103 utils.checkIsDir (node, () => value);
101- assert (utils .isAbsolute (value));
102- _cwd = value;
104+ assert (_context .isAbsolute (value));
105+ _context = style. contextFor ( value) ;
103106 }
104107
105108 @override
@@ -154,7 +157,7 @@ class _MemoryFileSystem extends FileSystem
154157 /// Gets the node backing for the current working directory. Note that this
155158 /// can return null if the directory has been deleted or moved from under our
156159 /// feet.
157- DirectoryNode get _current => findNode (_cwd );
160+ DirectoryNode get _current => findNode (cwd );
158161
159162 @override
160163 Node findNode (
@@ -169,13 +172,15 @@ class _MemoryFileSystem extends FileSystem
169172 throw new ArgumentError .notNull ('path' );
170173 }
171174
172- if (utils .isAbsolute (path)) {
175+ if (_context .isAbsolute (path)) {
173176 reference = _root;
177+ path = path.substring (style.drive.length);
174178 } else {
175179 reference ?? = _current;
176180 }
177181
178- List <String > parts = path.split (separator)..removeWhere (utils.isEmpty);
182+ List <String > parts = path.split (style.separator)
183+ ..removeWhere (utils.isEmpty);
179184 DirectoryNode directory = reference.directory;
180185 Node child = directory;
181186
@@ -200,7 +205,9 @@ class _MemoryFileSystem extends FileSystem
200205 pathWithSymlinks.add (basename);
201206 }
202207
203- PathGenerator subpath = utils.subpath (parts, 0 , i);
208+ // Generates a subpath for the current segment.
209+ String subpath () => parts.sublist (0 , i + 1 ).join (_context.separator);
210+
204211 if (utils.isLink (child) && (i < finalSegment || followTailLink)) {
205212 if (visitLinks || segmentVisitor == null ) {
206213 if (segmentVisitor != null ) {
0 commit comments