Bug 1383081 - (DLC) DownloadAction: Flush stream before verifying checksum. r?mcomella
MozReview-Commit-ID: 9hrUM9Jv6dA
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
@@ -232,16 +232,20 @@ public class DownloadAction extends Base
// a reference to that stream we wouldn't be able to close it if GZInputStream throws.
// (The BufferedInputStream constructor doesn't throw, so we don't need to care about it.)
inputStream = new BufferedInputStream(new FileInputStream(sourceFile));
gzInputStream = new GZIPInputStream(inputStream);
outputStream = new BufferedOutputStream(new FileOutputStream(temporaryFile));
IOUtils.copy(gzInputStream, outputStream);
+ // We need to flush the output stream here so that everything is written before we verify
+ // the checksum of the file.
+ outputStream.flush();
+
if (!verify(temporaryFile, checksum)) {
Log.w(LOGTAG, "Checksum of extracted file does not match.");
return;
}
move(temporaryFile, destinationFile);
} catch (IOException e) {
// We could not extract to the destination: Keep temporary file and try again next time we run.