2013-08-31 23:18:28 +04:00
|
|
|
/*
|
2015-01-24 16:26:26 +03:00
|
|
|
* Copyright 2013-2015, Haiku, Inc. All Rights Reserved.
|
2013-08-31 23:18:28 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
2013-09-28 21:12:47 +04:00
|
|
|
* Rene Gollent <rene@gollent.com>
|
2013-08-31 23:18:28 +04:00
|
|
|
*/
|
|
|
|
#ifndef _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|
|
|
|
#define _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|
|
|
|
|
|
|
|
|
2014-06-15 18:27:30 +04:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
#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>
|
2013-09-28 21:12:47 +04:00
|
|
|
#include <package/Job.h>
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
|
2014-06-14 21:06:11 +04:00
|
|
|
class BCommitTransactionResult;
|
|
|
|
|
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
namespace BManager {
|
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
2013-09-01 16:12:22 +04:00
|
|
|
using BPackageKit::BPrivate::BActivationTransaction;
|
|
|
|
using BPackageKit::BPrivate::BDaemonClient;
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
class BPackageManager : protected BSupportKit::BJobStateListener {
|
2013-08-31 23:18:28 +04:00
|
|
|
public:
|
|
|
|
class RemoteRepository;
|
2014-06-15 18:27:30 +04:00
|
|
|
class LocalRepository;
|
|
|
|
class MiscLocalRepository;
|
2013-08-31 23:18:28 +04:00
|
|
|
class InstalledRepository;
|
|
|
|
class Transaction;
|
2013-09-01 14:19:09 +04:00
|
|
|
class InstallationInterface;
|
|
|
|
class ClientInstallationInterface;
|
2013-08-31 23:18:28 +04:00
|
|
|
class UserInteractionHandler;
|
|
|
|
|
|
|
|
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(
|
2013-11-21 15:54:20 +04:00
|
|
|
BPackageInstallationLocation location,
|
|
|
|
InstallationInterface*
|
|
|
|
installationInterface,
|
|
|
|
UserInteractionHandler*
|
|
|
|
userInteractionHandler);
|
2013-09-28 05:52:43 +04:00
|
|
|
virtual ~BPackageManager();
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
void Init(uint32 flags);
|
|
|
|
|
2014-10-26 01:11:36 +03:00
|
|
|
void SetDebugLevel(int32 level);
|
|
|
|
// 0 - 10 (passed to libsolv)
|
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
BSolver* Solver() const
|
|
|
|
{ return fSolver; }
|
|
|
|
|
|
|
|
const InstalledRepository* SystemRepository() const
|
|
|
|
{ return fSystemRepository; }
|
|
|
|
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);
|
2013-09-10 20:54:10 +04:00
|
|
|
void Install(const BSolverPackageSpecifierList&
|
|
|
|
packages);
|
2013-08-31 23:18:28 +04:00
|
|
|
void Uninstall(const char* const* packages,
|
|
|
|
int packageCount);
|
2013-09-10 20:54:10 +04:00
|
|
|
void Uninstall(const BSolverPackageSpecifierList&
|
|
|
|
packages);
|
2013-08-31 23:18:28 +04:00
|
|
|
void Update(const char* const* packages,
|
|
|
|
int packageCount);
|
2013-09-10 20:54:10 +04:00
|
|
|
void Update(const BSolverPackageSpecifierList&
|
|
|
|
packages);
|
2014-01-25 13:46:42 +04:00
|
|
|
void FullSync();
|
2013-08-31 23:18:28 +04:00
|
|
|
|
2013-09-10 20:55:44 +04:00
|
|
|
void VerifyInstallation();
|
|
|
|
|
2013-09-28 05:52:43 +04:00
|
|
|
|
|
|
|
virtual status_t DownloadPackage(const BString& fileURL,
|
|
|
|
const BEntry& targetEntry,
|
|
|
|
const BString& checksum);
|
|
|
|
virtual status_t RefreshRepository(
|
|
|
|
const BRepositoryConfig& repoConfig);
|
|
|
|
|
2013-09-10 20:42:57 +04:00
|
|
|
protected:
|
|
|
|
InstalledRepository& InstallationRepository();
|
|
|
|
|
2013-09-28 21:12:47 +04:00
|
|
|
protected:
|
|
|
|
// BJobStateListener
|
2015-05-18 19:21:58 +03:00
|
|
|
virtual void JobStarted(BSupportKit::BJob* job);
|
|
|
|
virtual void JobProgress(BSupportKit::BJob* job);
|
|
|
|
virtual void JobSucceeded(BSupportKit::BJob* job);
|
2013-09-28 21:12:47 +04:00
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
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(
|
2014-06-15 18:27:30 +04:00
|
|
|
LocalRepository* repository,
|
|
|
|
BSolverPackage* package,
|
2013-08-31 23:18:28 +04:00
|
|
|
const BEntry& entry);
|
|
|
|
int32 _FindBasePackage(const PackageList& packages,
|
|
|
|
const BPackageInfo& info);
|
|
|
|
|
|
|
|
void _AddInstalledRepository(
|
|
|
|
InstalledRepository* repository);
|
|
|
|
void _AddRemoteRepository(BPackageRoster& roster,
|
|
|
|
const char* name, bool refresh);
|
2013-09-29 15:14:07 +04:00
|
|
|
status_t _GetRepositoryCache(BPackageRoster& roster,
|
|
|
|
const BRepositoryConfig& config,
|
|
|
|
bool refresh, BRepositoryCache& _cache);
|
2013-08-31 23:18:28 +04:00
|
|
|
|
2014-06-15 18:27:30 +04:00
|
|
|
void _AddPackageSpecifiers(
|
|
|
|
const char* const* searchStrings,
|
|
|
|
int searchStringCount,
|
|
|
|
BSolverPackageSpecifierList& specifierList);
|
|
|
|
bool _IsLocalPackage(const char* fileName);
|
|
|
|
BSolverPackage* _AddLocalPackage(const char* fileName);
|
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
bool _NextSpecificInstallationLocation();
|
|
|
|
|
|
|
|
protected:
|
2014-10-26 01:11:36 +03:00
|
|
|
int32 fDebugLevel;
|
2013-08-31 23:18:28 +04:00
|
|
|
BPackageInstallationLocation fLocation;
|
|
|
|
BSolver* fSolver;
|
|
|
|
InstalledRepository* fSystemRepository;
|
|
|
|
InstalledRepository* fHomeRepository;
|
|
|
|
InstalledRepositoryList fInstalledRepositories;
|
|
|
|
RemoteRepositoryList fOtherRepositories;
|
2014-06-15 18:27:30 +04:00
|
|
|
MiscLocalRepository* fLocalRepository;
|
2013-08-31 23:18:28 +04:00
|
|
|
TransactionList fTransactions;
|
|
|
|
|
|
|
|
// must be set by the derived class
|
2013-09-01 14:19:09 +04:00
|
|
|
InstallationInterface* fInstallationInterface;
|
2013-08-31 23:18:28 +04:00
|
|
|
UserInteractionHandler* fUserInteractionHandler;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BPackageManager::RemoteRepository : public BSolverRepository {
|
|
|
|
public:
|
|
|
|
RemoteRepository(
|
|
|
|
const BRepositoryConfig& config);
|
|
|
|
|
|
|
|
const BRepositoryConfig& Config() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BRepositoryConfig fConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-15 18:27:30 +04:00
|
|
|
class BPackageManager::LocalRepository : public BSolverRepository {
|
|
|
|
public:
|
|
|
|
LocalRepository();
|
|
|
|
LocalRepository(const BString& name);
|
|
|
|
|
|
|
|
virtual void GetPackagePath(BSolverPackage* package,
|
|
|
|
BPath& _path) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BPackageManager::MiscLocalRepository : public LocalRepository {
|
|
|
|
public:
|
|
|
|
MiscLocalRepository();
|
|
|
|
|
|
|
|
BSolverPackage* AddLocalPackage(const char* fileName);
|
|
|
|
|
|
|
|
virtual void GetPackagePath(BSolverPackage* package,
|
|
|
|
BPath& _path);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::map<BSolverPackage*, std::string> PackagePathMap;
|
|
|
|
private:
|
|
|
|
PackagePathMap fPackagePaths;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BPackageManager::InstalledRepository : public LocalRepository {
|
2013-08-31 23:18:28 +04:00
|
|
|
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; }
|
|
|
|
|
2014-06-15 18:27:30 +04:00
|
|
|
virtual void GetPackagePath(BSolverPackage* package,
|
|
|
|
BPath& _path);
|
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
void DisablePackage(BSolverPackage* package);
|
2013-09-10 20:58:07 +04:00
|
|
|
// throws, if already disabled
|
|
|
|
bool EnablePackage(BSolverPackage* package);
|
|
|
|
// returns whether it was disabled
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-01 14:19:09 +04:00
|
|
|
class BPackageManager::InstallationInterface {
|
2013-08-31 23:18:28 +04:00
|
|
|
public:
|
2013-09-01 14:19:09 +04:00
|
|
|
virtual ~InstallationInterface();
|
|
|
|
|
|
|
|
virtual void InitInstalledRepository(
|
|
|
|
InstalledRepository& repository) = 0;
|
2013-09-10 20:57:33 +04:00
|
|
|
virtual void ResultComputed(InstalledRepository& repository);
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
virtual status_t PrepareTransaction(Transaction& transaction)
|
|
|
|
= 0;
|
|
|
|
virtual status_t CommitTransaction(Transaction& transaction,
|
package daemon: Rework error and issue propagation to client
* BDaemonClient: Move inner class BCommitTransactionResult to top level
and make it public.
* BCommitTransactionResult:
- Add a whole bunch of specific error code enum values. Such an error
code is now the primary error, as opposed to before where we would
mix status_t and enum value errors. There's a systemError property
of type status_t which may provide additional information, though
(depending on the primary error type).
- Remove the errorMessage property. Due to mapping all errors to the
specific error codes this is no longer necessary. Mixing such a
message with another error description is also not very helpful when
it comes to localization (still not supported, though).
- Add several properties (paths, strings, error codes) that serve as
arguments to the primary error and are used by FullErrorMessage().
- Add issues property, a list of instances of new class
BTransactionIssue. Those describe non-critical issues (e.g. failed
update of a settings file) that occurred in the process of
committing the transaction. Those issues should be presented to the
user by the package management program.
* Exception: Adjust to transport the BCommitTransactionResult
properties.
* CommitTransactionHandler, FsTransactions, Root, Volume: Adjust to
BCommitTransactionResult/Exception changes.
* CommitTransactionHandler: Now requires a BCommitTransactionResult to
which it adds the issues it encounters. The reply BMessage is no
longer needed, though.
* Volume: Refactor common code from the three methods that use
CommitTransactionHandler into new method _CommitTransaction.
2014-06-14 19:40:57 +04:00
|
|
|
BCommitTransactionResult& _result) = 0;
|
2013-08-31 23:18:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-01 14:19:09 +04:00
|
|
|
class BPackageManager::ClientInstallationInterface
|
|
|
|
: public InstallationInterface {
|
2013-08-31 23:18:28 +04:00
|
|
|
public:
|
2013-09-01 14:19:09 +04:00
|
|
|
ClientInstallationInterface();
|
|
|
|
virtual ~ClientInstallationInterface();
|
|
|
|
|
|
|
|
virtual void InitInstalledRepository(
|
|
|
|
InstalledRepository& repository);
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
virtual status_t PrepareTransaction(Transaction& transaction);
|
|
|
|
virtual status_t CommitTransaction(Transaction& transaction,
|
package daemon: Rework error and issue propagation to client
* BDaemonClient: Move inner class BCommitTransactionResult to top level
and make it public.
* BCommitTransactionResult:
- Add a whole bunch of specific error code enum values. Such an error
code is now the primary error, as opposed to before where we would
mix status_t and enum value errors. There's a systemError property
of type status_t which may provide additional information, though
(depending on the primary error type).
- Remove the errorMessage property. Due to mapping all errors to the
specific error codes this is no longer necessary. Mixing such a
message with another error description is also not very helpful when
it comes to localization (still not supported, though).
- Add several properties (paths, strings, error codes) that serve as
arguments to the primary error and are used by FullErrorMessage().
- Add issues property, a list of instances of new class
BTransactionIssue. Those describe non-critical issues (e.g. failed
update of a settings file) that occurred in the process of
committing the transaction. Those issues should be presented to the
user by the package management program.
* Exception: Adjust to transport the BCommitTransactionResult
properties.
* CommitTransactionHandler, FsTransactions, Root, Volume: Adjust to
BCommitTransactionResult/Exception changes.
* CommitTransactionHandler: Now requires a BCommitTransactionResult to
which it adds the issues it encounters. The reply BMessage is no
longer needed, though.
* Volume: Refactor common code from the three methods that use
CommitTransactionHandler into new method _CommitTransaction.
2014-06-14 19:40:57 +04:00
|
|
|
BCommitTransactionResult& _result);
|
2013-08-31 23:18:28 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
BDaemonClient fDaemonClient;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BPackageManager::UserInteractionHandler {
|
|
|
|
public:
|
|
|
|
virtual ~UserInteractionHandler();
|
|
|
|
|
2013-11-21 15:58:43 +04:00
|
|
|
virtual void HandleProblems();
|
|
|
|
virtual void ConfirmChanges(bool fromMostSpecific);
|
2013-08-31 23:18:28 +04:00
|
|
|
|
2013-11-21 15:58:43 +04:00
|
|
|
virtual void Warn(status_t error, const char* format, ...);
|
2013-09-28 21:12:47 +04:00
|
|
|
|
|
|
|
virtual void ProgressPackageDownloadStarted(
|
2013-11-21 15:58:43 +04:00
|
|
|
const char* packageName);
|
2013-09-28 21:12:47 +04:00
|
|
|
virtual void ProgressPackageDownloadActive(
|
|
|
|
const char* packageName,
|
2015-01-24 16:26:26 +03:00
|
|
|
float completionPercentage,
|
|
|
|
off_t bytes, off_t totalBytes);
|
2013-09-28 21:12:47 +04:00
|
|
|
virtual void ProgressPackageDownloadComplete(
|
2013-11-21 15:58:43 +04:00
|
|
|
const char* packageName);
|
2013-09-28 21:12:47 +04:00
|
|
|
virtual void ProgressPackageChecksumStarted(
|
2013-11-21 15:58:43 +04:00
|
|
|
const char* title);
|
2013-09-28 21:12:47 +04:00
|
|
|
virtual void ProgressPackageChecksumComplete(
|
2013-11-21 15:58:43 +04:00
|
|
|
const char* title);
|
2013-09-28 21:12:47 +04:00
|
|
|
|
2013-08-31 23:18:28 +04:00
|
|
|
virtual void ProgressStartApplyingChanges(
|
2013-11-21 15:58:43 +04:00
|
|
|
InstalledRepository& repository);
|
2013-08-31 23:18:28 +04:00
|
|
|
virtual void ProgressTransactionCommitted(
|
|
|
|
InstalledRepository& repository,
|
2014-06-14 21:06:11 +04:00
|
|
|
const BCommitTransactionResult& result);
|
2013-08-31 23:18:28 +04:00
|
|
|
virtual void ProgressApplyingChangesDone(
|
2013-11-21 15:58:43 +04:00
|
|
|
InstalledRepository& repository);
|
2013-08-31 23:18:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
} // namespace BManager
|
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
|