From eaba161d43597ff6e40dd1794c92d75dc56f6583 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Wed, 5 Jul 2017 23:35:14 +0200 Subject: [PATCH] Replace current json only if new one is valid --- src/org/lineageos/updater/UpdatesActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 2aacf43c..006bfb8b 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -151,10 +151,11 @@ public class UpdatesActivity extends AppCompatActivity { } private void downloadUpdatesList() { - File jsonFile = Utils.getCachedUpdateList(this); + final File jsonFile = Utils.getCachedUpdateList(this); + final File jsonFileTmp = new File(jsonFile.getAbsolutePath() + ".tmp"); String url = Utils.getServerURL(this); Log.d(TAG, "Checking " + url); - DownloadClient.downloadFile(url, jsonFile, new DownloadClient.DownloadCallback() { + DownloadClient.downloadFile(url, jsonFileTmp, new DownloadClient.DownloadCallback() { @Override public void onFailure(boolean cancelled) { Log.e(TAG, "Could not download updates list"); @@ -173,6 +174,7 @@ public class UpdatesActivity extends AppCompatActivity { try { Log.d(TAG, "List downloaded"); loadUpdatesList(); + jsonFileTmp.renameTo(jsonFile); } catch (IOException | JSONException e) { Log.e(TAG, "Could not read json", e); }