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