Add DownloadFileRequest

Downloads a file and optionally checks its checksum.
This commit is contained in:
Ingo Weinhold 2013-04-20 21:22:34 +02:00
parent cca3f3b743
commit 69a53ac5b4
5 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1 @@
#include <../os/package/DownloadFileRequest.h>

View File

@ -0,0 +1,41 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__DOWNLOAD_FILE_REQUEST_H_
#define _PACKAGE__DOWNLOAD_FILE_REQUEST_H_
#include <Entry.h>
#include <String.h>
#include <package/Context.h>
#include <package/Request.h>
namespace BPackageKit {
class DownloadFileRequest : public BRequest {
typedef BRequest inherited;
public:
DownloadFileRequest(const BContext& context,
const BString& fileURL,
const BEntry& targetEntry,
const BString& checksum = BString());
virtual ~DownloadFileRequest();
virtual status_t CreateInitialJobs();
private:
BString fFileURL;
BEntry fTargetEntry;
BString fChecksum;
};
} // namespace BPackageKit
#endif // _PACKAGE__DOWNLOAD_FILE_REQUEST_H_

View File

@ -73,6 +73,7 @@ BuildPlatformSharedLibrary libpackage_build.so
BlockBufferCacheNoLock.cpp
ChecksumAccessors.cpp
Context.cpp
DownloadFileRequest.cpp
DropRepositoryRequest.cpp
FetchFileJob.cpp
InstallationLocationInfo.cpp

View File

@ -0,0 +1,83 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de>
*/
#include <package/DownloadFileRequest.h>
#include <package/FetchFileJob.h>
#include <package/ValidateChecksumJob.h>
namespace BPackageKit {
using namespace BPrivate;
DownloadFileRequest::DownloadFileRequest(const BContext& context,
const BString& fileURL, const BEntry& targetEntry, const BString& checksum)
:
inherited(context),
fFileURL(fileURL),
fTargetEntry(targetEntry),
fChecksum(checksum)
{
if (fInitStatus == B_OK) {
if (fFileURL.IsEmpty())
fInitStatus = B_BAD_VALUE;
else
fInitStatus = targetEntry.InitCheck();
}
}
DownloadFileRequest::~DownloadFileRequest()
{
}
status_t
DownloadFileRequest::CreateInitialJobs()
{
status_t error = InitCheck();
if (error != B_OK)
return B_NO_INIT;
// create the download job
FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext,
BString("Downloading ") << fFileURL, fFileURL, fTargetEntry);
if (fetchJob == NULL)
return B_NO_MEMORY;
if ((error = QueueJob(fetchJob)) != B_OK) {
delete fetchJob;
return error;
}
// create the checksum validation job
if (fChecksum.IsEmpty())
return B_OK;
ValidateChecksumJob* validateJob = new (std::nothrow) ValidateChecksumJob(
fContext, BString("Validating checksum for ") << fFileURL,
new (std::nothrow) StringChecksumAccessor(fChecksum),
new (std::nothrow) GeneralFileChecksumAccessor(fTargetEntry, true));
if (validateJob == NULL)
return B_NO_MEMORY;
if ((error = QueueJob(validateJob)) != B_OK) {
delete validateJob;
return error;
}
return B_OK;
}
} // namespace BPackageKit

View File

@ -53,6 +53,7 @@ SharedLibrary libpackage.so
ChecksumAccessors.cpp
Context.cpp
DaemonClient.cpp
DownloadFileRequest.cpp
DropRepositoryRequest.cpp
FetchFileJob.cpp
InstallationLocationInfo.cpp