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

Side by Side Diff: sdk/lib/io/file_system_entity.dart

Issue 252123005: Make FileStat have millisecond precisions, for linux, mac and android. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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
« no previous file with comments | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 7 /**
8 * The type of an entity on the file system, such as a file, directory, or link. 8 * The type of an entity on the file system, such as a file, directory, or link.
9 * 9 *
10 * These constants are used by the [FileSystemEntity] class 10 * These constants are used by the [FileSystemEntity] class
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * FileSystemEntityType.NOT_FOUND and the other fields invalid. 97 * FileSystemEntityType.NOT_FOUND and the other fields invalid.
98 */ 98 */
99 static FileStat statSync(String path) { 99 static FileStat statSync(String path) {
100 // Trailing path is not supported on Windows. 100 // Trailing path is not supported on Windows.
101 if (Platform.isWindows) { 101 if (Platform.isWindows) {
102 path = FileSystemEntity._trimTrailingPathSeparators(path); 102 path = FileSystemEntity._trimTrailingPathSeparators(path);
103 } 103 }
104 var data = _statSync(path); 104 var data = _statSync(path);
105 if (data is OSError) return FileStat._notFound; 105 if (data is OSError) return FileStat._notFound;
106 return new FileStat._internal( 106 return new FileStat._internal(
107 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), 107 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]),
108 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), 108 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]),
109 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000), 109 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]),
110 FileSystemEntityType._lookup(data[_TYPE]), 110 FileSystemEntityType._lookup(data[_TYPE]),
111 data[_MODE], 111 data[_MODE],
112 data[_SIZE]); 112 data[_SIZE]);
113 } 113 }
114 114
115 /** 115 /**
116 * Asynchronously calls the operating system's stat() function on [path]. 116 * Asynchronously calls the operating system's stat() function on [path].
117 * Returns a Future which completes with a [FileStat] object containing 117 * Returns a Future which completes with a [FileStat] object containing
118 * the data returned by stat(). 118 * the data returned by stat().
119 * If the call fails, completes the future with a [FileStat] object with 119 * If the call fails, completes the future with a [FileStat] object with
120 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid. 120 * .type set to FileSystemEntityType.NOT_FOUND and the other fields invalid.
121 */ 121 */
122 static Future<FileStat> stat(String path) { 122 static Future<FileStat> stat(String path) {
123 // Trailing path is not supported on Windows. 123 // Trailing path is not supported on Windows.
124 if (Platform.isWindows) { 124 if (Platform.isWindows) {
125 path = FileSystemEntity._trimTrailingPathSeparators(path); 125 path = FileSystemEntity._trimTrailingPathSeparators(path);
126 } 126 }
127 return _IOService.dispatch(_FILE_STAT, [path]).then((response) { 127 return _IOService.dispatch(_FILE_STAT, [path]).then((response) {
128 if (_isErrorResponse(response)) { 128 if (_isErrorResponse(response)) {
129 return FileStat._notFound; 129 return FileStat._notFound;
130 } 130 }
131 // Unwrap the real list from the "I'm not an error" wrapper. 131 // Unwrap the real list from the "I'm not an error" wrapper.
132 List data = response[1]; 132 List data = response[1];
133 return new FileStat._internal( 133 return new FileStat._internal(
134 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME] * 1000), 134 new DateTime.fromMillisecondsSinceEpoch(data[_CHANGED_TIME]),
135 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME] * 1000), 135 new DateTime.fromMillisecondsSinceEpoch(data[_MODIFIED_TIME]),
136 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME] * 1000), 136 new DateTime.fromMillisecondsSinceEpoch(data[_ACCESSED_TIME]),
137 FileSystemEntityType._lookup(data[_TYPE]), 137 FileSystemEntityType._lookup(data[_TYPE]),
138 data[_MODE], 138 data[_MODE],
139 data[_SIZE]); 139 data[_SIZE]);
140 }); 140 });
141 } 141 }
142 142
143 String toString() => """ 143 String toString() => """
144 FileStat: type $type 144 FileStat: type $type
145 changed $changed 145 changed $changed
146 modified $modified 146 modified $modified
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 return buffer.toString(); 806 return buffer.toString();
807 } 807 }
808 } 808 }
809 809
810 810
811 class _FileSystemWatcher { 811 class _FileSystemWatcher {
812 external static Stream<FileSystemEvent> watch( 812 external static Stream<FileSystemEvent> watch(
813 String path, int events, bool recursive); 813 String path, int events, bool recursive);
814 external static bool get isSupported; 814 external static bool get isSupported;
815 } 815 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698