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); |
11 static const NOT_FOUND = const FileSystemEntityType._internal(3); | 11 static const NOT_FOUND = const FileSystemEntityType._internal(3); |
12 static const _typeList = const [FileSystemEntityType.FILE, | 12 static const _typeList = const [FileSystemEntityType.FILE, |
13 FileSystemEntityType.DIRECTORY, | 13 FileSystemEntityType.DIRECTORY, |
14 FileSystemEntityType.LINK, | 14 FileSystemEntityType.LINK, |
15 FileSystemEntityType.NOT_FOUND]; | 15 FileSystemEntityType.NOT_FOUND]; |
16 const FileSystemEntityType._internal(int this._type); | 16 final int _type; |
| 17 |
| 18 const FileSystemEntityType._internal(this._type); |
17 | 19 |
18 static FileSystemEntityType _lookup(int type) => _typeList[type]; | 20 static FileSystemEntityType _lookup(int type) => _typeList[type]; |
19 String toString() => const ['FILE', 'DIRECTORY', 'LINK', 'NOT_FOUND'][_type]; | 21 String toString() => const ['FILE', 'DIRECTORY', 'LINK', 'NOT_FOUND'][_type]; |
20 | |
21 final int _type; | |
22 } | 22 } |
23 | 23 |
24 /** | 24 /** |
25 * A FileStat object represents the result of calling the POSIX stat() function | 25 * A FileStat object represents the result of calling the POSIX stat() function |
26 * on a file system object. It is an immutable object, representing the | 26 * on a file system object. It is an immutable object, representing the |
27 * snapshotted values returned by the stat() call. | 27 * snapshotted values returned by the stat() call. |
28 */ | 28 */ |
29 class FileStat { | 29 class FileStat { |
30 // These must agree with enum FileStat in file.h. | 30 // These must agree with enum FileStat in file.h. |
31 static const _TYPE = 0; | 31 static const _TYPE = 0; |
32 static const _CHANGED_TIME = 1; | 32 static const _CHANGED_TIME = 1; |
33 static const _MODIFIED_TIME = 2; | 33 static const _MODIFIED_TIME = 2; |
34 static const _ACCESSED_TIME = 3; | 34 static const _ACCESSED_TIME = 3; |
35 static const _MODE = 4; | 35 static const _MODE = 4; |
36 static const _SIZE = 5; | 36 static const _SIZE = 5; |
37 | 37 |
| 38 /** |
| 39 * The time of the last change to the data or metadata of the file system |
| 40 * object. On Windows platforms, this is instead the file creation time. |
| 41 */ |
| 42 final DateTime changed; |
| 43 /** |
| 44 * The time of the last change to the data of the file system |
| 45 * object. |
| 46 */ |
| 47 final DateTime modified; |
| 48 /** |
| 49 * The time of the last access to the data of the file system |
| 50 * object. On Windows platforms, this may have 1 day granularity, and be |
| 51 * out of date by an hour. |
| 52 */ |
| 53 final DateTime accessed; |
| 54 /** |
| 55 * The type of the object (file, directory, or link). If the call to |
| 56 * stat() fails, the type of the returned object is NOT_FOUND. |
| 57 */ |
| 58 final FileSystemEntityType type; |
| 59 /** |
| 60 * The mode of the file system object. Permissions are encoded in the lower |
| 61 * 16 bits of this number, and can be decoded using the [modeString] getter. |
| 62 */ |
| 63 final int mode; |
| 64 /** |
| 65 * The size of the file system object. |
| 66 */ |
| 67 final int size; |
| 68 |
38 FileStat._internal(this.changed, | 69 FileStat._internal(this.changed, |
39 this.modified, | 70 this.modified, |
40 this.accessed, | 71 this.accessed, |
41 this.type, | 72 this.type, |
42 this.mode, | 73 this.mode, |
43 this.size); | 74 this.size); |
44 | 75 |
45 external static List<int> _statSync(String path); | 76 external static List<int> _statSync(String path); |
46 | 77 |
47 | 78 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 * letter for missing permissions. Extra permission bits may be represented | 135 * letter for missing permissions. Extra permission bits may be represented |
105 * by prepending "(suid)", "(guid)", and/or "(sticky)" to the mode string. | 136 * by prepending "(suid)", "(guid)", and/or "(sticky)" to the mode string. |
106 */ | 137 */ |
107 String modeString() { | 138 String modeString() { |
108 var permissions = mode & 0xFFF; | 139 var permissions = mode & 0xFFF; |
109 var codes = const ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx']; | 140 var codes = const ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx']; |
110 var result = []; | 141 var result = []; |
111 if ((permissions & 0x800) != 0) result.add("(suid) "); | 142 if ((permissions & 0x800) != 0) result.add("(suid) "); |
112 if ((permissions & 0x400) != 0) result.add("(guid) "); | 143 if ((permissions & 0x400) != 0) result.add("(guid) "); |
113 if ((permissions & 0x200) != 0) result.add("(sticky) "); | 144 if ((permissions & 0x200) != 0) result.add("(sticky) "); |
114 result.add(codes[(permissions >> 6) & 0x7]); | 145 result |
115 result.add(codes[(permissions >> 3) & 0x7]); | 146 ..add(codes[(permissions >> 6) & 0x7]) |
116 result.add(codes[permissions & 0x7]); | 147 ..add(codes[(permissions >> 3) & 0x7]) |
| 148 ..add(codes[permissions & 0x7]); |
117 return result.join(); | 149 return result.join(); |
118 } | 150 } |
119 | |
120 /** | |
121 * The time of the last change to the data or metadata of the file system | |
122 * object. On Windows platforms, this is instead the file creation time. | |
123 */ | |
124 final DateTime changed; | |
125 /** | |
126 * The time of the last change to the data of the file system | |
127 * object. | |
128 */ | |
129 final DateTime modified; | |
130 /** | |
131 * The time of the last access to the data of the file system | |
132 * object. On Windows platforms, this may have 1 day granularity, and be | |
133 * out of date by an hour. | |
134 */ | |
135 final DateTime accessed; | |
136 /** | |
137 * The type of the object (file, directory, or link). If the call to | |
138 * stat() fails, the type of the returned object is NOT_FOUND. | |
139 */ | |
140 final FileSystemEntityType type; | |
141 /** | |
142 * The mode of the file system object. Permissions are encoded in the lower | |
143 * 16 bits of this number, and can be decoded using the [modeString] getter. | |
144 */ | |
145 final int mode; | |
146 /** | |
147 * The size of the file system object. | |
148 */ | |
149 final int size; | |
150 } | 151 } |
151 | 152 |
152 | 153 |
153 /** | 154 /** |
154 * A [FileSystemEntity] is a common super class for [File] and | 155 * A [FileSystemEntity] is a common super class for [File] and |
155 * [Directory] objects. | 156 * [Directory] objects. |
156 * | 157 * |
157 * [FileSystemEntity] objects are returned from directory listing | 158 * [FileSystemEntity] objects are returned from directory listing |
158 * operations. To determine if a FileSystemEntity is a [File] or a | 159 * operations. To determine if a FileSystemEntity is a [File] or a |
159 * [Directory], perform a type check: | 160 * [Directory], perform a type check: |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 return buffer.toString(); | 740 return buffer.toString(); |
740 } | 741 } |
741 } | 742 } |
742 | 743 |
743 | 744 |
744 class _FileSystemWatcher { | 745 class _FileSystemWatcher { |
745 external static Stream<FileSystemEvent> watch( | 746 external static Stream<FileSystemEvent> watch( |
746 String path, int events, bool recursive); | 747 String path, int events, bool recursive); |
747 external static bool get isSupported; | 748 external static bool get isSupported; |
748 } | 749 } |
OLD | NEW |