Chromium Code Reviews| Index: sdk/lib/io/file_system_entity.dart |
| diff --git a/sdk/lib/io/file_system_entity.dart b/sdk/lib/io/file_system_entity.dart |
| index bbe8cd5975f0f2d47cad3aeafe22ef76f1e4ddb9..04569d2351bcb4a7f898b1bdd375106b64d3c14e 100644 |
| --- a/sdk/lib/io/file_system_entity.dart |
| +++ b/sdk/lib/io/file_system_entity.dart |
| @@ -4,6 +4,16 @@ |
| part of dart.io; |
| +class FileSystemEntityType { |
| + static const FILE = const FileSystemEntityType._internal(0); |
| + static const DIRECTORY = const FileSystemEntityType._internal(1); |
| + static const LINK = const FileSystemEntityType._internal(2); |
| + static const NOT_FOUND = const FileSystemEntityType._internal(3); |
|
Bob Nystrom
2013/03/06 19:02:52
This feels wrong to me. "NOT FOUND" isn't a kind o
Bill Hesse
2013/03/07 09:53:12
I think the exception can be harder to handle than
Søren Gjesse
2013/03/07 11:33:30
I agree with Bill here. Lets call it "NONEXISTENT"
|
| + const FileSystemEntityType._internal(int this._type); |
| + final int _type; |
| + String toString() => ['FILE', 'DIRECTORY', 'LINK', 'NOT_FOUND'][_type]; |
|
Bob Nystrom
2013/03/06 19:02:52
Why not just make the type the string instead of a
Bill Hesse
2013/03/07 09:53:12
I'd like other's comments on this. This is an imp
Søren Gjesse
2013/03/07 11:33:30
This is an implementation issue so I don't care wh
|
| +} |
| + |
| /** |
| * A [FileSystemEntity] is a common super class for [File] and |
| * [Directory] objects. |
| @@ -16,4 +26,33 @@ part of dart.io; |
| */ |
| abstract class FileSystemEntity { |
|
Bob Nystrom
2013/03/06 19:02:52
Tangential, but how about "Entry" for this type na
Bill Hesse
2013/03/07 09:53:12
I think that is a good idea too. What do others t
Søren Gjesse
2013/03/07 11:33:30
I think Entry is a better name. I kind of says tha
|
| String get path; |
| + |
| + external static int _getType(String path, bool followLinks); |
| + |
| + static int _getTypeSync(String path, bool followLinks) { |
| + var result = _getType(path, followLinks); |
| + _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| + return result; |
| + } |
| + |
| + static FileSystemEntityType typeSync(String path, {bool followLinks: true}) |
|
Søren Gjesse
2013/03/06 17:47:33
Use { } body for multiline methods.
Bill Hesse
2013/03/07 09:53:12
Moved to a static method, and done.
On 2013/03/06
|
| + => [FileSystemEntityType.FILE, |
| + FileSystemEntityType.DIRECTORY, |
| + FileSystemEntityType.LINK, |
| + FileSystemEntityType.NOT_FOUND][_getTypeSync(path, followLinks)]; |
| + |
| + static bool isLinkSync(String path) => |
| + (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); |
| + |
| + static bool isFileSync(String path) => |
| + (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); |
| + |
| + static bool isDirectorySync(String path) => |
| + (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
| + |
| + static _throwIfError(Object result, String msg) { |
| + if (result is OSError) { |
| + throw new FileIOException(msg, result); |
| + } |
| + } |
| } |