Chromium Code Reviews| 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 library watcher.directory_watcher.mac_os; | 5 library watcher.directory_watcher.mac_os; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 if (MacOSDirectoryWatcher.logDebugInfo) { | 172 if (MacOSDirectoryWatcher.logDebugInfo) { |
| 173 print("[$_id] canonical event for $relativePath: " | 173 print("[$_id] canonical event for $relativePath: " |
| 174 "${_formatEvent(canonicalEvent)}"); | 174 "${_formatEvent(canonicalEvent)}"); |
| 175 print("[$_id] actionable events for $relativePath: " | 175 print("[$_id] actionable events for $relativePath: " |
| 176 "${events.map(_formatEvent)}"); | 176 "${events.map(_formatEvent)}"); |
| 177 } | 177 } |
| 178 | 178 |
| 179 for (var event in events) { | 179 for (var event in events) { |
| 180 if (event is FileSystemCreateEvent) { | 180 if (event is FileSystemCreateEvent) { |
| 181 if (!event.isDirectory) { | 181 if (!event.isDirectory) { |
| 182 // Don't emit ADD events for files or directories that we already | 182 // If we already know about the file, treat it like a modification. |
|
nweiz
2015/01/22 00:20:19
"treat it" -> "treat an ADD event"
| |
| 183 // know about. Such an event comes from FSEvents reporting an add | 183 // This can happen if a file is copied on top of an existing one. |
| 184 // that happened prior to the watch beginning. | 184 // We'll see an ADD event for the latter file when from the user's |
| 185 if (_files.contains(path)) continue; | 185 // perspective, the file's contents just changed. |
| 186 var type = _files.contains(path) | |
| 187 ? ChangeType.MODIFY | |
| 188 : ChangeType.ADD; | |
| 186 | 189 |
| 187 _emitEvent(ChangeType.ADD, path); | 190 _emitEvent(type, path); |
| 188 _files.add(path); | 191 _files.add(path); |
| 189 continue; | 192 continue; |
| 190 } | 193 } |
| 191 | 194 |
| 192 if (_files.containsDir(path)) continue; | 195 if (_files.containsDir(path)) continue; |
| 193 | 196 |
| 194 var stream = Chain.track(new Directory(path).list(recursive: true)); | 197 var stream = Chain.track(new Directory(path).list(recursive: true)); |
| 195 _listSubscription = stream.listen((entity) { | 198 _listSubscription = stream.listen((entity) { |
| 196 if (entity is Directory) return; | 199 if (entity is Directory) return; |
| 197 if (_files.contains(path)) return; | 200 if (_files.contains(path)) return; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 } else if (event is FileSystemDeleteEvent) { | 491 } else if (event is FileSystemDeleteEvent) { |
| 489 return "delete $type $path"; | 492 return "delete $type $path"; |
| 490 } else if (event is FileSystemModifyEvent) { | 493 } else if (event is FileSystemModifyEvent) { |
| 491 return "modify $type $path"; | 494 return "modify $type $path"; |
| 492 } else if (event is FileSystemMoveEvent) { | 495 } else if (event is FileSystemMoveEvent) { |
| 493 return "move $type $path to " | 496 return "move $type $path to " |
| 494 "${p.relative(event.destination, from: directory)}"; | 497 "${p.relative(event.destination, from: directory)}"; |
| 495 } | 498 } |
| 496 } | 499 } |
| 497 } | 500 } |
| OLD | NEW |