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

Unified Diff: dart/site/try/project_server.dart

Issue 224373003: Detect concurrent edits. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months 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 | « no previous file | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/site/try/project_server.dart
diff --git a/dart/site/try/project_server.dart b/dart/site/try/project_server.dart
index 4c250cf371518b4ca798347fea9efeb5766113c8..d71d87043616f85c4c83ddfbddd485ad454fa755 100644
--- a/dart/site/try/project_server.dart
+++ b/dart/site/try/project_server.dart
@@ -6,6 +6,9 @@ library trydart.projectServer;
import 'dart:io';
+import 'dart:async' show
+ Future;
+
import 'dart:convert' show
HtmlEscape,
JSON,
@@ -29,10 +32,33 @@ class WatchHandler {
: this.watchedFiles = watchedFiles.toSet();
handleFileSystemEvent(FileSystemEvent event) {
- String type = event.isDirectory ? 'directory' : 'file';
- String eventType = fsEventNames[event.type];
- if (eventType == null) eventType = 'unknown';
- socket.add(JSON.encode({eventType: [event.path]}));
+ if (event.isDirectory) return;
+ String type = fsEventNames[event.type];
+ if (type == null) type = 'unknown';
+ String path = new Uri.file(event.path).pathSegments.last;
+ shouldIgnore(type, path).then((bool ignored) {
+ if (ignored) return;
+ socket.add(JSON.encode({type: [path]}));
+ });
+ }
+
+ Future<bool> shouldIgnore(String type, String path) {
+ switch (type) {
+ case 'create':
+ return new Future<bool>.value(!watchedFiles.contains(path));
+ case 'delete':
+ return Conversation.listProjectFiles().then((List<String> files) {
+ watchedFiles
+ ..retainAll(files)
+ ..addAll(files);
+ return watchedFiles.contains(path);
+ });
+ case 'modify':
+ return new Future<bool>.value(false);
+ default:
+ print('Unhandled fs-event for $path ($type).');
+ return new Future<bool>.value(true);
+ }
}
onData(_) {
« no previous file with comments | « no previous file | dart/site/try/src/interaction_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698