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

Side by Side Diff: pkg/front_end/lib/physical_file_system.dart

Issue 2844903002: Extend file-system abstraction with a couple methods, remove context (Closed)
Patch Set: fix test in windows bot Created 3 years, 7 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 front_end.physical_file_system; 5 library front_end.physical_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:path/path.dart' as p;
11
12 import 'file_system.dart'; 10 import 'file_system.dart';
13 11
14 /// Concrete implementation of [FileSystem] which performs its operations using 12 /// Concrete implementation of [FileSystem] which performs its operations using
15 /// I/O. 13 /// I/O.
16 /// 14 ///
17 /// Not intended to be implemented or extended by clients. 15 /// Not intended to be implemented or extended by clients.
18 class PhysicalFileSystem implements FileSystem { 16 class PhysicalFileSystem implements FileSystem {
19 static final PhysicalFileSystem instance = new PhysicalFileSystem._(); 17 static final PhysicalFileSystem instance = new PhysicalFileSystem._();
20 18
21 PhysicalFileSystem._(); 19 PhysicalFileSystem._();
22 20
23 @override 21 @override
24 p.Context get context => p.context;
25
26 @override
27 FileSystemEntity entityForUri(Uri uri) { 22 FileSystemEntity entityForUri(Uri uri) {
28 if (uri.scheme != 'file' && uri.scheme != '') { 23 if (uri.scheme != 'file' && uri.scheme != '') {
29 throw new ArgumentError('File URI expected'); 24 throw new ArgumentError('File URI expected');
30 } 25 }
31 return new _PhysicalFileSystemEntity(Uri.base.resolveUri(uri)); 26 return new _PhysicalFileSystemEntity(Uri.base.resolveUri(uri));
32 } 27 }
33 } 28 }
34 29
35 /// Concrete implementation of [FileSystemEntity] for use by 30 /// Concrete implementation of [FileSystemEntity] for use by
36 /// [PhysicalFileSystem]. 31 /// [PhysicalFileSystem].
37 class _PhysicalFileSystemEntity implements FileSystemEntity { 32 class _PhysicalFileSystemEntity implements FileSystemEntity {
38 @override 33 @override
39 final Uri uri; 34 final Uri uri;
40 35
41 _PhysicalFileSystemEntity(this.uri); 36 _PhysicalFileSystemEntity(this.uri);
42 37
43 @override 38 @override
44 int get hashCode => uri.hashCode; 39 int get hashCode => uri.hashCode;
45 40
46 @override 41 @override
47 bool operator ==(Object other) => 42 bool operator ==(Object other) =>
48 other is _PhysicalFileSystemEntity && other.uri == uri; 43 other is _PhysicalFileSystemEntity && other.uri == uri;
49 44
50 @override 45 @override
51 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes(); 46 Future<List<int>> readAsBytes() => new io.File.fromUri(uri).readAsBytes();
52 47
53 @override 48 @override
54 Future<String> readAsString() => new io.File.fromUri(uri).readAsString(); 49 Future<String> readAsString() => new io.File.fromUri(uri).readAsString();
50
51 @override
52 Future<bool> exists() async {
53 if (await io.FileSystemEntity.isFile(uri.toFilePath())) {
54 return new io.File.fromUri(uri).exists();
55 } else {
56 return new io.Directory.fromUri(uri).exists();
57 }
58 }
59
60 @override
61 Future<DateTime> lastModified() => new io.File.fromUri(uri).lastModified();
55 } 62 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/memory_file_system.dart ('k') | pkg/front_end/test/dependency_grapher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698