@@ -56,20 +56,24 @@ class MemoryFileSystem extends FileSystem {
5656 @override
5757 File file (String path) => new _MemoryFile (this , path);
5858
59+ @override
60+ Link link (String path) => new _MemoryLink (this , path);
61+
5962 @override
6063 Directory get currentDirectory => directory (_cwd);
6164
6265 @override
6366 set currentDirectory (dynamic path) {
6467 String value;
65- if (path is Directory ) {
68+ if (path is io. Directory ) {
6669 value = path.path;
6770 } else if (path is String ) {
6871 value = path;
6972 } else {
70- throw new TypeError ( );
73+ throw new ArgumentError ( 'Invalid type for "path": ${ path ?. runtimeType }' );
7174 }
72- value = _context.canonicalize (value);
75+
76+ value = directory (value).resolveSymbolicLinksSync ();
7377 _Node node = _findNode (value);
7478 _checkExists (node, () => value);
7579 _checkIsDir (node, () => value);
@@ -83,7 +87,7 @@ class MemoryFileSystem extends FileSystem {
8387 @override
8488 io.FileStat statSync (String path) {
8589 try {
86- return _findNode (path)? .stat;
90+ return _findNode (path)? .stat ?? _MemoryFileStat ._notFound ;
8791 } on io.FileSystemException {
8892 return _MemoryFileStat ._notFound;
8993 }
@@ -95,8 +99,8 @@ class MemoryFileSystem extends FileSystem {
9599
96100 @override
97101 bool identicalSync (String path1, String path2) {
98- _Node node1 = _findNode (path1);
99- _Node node2 = _findNode (path2);
102+ _Node node1 = _findNode (path1, resolveTailLink : true );
103+ _Node node2 = _findNode (path2, resolveTailLink : true );
100104 return node1 != null && node1 == node2;
101105 }
102106
@@ -114,16 +118,13 @@ class MemoryFileSystem extends FileSystem {
114118 io.FileSystemEntityType typeSync (String path, {bool followLinks: true }) {
115119 _Node node;
116120 try {
117- node = _findNode (path);
121+ node = _findNode (path, resolveTailLink : followLinks );
118122 } on io.FileSystemException {
119123 node = null ;
120124 }
121- if (node = null ) {
125+ if (node == null ) {
122126 return io.FileSystemEntityType .NOT_FOUND ;
123127 }
124- if (followLinks && _isLink (node)) {
125- node = _resolveLinks (node, () => path);
126- }
127128 return node.type;
128129 }
129130
@@ -146,8 +147,9 @@ class MemoryFileSystem extends FileSystem {
146147 ///
147148 /// If the last element in [path] represents a symbolic link, this will
148149 /// return the [_LinkNode] node for the link (it will not return the
149- /// node to which the link points). However, directory links in the middle
150- /// of the path will be followed in order to find the node.
150+ /// node to which the link points), unless [resolveTailLink] is true.
151+ /// Directory links in the middle of the path will be followed in order to
152+ /// find the node regardless of the value of [resolveTailLink] .
151153 ///
152154 /// If [segmentVisitor] is specified, it will be invoked for every path
153155 /// segment visited along the way starting where the reference (root folder
@@ -164,7 +166,8 @@ class MemoryFileSystem extends FileSystem {
164166 String path, {
165167 _Node reference,
166168 _SegmentVisitor segmentVisitor,
167- StringBuffer pathWithSymlinks,
169+ List <String > pathWithSymlinks,
170+ bool resolveTailLink: false ,
168171 }) {
169172 if (path == null ) {
170173 throw new ArgumentError .notNull ('path' );
@@ -207,12 +210,17 @@ class MemoryFileSystem extends FileSystem {
207210 if (_isLink (child)) {
208211 child = _resolveLinks (child, subpath, ledger: pathWithSymlinks);
209212 } else if (pathWithSymlinks != null ) {
210- pathWithSymlinks..write (_separator)..write (basename);
213+ pathWithSymlinks..add (_separator)..add (basename);
211214 }
212215 _checkIsDir (child, subpath);
213216 directory = child;
217+ } else if (pathWithSymlinks != null ) {
218+ pathWithSymlinks..add (_separator)..add (basename);
214219 }
215220 }
221+ if (_isLink (child) && resolveTailLink) {
222+ child = _resolveLinks (child, () => path);
223+ }
216224 return child;
217225 }
218226}
0 commit comments