BPathFinder: Add BPackageResolvableExpression initialization
Add a constructor and a SetTo() method with a BPackageResolvableExpression parameter instead of a path. The path of the package satisfying the expression is used. The new functionality lives in libpackage as it uses the package kit.
This commit is contained in:
parent
ee8e91583e
commit
62b164bd71
@ -15,7 +15,16 @@ class BStringList;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
class BPackageResolvableExpression;
|
||||
}
|
||||
|
||||
|
||||
class BPathFinder {
|
||||
public:
|
||||
typedef BPackageKit::BPackageResolvableExpression
|
||||
BResolvableExpression;
|
||||
|
||||
public:
|
||||
BPathFinder(const void* codePointer = NULL,
|
||||
const char* dependency = NULL);
|
||||
@ -23,6 +32,10 @@ public:
|
||||
const char* dependency = NULL);
|
||||
BPathFinder(const entry_ref& ref,
|
||||
const char* dependency = NULL);
|
||||
BPathFinder(
|
||||
const BResolvableExpression& expression,
|
||||
const char* dependency = NULL);
|
||||
// requires libpackage
|
||||
|
||||
status_t SetTo(const void* codePointer = NULL,
|
||||
const char* dependency = NULL);
|
||||
@ -30,6 +43,9 @@ public:
|
||||
const char* dependency = NULL);
|
||||
status_t SetTo(const entry_ref& ref,
|
||||
const char* dependency = NULL);
|
||||
status_t SetTo(const BResolvableExpression& expression,
|
||||
const char* dependency = NULL);
|
||||
// requires libpackage
|
||||
|
||||
status_t FindPath(const char* architecture,
|
||||
path_base_directory baseDirectory,
|
||||
@ -64,7 +80,7 @@ private:
|
||||
BString fPath;
|
||||
BString fDependency;
|
||||
status_t fInitStatus;
|
||||
uint32 fReserved[4];
|
||||
addr_t fReserved[4];
|
||||
};
|
||||
|
||||
|
||||
|
@ -5,6 +5,7 @@ UsePrivateHeaders
|
||||
shared
|
||||
storage
|
||||
;
|
||||
UsePrivateSystemHeaders ;
|
||||
|
||||
HPKG_SOURCES =
|
||||
AttributeDataReader.cpp
|
||||
@ -103,6 +104,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
PackageResolvableExpression.cpp
|
||||
PackageRoster.cpp
|
||||
PackageVersion.cpp
|
||||
PathFinder.cpp
|
||||
RefreshRepositoryRequest.cpp
|
||||
RemoveRepositoryJob.cpp
|
||||
RepositoryCache.cpp
|
||||
|
93
src/kits/package/PathFinder.cpp
Normal file
93
src/kits/package/PathFinder.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <PathFinder.h>
|
||||
|
||||
#include <package/PackageResolvableExpression.h>
|
||||
#include <package/solver/SolverPackage.h>
|
||||
|
||||
#include <directories.h>
|
||||
#include <package/manager/PackageManager.h>
|
||||
|
||||
|
||||
// NOTE: This is only the package kit specific part of BPathFinder. Everything
|
||||
// else is implemented in the storage kit.
|
||||
|
||||
|
||||
using namespace BPackageKit;
|
||||
using namespace BPackageKit::BPrivate;
|
||||
using namespace BPackageKit::BManager::BPrivate;
|
||||
|
||||
|
||||
static status_t
|
||||
find_package(const BPackageResolvableExpression& expression,
|
||||
BString& _versionedPackageName)
|
||||
{
|
||||
if (expression.InitCheck() != B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// create the package manager -- we only want to use its solver
|
||||
BPackageManager::ClientInstallationInterface installationInterface;
|
||||
BPackageManager::UserInteractionHandler userInteractionHandler;
|
||||
BPackageManager packageManager(B_PACKAGE_INSTALLATION_LOCATION_HOME,
|
||||
&installationInterface, &userInteractionHandler);
|
||||
packageManager.Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES);
|
||||
|
||||
// search
|
||||
BObjectList<BSolverPackage> packages;
|
||||
status_t error = packageManager.Solver()->FindPackages(expression.Name(),
|
||||
BSolver::B_FIND_IN_NAME | BSolver::B_FIND_IN_PROVIDES, packages);
|
||||
if (error != B_OK)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
|
||||
// find the newest matching package
|
||||
BSolverPackage* foundPackage = NULL;
|
||||
for (int32 i = 0; BSolverPackage* package = packages.ItemAt(i); i++) {
|
||||
if (package->Info().Matches(expression)
|
||||
&& (foundPackage == NULL
|
||||
|| package->Info().Version().Compare(
|
||||
foundPackage->Info().Version()) > 0)) {
|
||||
foundPackage = package;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPackage == NULL)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
|
||||
BString version = foundPackage->Info().Version().ToString();
|
||||
_versionedPackageName = foundPackage->VersionedName();
|
||||
return _versionedPackageName.IsEmpty() ? B_NO_MEMORY : B_OK;
|
||||
}
|
||||
|
||||
|
||||
BPathFinder::BPathFinder(const BResolvableExpression& expression,
|
||||
const char* dependency)
|
||||
{
|
||||
SetTo(expression, dependency);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPathFinder::SetTo(const BResolvableExpression& expression,
|
||||
const char* dependency)
|
||||
{
|
||||
BString versionedPackageName;
|
||||
fInitStatus = find_package(expression, versionedPackageName);
|
||||
if (fInitStatus != B_OK)
|
||||
return fInitStatus;
|
||||
|
||||
BString packageLinksPath;
|
||||
packageLinksPath.SetToFormat(kSystemPackageLinksDirectory "/%s",
|
||||
versionedPackageName.String());
|
||||
if (packageLinksPath.IsEmpty())
|
||||
return fInitStatus = B_NO_MEMORY;
|
||||
|
||||
struct stat st;
|
||||
if (lstat(packageLinksPath, &st) < 0)
|
||||
return fInitStatus = B_ENTRY_NOT_FOUND;
|
||||
|
||||
return _SetTo(NULL, packageLinksPath, dependency);
|
||||
}
|
@ -11,6 +11,10 @@
|
||||
#include <StringList.h>
|
||||
|
||||
|
||||
// NOTE: The package kit specific part of BPathFinder (BResolvableExpression
|
||||
// constructor and SetTo()) is implemented in the package kit.
|
||||
|
||||
|
||||
BPathFinder::BPathFinder(const void* codePointer, const char* dependency)
|
||||
{
|
||||
_SetTo(codePointer, NULL, dependency);
|
||||
|
Loading…
Reference in New Issue
Block a user