Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 class FileSystemEntityType { | 7 class FileSystemEntityType { |
| 8 static const FILE = const FileSystemEntityType._internal(0); | 8 static const FILE = const FileSystemEntityType._internal(0); |
| 9 static const DIRECTORY = const FileSystemEntityType._internal(1); | 9 static const DIRECTORY = const FileSystemEntityType._internal(1); |
| 10 static const LINK = const FileSystemEntityType._internal(2); | 10 static const LINK = const FileSystemEntityType._internal(2); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 * [FileSystemEntity] objects are returned from directory listing | 28 * [FileSystemEntity] objects are returned from directory listing |
| 29 * operations. To determine if a FileSystemEntity is a [File] or a | 29 * operations. To determine if a FileSystemEntity is a [File] or a |
| 30 * [Directory], perform a type check: | 30 * [Directory], perform a type check: |
| 31 * | 31 * |
| 32 * if (entity is File) (entity as File).readAsStringSync(); | 32 * if (entity is File) (entity as File).readAsStringSync(); |
| 33 */ | 33 */ |
| 34 abstract class FileSystemEntity { | 34 abstract class FileSystemEntity { |
| 35 String get path; | 35 String get path; |
| 36 | 36 |
| 37 external static int _getType(String path, bool followLinks); | 37 external static int _getType(String path, bool followLinks); |
| 38 external static bool _identical(String file1, String file2); | |
| 38 | 39 |
| 39 static int _getTypeSync(String path, bool followLinks) { | 40 static int _getTypeSync(String path, bool followLinks) { |
| 40 var result = _getType(path, followLinks); | 41 var result = _getType(path, followLinks); |
| 41 _throwIfError(result, 'Error getting type of FileSystemEntity'); | 42 _throwIfError(result, 'Error getting type of FileSystemEntity'); |
| 42 return result; | 43 return result; |
| 43 } | 44 } |
| 44 | 45 |
|
Søren Gjesse
2013/03/20 07:49:45
I think we need a doc comment here explaining exac
| |
| 46 static bool identicalSync(String file1, String file2) { | |
|
Søren Gjesse
2013/03/20 07:49:45
path1 and path2?
| |
| 47 var result = _identical(file1, file2); | |
| 48 _throwIfError(result, 'Error in FileSystemEntity.identical'); | |
| 49 return result; | |
| 50 } | |
| 51 | |
| 45 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) | 52 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) |
| 46 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); | 53 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); |
| 47 | 54 |
| 48 static bool isLinkSync(String path) => | 55 static bool isLinkSync(String path) => |
| 49 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); | 56 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); |
| 50 | 57 |
| 51 static bool isFileSync(String path) => | 58 static bool isFileSync(String path) => |
| 52 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); | 59 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); |
| 53 | 60 |
| 54 static bool isDirectorySync(String path) => | 61 static bool isDirectorySync(String path) => |
| 55 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); | 62 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
| 56 | 63 |
| 57 static _throwIfError(Object result, String msg) { | 64 static _throwIfError(Object result, String msg) { |
| 58 if (result is OSError) { | 65 if (result is OSError) { |
| 59 throw new FileIOException(msg, result); | 66 throw new FileIOException(msg, result); |
| 67 } else if (result is ArgumentError) { | |
| 68 throw result; | |
| 60 } | 69 } |
| 61 } | 70 } |
| 62 } | 71 } |
| OLD | NEW |