xbps-query(8: added --cat=FILE mode support.
- This mode prints to stdout the matching FILE stored in a binary package. - ABI break: renamed xbps_get_pkg_plist_from_binpkg() xbps_binpkg_get_plist(). - Added xbps_binpkg_get_file() as a generic way to get pkg file contents. - Removed useless comments from xbps_api_impl.h.
This commit is contained in:
@@ -46,6 +46,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 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 *,
|
||||
bool *);
|
||||
|
||||
@@ -62,6 +62,7 @@ usage(bool fail)
|
||||
" -o --ownedby FILE Search for package files by matching STRING or REGEX\n"
|
||||
" -S --show PKG Show information for PKG [default mode]\n"
|
||||
" -s --search PKG Search for packages by matching PKG, STRING or REGEX\n"
|
||||
" --cat=FILE PKG Print FILE from PKG binpkg to stdout\n"
|
||||
" -f --files PKG Show package files for PKG\n"
|
||||
" -x --deps PKG Show dependencies for PKG\n"
|
||||
" -X --revdeps PKG Show reverse dependencies for PKG\n");
|
||||
@@ -86,7 +87,6 @@ main(int argc, char **argv)
|
||||
{ "ownedby", required_argument, NULL, 'o' },
|
||||
{ "property", required_argument, NULL, 'p' },
|
||||
{ "repository", optional_argument, NULL, 'R' },
|
||||
{ "regex", no_argument, NULL, 0 },
|
||||
{ "rootdir", required_argument, NULL, 'r' },
|
||||
{ "show", required_argument, NULL, 'S' },
|
||||
{ "search", required_argument, NULL, 's' },
|
||||
@@ -95,17 +95,19 @@ main(int argc, char **argv)
|
||||
{ "files", required_argument, NULL, 'f' },
|
||||
{ "deps", required_argument, NULL, 'x' },
|
||||
{ "revdeps", required_argument, NULL, 'X' },
|
||||
{ "regex", no_argument, NULL, 0 },
|
||||
{ "fulldeptree", no_argument, NULL, 1 },
|
||||
{ "cat", required_argument, NULL, 2 },
|
||||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
struct xbps_handle xh;
|
||||
const char *pkg, *rootdir, *cachedir, *confdir, *props;
|
||||
const char *pkg, *rootdir, *cachedir, *confdir, *props, *catfile;
|
||||
int c, flags, rv;
|
||||
bool list_pkgs, list_repos, orphans, own;
|
||||
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
|
||||
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
|
||||
|
||||
rootdir = cachedir = confdir = props = pkg = NULL;
|
||||
rootdir = cachedir = confdir = props = pkg = catfile = NULL;
|
||||
flags = rv = c = 0;
|
||||
list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false;
|
||||
list_manual = show_prop = show_files = false;
|
||||
@@ -195,6 +197,9 @@ main(int argc, char **argv)
|
||||
case 1:
|
||||
fulldeptree = true;
|
||||
break;
|
||||
case 2:
|
||||
catfile = optarg;
|
||||
break;
|
||||
case '?':
|
||||
usage(true);
|
||||
/* NOTREACHED */
|
||||
@@ -256,6 +261,10 @@ main(int argc, char **argv)
|
||||
/* search mode */
|
||||
rv = search(&xh, repo_mode, pkg, props, regex);
|
||||
|
||||
} else if (catfile) {
|
||||
/* repo cat file mode */
|
||||
rv = repo_cat_file(&xh, pkg, catfile);
|
||||
|
||||
} else if (show || show_prop) {
|
||||
/* show mode */
|
||||
if (repo_mode)
|
||||
|
||||
@@ -136,7 +136,7 @@ repo_match_cb(struct xbps_handle *xhp,
|
||||
|
||||
bfile = xbps_repository_pkg_path(xhp, obj);
|
||||
assert(bfile);
|
||||
filesd = xbps_get_pkg_plist_from_binpkg(bfile, "./files.plist");
|
||||
filesd = xbps_binpkg_get_plist(bfile, "/files.plist");
|
||||
if (filesd == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s: couldn't fetch files.plist from %s: %s\n",
|
||||
pkgver, bfile, strerror(errno));
|
||||
|
||||
@@ -307,6 +307,31 @@ repo_show_pkg_info(struct xbps_handle *xhp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
char *url, *buf;
|
||||
|
||||
pkgd = xbps_rpool_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);
|
||||
buf = xbps_binpkg_get_file(url, file);
|
||||
free(url);
|
||||
if (buf == NULL)
|
||||
return ENOENT;
|
||||
|
||||
printf("%s", buf);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.Dd November 5, 2014
|
||||
.Dd November 17, 2014
|
||||
.Dt XBPS-QUERY 8
|
||||
.Sh NAME
|
||||
.Nm xbps-query
|
||||
@@ -211,6 +211,12 @@ If the
|
||||
option is set, the matched
|
||||
.Ar PKG
|
||||
in repositories will be shown.
|
||||
.It Fl -repository Fl -cat Ar FILE Ar PKG
|
||||
Prints the file
|
||||
.Ar FILE
|
||||
stored in binary package
|
||||
.Ar PKG
|
||||
to stdout. This expects an absolute path.
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width XBPS_TARGET_ARCH
|
||||
|
||||
Reference in New Issue
Block a user