Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: pkg/watcher/lib/src/directory_watcher/mac_os.dart

Issue 71353011: Roll forward r30205. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/pkg.status ('k') | pkg/watcher/test/directory_watcher/mac_os_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/watcher/lib/src/directory_watcher/mac_os.dart
diff --git a/pkg/watcher/lib/src/directory_watcher/mac_os.dart b/pkg/watcher/lib/src/directory_watcher/mac_os.dart
index 5b1feb342f2a220316c339af1e01dd8a3f6eba23..09fdd66d94f08f4c369c6a1cad9dc4253462c4f1 100644
--- a/pkg/watcher/lib/src/directory_watcher/mac_os.dart
+++ b/pkg/watcher/lib/src/directory_watcher/mac_os.dart
@@ -7,6 +7,8 @@ library watcher.directory_watcher.mac_os;
import 'dart:async';
import 'dart:io';
+import 'package:path/path.dart' as p;
+
import '../constructable_file_system_event.dart';
import '../path_set.dart';
import '../utils.dart';
@@ -24,6 +26,9 @@ import 'resubscribable.dart';
/// This also works around issues 14793, 14806, and 14849 in the implementation
/// of [Directory.watch].
class MacOSDirectoryWatcher extends ResubscribableDirectoryWatcher {
+ // TODO(nweiz): remove this when issue 15042 is fixed.
+ static bool logDebugInfo = false;
+
MacOSDirectoryWatcher(String directory)
: super(directory, () => new _MacOSDirectoryWatcher(directory));
}
@@ -78,7 +83,12 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
if (entity is! Directory) _files.add(entity.path);
},
onError: _emitError,
- onDone: _readyCompleter.complete,
+ onDone: () {
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("watcher is ready");
+ }
+ _readyCompleter.complete();
+ },
cancelOnError: true);
}
@@ -94,12 +104,38 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
/// The callback that's run when [Directory.watch] emits a batch of events.
void _onBatch(List<FileSystemEvent> batch) {
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("======== batch:");
+ for (var event in batch) {
+ print(" ${_formatEvent(event)}");
+ }
+
+ print("known files:");
+ for (var foo in _files.toSet()) {
+ print(" ${p.relative(foo, from: directory)}");
+ }
+ }
+
batches++;
_sortEvents(batch).forEach((path, events) {
+ var relativePath = p.relative(path, from: directory);
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("events for $relativePath:\n");
+ for (var event in events) {
+ print(" ${_formatEvent(event)}");
+ }
+ }
+
var canonicalEvent = _canonicalEvent(events);
events = canonicalEvent == null ?
_eventsBasedOnFileSystem(path) : [canonicalEvent];
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("canonical event for $relativePath: "
+ "${_formatEvent(canonicalEvent)}");
+ print("actionable events for $relativePath: "
+ "${events.map(_formatEvent)}");
+ }
for (var event in events) {
if (event is FileSystemCreateEvent) {
@@ -113,7 +149,12 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
if (entity is Directory) return;
_emitEvent(ChangeType.ADD, entity.path);
_files.add(entity.path);
- }, onError: _emitError, cancelOnError: true);
+ }, onError: (e, stackTrace) {
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("got error listing $relativePath: $e");
+ }
+ _emitError(e, stackTrace);
+ }, cancelOnError: true);
} else if (event is FileSystemModifyEvent) {
assert(!event.isDirectory);
_emitEvent(ChangeType.MODIFY, path);
@@ -125,6 +166,10 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
}
}
});
+
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("========");
+ }
}
/// Sort all the events in a batch into sets based on their path.
@@ -261,6 +306,13 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
var fileExists = new File(path).existsSync();
var dirExists = new Directory(path).existsSync();
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("file existed: $fileExisted");
+ print("dir existed: $dirExisted");
+ print("file exists: $fileExists");
+ print("dir exists: $dirExists");
+ }
+
var events = [];
if (fileExisted) {
if (fileExists) {
@@ -330,6 +382,10 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
// watch beginning.
if (type == ChangeType.ADD && _files.contains(path)) return;
+ if (MacOSDirectoryWatcher.logDebugInfo) {
+ print("emitting $type ${p.relative(path, from: directory)}");
+ }
+
_eventsController.add(new WatchEvent(type, path));
}
@@ -350,4 +406,23 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
}, cancelOnError: cancelOnError);
_subscriptions.add(subscription);
}
+
+ // TODO(nweiz): remove this when issue 15042 is fixed.
+ /// Return a human-friendly string representation of [event].
+ String _formatEvent(FileSystemEvent event) {
+ if (event == null) return 'null';
+
+ var path = p.relative(event.path, from: directory);
+ var type = event.isDirectory ? 'directory' : 'file';
+ if (event is FileSystemCreateEvent) {
+ return "create $type $path";
+ } else if (event is FileSystemDeleteEvent) {
+ return "delete $type $path";
+ } else if (event is FileSystemModifyEvent) {
+ return "modify $type $path";
+ } else if (event is FileSystemMoveEvent) {
+ return "move $type $path to "
+ "${p.relative(event.destination, from: directory)}";
+ }
+ }
}
« no previous file with comments | « pkg/pkg.status ('k') | pkg/watcher/test/directory_watcher/mac_os_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698