NotesCache: Save file atomically

Fixes APP-QV
This commit is contained in:
Vishesh Handa
2021-03-02 10:19:12 +01:00
parent 85de0d9dd0
commit ae70ab8b8f

View File

@ -121,6 +121,10 @@ class NotesCache {
rethrow;
}
if (contents.isEmpty) {
return [];
}
try {
return json.decode(contents).cast<String>();
} catch (ex, st) {
@ -131,8 +135,12 @@ class NotesCache {
}
@visibleForTesting
Future<void> saveToDisk(List<String> files) {
Future<void> saveToDisk(List<String> files) async {
var contents = json.encode(files);
return File(filePath).writeAsString(contents);
var newFilePath = filePath + ".new";
var file = File(newFilePath);
await file.writeAsString(contents);
await file.rename(filePath);
}
}