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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
8 static const FILE = const FileSystemEntityType._internal(0);
9 static const DIRECTORY = const FileSystemEntityType._internal(1);
10 static const LINK = const FileSystemEntityType._internal(2);
11 static const NOT_FOUND = const FileSystemEntityType._internal(3);
12 static const _typeList = const [FileSystemEntityType.FILE,
13 FileSystemEntityType.DIRECTORY,
14 FileSystemEntityType.LINK,
15 FileSystemEntityType.NOT_FOUND];
16 const FileSystemEntityType._internal(int this._type);
17
18 static FileSystemEntityType _lookup(int type) => _typeList[type];
19 String toString() => const ['FILE', 'DIRECTORY', 'LINK', 'NOT_FOUND'][_type];
20
21 final int _type;
22 }
23
7 /** 24 /**
8 * A [FileSystemEntity] is a common super class for [File] and 25 * A [FileSystemEntity] is a common super class for [File] and
9 * [Directory] objects. 26 * [Directory] objects.
10 * 27 *
11 * [FileSystemEntity] objects are returned from directory listing 28 * [FileSystemEntity] objects are returned from directory listing
12 * operations. To determine if a FileSystemEntity is a [File] or a 29 * operations. To determine if a FileSystemEntity is a [File] or a
13 * [Directory], perform a type check: 30 * [Directory], perform a type check:
14 * 31 *
15 * if (entity is File) (entity as File).readAsStringSync(); 32 * if (entity is File) (entity as File).readAsStringSync();
16 */ 33 */
17 abstract class FileSystemEntity { 34 abstract class FileSystemEntity {
18 String get path; 35 String get path;
36
37 external static int _getType(String path, bool followLinks);
38
39 static int _getTypeSync(String path, bool followLinks) {
40 var result = _getType(path, followLinks);
41 _throwIfError(result, 'Error getting type of FileSystemEntity');
42 return result;
43 }
44
45 static FileSystemEntityType typeSync(String path, {bool followLinks: true})
46 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks));
47
48 static bool isLinkSync(String path) =>
49 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type);
50
51 static bool isFileSync(String path) =>
52 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type);
53
54 static bool isDirectorySync(String path) =>
55 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type);
56
57 static _throwIfError(Object result, String msg) {
58 if (result is OSError) {
59 throw new FileIOException(msg, result);
60 }
61 }
19 } 62 }
OLDNEW
« 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