download bundle atomically
Reviewed By: javache Differential Revision: D5697494 fbshipit-source-id: 9217194b609aabf3da23a092b3e5887925bb9bbc
This commit is contained in:
parent
c68bb6a72c
commit
d63cf13ce1
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue