mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
fix(mobile): replace an unreadable diagnostics install ID file
A file that cannot be read back, such as one that is not text, made the install ID lookup give up, so every report went out without one. Replace it with a new ID instead, as already happens for an empty file. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -60,8 +60,13 @@ Future<String?> diagnosticInstallId({
|
||||
final dir = await (directory ?? _installIdDirectory)();
|
||||
final file = File('${dir.path}/$_installIdFile');
|
||||
if (await file.exists()) {
|
||||
final saved = (await file.readAsString()).trim();
|
||||
if (saved.isNotEmpty) return saved;
|
||||
try {
|
||||
final saved = (await file.readAsString()).trim();
|
||||
if (saved.isNotEmpty) return saved;
|
||||
} on FileSystemException {
|
||||
// Unreadable, for instance not text: a damaged file is replaced below,
|
||||
// not a reason to send reports without an install ID.
|
||||
}
|
||||
}
|
||||
final created = const Uuid().v4();
|
||||
await dir.create(recursive: true);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:buzz/shared/diagnostics/diagnostic_startup.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
// A damaged file is replaced, so reports still carry one install ID from
|
||||
// then on.
|
||||
for (final (name, contents) in <(String, List<int>)>[
|
||||
('empty', []),
|
||||
('blank', [0x20, 0x0a]),
|
||||
('not text', [0xff, 0xfe, 0xc3, 0x28]),
|
||||
]) {
|
||||
test('a $name install ID file is replaced with one that is kept', () async {
|
||||
final directory = await Directory.systemTemp.createTemp('install');
|
||||
addTearDown(() => directory.delete(recursive: true));
|
||||
await File(
|
||||
'${directory.path}/diagnostics_install_id',
|
||||
).writeAsBytes(contents);
|
||||
|
||||
final id = await diagnosticInstallId(directory: () async => directory);
|
||||
|
||||
expect(id, isNotNull);
|
||||
expect(id, isNotEmpty);
|
||||
expect(await diagnosticInstallId(directory: () async => directory), id);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user