download bundle atomically

Reviewed By: javache

Differential Revision: D5697494

fbshipit-source-id: 9217194b609aabf3da23a092b3e5887925bb9bbc
This commit is contained in:
Ben Nham 2017-08-30 05:12:34 -07:00 committed by Facebook Github Bot
parent c68bb6a72c
commit d63cf13ce1
1 changed files with 8 additions and 2 deletions

View File

@ -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);
}
}
}