| 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; | 
|   11 import 'package:stack_trace/stack_trace.dart'; |   11 import 'package:stack_trace/stack_trace.dart'; | 
|   12  |   12  | 
|   13 import '../constructable_file_system_event.dart'; |   13 import '../constructable_file_system_event.dart'; | 
|   14 import '../path_set.dart'; |   14 import '../path_set.dart'; | 
|   15 import '../utils.dart'; |   15 import '../utils.dart'; | 
|   16 import '../watch_event.dart'; |   16 import '../watch_event.dart'; | 
|   17 import 'resubscribable.dart'; |   17 import 'resubscribable.dart'; | 
|   18  |   18  | 
|   19 /// Uses the FSEvents subsystem to watch for filesystem events. |   19 /// Uses the FSEvents subsystem to watch for filesystem events. | 
|   20 /// |   20 /// | 
|   21 /// FSEvents has two main idiosyncrasies that this class works around. First, it |   21 /// FSEvents has two main idiosyncrasies that this class works around. First, it | 
|   22 /// will occasionally report events that occurred before the filesystem watch |   22 /// will occasionally report events that occurred before the filesystem watch | 
|   23 /// was initiated. Second, if multiple events happen to the same file in close |   23 /// was initiated. Second, if multiple events happen to the same file in close | 
|   24 /// succession, it won't report them in the order they occurred. See issue |   24 /// succession, it won't report them in the order they occurred. See issue | 
|   25 /// 14373. |   25 /// 14373. | 
|   26 /// |   26 /// | 
|   27 /// This also works around issues 15458 and 14849 in the implementation of |   27 /// This also works around issue 14849 in the implementation of | 
|   28 /// [Directory.watch]. |   28 /// [Directory.watch]. | 
|   29 class MacOSDirectoryWatcher extends ResubscribableDirectoryWatcher { |   29 class MacOSDirectoryWatcher extends ResubscribableDirectoryWatcher { | 
|   30   // TODO(nweiz): remove these when issue 15042 is fixed. |   30   // TODO(nweiz): remove these when issue 15042 is fixed. | 
|   31   static var logDebugInfo = false; |   31   static var logDebugInfo = false; | 
|   32   static var _count = 0; |   32   static var _count = 0; | 
|   33  |   33  | 
|   34   MacOSDirectoryWatcher(String directory) |   34   MacOSDirectoryWatcher(String directory) | 
|   35       : super(directory, () => new _MacOSDirectoryWatcher(directory, _count++)); |   35       : super(directory, () => new _MacOSDirectoryWatcher(directory, _count++)); | 
|   36 } |   36 } | 
|   37  |   37  | 
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  288     // but not the CREATE. |  288     // but not the CREATE. | 
|  289     if (type == FileSystemEvent.CREATE && hadModifyEvent && |  289     if (type == FileSystemEvent.CREATE && hadModifyEvent && | 
|  290         _files.contains(batch.first.path)) { |  290         _files.contains(batch.first.path)) { | 
|  291       type = FileSystemEvent.MODIFY; |  291       type = FileSystemEvent.MODIFY; | 
|  292     } |  292     } | 
|  293  |  293  | 
|  294     switch (type) { |  294     switch (type) { | 
|  295       case FileSystemEvent.CREATE: |  295       case FileSystemEvent.CREATE: | 
|  296         return new ConstructableFileSystemCreateEvent(batch.first.path, isDir); |  296         return new ConstructableFileSystemCreateEvent(batch.first.path, isDir); | 
|  297       case FileSystemEvent.DELETE: |  297       case FileSystemEvent.DELETE: | 
|  298         // Issue 15458 means that DELETE events for directories can actually |  | 
|  299         // mean CREATE, so we always check the filesystem for them. |  | 
|  300         if (isDir) return null; |  | 
|  301         return new ConstructableFileSystemCreateEvent(batch.first.path, false); |  298         return new ConstructableFileSystemCreateEvent(batch.first.path, false); | 
|  302       case FileSystemEvent.MODIFY: |  299       case FileSystemEvent.MODIFY: | 
|  303         return new ConstructableFileSystemModifyEvent( |  300         return new ConstructableFileSystemModifyEvent( | 
|  304             batch.first.path, isDir, false); |  301             batch.first.path, isDir, false); | 
|  305       default: assert(false); |  302       default: assert(false); | 
|  306     } |  303     } | 
|  307   } |  304   } | 
|  308  |  305  | 
|  309   /// Returns one or more events that describe the change between the last known |  306   /// Returns one or more events that describe the change between the last known | 
|  310   /// state of [path] and its current state on the filesystem. |  307   /// state of [path] and its current state on the filesystem. | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  428     } else if (event is FileSystemDeleteEvent) { |  425     } else if (event is FileSystemDeleteEvent) { | 
|  429       return "delete $type $path"; |  426       return "delete $type $path"; | 
|  430     } else if (event is FileSystemModifyEvent) { |  427     } else if (event is FileSystemModifyEvent) { | 
|  431       return "modify $type $path"; |  428       return "modify $type $path"; | 
|  432     } else if (event is FileSystemMoveEvent) { |  429     } else if (event is FileSystemMoveEvent) { | 
|  433       return "move $type $path to " |  430       return "move $type $path to " | 
|  434           "${p.relative(event.destination, from: directory)}"; |  431           "${p.relative(event.destination, from: directory)}"; | 
|  435     } |  432     } | 
|  436   } |  433   } | 
|  437 } |  434 } | 
| OLD | NEW |