mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 16:46:51 +08:00
NotesCache: Save file atomically
Fixes APP-QV
This commit is contained in:
@ -121,6 +121,10 @@ class NotesCache {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contents.isEmpty) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return json.decode(contents).cast<String>();
|
return json.decode(contents).cast<String>();
|
||||||
} catch (ex, st) {
|
} catch (ex, st) {
|
||||||
@ -131,8 +135,12 @@ class NotesCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<void> saveToDisk(List<String> files) {
|
Future<void> saveToDisk(List<String> files) async {
|
||||||
var contents = json.encode(files);
|
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