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

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

Powered by Google App Engine
This is Rietveld 408576698