headOf method
The current revision of the container, or null when it does not exist.
Implementation
@override
Future<String?> headOf(String locator) async {
if (!_isDirectoryLocator(locator)) {
final file = File(locator);
return file.existsSync() ? _fileToken(file) : null;
}
final dir = Directory(locator);
if (!dir.existsSync()) return null;
_recover(dir);
// A staged temp is not part of the container: counting one would move the
// head of a container nobody changed, and turn a crashed save into a CAS
// conflict for the next one.
final tokens = <String>[
for (final file in dir.listSync(recursive: true).whereType<File>())
if (!_isScratch(_relative(dir, file.path)))
'${_relative(dir, file.path)}=${_fileToken(file)}',
]..sort();
return _digest(tokens.join('\n'));
}