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 <String.h>
|
||||
|
||||
|
||||
class BEntry;
|
||||
#include <package/RepositoryHeader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@@ -28,7 +27,7 @@ public:
|
||||
status_t SetTo(const BEntry& entry);
|
||||
status_t InitCheck() const;
|
||||
|
||||
// const RepositoryHeader* Header() const;
|
||||
const BRepositoryHeader& Header() const;
|
||||
const BEntry& Entry() const;
|
||||
bool IsUserSpecific() const;
|
||||
|
||||
@@ -38,7 +37,7 @@ private:
|
||||
status_t fInitStatus;
|
||||
|
||||
BEntry fEntry;
|
||||
// RepositoryHeader* fHeader;
|
||||
BRepositoryHeader fHeader;
|
||||
bool fIsUserSpecific;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,62 +6,46 @@
|
||||
#define _PACKAGE__REPOSITORY_CONFIG_H_
|
||||
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BEntry;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
class BRepositoryConfig : public BArchivable {
|
||||
typedef BArchivable inherited;
|
||||
|
||||
class BRepositoryConfig {
|
||||
public:
|
||||
BRepositoryConfig();
|
||||
BRepositoryConfig(const BString& name,
|
||||
const BString& url,
|
||||
uint8 priority = kDefaultPriority);
|
||||
const BString& url, uint8 priority);
|
||||
BRepositoryConfig(const BEntry& entry);
|
||||
BRepositoryConfig(BMessage* data);
|
||||
virtual ~BRepositoryConfig();
|
||||
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
status_t StoreAsConfigFile(const BEntry& entry) const;
|
||||
status_t Store(const BEntry& entry) const;
|
||||
|
||||
status_t SetTo(const BEntry& entry);
|
||||
status_t SetTo(const BMessage* data);
|
||||
status_t InitCheck() const;
|
||||
|
||||
const BString& Name() const;
|
||||
const BString& URL() const;
|
||||
const BString& BaseURL() const;
|
||||
uint8 Priority() const;
|
||||
bool IsUserSpecific() const;
|
||||
|
||||
const BEntry& Entry() const;
|
||||
|
||||
void SetName(const BString& name);
|
||||
void SetURL(const BString& url);
|
||||
void SetBaseURL(const BString& url);
|
||||
void SetPriority(uint8 priority);
|
||||
void SetIsUserSpecific(bool isUserSpecific);
|
||||
|
||||
public:
|
||||
static BRepositoryConfig* Instantiate(BMessage* data);
|
||||
|
||||
static const uint8 kDefaultPriority;
|
||||
static const char* kNameField;
|
||||
static const char* kURLField;
|
||||
static const char* kPriorityField;
|
||||
static const uint8 kUnsetPriority = 0;
|
||||
|
||||
private:
|
||||
status_t fInitStatus;
|
||||
|
||||
BString fName;
|
||||
BString fURL;
|
||||
BString fBaseURL;
|
||||
uint8 fPriority;
|
||||
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 {
|
||||
typedef BJob inherited;
|
||||
typedef BJob inherited;
|
||||
|
||||
public:
|
||||
ActivateRepositoryCacheJob(
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace BPrivate {
|
||||
|
||||
|
||||
class ActivateRepositoryConfigJob : public BJob {
|
||||
typedef BJob inherited;
|
||||
typedef BJob inherited;
|
||||
|
||||
public:
|
||||
ActivateRepositoryConfigJob(
|
||||
const BContext& context,
|
||||
const BString& title,
|
||||
const BEntry& archivedRepoConfigEntry,
|
||||
const BEntry& archivedRepoHeaderEntry,
|
||||
const BString& repositoryBaseURL,
|
||||
const BDirectory& targetDirectory);
|
||||
virtual ~ActivateRepositoryConfigJob();
|
||||
@@ -37,7 +37,7 @@ protected:
|
||||
virtual void Cleanup(status_t jobResult);
|
||||
|
||||
private:
|
||||
BEntry fArchivedRepoConfigEntry;
|
||||
BEntry fArchivedRepoHeaderEntry;
|
||||
BString fRepositoryBaseURL;
|
||||
BDirectory fTargetDirectory;
|
||||
BEntry fTargetEntry;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace BPrivate {
|
||||
|
||||
|
||||
class FetchFileJob : public BJob {
|
||||
typedef BJob inherited;
|
||||
typedef BJob inherited;
|
||||
|
||||
public:
|
||||
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 {
|
||||
typedef BJob inherited;
|
||||
typedef BJob inherited;
|
||||
|
||||
public:
|
||||
ValidateChecksumJob(
|
||||
|
||||
@@ -4,6 +4,7 @@ UsePrivateHeaders support ;
|
||||
|
||||
BinCommand pkgman :
|
||||
command_add_repo.cpp
|
||||
command_drop_repo.cpp
|
||||
command_list_repos.cpp
|
||||
command_refresh.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);
|
||||
|
||||
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);
|
||||
|
||||
// if (strcmp(command, "drop-repo") == 0)
|
||||
// return command_drop_repo(argc - 1, argv + 1);
|
||||
if (strncmp(command, "drop-r", 6) == 0)
|
||||
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);
|
||||
|
||||
if (strcmp(command, "refresh") == 0)
|
||||
if (strncmp(command, "refr", 4) == 0)
|
||||
return command_refresh(argc - 1, argv + 1);
|
||||
|
||||
// if (strcmp(command, "search") == 0)
|
||||
|
||||
@@ -10,9 +10,13 @@
|
||||
#include <package/ActivateRepositoryConfigJob.h>
|
||||
|
||||
#include <File.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/RepositoryHeader.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@@ -22,11 +26,11 @@ namespace BPrivate {
|
||||
|
||||
ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
|
||||
const BContext& context, const BString& title,
|
||||
const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL,
|
||||
const BEntry& archivedRepoHeaderEntry, const BString& repositoryBaseURL,
|
||||
const BDirectory& targetDirectory)
|
||||
:
|
||||
inherited(context, title),
|
||||
fArchivedRepoConfigEntry(archivedRepoConfigEntry),
|
||||
fArchivedRepoHeaderEntry(archivedRepoHeaderEntry),
|
||||
fRepositoryBaseURL(repositoryBaseURL),
|
||||
fTargetDirectory(targetDirectory)
|
||||
{
|
||||
@@ -41,7 +45,7 @@ ActivateRepositoryConfigJob::~ActivateRepositoryConfigJob()
|
||||
status_t
|
||||
ActivateRepositoryConfigJob::Execute()
|
||||
{
|
||||
BFile archiveFile(&fArchivedRepoConfigEntry, B_READ_ONLY);
|
||||
BFile archiveFile(&fArchivedRepoHeaderEntry, B_READ_ONLY);
|
||||
status_t result = archiveFile.InitCheck();
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
@@ -50,16 +54,17 @@ ActivateRepositoryConfigJob::Execute()
|
||||
if ((result = archive.Unflatten(&archiveFile)) != B_OK)
|
||||
return result;
|
||||
|
||||
BRepositoryConfig* repoConfig = BRepositoryConfig::Instantiate(&archive);
|
||||
if (repoConfig == NULL)
|
||||
BRepositoryHeader* repoHeader = BRepositoryHeader::Instantiate(&archive);
|
||||
if (repoHeader == NULL)
|
||||
return B_BAD_DATA;
|
||||
if ((result = repoConfig->InitCheck()) != B_OK)
|
||||
ObjectDeleter<BRepositoryHeader> repoHeaderDeleter(repoHeader);
|
||||
if ((result = repoHeader->InitCheck()) != B_OK)
|
||||
return result;
|
||||
|
||||
fTargetEntry.SetTo(&fTargetDirectory, repoConfig->Name().String());
|
||||
fTargetEntry.SetTo(&fTargetDirectory, repoHeader->Name().String());
|
||||
if (fTargetEntry.Exists()) {
|
||||
BString description = BString("A repository configuration for ")
|
||||
<< repoConfig->Name() << " already exists.";
|
||||
<< repoHeader->Name() << " already exists.";
|
||||
BString question("overwrite?");
|
||||
bool yes = fContext.DecisionProvider().YesNoDecisionNeeded(
|
||||
description, question, "yes", "no", "no");
|
||||
@@ -69,13 +74,17 @@ ActivateRepositoryConfigJob::Execute()
|
||||
}
|
||||
}
|
||||
|
||||
// inject the URL that was actually used and write the config file
|
||||
repoConfig->SetURL(fRepositoryBaseURL);
|
||||
if ((result = repoConfig->StoreAsConfigFile(fTargetEntry)) != B_OK)
|
||||
// create and store the configuration (injecting the BaseURL that was
|
||||
// actually used)
|
||||
BRepositoryConfig repoConfig;
|
||||
repoConfig.SetName(repoHeader->Name());
|
||||
repoConfig.SetBaseURL(fRepositoryBaseURL);
|
||||
repoConfig.SetPriority(repoHeader->Priority());
|
||||
if ((result = repoConfig.Store(fTargetEntry)) != B_OK)
|
||||
return result;
|
||||
|
||||
// store name of activated repository as result
|
||||
fRepositoryName = repoConfig->Name();
|
||||
fRepositoryName = repoConfig.Name();
|
||||
|
||||
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
|
||||
ChecksumAccessors.cpp
|
||||
Context.cpp
|
||||
DropRepositoryRequest.cpp
|
||||
FetchFileJob.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
PackageRoster.cpp
|
||||
RefreshRepositoryRequest.cpp
|
||||
RemoveRepositoryJob.cpp
|
||||
RepositoryCache.cpp
|
||||
RepositoryConfig.cpp
|
||||
# RepositoryHeader.cpp
|
||||
RepositoryHeader.cpp
|
||||
Request.cpp
|
||||
TempfileManager.cpp
|
||||
ValidateChecksumJob.cpp
|
||||
|
||||
@@ -58,10 +58,10 @@ BRefreshRepositoryRequest::CreateInitialJobs()
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
BString repoChecksumURL
|
||||
= BString(fRepoConfig.URL()) << "/" << "repo.sha256";
|
||||
= BString(fRepoConfig.BaseURL()) << "/" << "repo.sha256";
|
||||
FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob(
|
||||
fContext,
|
||||
BString("Fetching repository checksum from ") << fRepoConfig.URL(),
|
||||
BString("Fetching repository checksum from ") << fRepoConfig.BaseURL(),
|
||||
repoChecksumURL, fFetchedChecksumFile);
|
||||
if (fetchChecksumJob == NULL)
|
||||
return B_NO_MEMORY;
|
||||
@@ -119,9 +119,9 @@ BRefreshRepositoryRequest::_FetchRepositoryCache()
|
||||
status_t result = fContext.GetNewTempfile("repocache-", &tempRepoCache);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
BString repoCacheURL = BString(fRepoConfig.URL()) << "/" << "repo";
|
||||
BString repoCacheURL = BString(fRepoConfig.BaseURL()) << "/" << "repo";
|
||||
FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext,
|
||||
BString("Fetching repository-cache from ") << fRepoConfig.URL(),
|
||||
BString("Fetching repository-cache from ") << fRepoConfig.BaseURL(),
|
||||
repoCacheURL, tempRepoCache);
|
||||
if (fetchCacheJob == NULL)
|
||||
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 <stdlib.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Directory.h>
|
||||
@@ -31,8 +29,10 @@ BRepositoryCache::BRepositoryCache()
|
||||
|
||||
|
||||
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
|
||||
BRepositoryCache::IsUserSpecific() const
|
||||
{
|
||||
@@ -73,7 +80,6 @@ status_t
|
||||
BRepositoryCache::SetTo(const BEntry& entry)
|
||||
{
|
||||
fEntry = entry;
|
||||
fInitStatus = B_NO_INIT;
|
||||
|
||||
BFile file(&entry, B_READ_ONLY);
|
||||
status_t result = file.InitCheck();
|
||||
@@ -84,7 +90,8 @@ BRepositoryCache::SetTo(const BEntry& entry)
|
||||
if ((result = headerMsg.Unflatten(&file)) != B_OK)
|
||||
return result;
|
||||
|
||||
// TODO: unarchive header and read packages
|
||||
if ((result = fHeader.SetTo(&headerMsg)) != B_OK)
|
||||
return result;
|
||||
|
||||
BPath userSettingsPath;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
|
||||
@@ -93,10 +100,30 @@ BRepositoryCache::SetTo(const BEntry& entry)
|
||||
} else
|
||||
fIsUserSpecific = false;
|
||||
|
||||
fInitStatus = 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
|
||||
|
||||
@@ -23,16 +23,10 @@
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
const uint8 BRepositoryConfig::kDefaultPriority = 50;
|
||||
const char* BRepositoryConfig::kNameField = "name";
|
||||
const char* BRepositoryConfig::kURLField = "url";
|
||||
const char* BRepositoryConfig::kPriorityField = "priority";
|
||||
|
||||
|
||||
BRepositoryConfig::BRepositoryConfig()
|
||||
:
|
||||
fInitStatus(B_NO_INIT),
|
||||
fPriority(kDefaultPriority),
|
||||
fPriority(kUnsetPriority),
|
||||
fIsUserSpecific(false)
|
||||
{
|
||||
}
|
||||
@@ -44,20 +38,12 @@ BRepositoryConfig::BRepositoryConfig(const BEntry& entry)
|
||||
}
|
||||
|
||||
|
||||
BRepositoryConfig::BRepositoryConfig(BMessage* data)
|
||||
:
|
||||
inherited(data)
|
||||
{
|
||||
SetTo(data);
|
||||
}
|
||||
|
||||
|
||||
BRepositoryConfig::BRepositoryConfig(const BString& name, const BString& url,
|
||||
uint8 priority)
|
||||
BRepositoryConfig::BRepositoryConfig(const BString& name,
|
||||
const BString& baseURL, uint8 priority)
|
||||
:
|
||||
fInitStatus(B_OK),
|
||||
fName(name),
|
||||
fURL(url),
|
||||
fBaseURL(baseURL),
|
||||
fPriority(priority),
|
||||
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
|
||||
BRepositoryConfig::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, 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
|
||||
BRepositoryConfig::Store(const BEntry& entry) const
|
||||
{
|
||||
BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||
status_t result = file.InitCheck();
|
||||
@@ -107,7 +65,7 @@ BRepositoryConfig::StoreAsConfigFile(const BEntry& entry) const
|
||||
|
||||
BString configString;
|
||||
configString
|
||||
<< "url=" << fURL << "\n"
|
||||
<< "url=" << fBaseURL << "\n"
|
||||
<< "priority=" << fPriority << "\n";
|
||||
|
||||
int32 size = configString.Length();
|
||||
@@ -169,9 +127,9 @@ BRepositoryConfig::SetTo(const BEntry& entry)
|
||||
return result;
|
||||
|
||||
fName = name;
|
||||
fURL = url;
|
||||
fBaseURL = url;
|
||||
fPriority = priorityString == NULL
|
||||
? kDefaultPriority : atoi(priorityString);
|
||||
? kUnsetPriority : atoi(priorityString);
|
||||
|
||||
BPath userSettingsPath;
|
||||
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&
|
||||
BRepositoryConfig::Name() const
|
||||
{
|
||||
@@ -218,9 +152,9 @@ BRepositoryConfig::Name() const
|
||||
|
||||
|
||||
const BString&
|
||||
BRepositoryConfig::URL() const
|
||||
BRepositoryConfig::BaseURL() const
|
||||
{
|
||||
return fURL;
|
||||
return fBaseURL;
|
||||
}
|
||||
|
||||
|
||||
@@ -253,9 +187,9 @@ BRepositoryConfig::SetName(const BString& name)
|
||||
|
||||
|
||||
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 <zooey@hirschkaefer.de>
|
||||
*/
|
||||
|
||||
|
||||
#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 <String.h>
|
||||
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/RepositoryHeader.h>
|
||||
|
||||
|
||||
using namespace BPackageKit;
|
||||
@@ -20,22 +20,21 @@ main(int argc, const char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
BRepositoryConfig repoConfig(argv[1], argv[2], atoi(argv[3]));
|
||||
status_t status = repoConfig.InitCheck();
|
||||
if (status != B_OK) {
|
||||
fprintf(stderr, "couldn't initialize repository-config\n");
|
||||
return 1;
|
||||
}
|
||||
BRepositoryHeader repoHeader;
|
||||
repoHeader.SetName(argv[1]);
|
||||
repoHeader.SetOriginalBaseURL(argv[2]);
|
||||
repoHeader.SetPriority(atoi(argv[3]));
|
||||
|
||||
BMessage repoConfigArchive;
|
||||
if ((status = repoConfig.Archive(&repoConfigArchive)) != B_OK) {
|
||||
fprintf(stderr, "couldn't archive repository-config\n");
|
||||
BMessage repoHeaderArchive;
|
||||
status_t result = repoHeader.Archive(&repoHeaderArchive);
|
||||
if (result != B_OK) {
|
||||
fprintf(stderr, "couldn't archive repository-header\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
BFile output(argv[1], B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||
if ((status = repoConfigArchive.Flatten(&output)) != B_OK) {
|
||||
fprintf(stderr, "couldn't flatten repository-config archive\n");
|
||||
if ((result = repoHeaderArchive.Flatten(&output)) != B_OK) {
|
||||
fprintf(stderr, "couldn't flatten repository-header archive\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -69,8 +68,8 @@ main(int argc, const char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
status = pkg.Flatten(&output);
|
||||
if (status != B_OK) {
|
||||
result = pkg.Flatten(&output);
|
||||
if (result != B_OK) {
|
||||
fprintf(stderr, "couldn't flatten pkg message #%d\n", i + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user