| 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; | 5 library watcher.directory_watcher; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:crypto/crypto.dart'; | 10 import 'package:crypto/crypto.dart'; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 /// Processes [file] to determine if it has been modified since the last | 150 /// Processes [file] to determine if it has been modified since the last |
| 151 /// time it was scanned. | 151 /// time it was scanned. |
| 152 Future _processFile(String file) { | 152 Future _processFile(String file) { |
| 153 assert(_state != _WatchState.UNSUBSCRIBED); | 153 assert(_state != _WatchState.UNSUBSCRIBED); |
| 154 | 154 |
| 155 // `null` is the sentinel which means the directory listing is complete. | 155 // `null` is the sentinel which means the directory listing is complete. |
| 156 if (file == null) return _completePoll(); | 156 if (file == null) return _completePoll(); |
| 157 | 157 |
| 158 return getModificationTime(file).then((modified) { | 158 return getModificationTime(file).then((modified) { |
| 159 if (_checkForCancel()) return; | 159 if (_checkForCancel()) return null; |
| 160 | 160 |
| 161 var lastStatus = _statuses[file]; | 161 var lastStatus = _statuses[file]; |
| 162 | 162 |
| 163 // If its modification time hasn't changed, assume the file is unchanged. | 163 // If its modification time hasn't changed, assume the file is unchanged. |
| 164 if (lastStatus != null && lastStatus.modified == modified) { | 164 if (lastStatus != null && lastStatus.modified == modified) { |
| 165 // The file is still here. | 165 // The file is still here. |
| 166 _polledFiles.add(file); | 166 _polledFiles.add(file); |
| 167 return; | 167 return null; |
| 168 } | 168 } |
| 169 | 169 |
| 170 return _hashFile(file).then((hash) { | 170 return _hashFile(file).then((hash) { |
| 171 if (_checkForCancel()) return; | 171 if (_checkForCancel()) return; |
| 172 | 172 |
| 173 var status = new _FileStatus(modified, hash); | 173 var status = new _FileStatus(modified, hash); |
| 174 _statuses[file] = status; | 174 _statuses[file] = status; |
| 175 _polledFiles.add(file); | 175 _polledFiles.add(file); |
| 176 | 176 |
| 177 // Only notify while in the watching state. | 177 // Only notify while in the watching state. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 class _FileStatus { | 273 class _FileStatus { |
| 274 /// The last time the file was modified. | 274 /// The last time the file was modified. |
| 275 DateTime modified; | 275 DateTime modified; |
| 276 | 276 |
| 277 /// The SHA-1 hash of the contents of the file. | 277 /// The SHA-1 hash of the contents of the file. |
| 278 List<int> hash; | 278 List<int> hash; |
| 279 | 279 |
| 280 _FileStatus(this.modified, this.hash); | 280 _FileStatus(this.modified, this.hash); |
| 281 } | 281 } |
| OLD | NEW |