9
9
#include < stdlib.h>
10
10
#include < string.h>
11
11
12
+ #include < package/PackageResolvableExpression.h>
12
13
#include < Path.h>
13
14
#include < PathFinder.h>
14
15
#include < StringList.h>
@@ -115,6 +116,12 @@ static const char* kUsage =
115
116
" -p, --path <path>\n "
116
117
" Print only one path, the one for the installation location that\n "
117
118
" contains the path <path>.\n "
119
+ " -r, --resolvable <expression>\n "
120
+ " Print only one path, the one for the installation location for the\n "
121
+ " package providing the resolvable matching the expression\n "
122
+ " <expression>. The expressions can be a simple resolvable name or\n "
123
+ " a resolvable name with operator and version (e.g.\n "
124
+ " \" cmd:perl >= 5\" ; must be one argument).\n "
118
125
;
119
126
120
127
@@ -132,6 +139,7 @@ main(int argc, const char* const* argv)
132
139
const char * architecture = NULL ;
133
140
const char * dependency = NULL ;
134
141
const char * referencePath = NULL ;
142
+ const char * resolvable = NULL ;
135
143
bool existingOnly = false ;
136
144
const char * separator = NULL ;
137
145
@@ -141,11 +149,12 @@ main(int argc, const char* const* argv)
141
149
{ " dependency" , required_argument, 0 , ' d' },
142
150
{ " help" , no_argument, 0 , ' h' },
143
151
{ " path" , required_argument, 0 , ' p' },
152
+ { " resolvable" , required_argument, 0 , ' pr' },
144
153
{ 0 , 0 , 0 , 0 }
145
154
};
146
155
147
156
opterr = 0 ; // don't print errors
148
- int c = getopt_long (argc, (char **)argv, " +a:c:d:ehlp:" ,
157
+ int c = getopt_long (argc, (char **)argv, " +a:c:d:ehlp:r: " ,
149
158
sLongOptions , NULL );
150
159
if (c == -1 )
151
160
break ;
@@ -183,6 +192,10 @@ main(int argc, const char* const* argv)
183
192
referencePath = optarg;
184
193
break ;
185
194
195
+ case ' r' :
196
+ resolvable = optarg;
197
+ break ;
198
+
186
199
default :
187
200
print_usage_and_exit (true );
188
201
break ;
@@ -199,6 +212,10 @@ main(int argc, const char* const* argv)
199
212
if (optind >= argc)
200
213
subPath = argv[optind++];
201
214
215
+ // only one of path or resolvable may be specified
216
+ if (referencePath != NULL && resolvable != NULL )
217
+ print_usage_and_exit (true );
218
+
202
219
// resolve the directory constant
203
220
path_base_directory baseDirectory = B_FIND_PATH_IMAGE_PATH;
204
221
bool found = false ;
@@ -217,11 +234,19 @@ main(int argc, const char* const* argv)
217
234
exit (1 );
218
235
}
219
236
220
- if (referencePath != NULL ) {
237
+ if (referencePath != NULL || resolvable != NULL ) {
238
+ BPathFinder pathFinder;
239
+ if (referencePath != NULL ) {
240
+ pathFinder.SetTo (referencePath, dependency);
241
+ } else {
242
+ pathFinder.SetTo (
243
+ BPackageKit::BPackageResolvableExpression (resolvable),
244
+ dependency);
245
+ }
246
+
221
247
BPath path;
222
- status_t error = BPathFinder (referencePath, dependency).FindPath (
223
- architecture, baseDirectory, subPath,
224
- existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0 , path);
248
+ status_t error =pathFinder.FindPath (architecture, baseDirectory,
249
+ subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0 , path);
225
250
if (error != B_OK) {
226
251
fprintf (stderr, " Error: Failed to find path: %s\n " ,
227
252
strerror (error));
0 commit comments