Add DownloadFileRequest
Downloads a file and optionally checks its checksum.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
#include <../os/package/DownloadFileRequest.h>
|
||||||
@@ -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_
|
||||||
@@ -73,6 +73,7 @@ BuildPlatformSharedLibrary libpackage_build.so
|
|||||||
BlockBufferCacheNoLock.cpp
|
BlockBufferCacheNoLock.cpp
|
||||||
ChecksumAccessors.cpp
|
ChecksumAccessors.cpp
|
||||||
Context.cpp
|
Context.cpp
|
||||||
|
DownloadFileRequest.cpp
|
||||||
DropRepositoryRequest.cpp
|
DropRepositoryRequest.cpp
|
||||||
FetchFileJob.cpp
|
FetchFileJob.cpp
|
||||||
InstallationLocationInfo.cpp
|
InstallationLocationInfo.cpp
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ingo Weinhold <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -53,6 +53,7 @@ SharedLibrary libpackage.so
|
|||||||
ChecksumAccessors.cpp
|
ChecksumAccessors.cpp
|
||||||
Context.cpp
|
Context.cpp
|
||||||
DaemonClient.cpp
|
DaemonClient.cpp
|
||||||
|
DownloadFileRequest.cpp
|
||||||
DropRepositoryRequest.cpp
|
DropRepositoryRequest.cpp
|
||||||
FetchFileJob.cpp
|
FetchFileJob.cpp
|
||||||
InstallationLocationInfo.cpp
|
InstallationLocationInfo.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user