findpaths: Add '-r' option
It allows finding a path for a resolvable expression.
This commit is contained in:
+5
-1
@@ -115,7 +115,6 @@ if $(TARGET_PLATFORM) = libbe_test {
|
|||||||
StdBinCommands
|
StdBinCommands
|
||||||
alert.cpp
|
alert.cpp
|
||||||
eject.cpp
|
eject.cpp
|
||||||
findpaths.cpp
|
|
||||||
getarch.cpp
|
getarch.cpp
|
||||||
hey.cpp
|
hey.cpp
|
||||||
reindex.cpp
|
reindex.cpp
|
||||||
@@ -190,6 +189,11 @@ StdBinCommands
|
|||||||
mail.cpp
|
mail.cpp
|
||||||
: be libmail.so : $(haiku-utils_rsrc) ;
|
: be libmail.so : $(haiku-utils_rsrc) ;
|
||||||
|
|
||||||
|
# standard commands that need libbe.so, libpackage.so, libsupc++.so
|
||||||
|
StdBinCommands
|
||||||
|
findpaths.cpp
|
||||||
|
: be package $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ;
|
||||||
|
|
||||||
# standard commands that need libbe.so, libdevice.so
|
# standard commands that need libbe.so, libdevice.so
|
||||||
StdBinCommands
|
StdBinCommands
|
||||||
listusb.cpp
|
listusb.cpp
|
||||||
|
|||||||
+30
-5
@@ -9,6 +9,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <package/PackageResolvableExpression.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <PathFinder.h>
|
#include <PathFinder.h>
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
@@ -115,6 +116,12 @@ static const char* kUsage =
|
|||||||
" -p, --path <path>\n"
|
" -p, --path <path>\n"
|
||||||
" Print only one path, the one for the installation location that\n"
|
" Print only one path, the one for the installation location that\n"
|
||||||
" contains the path <path>.\n"
|
" contains the path <path>.\n"
|
||||||
|
" -r, --resolvable <expression>\n"
|
||||||
|
" Print only one path, the one for the installation location for the\n"
|
||||||
|
" package providing the resolvable matching the expression\n"
|
||||||
|
" <expression>. The expressions can be a simple resolvable name or\n"
|
||||||
|
" a resolvable name with operator and version (e.g.\n"
|
||||||
|
" \"cmd:perl >= 5\"; must be one argument).\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@@ -132,6 +139,7 @@ main(int argc, const char* const* argv)
|
|||||||
const char* architecture = NULL;
|
const char* architecture = NULL;
|
||||||
const char* dependency = NULL;
|
const char* dependency = NULL;
|
||||||
const char* referencePath = NULL;
|
const char* referencePath = NULL;
|
||||||
|
const char* resolvable = NULL;
|
||||||
bool existingOnly = false;
|
bool existingOnly = false;
|
||||||
const char* separator = NULL;
|
const char* separator = NULL;
|
||||||
|
|
||||||
@@ -141,11 +149,12 @@ main(int argc, const char* const* argv)
|
|||||||
{ "dependency", required_argument, 0, 'd' },
|
{ "dependency", required_argument, 0, 'd' },
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ "path", required_argument, 0, 'p' },
|
{ "path", required_argument, 0, 'p' },
|
||||||
|
{ "resolvable", required_argument, 0, 'pr' },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:",
|
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:r:",
|
||||||
sLongOptions, NULL);
|
sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@@ -183,6 +192,10 @@ main(int argc, const char* const* argv)
|
|||||||
referencePath = optarg;
|
referencePath = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
resolvable = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print_usage_and_exit(true);
|
print_usage_and_exit(true);
|
||||||
break;
|
break;
|
||||||
@@ -199,6 +212,10 @@ main(int argc, const char* const* argv)
|
|||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
subPath = argv[optind++];
|
subPath = argv[optind++];
|
||||||
|
|
||||||
|
// only one of path or resolvable may be specified
|
||||||
|
if (referencePath != NULL && resolvable != NULL)
|
||||||
|
print_usage_and_exit(true);
|
||||||
|
|
||||||
// resolve the directory constant
|
// resolve the directory constant
|
||||||
path_base_directory baseDirectory = B_FIND_PATH_IMAGE_PATH;
|
path_base_directory baseDirectory = B_FIND_PATH_IMAGE_PATH;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@@ -217,11 +234,19 @@ main(int argc, const char* const* argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (referencePath != NULL) {
|
if (referencePath != NULL || resolvable != NULL) {
|
||||||
|
BPathFinder pathFinder;
|
||||||
|
if (referencePath != NULL) {
|
||||||
|
pathFinder.SetTo(referencePath, dependency);
|
||||||
|
} else {
|
||||||
|
pathFinder.SetTo(
|
||||||
|
BPackageKit::BPackageResolvableExpression(resolvable),
|
||||||
|
dependency);
|
||||||
|
}
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
status_t error = BPathFinder(referencePath, dependency).FindPath(
|
status_t error =pathFinder.FindPath(architecture, baseDirectory,
|
||||||
architecture, baseDirectory, subPath,
|
subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
|
||||||
existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
|
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
fprintf(stderr, "Error: Failed to find path: %s\n",
|
fprintf(stderr, "Error: Failed to find path: %s\n",
|
||||||
strerror(error));
|
strerror(error));
|
||||||
|
|||||||
Reference in New Issue
Block a user