From d63cf13ce16d3a0d64f3296c39420397e2bd750b Mon Sep 17 00:00:00 2001 From: Ben Nham Date: Wed, 30 Aug 2017 05:12:34 -0700 Subject: [PATCH] download bundle atomically Reviewed By: javache Differential Revision: D5697494 fbshipit-source-id: 9217194b609aabf3da23a092b3e5887925bb9bbc --- .../facebook/react/devsupport/BundleDownloader.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BundleDownloader.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BundleDownloader.java index bb82d25b4..02dbf9dea 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BundleDownloader.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BundleDownloader.java @@ -172,15 +172,21 @@ public class BundleDownloader { return; } + File tmpFile = new File(outputFile.getPath() + ".tmp"); Sink output = null; try { - output = Okio.sink(outputFile); + output = Okio.sink(tmpFile); body.readAll(output); - callback.onSuccess(); } finally { if (output != null) { output.close(); } } + + if (tmpFile.renameTo(outputFile)) { + callback.onSuccess(); + } else { + throw new IOException("Couldn't rename " + tmpFile + " to " + outputFile); + } } }