Avoid JSON corruption when storage full (#2089)

This commit is contained in:
Imran Remtulla
2025-01-27 19:55:12 -05:00
parent fcf3c8b635
commit a7a5749d4f

View File

@ -1454,8 +1454,10 @@ class AppsProvider with ChangeNotifier {
app = getCorrectedInstallStatusAppIfPossible(app, info) ?? app;
}
if (!onlyIfExists || this.apps.containsKey(app.id)) {
File('${(await getAppsDir()).path}/${app.id}.json')
.writeAsStringSync(jsonEncode(app.toJson()));
String filePath = '${(await getAppsDir()).path}/${app.id}.json';
File('$filePath.tmp')
.writeAsStringSync(jsonEncode(app.toJson())); // #2089
File('$filePath.tmp').renameSync(filePath);
}
try {
this.apps.update(app.id,