Add DownloadFileRequest
Downloads a file and optionally checks its checksum.
This commit is contained in:
parent
cca3f3b743
commit
69a53ac5b4
1
headers/build/os/package/DownloadFileRequest.h
Normal file
1
headers/build/os/package/DownloadFileRequest.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../os/package/DownloadFileRequest.h>
|
41
headers/os/package/DownloadFileRequest.h
Normal file
41
headers/os/package/DownloadFileRequest.h
Normal 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_
|
@ -73,6 +73,7 @@ BuildPlatformSharedLibrary libpackage_build.so
|
||||
BlockBufferCacheNoLock.cpp
|
||||
ChecksumAccessors.cpp
|
||||
Context.cpp
|
||||
DownloadFileRequest.cpp
|
||||
DropRepositoryRequest.cpp
|
||||
FetchFileJob.cpp
|
||||
InstallationLocationInfo.cpp
|
||||
|
83
src/kits/package/DownloadFileRequest.cpp
Normal file
83
src/kits/package/DownloadFileRequest.cpp
Normal 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
|
@ -53,6 +53,7 @@ SharedLibrary libpackage.so
|
||||
ChecksumAccessors.cpp
|
||||
Context.cpp
|
||||
DaemonClient.cpp
|
||||
DownloadFileRequest.cpp
|
||||
DropRepositoryRequest.cpp
|
||||
FetchFileJob.cpp
|
||||
InstallationLocationInfo.cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user