xbps-query: add repo and pkgdb mode to --cat

This commit is contained in:
Duncan Overbruck
2021-12-19 16:07:25 +01:00
parent 3939d9aeb5
commit f5355e53cd
7 changed files with 75 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ int show_pkg_info_from_metadir(struct xbps_handle *, const char *,
int show_pkg_files(xbps_dictionary_t);
int show_pkg_files_from_metadir(struct xbps_handle *, const char *);
int repo_show_pkg_files(struct xbps_handle *, const char *);
int cat_file(struct xbps_handle *, const char *, const char *);
int repo_cat_file(struct xbps_handle *, const char *, const char *);
int repo_show_pkg_info(struct xbps_handle *, const char *, const char *);
int repo_show_pkg_namedesc(struct xbps_handle *, xbps_object_t, void *,

View File

@@ -288,8 +288,10 @@ main(int argc, char **argv)
} else if (catfile) {
/* repo cat file mode */
rv = repo_cat_file(&xh, pkg, catfile);
if (repo_mode)
rv = repo_cat_file(&xh, pkg, catfile);
else
rv = cat_file(&xh, pkg, catfile);
} else if (show || show_prop) {
/* show mode */
if (repo_mode)

View File

@@ -281,6 +281,27 @@ repo_show_pkg_info(struct xbps_handle *xhp,
return 0;
}
int
cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
{
xbps_dictionary_t pkgd;
char *url;
int rv;
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgd == NULL)
return errno;
url = xbps_repository_pkg_path(xhp, pkgd);
if (url == NULL)
return EINVAL;
xbps_dbg_printf(xhp, "matched pkg at %s\n", url);
rv = xbps_archive_fetch_file_into_fd(url, file, STDOUT_FILENO);
free(url);
return rv;
}
int
repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
{