mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 08:36:50 +08:00
NotesCache: Save file atomically
Fixes APP-QV
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user