diff --git a/NEWS b/NEWS index 20c15225..c7b24841 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,8 @@ xbps-X.XX.X (2020-XX-XX): * xbps-remove(1): fix dry run cache cleaning inconsistencies. [duncaen] + * xbps-query(1): --cat now works in either repo or pkgdb mode. [duncaen] + * xbps.d(5): describe ignorepkg more precisely. [chocimier] xbps-0.59.1 (2020-04-01): diff --git a/bin/xbps-query/defs.h b/bin/xbps-query/defs.h index 1ccd710e..2a174725 100644 --- a/bin/xbps-query/defs.h +++ b/bin/xbps-query/defs.h @@ -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 *, diff --git a/bin/xbps-query/main.c b/bin/xbps-query/main.c index b893cadd..44316c1a 100644 --- a/bin/xbps-query/main.c +++ b/bin/xbps-query/main.c @@ -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) diff --git a/bin/xbps-query/show-info-files.c b/bin/xbps-query/show-info-files.c index dc3b8fe4..2acbe922 100644 --- a/bin/xbps-query/show-info-files.c +++ b/bin/xbps-query/show-info-files.c @@ -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) { diff --git a/tests/xbps/xbps-query/Kyuafile b/tests/xbps/xbps-query/Kyuafile index 20bc1fdf..3a3dbfe0 100644 --- a/tests/xbps/xbps-query/Kyuafile +++ b/tests/xbps/xbps-query/Kyuafile @@ -3,3 +3,4 @@ syntax("kyuafile", 1) test_suite("xbps-query") atf_test_program{name="ignore_repos_test"} atf_test_program{name="remote_test"} +atf_test_program{name="query_test"} diff --git a/tests/xbps/xbps-query/Makefile b/tests/xbps/xbps-query/Makefile index 0d5271a5..7c0b8294 100644 --- a/tests/xbps/xbps-query/Makefile +++ b/tests/xbps/xbps-query/Makefile @@ -1,7 +1,7 @@ TOPDIR = ../../.. -include $(TOPDIR)/config.mk -TESTSHELL = ignore_repos_test remote_test +TESTSHELL = ignore_repos_test remote_test query_test TESTSSUBDIR = xbps/xbps-query EXTRA_FILES = Kyuafile diff --git a/tests/xbps/xbps-query/query_test.sh b/tests/xbps/xbps-query/query_test.sh new file mode 100644 index 00000000..284e1470 --- /dev/null +++ b/tests/xbps/xbps-query/query_test.sh @@ -0,0 +1,45 @@ +#! /usr/bin/env atf-sh + +cat_file_head() { + atf_set "descr" "xbps-query(1) --cat: cat pkgdb file" +} + +cat_file_body() { + mkdir -p repo pkg_A/bin + echo "hello world!" > pkg_A/bin/file + cd repo + xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a *.xbps + atf_check_equal $? 0 + cd .. + mkdir root + xbps-install -r root --repository=repo -dvy foo + atf_check_equal $? 0 + res=$(xbps-query -r root -dv -C empty.conf --cat /bin/file foo) + atf_check_equal $? 0 + atf_check_equal "$res" "hello world!" +} + +repo_cat_file_head() { + atf_set "descr" "xbps-query(1) -R --cat: cat repo file" +} + +repo_cat_file_body() { + mkdir -p repo pkg_A/bin + echo "hello world!" > pkg_A/bin/file + cd repo + xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a *.xbps + atf_check_equal $? 0 + cd .. + res=$(xbps-query -r root -dv --repository=repo -C empty.conf --cat /bin/file foo) + atf_check_equal $? 0 + atf_check_equal "$res" "hello world!" +} + +atf_init_test_cases() { + atf_add_test_case cat_file + atf_add_test_case repo_cat_file +}