Refactor reusable pkgman code into libpackage
* Move RepositoryBuilder class to libpackage and add B* prefix to name. * Pull BPackageManager class out of PackageManager and move to libpackage. The base class is customizable via three handler objects responsible for transaction handling, request execution, respectively user interaction. * Reorganize _ApplyPackageChanges(): Now we first prepare the transactions for all affected installation locations (downloading files etc.) and then commit them.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#include <../private/package/manager/Exceptions.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <../private/package/manager/RepositoryBuilder.h>
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <[email protected]>
|
||||
*/
|
||||
#ifndef _PACKAGE__MANAGER__PRIVATE__EXCEPTIONS_H_
|
||||
#define _PACKAGE__MANAGER__PRIVATE__EXCEPTIONS_H_
|
||||
|
||||
|
||||
#include <package/Context.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BManager {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BException {
|
||||
public:
|
||||
BException();
|
||||
BException(const BString& message);
|
||||
|
||||
const BString& Message() const
|
||||
{ return fMessage; }
|
||||
|
||||
protected:
|
||||
BString fMessage;
|
||||
};
|
||||
|
||||
|
||||
class BFatalErrorException : public BException {
|
||||
public:
|
||||
BFatalErrorException();
|
||||
BFatalErrorException(const char* format, ...);
|
||||
BFatalErrorException(status_t error,
|
||||
const char* format, ...);
|
||||
|
||||
const BString& Details() const
|
||||
{ return fDetails; }
|
||||
BFatalErrorException& SetDetails(const BString& details);
|
||||
|
||||
status_t Error() const
|
||||
{ return fError; }
|
||||
|
||||
private:
|
||||
BString fDetails;
|
||||
status_t fError;
|
||||
};
|
||||
|
||||
|
||||
class BAbortedByUserException : public BException {
|
||||
public:
|
||||
BAbortedByUserException();
|
||||
};
|
||||
|
||||
|
||||
class BNothingToDoException : public BException {
|
||||
public:
|
||||
BNothingToDoException();
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BManager
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__MANAGER__PRIVATE__EXCEPTIONS_H_
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <[email protected]>
|
||||
*/
|
||||
#ifndef _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|
||||
#define _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|
||||
|
||||
|
||||
#include <Directory.h>
|
||||
#include <ObjectList.h>
|
||||
#include <package/Context.h>
|
||||
#include <package/PackageDefs.h>
|
||||
#include <package/PackageRoster.h>
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/solver/Solver.h>
|
||||
#include <package/solver/SolverRepository.h>
|
||||
|
||||
#include <package/ActivationTransaction.h>
|
||||
#include <package/DaemonClient.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BManager {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
using namespace BPackageKit::BPrivate;
|
||||
|
||||
|
||||
class BPackageManager {
|
||||
public:
|
||||
class RemoteRepository;
|
||||
class InstalledRepository;
|
||||
class Transaction;
|
||||
class TransactionHandler;
|
||||
class DaemonClientTransactionHandler;
|
||||
class UserInteractionHandler;
|
||||
class RequestHandler;
|
||||
|
||||
typedef BObjectList<RemoteRepository> RemoteRepositoryList;
|
||||
typedef BObjectList<InstalledRepository> InstalledRepositoryList;
|
||||
typedef BObjectList<BSolverPackage> PackageList;
|
||||
typedef BObjectList<Transaction> TransactionList;
|
||||
|
||||
enum {
|
||||
B_ADD_INSTALLED_REPOSITORIES = 0x01,
|
||||
B_ADD_REMOTE_REPOSITORIES = 0x02,
|
||||
B_REFRESH_REPOSITORIES = 0x04,
|
||||
};
|
||||
|
||||
public:
|
||||
BPackageManager(
|
||||
BPackageInstallationLocation location);
|
||||
~BPackageManager();
|
||||
|
||||
void Init(uint32 flags);
|
||||
|
||||
BSolver* Solver() const
|
||||
{ return fSolver; }
|
||||
|
||||
const InstalledRepository* SystemRepository() const
|
||||
{ return fSystemRepository; }
|
||||
const InstalledRepository* CommonRepository() const
|
||||
{ return fCommonRepository; }
|
||||
const InstalledRepository* HomeRepository() const
|
||||
{ return fHomeRepository; }
|
||||
const InstalledRepositoryList& InstalledRepositories() const
|
||||
{ return fInstalledRepositories; }
|
||||
const RemoteRepositoryList& OtherRepositories() const
|
||||
{ return fOtherRepositories; }
|
||||
|
||||
void Install(const char* const* packages,
|
||||
int packageCount);
|
||||
void Uninstall(const char* const* packages,
|
||||
int packageCount);
|
||||
void Update(const char* const* packages,
|
||||
int packageCount);
|
||||
|
||||
private:
|
||||
void _HandleProblems();
|
||||
void _AnalyzeResult();
|
||||
void _ConfirmChanges(bool fromMostSpecific = false);
|
||||
void _ApplyPackageChanges(
|
||||
bool fromMostSpecific = false);
|
||||
void _PreparePackageChanges(
|
||||
InstalledRepository&
|
||||
installationRepository);
|
||||
void _CommitPackageChanges(Transaction& transaction);
|
||||
|
||||
void _ClonePackageFile(
|
||||
InstalledRepository* repository,
|
||||
const BString& fileName,
|
||||
const BEntry& entry);
|
||||
int32 _FindBasePackage(const PackageList& packages,
|
||||
const BPackageInfo& info);
|
||||
|
||||
InstalledRepository& _InstallationRepository();
|
||||
|
||||
void _AddInstalledRepository(
|
||||
InstalledRepository* repository);
|
||||
void _AddRemoteRepository(BPackageRoster& roster,
|
||||
const char* name, bool refresh);
|
||||
status_t _GetRepositoryConfig(BPackageRoster& roster,
|
||||
const char* name, bool refresh,
|
||||
BRepositoryConfig& _config);
|
||||
|
||||
bool _NextSpecificInstallationLocation();
|
||||
|
||||
protected:
|
||||
BPackageInstallationLocation fLocation;
|
||||
BSolver* fSolver;
|
||||
InstalledRepository* fSystemRepository;
|
||||
InstalledRepository* fCommonRepository;
|
||||
InstalledRepository* fHomeRepository;
|
||||
InstalledRepositoryList fInstalledRepositories;
|
||||
RemoteRepositoryList fOtherRepositories;
|
||||
TransactionList fTransactions;
|
||||
|
||||
// must be set by the derived class
|
||||
TransactionHandler* fTransactionHandler;
|
||||
RequestHandler* fRequestHandler;
|
||||
UserInteractionHandler* fUserInteractionHandler;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::RemoteRepository : public BSolverRepository {
|
||||
public:
|
||||
RemoteRepository(
|
||||
const BRepositoryConfig& config);
|
||||
|
||||
const BRepositoryConfig& Config() const;
|
||||
|
||||
private:
|
||||
BRepositoryConfig fConfig;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::InstalledRepository : public BSolverRepository {
|
||||
public:
|
||||
typedef BObjectList<BSolverPackage> PackageList;
|
||||
|
||||
public:
|
||||
InstalledRepository(const char* name,
|
||||
BPackageInstallationLocation location,
|
||||
int32 priority);
|
||||
|
||||
BPackageInstallationLocation Location() const
|
||||
{ return fLocation; }
|
||||
const char* InitialName() const
|
||||
{ return fInitialName; }
|
||||
int32 InitialPriority() const
|
||||
{ return fInitialPriority; }
|
||||
|
||||
void DisablePackage(BSolverPackage* package);
|
||||
|
||||
PackageList& PackagesToActivate()
|
||||
{ return fPackagesToActivate; }
|
||||
PackageList& PackagesToDeactivate()
|
||||
{ return fPackagesToDeactivate; }
|
||||
|
||||
bool HasChanges() const;
|
||||
void ApplyChanges();
|
||||
|
||||
private:
|
||||
PackageList fDisabledPackages;
|
||||
PackageList fPackagesToActivate;
|
||||
PackageList fPackagesToDeactivate;
|
||||
const char* fInitialName;
|
||||
BPackageInstallationLocation fLocation;
|
||||
int32 fInitialPriority;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::Transaction {
|
||||
public:
|
||||
Transaction(InstalledRepository& repository);
|
||||
~Transaction();
|
||||
|
||||
InstalledRepository& Repository()
|
||||
{ return fRepository; }
|
||||
BActivationTransaction& ActivationTransaction()
|
||||
{ return fTransaction; }
|
||||
BDirectory& TransactionDirectory()
|
||||
{ return fTransactionDirectory; }
|
||||
|
||||
private:
|
||||
InstalledRepository& fRepository;
|
||||
BActivationTransaction fTransaction;
|
||||
BDirectory fTransactionDirectory;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::TransactionHandler {
|
||||
public:
|
||||
virtual ~TransactionHandler();
|
||||
|
||||
virtual status_t PrepareTransaction(Transaction& transaction)
|
||||
= 0;
|
||||
virtual status_t CommitTransaction(Transaction& transaction,
|
||||
BDaemonClient::BCommitTransactionResult&
|
||||
_result) = 0;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::DaemonClientTransactionHandler
|
||||
: public TransactionHandler {
|
||||
public:
|
||||
DaemonClientTransactionHandler();
|
||||
virtual ~DaemonClientTransactionHandler();
|
||||
|
||||
virtual status_t PrepareTransaction(Transaction& transaction);
|
||||
virtual status_t CommitTransaction(Transaction& transaction,
|
||||
BDaemonClient::BCommitTransactionResult&
|
||||
_result);
|
||||
|
||||
private:
|
||||
BDaemonClient fDaemonClient;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::RequestHandler {
|
||||
public:
|
||||
virtual ~RequestHandler();
|
||||
|
||||
virtual status_t RefreshRepository(
|
||||
const BRepositoryConfig& repoConfig) = 0;
|
||||
virtual status_t DownloadPackage(const BString& fileURL,
|
||||
const BEntry& targetEntry,
|
||||
const BString& checksum) = 0;
|
||||
};
|
||||
|
||||
|
||||
class BPackageManager::UserInteractionHandler {
|
||||
public:
|
||||
virtual ~UserInteractionHandler();
|
||||
|
||||
virtual void HandleProblems() = 0;
|
||||
virtual void ConfirmChanges(bool fromMostSpecific) = 0;
|
||||
|
||||
virtual void Warn(status_t error, const char* format, ...)
|
||||
= 0;
|
||||
virtual void ProgressStartApplyingChanges(
|
||||
InstalledRepository& repository) = 0;
|
||||
virtual void ProgressTransactionCommitted(
|
||||
InstalledRepository& repository,
|
||||
const char* transactionDirectoryName) = 0;
|
||||
virtual void ProgressApplyingChangesDone(
|
||||
InstalledRepository& repository) = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BManager
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <[email protected]>
|
||||
*/
|
||||
#ifndef _PACKAGE__MANAGER__PRIVATE__REPOSITORY_BUILDER_H_
|
||||
#define _PACKAGE__MANAGER__PRIVATE__REPOSITORY_BUILDER_H_
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <package/PackageInfo.h>
|
||||
#include <package/solver/Solver.h>
|
||||
#include <package/solver/SolverPackage.h>
|
||||
#include <package/solver/SolverRepository.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BManager {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
typedef std::map<BSolverPackage*, BString> BPackagePathMap;
|
||||
|
||||
|
||||
class BRepositoryBuilder {
|
||||
public:
|
||||
BRepositoryBuilder(
|
||||
BSolverRepository& repository,
|
||||
const BString& name,
|
||||
const BString& errorName = BString());
|
||||
BRepositoryBuilder(
|
||||
BSolverRepository& repository,
|
||||
const BRepositoryConfig& config);
|
||||
BRepositoryBuilder(
|
||||
BSolverRepository& repository,
|
||||
const BRepositoryCache& cache,
|
||||
const BString& errorName = BString());
|
||||
|
||||
BRepositoryBuilder& SetPackagePathMap(
|
||||
BPackagePathMap* packagePaths);
|
||||
|
||||
BRepositoryBuilder& AddPackage(const BPackageInfo& info,
|
||||
const char* packageErrorName = NULL,
|
||||
BSolverPackage** _package = NULL);
|
||||
BRepositoryBuilder& AddPackage(const char* path,
|
||||
BSolverPackage** _package = NULL);
|
||||
BRepositoryBuilder& AddPackages(
|
||||
BPackageInstallationLocation location,
|
||||
const char* locationErrorName);
|
||||
BRepositoryBuilder& AddPackagesDirectory(const char* path);
|
||||
|
||||
BRepositoryBuilder& AddToSolver(BSolver* solver,
|
||||
bool isInstalled = false);
|
||||
|
||||
private:
|
||||
BSolverRepository& fRepository;
|
||||
BString fErrorName;
|
||||
BPackagePathMap* fPackagePaths;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BManager
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__MANAGER__PRIVATE__REPOSITORY_BUILDER_H_
|
||||
Reference in New Issue
Block a user