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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 var pair = {}; | 82 var pair = {}; |
83 if (event == RawSocketEvent.READ) { | 83 if (event == RawSocketEvent.READ) { |
84 String getPath(event) { | 84 String getPath(event) { |
85 var path = _path; | 85 var path = _path; |
86 if (event[2] != null) { | 86 if (event[2] != null) { |
87 path += Platform.pathSeparator; | 87 path += Platform.pathSeparator; |
88 path += event[2]; | 88 path += event[2]; |
89 } | 89 } |
90 return path; | 90 return path; |
91 } | 91 } |
| 92 bool getIsDir(event) { |
| 93 if (Platform.isWindows) { |
| 94 // Windows does not get 'isDir' as part of the event. |
| 95 return FileSystemEntity.isDirectorySync(path); |
| 96 } |
| 97 return (event[0] & FileSystemEvent._IS_DIR) != 0; |
| 98 } |
92 void add(event) { | 99 void add(event) { |
93 if ((event.type & _events) == 0) return; | 100 if ((event.type & _events) == 0) return; |
94 events.add(event); | 101 events.add(event); |
95 } | 102 } |
96 void rewriteMove(event) { | 103 void rewriteMove(event, isDir) { |
97 if (event[3]) { | 104 if (event[3]) { |
98 add(new FileSystemCreateEvent._(getPath(event))); | 105 add(new FileSystemCreateEvent._(getPath(event), isDir)); |
99 } else { | 106 } else { |
100 add(new FileSystemDeleteEvent._(getPath(event))); | 107 add(new FileSystemDeleteEvent._(getPath(event), isDir)); |
101 } | 108 } |
102 } | 109 } |
103 while (socket.available() > 0) { | 110 while (socket.available() > 0) { |
104 for (var event in _readEvents()) { | 111 for (var event in _readEvents()) { |
105 if (event == null) continue; | 112 if (event == null) continue; |
| 113 bool isDir = getIsDir(event); |
106 var path = getPath(event); | 114 var path = getPath(event); |
107 if ((event[0] & FileSystemEvent.CREATE) != 0) { | 115 if ((event[0] & FileSystemEvent.CREATE) != 0) { |
108 add(new FileSystemCreateEvent._(path)); | 116 add(new FileSystemCreateEvent._(path, isDir)); |
109 } | 117 } |
110 if ((event[0] & FileSystemEvent.MODIFY) != 0) { | 118 if ((event[0] & FileSystemEvent.MODIFY) != 0) { |
111 add(new FileSystemModifyEvent._(path, true)); | 119 add(new FileSystemModifyEvent._(path, isDir, true)); |
112 } | 120 } |
113 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { | 121 if ((event[0] & FileSystemEvent._MODIFY_ATTRIBUTES) != 0) { |
114 add(new FileSystemModifyEvent._(path, false)); | 122 add(new FileSystemModifyEvent._(path, isDir, false)); |
115 } | 123 } |
116 if ((event[0] & FileSystemEvent.MOVE) != 0) { | 124 if ((event[0] & FileSystemEvent.MOVE) != 0) { |
117 int link = event[1]; | 125 int link = event[1]; |
118 if (link > 0) { | 126 if (link > 0) { |
119 if (pair.containsKey(link)) { | 127 if (pair.containsKey(link)) { |
120 events.add( | 128 events.add(new FileSystemMoveEvent._( |
121 new FileSystemMoveEvent._(getPath(pair[link]), path)); | 129 getPath(pair[link]), isDir, path)); |
122 pair.remove(link); | 130 pair.remove(link); |
123 } else { | 131 } else { |
124 pair[link] = event; | 132 pair[link] = event; |
125 } | 133 } |
126 } else { | 134 } else { |
127 rewriteMove(event); | 135 rewriteMove(event, isDir); |
128 } | 136 } |
129 } | 137 } |
130 if ((event[0] & FileSystemEvent.DELETE) != 0) { | 138 if ((event[0] & FileSystemEvent.DELETE) != 0) { |
131 add(new FileSystemDeleteEvent._(path)); | 139 add(new FileSystemDeleteEvent._(path, isDir)); |
132 } | 140 } |
133 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { | 141 if ((event[0] & FileSystemEvent._DELETE_SELF) != 0) { |
134 add(new FileSystemDeleteEvent._(path)); | 142 add(new FileSystemDeleteEvent._(path, isDir)); |
135 stop = true; | 143 stop = true; |
136 } | 144 } |
137 } | 145 } |
138 } | 146 } |
139 for (var event in pair.values) { | 147 for (var event in pair.values) { |
140 rewriteMove(event); | 148 rewriteMove(event, getIsDir(event)); |
141 } | 149 } |
142 } else if (event == RawSocketEvent.CLOSED) { | 150 } else if (event == RawSocketEvent.CLOSED) { |
143 } else if (event == RawSocketEvent.READ_CLOSED) { | 151 } else if (event == RawSocketEvent.READ_CLOSED) { |
144 } else { | 152 } else { |
145 assert(false); | 153 assert(false); |
146 } | 154 } |
147 if (stop) socket.close(); | 155 if (stop) socket.close(); |
148 return events; | 156 return events; |
149 }) | 157 }) |
150 .listen(_controller.add, onDone: _cancel); | 158 .listen(_controller.add, onDone: _cancel); |
(...skipping 14 matching lines...) Expand all Loading... |
165 | 173 |
166 int _watchPath(String path, int events, bool recursive) | 174 int _watchPath(String path, int events, bool recursive) |
167 native "FileSystemWatcher_WatchPath"; | 175 native "FileSystemWatcher_WatchPath"; |
168 void _unwatchPath() native "FileSystemWatcher_UnwatchPath"; | 176 void _unwatchPath() native "FileSystemWatcher_UnwatchPath"; |
169 List _readEvents() native "FileSystemWatcher_ReadEvents"; | 177 List _readEvents() native "FileSystemWatcher_ReadEvents"; |
170 } | 178 } |
171 | 179 |
172 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { | 180 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { |
173 return new Uint8List.view(source.buffer, offsetInBytes, length); | 181 return new Uint8List.view(source.buffer, offsetInBytes, length); |
174 } | 182 } |
OLD | NEW |