Fix use of findpaths from inside chroot

The package kit needs to provide the package daemon with the node_ref of
the root directory, so the package daemon gives the correct results when
the request comes from inside a chroot.

Moreover, the package kit must be able to handle a root with a system
but no home package dir, as is the case inside the chroot environment
created by haikuporter.

Fixes #12602.
This commit is contained in:
Adrien Destugues
2016-08-20 07:57:52 +02:00
parent 23a6a63e83
commit 6262ccbbe8
4 changed files with 78 additions and 26 deletions
+33 -17
View File
@@ -10,11 +10,15 @@
#include <string.h>
#include <package/PackageResolvableExpression.h>
#include <package/manager/Exceptions.h>
#include <Path.h>
#include <PathFinder.h>
#include <StringList.h>
using namespace BPackageKit::BManager::BPrivate;
extern const char* __progname;
const char* kCommandName = __progname;
@@ -245,25 +249,37 @@ main(int argc, const char* const* argv)
}
if (referencePath != NULL || resolvable != NULL) {
BPathFinder pathFinder;
if (referencePath != NULL) {
pathFinder.SetTo(referencePath, dependency);
} else {
pathFinder.SetTo(
BPackageKit::BPackageResolvableExpression(resolvable),
dependency);
}
try {
BPathFinder pathFinder;
if (referencePath != NULL) {
pathFinder.SetTo(referencePath, dependency);
} else {
pathFinder.SetTo(
BPackageKit::BPackageResolvableExpression(resolvable),
dependency);
}
BPath path;
status_t error = pathFinder.FindPath(architecture, baseDirectory,
subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to find path: %s\n",
strerror(error));
exit(1);
}
BPath path;
status_t error = pathFinder.FindPath(architecture, baseDirectory,
subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to find path: %s\n",
strerror(error));
exit(1);
}
printf("%s\n", path.Path());
printf("%s\n", path.Path());
} catch(BFatalErrorException& exception) {
if (!exception.Details().IsEmpty())
fprintf(stderr, "%s", exception.Details().String());
if (exception.Error() == B_OK) {
fprintf(stderr, "Error: %s\n", exception.Message().String());
} else {
fprintf(stderr, "Error: %s: %s\n", exception.Message().String(),
strerror(exception.Error()));
}
return 1;
}
} else {
BStringList paths;
status_t error = BPathFinder::FindPaths(architecture, baseDirectory,