From ec8bba15874dfae44714d632d9ec5460b4c28aca Mon Sep 17 00:00:00 2001 From: Niels Sascha Reedijk Date: Tue, 2 Mar 2021 13:51:30 +0000 Subject: [PATCH] PackageKit: fix download logic for remote files This was broken in hrev54968, as some code was lost while switching to the new way the network services kits writes files to disk. This should fix #16822 Change-Id: I104d82e268ded287fd64db1cb902f94b71bad53b Reviewed-on: https://review.haiku-os.org/c/haiku/+/3760 Reviewed-by: Adrien Destugues --- src/kits/package/FetchFileJob.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/kits/package/FetchFileJob.cpp b/src/kits/package/FetchFileJob.cpp index bf29b5b1a6..389bc851b0 100644 --- a/src/kits/package/FetchFileJob.cpp +++ b/src/kits/package/FetchFileJob.cpp @@ -94,10 +94,31 @@ FetchFileJob::Execute() if (result != B_OK) return result; - BUrlRequest* request = BUrlProtocolRoster::MakeRequest(fFileURL.String(), - &fTargetFile, this); - if (request == NULL) - return B_BAD_VALUE; + result = FetchUtils::SetFileType(fTargetFile, + "application/x-vnd.haiku-package"); + if (result != B_OK) { + fprintf(stderr, "failed to set file type for '%s': %s\n", + DownloadFileName(), strerror(result)); + } + + do { + BUrlRequest* request = BUrlProtocolRoster::MakeRequest(fFileURL.String(), + &fTargetFile, this); + if (request == NULL) + return B_BAD_VALUE; + + // Try to resume the download where we left off + off_t currentPosition; + BHttpRequest* http = dynamic_cast(request); + if (http != NULL && fTargetFile.GetSize(¤tPosition) == B_OK + && currentPosition > 0) { + http->SetRangeStart(currentPosition); + fTargetFile.Seek(0, SEEK_END); + } + + thread_id thread = request->Run(); + wait_for_thread(thread, NULL); + } while (fError == B_IO_ERROR || fError == B_DEV_TIMEOUT); if (fError == B_OK) { result = FetchUtils::MarkDownloadComplete(fTargetFile);