Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8c781a1 authored by Gabriele M's avatar Gabriele M
Browse files

Use Content-Length if greater than current size

The server may temporarily report an incorrect size that is smaller
than the actual size. Content-Length is expected to always be
accurate, but its value does not correspond to the full file size
when resuming downloads. Use Content-Length only if it's bigger
than the currently known size.

Change-Id: I2cc06bfbd2349f21528047b4840f549fbe84964e
parent ab0ec471
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -157,19 +157,17 @@ public class UpdaterController implements Controller {
            @Override
            public void onResponse(int statusCode, String url, DownloadClient.Headers headers) {
                final Update update = mDownloads.get(downloadId).mUpdate;
                if (update.getFileSize() <= 0) {
                String contentLength = headers.get("Content-Length");
                if (contentLength != null) {
                    try {
                        long size = Long.parseLong(contentLength);
                            if (size > 0) {
                        if (update.getFileSize() < size) {
                            update.setFileSize(size);
                        }
                    } catch (NumberFormatException e) {
                        Log.e(TAG, "Could not get content-length");
                    }
                }
                }
                update.setStatus(UpdateStatus.DOWNLOADING);
                update.setPersistentStatus(UpdateStatus.Persistent.INCOMPLETE);
                new Thread(() -> mUpdatesDbHelper.addUpdateWithOnConflict(update,