Skip to content

Commit

Permalink
download bundle atomically
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D5697494

fbshipit-source-id: 9217194b609aabf3da23a092b3e5887925bb9bbc
  • Loading branch information
bnham authored and facebook-github-bot committed Aug 30, 2017
1 parent c68bb6a commit d63cf13
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,21 @@ private void processBundleResult(
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);
}
}
}

0 comments on commit d63cf13

Please sign in to comment.