Chromium Code Reviews| 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 physical_file_system; | 5 library 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:analyzer/src/generated/java_io.dart'; | 10 import 'package:analyzer/src/generated/java_io.dart'; |
| 11 import 'package:analyzer/src/generated/source_io.dart'; | 11 import 'package:analyzer/src/generated/source_io.dart'; |
| 12 import 'package:path/path.dart'; | 12 import 'package:path/path.dart'; |
| 13 import 'package:watcher/watcher.dart'; | 13 import 'package:watcher/watcher.dart'; |
| 14 | 14 |
| 15 import 'file_system.dart'; | 15 import 'file_system.dart'; |
| 16 | 16 |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A `dart:io` based implementation of [ResourceProvider]. | 19 * A `dart:io` based implementation of [ResourceProvider]. |
| 20 */ | 20 */ |
| 21 class PhysicalResourceProvider implements ResourceProvider { | 21 class PhysicalResourceProvider implements ResourceProvider { |
| 22 static final PhysicalResourceProvider INSTANCE = | 22 static final PhysicalResourceProvider INSTANCE = |
| 23 new PhysicalResourceProvider._(); | 23 new PhysicalResourceProvider._(); |
| 24 | 24 |
| 25 /** | |
| 26 * The name of the directory containing plugin specific subfolders used to | |
| 27 * store data across sessions. | |
| 28 */ | |
| 29 static final String SERVER_DIR = "dartServer"; | |
|
Paul Berry
2014/10/07 16:50:36
On Mac and Unix it's conventional to name these di
Brian Wilkerson
2014/10/07 16:57:51
Done
| |
| 30 | |
| 25 PhysicalResourceProvider._(); | 31 PhysicalResourceProvider._(); |
| 26 | 32 |
| 27 @override | 33 @override |
| 28 Context get pathContext => io.Platform.isWindows ? windows : posix; | 34 Context get pathContext => io.Platform.isWindows ? windows : posix; |
| 29 | 35 |
| 30 @override | 36 @override |
| 31 Resource getResource(String path) { | 37 Resource getResource(String path) { |
| 32 if (io.FileSystemEntity.isDirectorySync(path)) { | 38 if (io.FileSystemEntity.isDirectorySync(path)) { |
| 33 io.Directory directory = new io.Directory(path); | 39 io.Directory directory = new io.Directory(path); |
| 34 return new _PhysicalFolder(directory); | 40 return new _PhysicalFolder(directory); |
| 35 } else { | 41 } else { |
| 36 io.File file = new io.File(path); | 42 io.File file = new io.File(path); |
| 37 return new _PhysicalFile(file); | 43 return new _PhysicalFile(file); |
| 38 } | 44 } |
| 39 } | 45 } |
| 46 | |
| 47 @override | |
| 48 Folder getStateLocation(String pluginId) { | |
| 49 String home; | |
| 50 if (io.Platform.isWindows) { | |
| 51 home = io.Platform.environment['LOCALAPPDATA']; | |
| 52 } else { | |
| 53 home = io.Platform.environment['HOME']; | |
| 54 } | |
| 55 if (home != null && io.FileSystemEntity.isDirectorySync(home)) { | |
| 56 StringBuffer buffer = new StringBuffer(); | |
| 57 buffer.write(home); | |
| 58 buffer.write(pathContext.separator); | |
| 59 buffer.write(SERVER_DIR); | |
| 60 buffer.write(pathContext.separator); | |
| 61 buffer.write(pluginId); | |
|
Paul Berry
2014/10/07 16:50:36
IMHO it reads a lot nicer to construct paths using
Brian Wilkerson
2014/10/07 16:57:51
Done
| |
| 62 io.Directory directory = new io.Directory(buffer.toString()); | |
| 63 directory.createSync(recursive: true); | |
| 64 return new _PhysicalFolder(directory); | |
| 65 } | |
| 66 return null; | |
| 67 } | |
| 40 } | 68 } |
| 41 | 69 |
| 42 | 70 |
| 43 /** | 71 /** |
| 44 * A `dart:io` based implementation of [File]. | 72 * A `dart:io` based implementation of [File]. |
| 45 */ | 73 */ |
| 46 class _PhysicalFile extends _PhysicalResource implements File { | 74 class _PhysicalFile extends _PhysicalResource implements File { |
| 47 _PhysicalFile(io.File file) : super(file); | 75 _PhysicalFile(io.File file) : super(file); |
| 48 | 76 |
| 49 @override | 77 @override |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 bool operator ==(other) { | 176 bool operator ==(other) { |
| 149 if (runtimeType != other.runtimeType) { | 177 if (runtimeType != other.runtimeType) { |
| 150 return false; | 178 return false; |
| 151 } | 179 } |
| 152 return path == other.path; | 180 return path == other.path; |
| 153 } | 181 } |
| 154 | 182 |
| 155 @override | 183 @override |
| 156 String toString() => path; | 184 String toString() => path; |
| 157 } | 185 } |
| OLD | NEW |