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

Unified Diff: sdk/lib/io/file_system_entity.dart

Issue 12533008: dart:io | Add FileSystemEntity.typeSync to test for symbolic links. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
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..e13477b1c41e5b6c11e732e01977ccaa47d985b9 100644
--- a/sdk/lib/io/file_system_entity.dart
+++ b/sdk/lib/io/file_system_entity.dart
@@ -4,6 +4,23 @@
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);
+ static const _typeList = const [FileSystemEntityType.FILE,
+ FileSystemEntityType.DIRECTORY,
+ FileSystemEntityType.LINK,
+ FileSystemEntityType.NOT_FOUND];
+ const FileSystemEntityType._internal(int this._type);
+
+ static FileSystemEntityType _lookup(int type) => _typeList[type];
+ String toString() => const ['FILE', 'DIRECTORY', 'LINK', 'NOT_FOUND'][_type];
+
+ final int _type;
+}
+
/**
* A [FileSystemEntity] is a common super class for [File] and
* [Directory] objects.
@@ -16,4 +33,30 @@ part of dart.io;
*/
abstract class FileSystemEntity {
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})
+ => FileSystemEntityType._lookup(_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);
+ }
+ }
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/io_patch.dart ('k') | tests/standalone/io/file_system_links_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698