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 analyzer.file_system.physical_file_system; | 5 library analyzer.file_system.physical_file_system; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 */ | 122 */ |
123 class _PhysicalFile extends _PhysicalResource implements File { | 123 class _PhysicalFile extends _PhysicalResource implements File { |
124 _PhysicalFile(io.File file) : super(file); | 124 _PhysicalFile(io.File file) : super(file); |
125 | 125 |
126 @override | 126 @override |
127 Stream<WatchEvent> get changes => new FileWatcher(_entry.path).events; | 127 Stream<WatchEvent> get changes => new FileWatcher(_entry.path).events; |
128 | 128 |
129 @override | 129 @override |
130 int get modificationStamp { | 130 int get modificationStamp { |
131 try { | 131 try { |
132 io.File file = _entry as io.File; | 132 return _file.lastModifiedSync().millisecondsSinceEpoch; |
133 return file.lastModifiedSync().millisecondsSinceEpoch; | |
134 } on io.FileSystemException catch (exception) { | 133 } on io.FileSystemException catch (exception) { |
135 throw new FileSystemException(exception.path, exception.message); | 134 throw new FileSystemException(exception.path, exception.message); |
136 } | 135 } |
137 } | 136 } |
138 | 137 |
| 138 /** |
| 139 * Return the underlying file being represented by this wrapper. |
| 140 */ |
| 141 io.File get _file => _entry as io.File; |
| 142 |
139 @override | 143 @override |
140 Source createSource([Uri uri]) { | 144 Source createSource([Uri uri]) { |
141 return new FileSource(this, uri ?? pathContext.toUri(path)); | 145 return new FileSource(this, uri ?? pathContext.toUri(path)); |
142 } | 146 } |
143 | 147 |
144 @override | 148 @override |
145 bool isOrContains(String path) { | 149 bool isOrContains(String path) { |
146 return path == this.path; | 150 return path == this.path; |
147 } | 151 } |
148 | 152 |
149 @override | 153 @override |
150 List<int> readAsBytesSync() { | 154 List<int> readAsBytesSync() { |
151 try { | 155 try { |
152 io.File file = _entry as io.File; | 156 return _file.readAsBytesSync(); |
153 return file.readAsBytesSync(); | |
154 } on io.FileSystemException catch (exception) { | 157 } on io.FileSystemException catch (exception) { |
155 throw new FileSystemException(exception.path, exception.message); | 158 throw new FileSystemException(exception.path, exception.message); |
156 } | 159 } |
157 } | 160 } |
158 | 161 |
159 @override | 162 @override |
160 String readAsStringSync() { | 163 String readAsStringSync() { |
161 try { | 164 try { |
162 io.File file = _entry as io.File; | 165 return FileBasedSource.fileReadMode(_file.readAsStringSync()); |
163 return FileBasedSource.fileReadMode(file.readAsStringSync()); | |
164 } on io.FileSystemException catch (exception) { | 166 } on io.FileSystemException catch (exception) { |
165 throw new FileSystemException(exception.path, exception.message); | 167 throw new FileSystemException(exception.path, exception.message); |
166 } | 168 } |
167 } | 169 } |
168 | 170 |
169 @override | 171 @override |
170 File renameSync(String newPath) { | 172 File renameSync(String newPath) { |
171 try { | 173 try { |
172 io.File file = _entry as io.File; | 174 return new _PhysicalFile(_file.renameSync(newPath)); |
173 io.File newFile = file.renameSync(newPath); | |
174 return new _PhysicalFile(newFile); | |
175 } on io.FileSystemException catch (exception) { | 175 } on io.FileSystemException catch (exception) { |
176 throw new FileSystemException(exception.path, exception.message); | 176 throw new FileSystemException(exception.path, exception.message); |
177 } | 177 } |
| 178 } |
| 179 |
| 180 @override |
| 181 File resolveSymbolicLinksSync() { |
| 182 try { |
| 183 return new _PhysicalFile(new io.File(_file.resolveSymbolicLinksSync())); |
| 184 } on io.FileSystemException catch (exception) { |
| 185 throw new FileSystemException(exception.path, exception.message); |
| 186 } |
178 } | 187 } |
179 | 188 |
180 @override | 189 @override |
181 Uri toUri() => new Uri.file(path); | 190 Uri toUri() => new Uri.file(path); |
182 | 191 |
183 @override | 192 @override |
184 void writeAsBytesSync(List<int> bytes) { | 193 void writeAsBytesSync(List<int> bytes) { |
185 try { | 194 try { |
186 io.File file = _entry as io.File; | 195 _file.writeAsBytesSync(bytes); |
187 file.writeAsBytesSync(bytes); | |
188 } on io.FileSystemException catch (exception) { | 196 } on io.FileSystemException catch (exception) { |
189 throw new FileSystemException(exception.path, exception.message); | 197 throw new FileSystemException(exception.path, exception.message); |
190 } | 198 } |
191 } | 199 } |
192 | 200 |
193 @override | 201 @override |
194 void writeAsStringSync(String content) { | 202 void writeAsStringSync(String content) { |
195 try { | 203 try { |
196 io.File file = _entry as io.File; | 204 _file.writeAsStringSync(content); |
197 file.writeAsStringSync(content); | |
198 } on io.FileSystemException catch (exception) { | 205 } on io.FileSystemException catch (exception) { |
199 throw new FileSystemException(exception.path, exception.message); | 206 throw new FileSystemException(exception.path, exception.message); |
200 } | 207 } |
201 } | 208 } |
202 } | 209 } |
203 | 210 |
204 /** | 211 /** |
205 * A `dart:io` based implementation of [Folder]. | 212 * A `dart:io` based implementation of [Folder]. |
206 */ | 213 */ |
207 class _PhysicalFolder extends _PhysicalResource implements Folder { | 214 class _PhysicalFolder extends _PhysicalResource implements Folder { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 timer.cancel(); | 360 timer.cancel(); |
354 } | 361 } |
355 }); | 362 }); |
356 return completer.future; | 363 return completer.future; |
357 } | 364 } |
358 _isSpawning = true; | 365 _isSpawning = true; |
359 _runner = await IsolateRunner.spawn(); | 366 _runner = await IsolateRunner.spawn(); |
360 return _runner; | 367 return _runner; |
361 } | 368 } |
362 } | 369 } |
OLD | NEW |