| 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 path1, String path2); |
| 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 |
| 46 /** |
| 47 * Do two paths refer to the same object in the file system? |
| 48 * Links are not identical to their targets, and two links |
| 49 * are not identical just because they point to identical targets. |
| 50 * Links in intermediate directories in the paths are followed, though. |
| 51 * |
| 52 * Throws an error if one of the paths points to an object that does not |
| 53 * exist. |
| 54 * The target of a link can be compared by first getting it with Link.target. |
| 55 */ |
| 56 static bool identicalSync(String path1, String path2) { |
| 57 var result = _identical(path1, path2); |
| 58 _throwIfError(result, 'Error in FileSystemEntity.identical'); |
| 59 return result; |
| 60 } |
| 61 |
| 45 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) | 62 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) |
| 46 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); | 63 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); |
| 47 | 64 |
| 48 static bool isLinkSync(String path) => | 65 static bool isLinkSync(String path) => |
| 49 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); | 66 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); |
| 50 | 67 |
| 51 static bool isFileSync(String path) => | 68 static bool isFileSync(String path) => |
| 52 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); | 69 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); |
| 53 | 70 |
| 54 static bool isDirectorySync(String path) => | 71 static bool isDirectorySync(String path) => |
| 55 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); | 72 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); |
| 56 | 73 |
| 57 static _throwIfError(Object result, String msg) { | 74 static _throwIfError(Object result, String msg) { |
| 58 if (result is OSError) { | 75 if (result is OSError) { |
| 59 throw new FileIOException(msg, result); | 76 throw new FileIOException(msg, result); |
| 77 } else if (result is ArgumentError) { |
| 78 throw result; |
| 60 } | 79 } |
| 61 } | 80 } |
| 62 } | 81 } |
| OLD | NEW |