| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 @patch | 5 @patch class _File { |
| 6 class _File { | 6 @patch static _exists(String path) native "File_Exists"; |
| 7 @patch | 7 @patch static _create(String path) native "File_Create"; |
| 8 static _exists(String path) native "File_Exists"; | 8 @patch static _createLink(String path, String target) |
| 9 @patch | 9 native "File_CreateLink"; |
| 10 static _create(String path) native "File_Create"; | 10 @patch static _linkTarget(String path) native "File_LinkTarget"; |
| 11 @patch | 11 @patch static _deleteNative(String path) native "File_Delete"; |
| 12 static _createLink(String path, String target) native "File_CreateLink"; | 12 @patch static _deleteLinkNative(String path) native "File_DeleteLink"; |
| 13 @patch | 13 @patch static _rename(String oldPath, String newPath) |
| 14 static _linkTarget(String path) native "File_LinkTarget"; | 14 native "File_Rename"; |
| 15 @patch | 15 @patch static _renameLink(String oldPath, String newPath) |
| 16 static _deleteNative(String path) native "File_Delete"; | 16 native "File_RenameLink"; |
| 17 @patch | 17 @patch static _copy(String oldPath, String newPath) native "File_Copy"; |
| 18 static _deleteLinkNative(String path) native "File_DeleteLink"; | 18 @patch static _lengthFromPath(String path) native "File_LengthFromPath"; |
| 19 @patch | 19 @patch static _lastModified(String path) native "File_LastModified"; |
| 20 static _rename(String oldPath, String newPath) native "File_Rename"; | 20 @patch static _setLastModified(String path, int millis) |
| 21 @patch | |
| 22 static _renameLink(String oldPath, String newPath) native "File_RenameLink"; | |
| 23 @patch | |
| 24 static _copy(String oldPath, String newPath) native "File_Copy"; | |
| 25 @patch | |
| 26 static _lengthFromPath(String path) native "File_LengthFromPath"; | |
| 27 @patch | |
| 28 static _lastModified(String path) native "File_LastModified"; | |
| 29 @patch | |
| 30 static _setLastModified(String path, int millis) | |
| 31 native "File_SetLastModified"; | 21 native "File_SetLastModified"; |
| 32 @patch | 22 @patch static _lastAccessed(String path) native "File_LastAccessed"; |
| 33 static _lastAccessed(String path) native "File_LastAccessed"; | 23 @patch static _setLastAccessed(String path, int millis) |
| 34 @patch | |
| 35 static _setLastAccessed(String path, int millis) | |
| 36 native "File_SetLastAccessed"; | 24 native "File_SetLastAccessed"; |
| 37 @patch | 25 @patch static _open(String path, int mode) native "File_Open"; |
| 38 static _open(String path, int mode) native "File_Open"; | 26 @patch static int _openStdio(int fd) native "File_OpenStdio"; |
| 39 @patch | |
| 40 static int _openStdio(int fd) native "File_OpenStdio"; | |
| 41 } | 27 } |
| 42 | 28 |
| 43 @patch | 29 |
| 44 class _RandomAccessFileOps { | 30 @patch class _RandomAccessFileOps { |
| 45 @patch | 31 @patch factory _RandomAccessFileOps(int pointer) |
| 46 factory _RandomAccessFileOps(int pointer) => | 32 => new _RandomAccessFileOpsImpl(pointer); |
| 47 new _RandomAccessFileOpsImpl(pointer); | |
| 48 } | 33 } |
| 49 | 34 |
| 35 |
| 50 class _RandomAccessFileOpsImpl extends NativeFieldWrapperClass1 | 36 class _RandomAccessFileOpsImpl extends NativeFieldWrapperClass1 |
| 51 implements _RandomAccessFileOps { | 37 implements _RandomAccessFileOps { |
| 52 _RandomAccessFileOpsImpl._(); | 38 _RandomAccessFileOpsImpl._(); |
| 53 | 39 |
| 54 factory _RandomAccessFileOpsImpl(int pointer) => | 40 factory _RandomAccessFileOpsImpl(int pointer) |
| 55 new _RandomAccessFileOpsImpl._().._setPointer(pointer); | 41 => new _RandomAccessFileOpsImpl._().._setPointer(pointer); |
| 56 | 42 |
| 57 void _setPointer(int pointer) native "File_SetPointer"; | 43 void _setPointer(int pointer) native "File_SetPointer"; |
| 58 | 44 |
| 59 int getPointer() native "File_GetPointer"; | 45 int getPointer() native "File_GetPointer"; |
| 60 int close() native "File_Close"; | 46 int close() native "File_Close"; |
| 61 readByte() native "File_ReadByte"; | 47 readByte() native "File_ReadByte"; |
| 62 read(int bytes) native "File_Read"; | 48 read(int bytes) native "File_Read"; |
| 63 readInto(List<int> buffer, int start, int end) native "File_ReadInto"; | 49 readInto(List<int> buffer, int start, int end) native "File_ReadInto"; |
| 64 writeByte(int value) native "File_WriteByte"; | 50 writeByte(int value) native "File_WriteByte"; |
| 65 writeFrom(List<int> buffer, int start, int end) native "File_WriteFrom"; | 51 writeFrom(List<int> buffer, int start, int end) native "File_WriteFrom"; |
| 66 position() native "File_Position"; | 52 position() native "File_Position"; |
| 67 setPosition(int position) native "File_SetPosition"; | 53 setPosition(int position) native "File_SetPosition"; |
| 68 truncate(int length) native "File_Truncate"; | 54 truncate(int length) native "File_Truncate"; |
| 69 length() native "File_Length"; | 55 length() native "File_Length"; |
| 70 flush() native "File_Flush"; | 56 flush() native "File_Flush"; |
| 71 lock(int lock, int start, int end) native "File_Lock"; | 57 lock(int lock, int start, int end) native "File_Lock"; |
| 72 setTranslation(int translation) native "File_SetTranslation"; | 58 setTranslation(int translation) native "File_SetTranslation"; |
| 73 } | 59 } |
| 74 | 60 |
| 61 |
| 75 class _WatcherPath { | 62 class _WatcherPath { |
| 76 final int pathId; | 63 final int pathId; |
| 77 final String path; | 64 final String path; |
| 78 final int events; | 65 final int events; |
| 79 int count = 0; | 66 int count = 0; |
| 80 _WatcherPath(this.pathId, this.path, this.events); | 67 _WatcherPath(this.pathId, this.path, this.events); |
| 81 } | 68 } |
| 82 | 69 |
| 83 @patch | 70 |
| 84 class _FileSystemWatcher { | 71 @patch class _FileSystemWatcher { |
| 85 static int _id; | 72 static int _id; |
| 86 static final Map<int, _WatcherPath> _idMap = {}; | 73 static final Map<int, _WatcherPath> _idMap = {}; |
| 87 | 74 |
| 88 final String _path; | 75 final String _path; |
| 89 final int _events; | 76 final int _events; |
| 90 final bool _recursive; | 77 final bool _recursive; |
| 91 | 78 |
| 92 _WatcherPath _watcherPath; | 79 _WatcherPath _watcherPath; |
| 93 | 80 |
| 94 StreamController _broadcastController; | 81 StreamController _broadcastController; |
| 95 | 82 |
| 96 @patch | 83 @patch static Stream<FileSystemEvent> _watch( |
| 97 static Stream<FileSystemEvent> _watch( | |
| 98 String path, int events, bool recursive) { | 84 String path, int events, bool recursive) { |
| 99 if (Platform.isLinux) { | 85 if (Platform.isLinux) { |
| 100 return new _InotifyFileSystemWatcher(path, events, recursive)._stream; | 86 return new _InotifyFileSystemWatcher(path, events, recursive)._stream; |
| 101 } | 87 } |
| 102 if (Platform.isWindows) { | 88 if (Platform.isWindows) { |
| 103 return new _Win32FileSystemWatcher(path, events, recursive)._stream; | 89 return new _Win32FileSystemWatcher(path, events, recursive)._stream; |
| 104 } | 90 } |
| 105 if (Platform.isMacOS) { | 91 if (Platform.isMacOS) { |
| 106 return new _FSEventStreamFileSystemWatcher(path, events, recursive) | 92 return new _FSEventStreamFileSystemWatcher( |
| 107 ._stream; | 93 path, events, recursive)._stream; |
| 108 } | 94 } |
| 109 throw new FileSystemException( | 95 throw new FileSystemException( |
| 110 "File system watching is not supported on this platform"); | 96 "File system watching is not supported on this platform"); |
| 111 } | 97 } |
| 112 | 98 |
| 113 _FileSystemWatcher._(this._path, this._events, this._recursive) { | 99 _FileSystemWatcher._(this._path, this._events, this._recursive) { |
| 114 if (!isSupported) { | 100 if (!isSupported) { |
| 115 throw new FileSystemException( | 101 throw new FileSystemException( |
| 116 "File system watching is not supported on this platform", _path); | 102 "File system watching is not supported on this platform", |
| 103 _path); |
| 117 } | 104 } |
| 118 _broadcastController = | 105 _broadcastController = new StreamController.broadcast(onListen: _listen, |
| 119 new StreamController.broadcast(onListen: _listen, onCancel: _cancel); | 106 onCancel: _cancel); |
| 120 } | 107 } |
| 121 | 108 |
| 122 Stream get _stream => _broadcastController.stream; | 109 Stream get _stream => _broadcastController.stream; |
| 123 | 110 |
| 124 void _listen() { | 111 void _listen() { |
| 125 if (_id == null) { | 112 if (_id == null) { |
| 126 try { | 113 try { |
| 127 _id = _initWatcher(); | 114 _id = _initWatcher(); |
| 128 _newWatcher(); | 115 _newWatcher(); |
| 129 } catch (e) { | 116 } catch (e) { |
| 130 _broadcastController.addError(new FileSystemException( | 117 _broadcastController.addError(new FileSystemException( |
| 131 "Failed to initialize file system entity watcher", null, e)); | 118 "Failed to initialize file system entity watcher", null, e)); |
| 132 _broadcastController.close(); | 119 _broadcastController.close(); |
| 133 return; | 120 return; |
| 134 } | 121 } |
| 135 } | 122 } |
| 136 var pathId; | 123 var pathId; |
| 137 try { | 124 try { |
| 138 pathId = _watchPath(_id, _path, _events, _recursive); | 125 pathId = _watchPath(_id, _path, _events, _recursive); |
| 139 } catch (e) { | 126 } catch (e) { |
| 140 _broadcastController | 127 _broadcastController.addError(new FileSystemException( |
| 141 .addError(new FileSystemException("Failed to watch path", _path, e)); | 128 "Failed to watch path", _path, e)); |
| 142 _broadcastController.close(); | 129 _broadcastController.close(); |
| 143 return; | 130 return; |
| 144 } | 131 } |
| 145 if (!_idMap.containsKey(pathId)) { | 132 if (!_idMap.containsKey(pathId)) { |
| 146 _idMap[pathId] = new _WatcherPath(pathId, _path, _events); | 133 _idMap[pathId] = new _WatcherPath(pathId, _path, _events); |
| 147 } | 134 } |
| 148 _watcherPath = _idMap[pathId]; | 135 _watcherPath = _idMap[pathId]; |
| 149 _watcherPath.count++; | 136 _watcherPath.count++; |
| 150 _pathWatched().pipe(_broadcastController); | 137 _pathWatched().pipe(_broadcastController); |
| 151 } | 138 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 var pair = {}; | 177 var pair = {}; |
| 191 if (event == RawSocketEvent.READ) { | 178 if (event == RawSocketEvent.READ) { |
| 192 String getPath(event) { | 179 String getPath(event) { |
| 193 var path = _pathFromPathId(event[4]).path; | 180 var path = _pathFromPathId(event[4]).path; |
| 194 if (event[2] != null && event[2].isNotEmpty) { | 181 if (event[2] != null && event[2].isNotEmpty) { |
| 195 path += Platform.pathSeparator; | 182 path += Platform.pathSeparator; |
| 196 path += event[2]; | 183 path += event[2]; |
| 197 } | 184 } |
| 198 return path; | 185 return path; |
| 199 } | 186 } |
| 200 | |
| 201 bool getIsDir(event) { | 187 bool getIsDir(event) { |
| 202 if (Platform.isWindows) { | 188 if (Platform.isWindows) { |
| 203 // Windows does not get 'isDir' as part of the event. | 189 // Windows does not get 'isDir' as part of the event. |
| 204 return FileSystemEntity.isDirectorySync(getPath(event)); | 190 return FileSystemEntity.isDirectorySync(getPath(event)); |
| 205 } | 191 } |
| 206 return (event[0] & FileSystemEvent._IS_DIR) != 0; | 192 return (event[0] & FileSystemEvent._IS_DIR) != 0; |
| 207 } | 193 } |
| 208 | |
| 209 void add(id, event) { | 194 void add(id, event) { |
| 210 if ((event.type & _pathFromPathId(id).events) == 0) return; | 195 if ((event.type & _pathFromPathId(id).events) == 0) return; |
| 211 events.add([id, event]); | 196 events.add([id, event]); |
| 212 } | 197 } |
| 213 | |
| 214 void rewriteMove(event, isDir) { | 198 void rewriteMove(event, isDir) { |
| 215 if (event[3]) { | 199 if (event[3]) { |
| 216 add(event[4], new FileSystemCreateEvent._(getPath(event), isDir)); | 200 add(event[4], new FileSystemCreateEvent._(getPath(event), isDir)); |
| 217 } else { | 201 } else { |
| 218 add(event[4], new FileSystemDeleteEvent._(getPath(event), isDir)); | 202 add(event[4], new FileSystemDeleteEvent._(getPath(event), isDir)); |
| 219 } | 203 } |
| 220 } | 204 } |
| 221 | |
| 222 int eventCount; | 205 int eventCount; |
| 223 do { | 206 do { |
| 224 eventCount = 0; | 207 eventCount = 0; |
| 225 for (var event in _readEvents(id, pathId)) { | 208 for (var event in _readEvents(id, pathId)) { |
| 226 if (event == null) continue; | 209 if (event == null) continue; |
| 227 eventCount++; | 210 eventCount++; |
| 228 int pathId = event[4]; | 211 int pathId = event[4]; |
| 229 if (!_idMap.containsKey(pathId)) { | 212 if (!_idMap.containsKey(pathId)) { |
| 230 // Path is no longer being wathed. | 213 // Path is no longer being wathed. |
| 231 continue; | 214 continue; |
| 232 } | 215 } |
| 233 bool isDir = getIsDir(event); | 216 bool isDir = getIsDir(event); |
| 234 var path = getPath(event); | 217 var path = getPath(event); |
| 235 if ((event[0] & FileSystemEvent.CREATE) != 0) { | 218 if ((event[0] & FileSystemEvent.CREATE) != 0) { |
| 236 add(event[4], new FileSystemCreateEvent._(path, isDir)); | 219 add(event[4], new FileSystemCreateEvent._(path, isDir)); |
| 237 } | 220 } |
| 238 if ((event[0] & FileSystemEvent.MODIFY) != 0) { | 221 if ((event[0] & FileSystemEvent.MODIFY) != 0) { |
| 239 add(event[4], new FileSystemModifyEvent._(path, isDir, true)); | 222 add(event[4], new FileSystemModifyEvent._(path, isDir, true)); |
| 240 } | 223 } |
| 241 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { | 224 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { |
| 242 add(event[4], new FileSystemModifyEvent._(path, isDir, false)); | 225 add(event[4], new FileSystemModifyEvent._(path, isDir, false)); |
| 243 } | 226 } |
| 244 if ((event[0] & FileSystemEvent.MOVE) != 0) { | 227 if ((event[0] & FileSystemEvent.MOVE) != 0) { |
| 245 int link = event[1]; | 228 int link = event[1]; |
| 246 if (link > 0) { | 229 if (link > 0) { |
| 247 pair.putIfAbsent(pathId, () => {}); | 230 pair.putIfAbsent(pathId, () => {}); |
| 248 if (pair[pathId].containsKey(link)) { | 231 if (pair[pathId].containsKey(link)) { |
| 249 add( | 232 add(event[4], |
| 250 event[4], | |
| 251 new FileSystemMoveEvent._( | 233 new FileSystemMoveEvent._( |
| 252 getPath(pair[pathId][link]), isDir, path)); | 234 getPath(pair[pathId][link]), isDir, path)); |
| 253 pair[pathId].remove(link); | 235 pair[pathId].remove(link); |
| 254 } else { | 236 } else { |
| 255 pair[pathId][link] = event; | 237 pair[pathId][link] = event; |
| 256 } | 238 } |
| 257 } else { | 239 } else { |
| 258 rewriteMove(event, isDir); | 240 rewriteMove(event, isDir); |
| 259 } | 241 } |
| 260 } | 242 } |
| 261 if ((event[0] & FileSystemEvent.DELETE) != 0) { | 243 if ((event[0] & FileSystemEvent.DELETE) != 0) { |
| 262 add(event[4], new FileSystemDeleteEvent._(path, isDir)); | 244 add(event[4], new FileSystemDeleteEvent._(path, isDir)); |
| 263 } | 245 } |
| 264 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { | 246 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { |
| 265 add(event[4], new FileSystemDeleteEvent._(path, isDir)); | 247 add(event[4], new FileSystemDeleteEvent._(path, isDir)); |
| 266 // Signal done event. | 248 // Signal done event. |
| 267 stops.add([event[4], null]); | 249 stops.add([event[4], null]); |
| 268 } | 250 } |
| 269 } | 251 } |
| 270 } while (eventCount > 0); | 252 } while (eventCount > 0); |
| 271 // Be sure to clear this manually, as the sockets are not read through | 253 // Be sure to clear this manually, as the sockets are not read through |
| 272 // the _NativeSocket interface. | 254 // the _NativeSocket interface. |
| 273 native.available = 0; | 255 native.available = 0; |
| 274 for (var map in pair.values) { | 256 for (var map in pair.values) { |
| 275 for (var event in map.values) { | 257 for (var event in map.values) { |
| 276 rewriteMove(event, getIsDir(event)); | 258 rewriteMove(event, getIsDir(event)); |
| 277 } | 259 } |
| 278 } | 260 } |
| 279 } else if (event == RawSocketEvent.CLOSED) {} else if (event == | 261 } else if (event == RawSocketEvent.CLOSED) { |
| 280 RawSocketEvent.READ_CLOSED) {} else { | 262 } else if (event == RawSocketEvent.READ_CLOSED) { |
| 263 } else { |
| 281 assert(false); | 264 assert(false); |
| 282 } | 265 } |
| 283 events.addAll(stops); | 266 events.addAll(stops); |
| 284 return events; | 267 return events; |
| 285 }); | 268 }); |
| 286 } | 269 } |
| 287 | 270 |
| 288 @patch | 271 @patch static bool get isSupported |
| 289 static bool get isSupported native "FileSystemWatcher_IsSupported"; | 272 native "FileSystemWatcher_IsSupported"; |
| 290 | 273 |
| 291 static int _initWatcher() native "FileSystemWatcher_InitWatcher"; | 274 static int _initWatcher() native "FileSystemWatcher_InitWatcher"; |
| 292 static void _closeWatcher(int id) native "FileSystemWatcher_CloseWatcher"; | 275 static void _closeWatcher(int id) native "FileSystemWatcher_CloseWatcher"; |
| 293 | 276 |
| 294 static int _watchPath(int id, String path, int events, bool recursive) | 277 static int _watchPath(int id, String path, int events, bool recursive) |
| 295 native "FileSystemWatcher_WatchPath"; | 278 native "FileSystemWatcher_WatchPath"; |
| 296 static void _unwatchPath(int id, int path_id) | 279 static void _unwatchPath(int id, int path_id) |
| 297 native "FileSystemWatcher_UnwatchPath"; | 280 native "FileSystemWatcher_UnwatchPath"; |
| 298 static List _readEvents(int id, int path_id) | 281 static List _readEvents(int id, int path_id) |
| 299 native "FileSystemWatcher_ReadEvents"; | 282 native "FileSystemWatcher_ReadEvents"; |
| 300 static int _getSocketId(int id, int path_id) | 283 static int _getSocketId(int id, int path_id) |
| 301 native "FileSystemWatcher_GetSocketId"; | 284 native "FileSystemWatcher_GetSocketId"; |
| 302 } | 285 } |
| 303 | 286 |
| 287 |
| 304 class _InotifyFileSystemWatcher extends _FileSystemWatcher { | 288 class _InotifyFileSystemWatcher extends _FileSystemWatcher { |
| 305 static final Map<int, StreamController> _idMap = {}; | 289 static final Map<int, StreamController> _idMap = {}; |
| 306 static StreamSubscription _subscription; | 290 static StreamSubscription _subscription; |
| 307 | 291 |
| 308 _InotifyFileSystemWatcher(path, events, recursive) | 292 _InotifyFileSystemWatcher(path, events, recursive) |
| 309 : super._(path, events, recursive); | 293 : super._(path, events, recursive); |
| 310 | 294 |
| 311 void _newWatcher() { | 295 void _newWatcher() { |
| 312 int id = _FileSystemWatcher._id; | 296 int id = _FileSystemWatcher._id; |
| 313 _subscription = | 297 _subscription = _FileSystemWatcher._listenOnSocket(id, id, 0) |
| 314 _FileSystemWatcher._listenOnSocket(id, id, 0).listen((event) { | 298 .listen((event) { |
| 315 if (_idMap.containsKey(event[0])) { | 299 if (_idMap.containsKey(event[0])) { |
| 316 if (event[1] != null) { | 300 if (event[1] != null) { |
| 317 _idMap[event[0]].add(event[1]); | 301 _idMap[event[0]].add(event[1]); |
| 318 } else { | 302 } else { |
| 319 _idMap[event[0]].close(); | 303 _idMap[event[0]].close(); |
| 304 } |
| 320 } | 305 } |
| 321 } | 306 }); |
| 322 }); | |
| 323 } | 307 } |
| 324 | 308 |
| 325 void _doneWatcher() { | 309 void _doneWatcher() { |
| 326 _subscription.cancel(); | 310 _subscription.cancel(); |
| 327 } | 311 } |
| 328 | 312 |
| 329 Stream _pathWatched() { | 313 Stream _pathWatched() { |
| 330 var pathId = _watcherPath.pathId; | 314 var pathId = _watcherPath.pathId; |
| 331 if (!_idMap.containsKey(pathId)) { | 315 if (!_idMap.containsKey(pathId)) { |
| 332 _idMap[pathId] = new StreamController.broadcast(); | 316 _idMap[pathId] = new StreamController.broadcast(); |
| 333 } | 317 } |
| 334 return _idMap[pathId].stream; | 318 return _idMap[pathId].stream; |
| 335 } | 319 } |
| 336 | 320 |
| 337 void _pathWatchedEnd() { | 321 void _pathWatchedEnd() { |
| 338 var pathId = _watcherPath.pathId; | 322 var pathId = _watcherPath.pathId; |
| 339 if (!_idMap.containsKey(pathId)) return; | 323 if (!_idMap.containsKey(pathId)) return; |
| 340 _idMap[pathId].close(); | 324 _idMap[pathId].close(); |
| 341 _idMap.remove(pathId); | 325 _idMap.remove(pathId); |
| 342 } | 326 } |
| 343 } | 327 } |
| 344 | 328 |
| 329 |
| 345 class _Win32FileSystemWatcher extends _FileSystemWatcher { | 330 class _Win32FileSystemWatcher extends _FileSystemWatcher { |
| 346 StreamSubscription _subscription; | 331 StreamSubscription _subscription; |
| 347 StreamController _controller; | 332 StreamController _controller; |
| 348 | 333 |
| 349 _Win32FileSystemWatcher(path, events, recursive) | 334 _Win32FileSystemWatcher(path, events, recursive) |
| 350 : super._(path, events, recursive); | 335 : super._(path, events, recursive); |
| 351 | 336 |
| 352 Stream _pathWatched() { | 337 Stream _pathWatched() { |
| 353 var pathId = _watcherPath.pathId; | 338 var pathId = _watcherPath.pathId; |
| 354 _controller = new StreamController(); | 339 _controller = new StreamController(); |
| 355 _subscription = | 340 _subscription = _FileSystemWatcher._listenOnSocket(pathId, 0, pathId) |
| 356 _FileSystemWatcher._listenOnSocket(pathId, 0, pathId).listen((event) { | 341 .listen((event) { |
| 357 assert(event[0] == pathId); | 342 assert(event[0] == pathId); |
| 358 if (event[1] != null) { | 343 if (event[1] != null) { |
| 359 _controller.add(event[1]); | 344 _controller.add(event[1]); |
| 360 } else { | 345 } else { |
| 361 _controller.close(); | 346 _controller.close(); |
| 362 } | 347 } |
| 363 }); | 348 }); |
| 364 return _controller.stream; | 349 return _controller.stream; |
| 365 } | 350 } |
| 366 | 351 |
| 367 void _pathWatchedEnd() { | 352 void _pathWatchedEnd() { |
| 368 _subscription.cancel(); | 353 _subscription.cancel(); |
| 369 _controller.close(); | 354 _controller.close(); |
| 370 } | 355 } |
| 371 } | 356 } |
| 372 | 357 |
| 358 |
| 373 class _FSEventStreamFileSystemWatcher extends _FileSystemWatcher { | 359 class _FSEventStreamFileSystemWatcher extends _FileSystemWatcher { |
| 374 StreamSubscription _subscription; | 360 StreamSubscription _subscription; |
| 375 StreamController _controller; | 361 StreamController _controller; |
| 376 | 362 |
| 377 _FSEventStreamFileSystemWatcher(path, events, recursive) | 363 _FSEventStreamFileSystemWatcher(path, events, recursive) |
| 378 : super._(path, events, recursive); | 364 : super._(path, events, recursive); |
| 379 | 365 |
| 380 Stream _pathWatched() { | 366 Stream _pathWatched() { |
| 381 var pathId = _watcherPath.pathId; | 367 var pathId = _watcherPath.pathId; |
| 382 var socketId = _FileSystemWatcher._getSocketId(0, pathId); | 368 var socketId = _FileSystemWatcher._getSocketId(0, pathId); |
| 383 _controller = new StreamController(); | 369 _controller = new StreamController(); |
| 384 _subscription = | 370 _subscription = _FileSystemWatcher._listenOnSocket(socketId, 0, pathId) |
| 385 _FileSystemWatcher._listenOnSocket(socketId, 0, pathId).listen((event) { | 371 .listen((event) { |
| 386 if (event[1] != null) { | 372 if (event[1] != null) { |
| 387 _controller.add(event[1]); | 373 _controller.add(event[1]); |
| 388 } else { | 374 } else { |
| 389 _controller.close(); | 375 _controller.close(); |
| 390 } | 376 } |
| 391 }); | 377 }); |
| 392 return _controller.stream; | 378 return _controller.stream; |
| 393 } | 379 } |
| 394 | 380 |
| 395 void _pathWatchedEnd() { | 381 void _pathWatchedEnd() { |
| 396 _subscription.cancel(); | 382 _subscription.cancel(); |
| 397 _controller.close(); | 383 _controller.close(); |
| 398 } | 384 } |
| 399 } | 385 } |
| 400 | 386 |
| 387 |
| 401 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { | 388 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { |
| 402 return new Uint8List.view(source.buffer, offsetInBytes, length); | 389 return new Uint8List.view(source.buffer, offsetInBytes, length); |
| 403 } | 390 } |
| OLD | NEW |