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 class _File { |
6 /* patch */ static _exists(String path) native "File_Exists"; | 6 /* patch */ static _exists(String path) native "File_Exists"; |
7 /* patch */ static _create(String path) native "File_Create"; | 7 /* patch */ static _create(String path) native "File_Create"; |
8 /* patch */ static _createLink(String path, String target) | 8 /* patch */ static _createLink(String path, String target) |
9 native "File_CreateLink"; | 9 native "File_CreateLink"; |
10 /* patch */ static _linkTarget(String path) native "File_LinkTarget"; | 10 /* patch */ static _linkTarget(String path) native "File_LinkTarget"; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // Called when a new path is being watched. | 143 // Called when a new path is being watched. |
144 Stream _pathWatched() {} | 144 Stream _pathWatched() {} |
145 // Called when a path is no longer being watched. | 145 // Called when a path is no longer being watched. |
146 void _donePathWatched() {} | 146 void _donePathWatched() {} |
147 | 147 |
148 static _WatcherPath _pathFromPathId(int pathId) { | 148 static _WatcherPath _pathFromPathId(int pathId) { |
149 return _idMap[pathId]; | 149 return _idMap[pathId]; |
150 } | 150 } |
151 | 151 |
152 static Stream _listenOnSocket(int socketId, int id, int pathId) { | 152 static Stream _listenOnSocket(int socketId, int id, int pathId) { |
153 var socket = new _RawSocket(new _NativeSocket.watch(socketId)); | 153 var native = new _NativeSocket.watch(socketId); |
| 154 var socket = new _RawSocket(native); |
154 return socket.expand((event) { | 155 return socket.expand((event) { |
155 var stops = []; | 156 var stops = []; |
156 var events = []; | 157 var events = []; |
157 var pair = {}; | 158 var pair = {}; |
158 if (event == RawSocketEvent.READ) { | 159 if (event == RawSocketEvent.READ) { |
159 String getPath(event) { | 160 String getPath(event) { |
160 var path = _pathFromPathId(event[4]).path; | 161 var path = _pathFromPathId(event[4]).path; |
161 if (event[2] != null && event[2].isNotEmpty) { | 162 if (event[2] != null && event[2].isNotEmpty) { |
162 path += Platform.pathSeparator; | 163 path += Platform.pathSeparator; |
163 path += event[2]; | 164 path += event[2]; |
(...skipping 11 matching lines...) Expand all Loading... |
175 if ((event.type & _pathFromPathId(id).events) == 0) return; | 176 if ((event.type & _pathFromPathId(id).events) == 0) return; |
176 events.add([id, event]); | 177 events.add([id, event]); |
177 } | 178 } |
178 void rewriteMove(event, isDir) { | 179 void rewriteMove(event, isDir) { |
179 if (event[3]) { | 180 if (event[3]) { |
180 add(event[4], new FileSystemCreateEvent._(getPath(event), isDir)); | 181 add(event[4], new FileSystemCreateEvent._(getPath(event), isDir)); |
181 } else { | 182 } else { |
182 add(event[4], new FileSystemDeleteEvent._(getPath(event), isDir)); | 183 add(event[4], new FileSystemDeleteEvent._(getPath(event), isDir)); |
183 } | 184 } |
184 } | 185 } |
185 while (socket.available() > 0) { | 186 int eventCount; |
| 187 do { |
| 188 eventCount = 0; |
186 for (var event in _readEvents(id, pathId)) { | 189 for (var event in _readEvents(id, pathId)) { |
187 if (event == null) continue; | 190 if (event == null) continue; |
| 191 eventCount++; |
188 int pathId = event[4]; | 192 int pathId = event[4]; |
189 bool isDir = getIsDir(event); | 193 bool isDir = getIsDir(event); |
190 var path = getPath(event); | 194 var path = getPath(event); |
191 if ((event[0] & FileSystemEvent.CREATE) != 0) { | 195 if ((event[0] & FileSystemEvent.CREATE) != 0) { |
192 add(event[4], new FileSystemCreateEvent._(path, isDir)); | 196 add(event[4], new FileSystemCreateEvent._(path, isDir)); |
193 } | 197 } |
194 if ((event[0] & FileSystemEvent.MODIFY) != 0) { | 198 if ((event[0] & FileSystemEvent.MODIFY) != 0) { |
195 add(event[4], new FileSystemModifyEvent._(path, isDir, true)); | 199 add(event[4], new FileSystemModifyEvent._(path, isDir, true)); |
196 } | 200 } |
197 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { | 201 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { |
(...skipping 17 matching lines...) Expand all Loading... |
215 } | 219 } |
216 if ((event[0] & FileSystemEvent.DELETE) != 0) { | 220 if ((event[0] & FileSystemEvent.DELETE) != 0) { |
217 add(event[4], new FileSystemDeleteEvent._(path, isDir)); | 221 add(event[4], new FileSystemDeleteEvent._(path, isDir)); |
218 } | 222 } |
219 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { | 223 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { |
220 add(event[4], new FileSystemDeleteEvent._(path, isDir)); | 224 add(event[4], new FileSystemDeleteEvent._(path, isDir)); |
221 // Signal done event. | 225 // Signal done event. |
222 stops.add([event[4], null]); | 226 stops.add([event[4], null]); |
223 } | 227 } |
224 } | 228 } |
225 } | 229 } while (eventCount > 0); |
| 230 // Be sure to clear this manually, as the sockets are not read through |
| 231 // the _NativeSocket interface. |
| 232 native.available = 0; |
226 for (var map in pair.values) { | 233 for (var map in pair.values) { |
227 for (var event in map.values) { | 234 for (var event in map.values) { |
228 rewriteMove(event, getIsDir(event)); | 235 rewriteMove(event, getIsDir(event)); |
229 } | 236 } |
230 } | 237 } |
231 } else if (event == RawSocketEvent.CLOSED) { | 238 } else if (event == RawSocketEvent.CLOSED) { |
232 } else if (event == RawSocketEvent.READ_CLOSED) { | 239 } else if (event == RawSocketEvent.READ_CLOSED) { |
233 } else { | 240 } else { |
234 assert(false); | 241 assert(false); |
235 } | 242 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 void _pathWatchedEnd() { | 358 void _pathWatchedEnd() { |
352 _subscription.cancel(); | 359 _subscription.cancel(); |
353 _controller.close(); | 360 _controller.close(); |
354 } | 361 } |
355 } | 362 } |
356 | 363 |
357 | 364 |
358 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { | 365 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { |
359 return new Uint8List.view(source.buffer, offsetInBytes, length); | 366 return new Uint8List.view(source.buffer, offsetInBytes, length); |
360 } | 367 } |
OLD | NEW |