Skip to content

Commit 546e3e7

Browse files
committed
bin/xbps-query: use xbps_pkg_path_or_url
1 parent a8d4fc3 commit 546e3e7

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

bin/xbps-query/ownedby.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#include <stdio.h>
27-
#include <stdbool.h>
28-
#include <stdlib.h>
29-
#include <string.h>
26+
#include <assert.h>
27+
#include <dirent.h>
3028
#include <errno.h>
3129
#include <fnmatch.h>
32-
#include <dirent.h>
33-
#include <assert.h>
30+
#include <limits.h>
3431
#include <regex.h>
32+
#include <stdbool.h>
33+
#include <stdio.h>
34+
#include <stdlib.h>
35+
#include <string.h>
3536

3637
#include <xbps.h>
3738
#include "defs.h"
@@ -133,20 +134,24 @@ repo_match_cb(struct xbps_handle *xhp,
133134
void *arg,
134135
bool *done UNUSED)
135136
{
137+
char bfile[PATH_MAX];
136138
xbps_dictionary_t filesd;
137139
xbps_array_t files_keys;
138140
struct ffdata *ffd = arg;
139141
const char *pkgver = NULL;
140-
char *bfile;
142+
int r;
141143

142144
xbps_dictionary_set_cstring_nocopy(obj, "repository", ffd->repouri);
143145
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
144146

145-
bfile = xbps_repository_pkg_path(xhp, obj);
146-
assert(bfile);
147+
r = xbps_pkg_path_or_url(xhp, bfile, sizeof(bfile), obj);
148+
if (r < 0) {
149+
xbps_error_printf("could not get package path: %s\n", strerror(-r));
150+
return -r;
151+
}
147152
filesd = xbps_archive_fetch_plist(bfile, "/files.plist");
148-
if (filesd == NULL) {
149-
xbps_dbg_printf("%s: couldn't fetch files.plist from %s: %s\n",
153+
if (!filesd) {
154+
xbps_error_printf("%s: couldn't fetch files.plist from %s: %s\n",
150155
pkgver, bfile, strerror(errno));
151156
return EINVAL;
152157
}
@@ -157,7 +162,6 @@ repo_match_cb(struct xbps_handle *xhp,
157162
}
158163
xbps_object_release(files_keys);
159164
xbps_object_release(filesd);
160-
free(bfile);
161165

162166
return 0;
163167
}

bin/xbps-query/show-info-files.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -284,60 +284,69 @@ repo_show_pkg_info(struct xbps_handle *xhp,
284284
int
285285
cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
286286
{
287+
char bfile[PATH_MAX];
287288
xbps_dictionary_t pkgd;
288-
char *url;
289289
int rv;
290290

291291
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
292292
if (pkgd == NULL)
293293
return errno;
294294

295-
url = xbps_repository_pkg_path(xhp, pkgd);
296-
if (url == NULL)
297-
return EINVAL;
295+
rv = xbps_pkg_path_or_url(xhp, bfile, sizeof(bfile), pkgd);
296+
if (rv < 0) {
297+
xbps_error_printf("could not get package path: %s\n", strerror(-rv));
298+
return -rv;
299+
}
298300

299-
xbps_dbg_printf("matched pkg at %s\n", url);
300-
rv = xbps_archive_fetch_file_into_fd(url, file, STDOUT_FILENO);
301-
free(url);
302-
return rv;
301+
return xbps_archive_fetch_file_into_fd(bfile, file, STDOUT_FILENO);
303302
}
304303

305304
int
306305
repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
307306
{
307+
char bfile[PATH_MAX];
308308
xbps_dictionary_t pkgd;
309-
char *url;
310309
int rv;
311310

312311
pkgd = xbps_rpool_get_pkg(xhp, pkg);
313312
if (pkgd == NULL)
314313
return errno;
315314

316-
url = xbps_repository_pkg_path(xhp, pkgd);
317-
if (url == NULL)
318-
return EINVAL;
315+
rv = xbps_pkg_path_or_url(xhp, bfile, sizeof(bfile), pkgd);
316+
if (rv < 0) {
317+
xbps_error_printf("could not get package path: %s\n", strerror(-rv));
318+
return -rv;
319+
}
319320

320-
xbps_dbg_printf("matched pkg at %s\n", url);
321-
rv = xbps_archive_fetch_file_into_fd(url, file, STDOUT_FILENO);
322-
free(url);
323-
return rv;
321+
return xbps_archive_fetch_file_into_fd(bfile, file, STDOUT_FILENO);
324322
}
325323

326324
int
327325
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
328326
{
329-
xbps_dictionary_t pkgd;
327+
char bfile[PATH_MAX];
328+
xbps_dictionary_t pkgd, filesd;
330329
int rv;
331330

332-
pkgd = xbps_rpool_get_pkg_plist(xhp, pkg, "/files.plist");
333-
if (pkgd == NULL) {
331+
pkgd = xbps_rpool_get_pkg(xhp, pkg);
332+
if (pkgd == NULL)
333+
return errno;
334+
335+
rv = xbps_pkg_path_or_url(xhp, bfile, sizeof(bfile), pkgd);
336+
if (rv < 0) {
337+
xbps_error_printf("could not get package path: %s\n", strerror(-rv));
338+
return -rv;
339+
}
340+
341+
filesd = xbps_archive_fetch_plist(bfile, "/files.plist");
342+
if (filesd == NULL) {
334343
if (errno != ENOTSUP && errno != ENOENT) {
335344
xbps_error_printf("Unexpected error: %s\n", strerror(errno));
336345
}
337346
return errno;
338347
}
339348

340-
rv = show_pkg_files(pkgd);
341-
xbps_object_release(pkgd);
349+
rv = show_pkg_files(filesd);
350+
xbps_object_release(filesd);
342351
return rv;
343352
}

0 commit comments

Comments
 (0)