more work on package kit:
* rip BRepositoryHeader out of BRepositoryConfig and add support for it to BRepositoryCache * implement repository removal * some minor cleanups git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40290 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__DROP_REPOSITORY_REQUEST_H_
|
||||||
|
#define _PACKAGE__DROP_REPOSITORY_REQUEST_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <package/Context.h>
|
||||||
|
#include <package/Request.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
class DropRepositoryRequest : public BRequest {
|
||||||
|
typedef BRequest inherited;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DropRepositoryRequest(const BContext& context,
|
||||||
|
const BString& repositoryName);
|
||||||
|
virtual ~DropRepositoryRequest();
|
||||||
|
|
||||||
|
virtual status_t CreateInitialJobs();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BString fRepositoryName;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__ADD_REPOSITORY_REQUEST_H_
|
||||||
@@ -9,8 +9,7 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <package/RepositoryHeader.h>
|
||||||
class BEntry;
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
@@ -28,7 +27,7 @@ public:
|
|||||||
status_t SetTo(const BEntry& entry);
|
status_t SetTo(const BEntry& entry);
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
// const RepositoryHeader* Header() const;
|
const BRepositoryHeader& Header() const;
|
||||||
const BEntry& Entry() const;
|
const BEntry& Entry() const;
|
||||||
bool IsUserSpecific() const;
|
bool IsUserSpecific() const;
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ private:
|
|||||||
status_t fInitStatus;
|
status_t fInitStatus;
|
||||||
|
|
||||||
BEntry fEntry;
|
BEntry fEntry;
|
||||||
// RepositoryHeader* fHeader;
|
BRepositoryHeader fHeader;
|
||||||
bool fIsUserSpecific;
|
bool fIsUserSpecific;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,62 +6,46 @@
|
|||||||
#define _PACKAGE__REPOSITORY_CONFIG_H_
|
#define _PACKAGE__REPOSITORY_CONFIG_H_
|
||||||
|
|
||||||
|
|
||||||
#include <Archivable.h>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class BEntry;
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
class BRepositoryConfig : public BArchivable {
|
class BRepositoryConfig {
|
||||||
typedef BArchivable inherited;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BRepositoryConfig();
|
BRepositoryConfig();
|
||||||
BRepositoryConfig(const BString& name,
|
BRepositoryConfig(const BString& name,
|
||||||
const BString& url,
|
const BString& url, uint8 priority);
|
||||||
uint8 priority = kDefaultPriority);
|
|
||||||
BRepositoryConfig(const BEntry& entry);
|
BRepositoryConfig(const BEntry& entry);
|
||||||
BRepositoryConfig(BMessage* data);
|
|
||||||
virtual ~BRepositoryConfig();
|
virtual ~BRepositoryConfig();
|
||||||
|
|
||||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
status_t Store(const BEntry& entry) const;
|
||||||
|
|
||||||
status_t StoreAsConfigFile(const BEntry& entry) const;
|
|
||||||
|
|
||||||
status_t SetTo(const BEntry& entry);
|
status_t SetTo(const BEntry& entry);
|
||||||
status_t SetTo(const BMessage* data);
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
const BString& Name() const;
|
const BString& Name() const;
|
||||||
const BString& URL() const;
|
const BString& BaseURL() const;
|
||||||
uint8 Priority() const;
|
uint8 Priority() const;
|
||||||
bool IsUserSpecific() const;
|
bool IsUserSpecific() const;
|
||||||
|
|
||||||
const BEntry& Entry() const;
|
const BEntry& Entry() const;
|
||||||
|
|
||||||
void SetName(const BString& name);
|
void SetName(const BString& name);
|
||||||
void SetURL(const BString& url);
|
void SetBaseURL(const BString& url);
|
||||||
void SetPriority(uint8 priority);
|
void SetPriority(uint8 priority);
|
||||||
void SetIsUserSpecific(bool isUserSpecific);
|
void SetIsUserSpecific(bool isUserSpecific);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BRepositoryConfig* Instantiate(BMessage* data);
|
static const uint8 kUnsetPriority = 0;
|
||||||
|
|
||||||
static const uint8 kDefaultPriority;
|
|
||||||
static const char* kNameField;
|
|
||||||
static const char* kURLField;
|
|
||||||
static const char* kPriorityField;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t fInitStatus;
|
status_t fInitStatus;
|
||||||
|
|
||||||
BString fName;
|
BString fName;
|
||||||
BString fURL;
|
BString fBaseURL;
|
||||||
uint8 fPriority;
|
uint8 fPriority;
|
||||||
bool fIsUserSpecific;
|
bool fIsUserSpecific;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__REPOSITORY_HEADER_H_
|
||||||
|
#define _PACKAGE__REPOSITORY_HEADER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <Archivable.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
class BRepositoryHeader : public BArchivable {
|
||||||
|
typedef BArchivable inherited;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BRepositoryHeader();
|
||||||
|
BRepositoryHeader(BMessage* data);
|
||||||
|
virtual ~BRepositoryHeader();
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||||
|
|
||||||
|
status_t SetTo(const BMessage* data);
|
||||||
|
status_t InitCheck() const;
|
||||||
|
|
||||||
|
const BString& Name() const;
|
||||||
|
const BString& OriginalBaseURL() const;
|
||||||
|
const BString& Vendor() const;
|
||||||
|
const BString& ShortDescription() const;
|
||||||
|
const BString& LongDescription() const;
|
||||||
|
uint8 Priority() const;
|
||||||
|
|
||||||
|
void SetName(const BString& name);
|
||||||
|
void SetOriginalBaseURL(const BString& url);
|
||||||
|
void SetVendor(const BString& vendor);
|
||||||
|
void SetShortDescription(const BString& description);
|
||||||
|
void SetLongDescription(const BString& description);
|
||||||
|
void SetPriority(uint8 priority);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static BRepositoryHeader* Instantiate(BMessage* data);
|
||||||
|
|
||||||
|
static const uint8 kDefaultPriority;
|
||||||
|
|
||||||
|
static const char* kNameField;
|
||||||
|
static const char* kURLField;
|
||||||
|
static const char* kVendorField;
|
||||||
|
static const char* kShortDescriptionField;
|
||||||
|
static const char* kLongDescriptionField;
|
||||||
|
static const char* kPriorityField;
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t fInitStatus;
|
||||||
|
|
||||||
|
BString fName;
|
||||||
|
BString fOriginalBaseURL;
|
||||||
|
BString fVendor;
|
||||||
|
BString fShortDescription;
|
||||||
|
BString fLongDescription;
|
||||||
|
uint8 fPriority;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__REPOSITORY_HEADER_H_
|
||||||
@@ -19,7 +19,7 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
class ActivateRepositoryCacheJob : public BJob {
|
class ActivateRepositoryCacheJob : public BJob {
|
||||||
typedef BJob inherited;
|
typedef BJob inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ActivateRepositoryCacheJob(
|
ActivateRepositoryCacheJob(
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
class ActivateRepositoryConfigJob : public BJob {
|
class ActivateRepositoryConfigJob : public BJob {
|
||||||
typedef BJob inherited;
|
typedef BJob inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ActivateRepositoryConfigJob(
|
ActivateRepositoryConfigJob(
|
||||||
const BContext& context,
|
const BContext& context,
|
||||||
const BString& title,
|
const BString& title,
|
||||||
const BEntry& archivedRepoConfigEntry,
|
const BEntry& archivedRepoHeaderEntry,
|
||||||
const BString& repositoryBaseURL,
|
const BString& repositoryBaseURL,
|
||||||
const BDirectory& targetDirectory);
|
const BDirectory& targetDirectory);
|
||||||
virtual ~ActivateRepositoryConfigJob();
|
virtual ~ActivateRepositoryConfigJob();
|
||||||
@@ -37,7 +37,7 @@ protected:
|
|||||||
virtual void Cleanup(status_t jobResult);
|
virtual void Cleanup(status_t jobResult);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BEntry fArchivedRepoConfigEntry;
|
BEntry fArchivedRepoHeaderEntry;
|
||||||
BString fRepositoryBaseURL;
|
BString fRepositoryBaseURL;
|
||||||
BDirectory fTargetDirectory;
|
BDirectory fTargetDirectory;
|
||||||
BEntry fTargetEntry;
|
BEntry fTargetEntry;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
class FetchFileJob : public BJob {
|
class FetchFileJob : public BJob {
|
||||||
typedef BJob inherited;
|
typedef BJob inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FetchFileJob(const BContext& context,
|
FetchFileJob(const BContext& context,
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_
|
||||||
|
#define _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <package/Job.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveRepositoryJob : public BJob {
|
||||||
|
typedef BJob inherited;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RemoveRepositoryJob(
|
||||||
|
const BContext& context,
|
||||||
|
const BString& title,
|
||||||
|
const BString& repositoryName);
|
||||||
|
virtual ~RemoveRepositoryJob();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual status_t Execute();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BString fRepositoryName;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_
|
||||||
@@ -20,7 +20,7 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
class ValidateChecksumJob : public BJob {
|
class ValidateChecksumJob : public BJob {
|
||||||
typedef BJob inherited;
|
typedef BJob inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ValidateChecksumJob(
|
ValidateChecksumJob(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ UsePrivateHeaders support ;
|
|||||||
|
|
||||||
BinCommand pkgman :
|
BinCommand pkgman :
|
||||||
command_add_repo.cpp
|
command_add_repo.cpp
|
||||||
|
command_drop_repo.cpp
|
||||||
command_list_repos.cpp
|
command_list_repos.cpp
|
||||||
command_refresh.cpp
|
command_refresh.cpp
|
||||||
DecisionProvider.cpp
|
DecisionProvider.cpp
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <Errors.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include <package/DropRepositoryRequest.h>
|
||||||
|
#include <package/Context.h>
|
||||||
|
|
||||||
|
#include "DecisionProvider.h"
|
||||||
|
#include "JobStateListener.h"
|
||||||
|
#include "pkgman.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace BPackageKit;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: internationalization!
|
||||||
|
|
||||||
|
|
||||||
|
static const char* kCommandUsage =
|
||||||
|
"Usage: %s drop-repo <repo-name>\n"
|
||||||
|
"Drops (i.e. removes) the repository with the given name.\n"
|
||||||
|
"\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_command_usage_and_exit(bool error)
|
||||||
|
{
|
||||||
|
fprintf(error ? stderr : stdout, kCommandUsage, kProgramName);
|
||||||
|
exit(error ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
command_drop_repo(int argc, const char* const* argv)
|
||||||
|
{
|
||||||
|
bool yesMode = false;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
static struct option sLongOptions[] = {
|
||||||
|
{ "help", no_argument, 0, 'h' },
|
||||||
|
{ "yes", no_argument, 0, 'y' },
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
opterr = 0; // don't print errors
|
||||||
|
int c = getopt_long(argc, (char**)argv, "hu", sLongOptions, NULL);
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
print_command_usage_and_exit(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
yesMode = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
print_command_usage_and_exit(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The remaining argument is a repo name, i. e. one more argument.
|
||||||
|
if (argc != optind + 1)
|
||||||
|
print_command_usage_and_exit(true);
|
||||||
|
|
||||||
|
const char* repoName = argv[optind];
|
||||||
|
|
||||||
|
DecisionProvider decisionProvider;
|
||||||
|
// if (yesMode)
|
||||||
|
// decisionProvider.SetAcceptEverything(true);
|
||||||
|
JobStateListener listener;
|
||||||
|
BContext context(decisionProvider, listener);
|
||||||
|
|
||||||
|
status_t result;
|
||||||
|
DropRepositoryRequest dropRequest(context, repoName);
|
||||||
|
result = dropRequest.InitCheck();
|
||||||
|
if (result != B_OK)
|
||||||
|
DIE(result, "unable to create request for dropping repository");
|
||||||
|
result = dropRequest.CreateInitialJobs();
|
||||||
|
if (result != B_OK)
|
||||||
|
DIE(result, "unable to create necessary jobs");
|
||||||
|
|
||||||
|
while (BJob* job = dropRequest.PopRunnableJob()) {
|
||||||
|
result = job->Run();
|
||||||
|
delete job;
|
||||||
|
if (result == B_CANCELED)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -53,16 +53,16 @@ main(int argc, const char* const* argv)
|
|||||||
print_usage_and_exit(true);
|
print_usage_and_exit(true);
|
||||||
|
|
||||||
const char* command = argv[1];
|
const char* command = argv[1];
|
||||||
if (strcmp(command, "add-repo") == 0 || strcmp(command, "ar") == 0)
|
if (strncmp(command, "add-r", 5) == 0)
|
||||||
return command_add_repo(argc - 1, argv + 1);
|
return command_add_repo(argc - 1, argv + 1);
|
||||||
|
|
||||||
// if (strcmp(command, "drop-repo") == 0)
|
if (strncmp(command, "drop-r", 6) == 0)
|
||||||
// return command_drop_repo(argc - 1, argv + 1);
|
return command_drop_repo(argc - 1, argv + 1);
|
||||||
|
|
||||||
if (strcmp(command, "list-repos") == 0 || strcmp(command, "lr") == 0)
|
if (strncmp(command, "list-r", 6) == 0)
|
||||||
return command_list_repos(argc - 1, argv + 1);
|
return command_list_repos(argc - 1, argv + 1);
|
||||||
|
|
||||||
if (strcmp(command, "refresh") == 0)
|
if (strncmp(command, "refr", 4) == 0)
|
||||||
return command_refresh(argc - 1, argv + 1);
|
return command_refresh(argc - 1, argv + 1);
|
||||||
|
|
||||||
// if (strcmp(command, "search") == 0)
|
// if (strcmp(command, "search") == 0)
|
||||||
|
|||||||
@@ -10,9 +10,13 @@
|
|||||||
#include <package/ActivateRepositoryConfigJob.h>
|
#include <package/ActivateRepositoryConfigJob.h>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include <package/Context.h>
|
#include <package/Context.h>
|
||||||
#include <package/RepositoryConfig.h>
|
#include <package/RepositoryConfig.h>
|
||||||
|
#include <package/RepositoryHeader.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
@@ -22,11 +26,11 @@ namespace BPrivate {
|
|||||||
|
|
||||||
ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
|
ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
|
||||||
const BContext& context, const BString& title,
|
const BContext& context, const BString& title,
|
||||||
const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL,
|
const BEntry& archivedRepoHeaderEntry, const BString& repositoryBaseURL,
|
||||||
const BDirectory& targetDirectory)
|
const BDirectory& targetDirectory)
|
||||||
:
|
:
|
||||||
inherited(context, title),
|
inherited(context, title),
|
||||||
fArchivedRepoConfigEntry(archivedRepoConfigEntry),
|
fArchivedRepoHeaderEntry(archivedRepoHeaderEntry),
|
||||||
fRepositoryBaseURL(repositoryBaseURL),
|
fRepositoryBaseURL(repositoryBaseURL),
|
||||||
fTargetDirectory(targetDirectory)
|
fTargetDirectory(targetDirectory)
|
||||||
{
|
{
|
||||||
@@ -41,7 +45,7 @@ ActivateRepositoryConfigJob::~ActivateRepositoryConfigJob()
|
|||||||
status_t
|
status_t
|
||||||
ActivateRepositoryConfigJob::Execute()
|
ActivateRepositoryConfigJob::Execute()
|
||||||
{
|
{
|
||||||
BFile archiveFile(&fArchivedRepoConfigEntry, B_READ_ONLY);
|
BFile archiveFile(&fArchivedRepoHeaderEntry, B_READ_ONLY);
|
||||||
status_t result = archiveFile.InitCheck();
|
status_t result = archiveFile.InitCheck();
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
@@ -50,16 +54,17 @@ ActivateRepositoryConfigJob::Execute()
|
|||||||
if ((result = archive.Unflatten(&archiveFile)) != B_OK)
|
if ((result = archive.Unflatten(&archiveFile)) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
BRepositoryConfig* repoConfig = BRepositoryConfig::Instantiate(&archive);
|
BRepositoryHeader* repoHeader = BRepositoryHeader::Instantiate(&archive);
|
||||||
if (repoConfig == NULL)
|
if (repoHeader == NULL)
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
if ((result = repoConfig->InitCheck()) != B_OK)
|
ObjectDeleter<BRepositoryHeader> repoHeaderDeleter(repoHeader);
|
||||||
|
if ((result = repoHeader->InitCheck()) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
fTargetEntry.SetTo(&fTargetDirectory, repoConfig->Name().String());
|
fTargetEntry.SetTo(&fTargetDirectory, repoHeader->Name().String());
|
||||||
if (fTargetEntry.Exists()) {
|
if (fTargetEntry.Exists()) {
|
||||||
BString description = BString("A repository configuration for ")
|
BString description = BString("A repository configuration for ")
|
||||||
<< repoConfig->Name() << " already exists.";
|
<< repoHeader->Name() << " already exists.";
|
||||||
BString question("overwrite?");
|
BString question("overwrite?");
|
||||||
bool yes = fContext.DecisionProvider().YesNoDecisionNeeded(
|
bool yes = fContext.DecisionProvider().YesNoDecisionNeeded(
|
||||||
description, question, "yes", "no", "no");
|
description, question, "yes", "no", "no");
|
||||||
@@ -69,13 +74,17 @@ ActivateRepositoryConfigJob::Execute()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// inject the URL that was actually used and write the config file
|
// create and store the configuration (injecting the BaseURL that was
|
||||||
repoConfig->SetURL(fRepositoryBaseURL);
|
// actually used)
|
||||||
if ((result = repoConfig->StoreAsConfigFile(fTargetEntry)) != B_OK)
|
BRepositoryConfig repoConfig;
|
||||||
|
repoConfig.SetName(repoHeader->Name());
|
||||||
|
repoConfig.SetBaseURL(fRepositoryBaseURL);
|
||||||
|
repoConfig.SetPriority(repoHeader->Priority());
|
||||||
|
if ((result = repoConfig.Store(fTargetEntry)) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// store name of activated repository as result
|
// store name of activated repository as result
|
||||||
fRepositoryName = repoConfig->Name();
|
fRepositoryName = repoConfig.Name();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Oliver Tappe <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <package/DropRepositoryRequest.h>
|
||||||
|
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
#include <package/RemoveRepositoryJob.h>
|
||||||
|
#include <package/JobQueue.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
using namespace BPrivate;
|
||||||
|
|
||||||
|
|
||||||
|
DropRepositoryRequest::DropRepositoryRequest(const BContext& context,
|
||||||
|
const BString& repositoryName)
|
||||||
|
:
|
||||||
|
inherited(context),
|
||||||
|
fRepositoryName(repositoryName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DropRepositoryRequest::~DropRepositoryRequest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
DropRepositoryRequest::CreateInitialJobs()
|
||||||
|
{
|
||||||
|
status_t result = InitCheck();
|
||||||
|
if (result != B_OK)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
RemoveRepositoryJob* removeRepoJob
|
||||||
|
= new (std::nothrow) RemoveRepositoryJob(fContext,
|
||||||
|
BString("Removing repository ") << fRepositoryName,
|
||||||
|
fRepositoryName);
|
||||||
|
if (removeRepoJob == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
if ((result = QueueJob(removeRepoJob)) != B_OK) {
|
||||||
|
delete removeRepoJob;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
@@ -10,14 +10,16 @@ SharedLibrary libpackage.so
|
|||||||
Attributes.cpp
|
Attributes.cpp
|
||||||
ChecksumAccessors.cpp
|
ChecksumAccessors.cpp
|
||||||
Context.cpp
|
Context.cpp
|
||||||
|
DropRepositoryRequest.cpp
|
||||||
FetchFileJob.cpp
|
FetchFileJob.cpp
|
||||||
Job.cpp
|
Job.cpp
|
||||||
JobQueue.cpp
|
JobQueue.cpp
|
||||||
PackageRoster.cpp
|
PackageRoster.cpp
|
||||||
RefreshRepositoryRequest.cpp
|
RefreshRepositoryRequest.cpp
|
||||||
|
RemoveRepositoryJob.cpp
|
||||||
RepositoryCache.cpp
|
RepositoryCache.cpp
|
||||||
RepositoryConfig.cpp
|
RepositoryConfig.cpp
|
||||||
# RepositoryHeader.cpp
|
RepositoryHeader.cpp
|
||||||
Request.cpp
|
Request.cpp
|
||||||
TempfileManager.cpp
|
TempfileManager.cpp
|
||||||
ValidateChecksumJob.cpp
|
ValidateChecksumJob.cpp
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ BRefreshRepositoryRequest::CreateInitialJobs()
|
|||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
BString repoChecksumURL
|
BString repoChecksumURL
|
||||||
= BString(fRepoConfig.URL()) << "/" << "repo.sha256";
|
= BString(fRepoConfig.BaseURL()) << "/" << "repo.sha256";
|
||||||
FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob(
|
FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob(
|
||||||
fContext,
|
fContext,
|
||||||
BString("Fetching repository checksum from ") << fRepoConfig.URL(),
|
BString("Fetching repository checksum from ") << fRepoConfig.BaseURL(),
|
||||||
repoChecksumURL, fFetchedChecksumFile);
|
repoChecksumURL, fFetchedChecksumFile);
|
||||||
if (fetchChecksumJob == NULL)
|
if (fetchChecksumJob == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -119,9 +119,9 @@ BRefreshRepositoryRequest::_FetchRepositoryCache()
|
|||||||
status_t result = fContext.GetNewTempfile("repocache-", &tempRepoCache);
|
status_t result = fContext.GetNewTempfile("repocache-", &tempRepoCache);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
BString repoCacheURL = BString(fRepoConfig.URL()) << "/" << "repo";
|
BString repoCacheURL = BString(fRepoConfig.BaseURL()) << "/" << "repo";
|
||||||
FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext,
|
FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext,
|
||||||
BString("Fetching repository-cache from ") << fRepoConfig.URL(),
|
BString("Fetching repository-cache from ") << fRepoConfig.BaseURL(),
|
||||||
repoCacheURL, tempRepoCache);
|
repoCacheURL, tempRepoCache);
|
||||||
if (fetchCacheJob == NULL)
|
if (fetchCacheJob == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Oliver Tappe <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <package/RemoveRepositoryJob.h>
|
||||||
|
|
||||||
|
#include <Entry.h>
|
||||||
|
|
||||||
|
#include <package/Context.h>
|
||||||
|
#include <package/PackageRoster.h>
|
||||||
|
#include <package/RepositoryCache.h>
|
||||||
|
#include <package/RepositoryConfig.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
RemoveRepositoryJob::RemoveRepositoryJob(const BContext& context,
|
||||||
|
const BString& title, const BString& repositoryName)
|
||||||
|
:
|
||||||
|
inherited(context, title),
|
||||||
|
fRepositoryName(repositoryName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RemoveRepositoryJob::~RemoveRepositoryJob()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
RemoveRepositoryJob::Execute()
|
||||||
|
{
|
||||||
|
BPackageRoster roster;
|
||||||
|
BRepositoryConfig repoConfig;
|
||||||
|
status_t result = roster.GetRepositoryConfig(fRepositoryName, &repoConfig);
|
||||||
|
if (result != B_OK) {
|
||||||
|
if (result == B_ENTRY_NOT_FOUND) {
|
||||||
|
BString error = BString("repository '") << fRepositoryName
|
||||||
|
<< "' not found!";
|
||||||
|
SetErrorString(error);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
BString question = BString("Really remove the repository '")
|
||||||
|
<< fRepositoryName << "'?";
|
||||||
|
bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question,
|
||||||
|
"yes", "no", "no");
|
||||||
|
if (!yes)
|
||||||
|
return B_CANCELED;
|
||||||
|
|
||||||
|
BEntry repoConfigEntry = repoConfig.Entry();
|
||||||
|
if ((result = repoConfigEntry.Remove()) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
BRepositoryCache repoCache;
|
||||||
|
if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) {
|
||||||
|
BEntry repoCacheEntry = repoCache.Entry();
|
||||||
|
if ((result = repoCacheEntry.Remove()) != B_OK)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
@@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
#include <package/RepositoryCache.h>
|
#include <package/RepositoryCache.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -31,8 +29,10 @@ BRepositoryCache::BRepositoryCache()
|
|||||||
|
|
||||||
|
|
||||||
BRepositoryCache::BRepositoryCache(const BEntry& entry)
|
BRepositoryCache::BRepositoryCache(const BEntry& entry)
|
||||||
|
:
|
||||||
|
fIsUserSpecific(false)
|
||||||
{
|
{
|
||||||
SetTo(entry);
|
fInitStatus = SetTo(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,6 +55,13 @@ BRepositoryCache::Entry() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BRepositoryHeader&
|
||||||
|
BRepositoryCache::Header() const
|
||||||
|
{
|
||||||
|
return fHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BRepositoryCache::IsUserSpecific() const
|
BRepositoryCache::IsUserSpecific() const
|
||||||
{
|
{
|
||||||
@@ -73,7 +80,6 @@ status_t
|
|||||||
BRepositoryCache::SetTo(const BEntry& entry)
|
BRepositoryCache::SetTo(const BEntry& entry)
|
||||||
{
|
{
|
||||||
fEntry = entry;
|
fEntry = entry;
|
||||||
fInitStatus = B_NO_INIT;
|
|
||||||
|
|
||||||
BFile file(&entry, B_READ_ONLY);
|
BFile file(&entry, B_READ_ONLY);
|
||||||
status_t result = file.InitCheck();
|
status_t result = file.InitCheck();
|
||||||
@@ -84,7 +90,8 @@ BRepositoryCache::SetTo(const BEntry& entry)
|
|||||||
if ((result = headerMsg.Unflatten(&file)) != B_OK)
|
if ((result = headerMsg.Unflatten(&file)) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// TODO: unarchive header and read packages
|
if ((result = fHeader.SetTo(&headerMsg)) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
BPath userSettingsPath;
|
BPath userSettingsPath;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
|
||||||
@@ -93,10 +100,30 @@ BRepositoryCache::SetTo(const BEntry& entry)
|
|||||||
} else
|
} else
|
||||||
fIsUserSpecific = false;
|
fIsUserSpecific = false;
|
||||||
|
|
||||||
fInitStatus = B_OK;
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//status_t
|
||||||
|
//BRepositoryCache::_ReadPackageHeaders()
|
||||||
|
//{
|
||||||
|
//// if (fPackageHeaders != NULL)
|
||||||
|
//// return B_OK;
|
||||||
|
//
|
||||||
|
// BFile file(&fEntry, B_READ_ONLY);
|
||||||
|
// status_t result = file.InitCheck();
|
||||||
|
// if (result != B_OK)
|
||||||
|
// return result;
|
||||||
|
//
|
||||||
|
// BMessage headerMsg;
|
||||||
|
// if ((result = headerMsg.Unflatten(&file)) != B_OK)
|
||||||
|
// return result;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // TODO: read packages!
|
||||||
|
//
|
||||||
|
// return B_OK;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPackageKit
|
} // namespace BPackageKit
|
||||||
|
|||||||
@@ -23,16 +23,10 @@
|
|||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
const uint8 BRepositoryConfig::kDefaultPriority = 50;
|
|
||||||
const char* BRepositoryConfig::kNameField = "name";
|
|
||||||
const char* BRepositoryConfig::kURLField = "url";
|
|
||||||
const char* BRepositoryConfig::kPriorityField = "priority";
|
|
||||||
|
|
||||||
|
|
||||||
BRepositoryConfig::BRepositoryConfig()
|
BRepositoryConfig::BRepositoryConfig()
|
||||||
:
|
:
|
||||||
fInitStatus(B_NO_INIT),
|
fInitStatus(B_NO_INIT),
|
||||||
fPriority(kDefaultPriority),
|
fPriority(kUnsetPriority),
|
||||||
fIsUserSpecific(false)
|
fIsUserSpecific(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -44,20 +38,12 @@ BRepositoryConfig::BRepositoryConfig(const BEntry& entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BRepositoryConfig::BRepositoryConfig(BMessage* data)
|
BRepositoryConfig::BRepositoryConfig(const BString& name,
|
||||||
:
|
const BString& baseURL, uint8 priority)
|
||||||
inherited(data)
|
|
||||||
{
|
|
||||||
SetTo(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BRepositoryConfig::BRepositoryConfig(const BString& name, const BString& url,
|
|
||||||
uint8 priority)
|
|
||||||
:
|
:
|
||||||
fInitStatus(B_OK),
|
fInitStatus(B_OK),
|
||||||
fName(name),
|
fName(name),
|
||||||
fURL(url),
|
fBaseURL(baseURL),
|
||||||
fPriority(priority),
|
fPriority(priority),
|
||||||
fIsUserSpecific(false)
|
fIsUserSpecific(false)
|
||||||
{
|
{
|
||||||
@@ -69,36 +55,8 @@ BRepositoryConfig::~BRepositoryConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ BRepositoryConfig*
|
|
||||||
BRepositoryConfig::Instantiate(BMessage* data)
|
|
||||||
{
|
|
||||||
if (validate_instantiation(data, "BPackageKit::BRepositoryConfig"))
|
|
||||||
return new (std::nothrow) BRepositoryConfig(data);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BRepositoryConfig::Archive(BMessage* data, bool deep) const
|
BRepositoryConfig::Store(const BEntry& entry) const
|
||||||
{
|
|
||||||
status_t result = inherited::Archive(data, deep);
|
|
||||||
if (result != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
if ((result = data->AddString(kNameField, fName)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->AddString(kURLField, fURL)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->AddUInt8(kPriorityField, fPriority)) != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BRepositoryConfig::StoreAsConfigFile(const BEntry& entry) const
|
|
||||||
{
|
{
|
||||||
BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
status_t result = file.InitCheck();
|
status_t result = file.InitCheck();
|
||||||
@@ -107,7 +65,7 @@ BRepositoryConfig::StoreAsConfigFile(const BEntry& entry) const
|
|||||||
|
|
||||||
BString configString;
|
BString configString;
|
||||||
configString
|
configString
|
||||||
<< "url=" << fURL << "\n"
|
<< "url=" << fBaseURL << "\n"
|
||||||
<< "priority=" << fPriority << "\n";
|
<< "priority=" << fPriority << "\n";
|
||||||
|
|
||||||
int32 size = configString.Length();
|
int32 size = configString.Length();
|
||||||
@@ -169,9 +127,9 @@ BRepositoryConfig::SetTo(const BEntry& entry)
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
fName = name;
|
fName = name;
|
||||||
fURL = url;
|
fBaseURL = url;
|
||||||
fPriority = priorityString == NULL
|
fPriority = priorityString == NULL
|
||||||
? kDefaultPriority : atoi(priorityString);
|
? kUnsetPriority : atoi(priorityString);
|
||||||
|
|
||||||
BPath userSettingsPath;
|
BPath userSettingsPath;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
|
||||||
@@ -186,30 +144,6 @@ BRepositoryConfig::SetTo(const BEntry& entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BRepositoryConfig::SetTo(const BMessage* data)
|
|
||||||
{
|
|
||||||
fInitStatus = B_NO_INIT;
|
|
||||||
|
|
||||||
if (data == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
status_t result;
|
|
||||||
if ((result = data->FindString(kNameField, &fName)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->FindString(kURLField, &fURL)) != B_OK)
|
|
||||||
return result;
|
|
||||||
if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
fIsUserSpecific = false;
|
|
||||||
|
|
||||||
fInitStatus = B_OK;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const BString&
|
const BString&
|
||||||
BRepositoryConfig::Name() const
|
BRepositoryConfig::Name() const
|
||||||
{
|
{
|
||||||
@@ -218,9 +152,9 @@ BRepositoryConfig::Name() const
|
|||||||
|
|
||||||
|
|
||||||
const BString&
|
const BString&
|
||||||
BRepositoryConfig::URL() const
|
BRepositoryConfig::BaseURL() const
|
||||||
{
|
{
|
||||||
return fURL;
|
return fBaseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -253,9 +187,9 @@ BRepositoryConfig::SetName(const BString& name)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BRepositoryConfig::SetURL(const BString& url)
|
BRepositoryConfig::SetBaseURL(const BString& baseURL)
|
||||||
{
|
{
|
||||||
fURL = url;
|
fBaseURL = baseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Oliver Tappe <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <package/RepositoryHeader.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
const uint8 BRepositoryHeader::kDefaultPriority = 50;
|
||||||
|
|
||||||
|
const char* BRepositoryHeader::kNameField = "name";
|
||||||
|
const char* BRepositoryHeader::kURLField = "url";
|
||||||
|
const char* BRepositoryHeader::kVendorField = "vendor";
|
||||||
|
const char* BRepositoryHeader::kShortDescriptionField = "shortDescr";
|
||||||
|
const char* BRepositoryHeader::kLongDescriptionField = "longDescr";
|
||||||
|
const char* BRepositoryHeader::kPriorityField = "priority";
|
||||||
|
|
||||||
|
|
||||||
|
BRepositoryHeader::BRepositoryHeader()
|
||||||
|
:
|
||||||
|
fInitStatus(B_NO_INIT),
|
||||||
|
fPriority(kDefaultPriority)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRepositoryHeader::BRepositoryHeader(BMessage* data)
|
||||||
|
:
|
||||||
|
inherited(data)
|
||||||
|
{
|
||||||
|
fInitStatus = SetTo(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRepositoryHeader::~BRepositoryHeader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ BRepositoryHeader*
|
||||||
|
BRepositoryHeader::Instantiate(BMessage* data)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(data, "BPackageKit::BRepositoryHeader"))
|
||||||
|
return new (std::nothrow) BRepositoryHeader(data);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryHeader::Archive(BMessage* data, bool deep) const
|
||||||
|
{
|
||||||
|
status_t result = inherited::Archive(data, deep);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if ((result = data->AddString(kNameField, fName)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->AddString(kURLField, fOriginalBaseURL)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->AddString(kVendorField, fVendor)) != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->AddString(kShortDescriptionField, fShortDescription);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->AddString(kLongDescriptionField, fLongDescription);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->AddUInt8(kPriorityField, fPriority)) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryHeader::InitCheck() const
|
||||||
|
{
|
||||||
|
return fInitStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryHeader::SetTo(const BMessage* data)
|
||||||
|
{
|
||||||
|
if (data == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
status_t result;
|
||||||
|
if ((result = data->FindString(kNameField, &fName)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindString(kURLField, &fOriginalBaseURL)) != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindString(kVendorField, &fVendor)) != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->FindString(kShortDescriptionField, &fShortDescription);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
result = data->FindString(kLongDescriptionField, &fLongDescription);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BString&
|
||||||
|
BRepositoryHeader::Name() const
|
||||||
|
{
|
||||||
|
return fName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BString&
|
||||||
|
BRepositoryHeader::OriginalBaseURL() const
|
||||||
|
{
|
||||||
|
return fOriginalBaseURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BString&
|
||||||
|
BRepositoryHeader::Vendor() const
|
||||||
|
{
|
||||||
|
return fVendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BString&
|
||||||
|
BRepositoryHeader::ShortDescription() const
|
||||||
|
{
|
||||||
|
return fShortDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BString&
|
||||||
|
BRepositoryHeader::LongDescription() const
|
||||||
|
{
|
||||||
|
return fLongDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8
|
||||||
|
BRepositoryHeader::Priority() const
|
||||||
|
{
|
||||||
|
return fPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetName(const BString& name)
|
||||||
|
{
|
||||||
|
fName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetOriginalBaseURL(const BString& url)
|
||||||
|
{
|
||||||
|
fOriginalBaseURL = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetVendor(const BString& vendor)
|
||||||
|
{
|
||||||
|
fVendor = vendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetShortDescription(const BString& description)
|
||||||
|
{
|
||||||
|
fShortDescription = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetLongDescription(const BString& description)
|
||||||
|
{
|
||||||
|
fLongDescription = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BRepositoryHeader::SetPriority(uint8 priority)
|
||||||
|
{
|
||||||
|
fPriority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include <package/RepositoryConfig.h>
|
#include <package/RepositoryHeader.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace BPackageKit;
|
using namespace BPackageKit;
|
||||||
@@ -20,22 +20,21 @@ main(int argc, const char** argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BRepositoryConfig repoConfig(argv[1], argv[2], atoi(argv[3]));
|
BRepositoryHeader repoHeader;
|
||||||
status_t status = repoConfig.InitCheck();
|
repoHeader.SetName(argv[1]);
|
||||||
if (status != B_OK) {
|
repoHeader.SetOriginalBaseURL(argv[2]);
|
||||||
fprintf(stderr, "couldn't initialize repository-config\n");
|
repoHeader.SetPriority(atoi(argv[3]));
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
BMessage repoConfigArchive;
|
BMessage repoHeaderArchive;
|
||||||
if ((status = repoConfig.Archive(&repoConfigArchive)) != B_OK) {
|
status_t result = repoHeader.Archive(&repoHeaderArchive);
|
||||||
fprintf(stderr, "couldn't archive repository-config\n");
|
if (result != B_OK) {
|
||||||
|
fprintf(stderr, "couldn't archive repository-header\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BFile output(argv[1], B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
BFile output(argv[1], B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
if ((status = repoConfigArchive.Flatten(&output)) != B_OK) {
|
if ((result = repoHeaderArchive.Flatten(&output)) != B_OK) {
|
||||||
fprintf(stderr, "couldn't flatten repository-config archive\n");
|
fprintf(stderr, "couldn't flatten repository-header archive\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +68,8 @@ main(int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pkg.Flatten(&output);
|
result = pkg.Flatten(&output);
|
||||||
if (status != B_OK) {
|
if (result != B_OK) {
|
||||||
fprintf(stderr, "couldn't flatten pkg message #%d\n", i + 1);
|
fprintf(stderr, "couldn't flatten pkg message #%d\n", i + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user