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:
		
							
								
								
									
										5
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								NEWS
									
									
									
									
									
								
							| @@ -1,5 +1,10 @@ | |||||||
| xbps-0.42 (???): | xbps-0.42 (???): | ||||||
|  |  | ||||||
|  |  * xbps-query(8): added --cat=FILE mode to print FILE stored in a binary package | ||||||
|  |    to stdout. This works exactly as the --files mode: if the matching binary package | ||||||
|  |    is not available in the cachedir, xbps will establish a network connection | ||||||
|  |    to the target repository to get the contents of FILE on the fly. | ||||||
|  |  | ||||||
|  * Get rid of repodata index-files, that contained all pkg files of a repository |  * Get rid of repodata index-files, that contained all pkg files of a repository | ||||||
|    in the archive. That file was so huge that incresed the repository archive |    in the archive. That file was so huge that incresed the repository archive | ||||||
|    size by 8x. That means that `xbps-query -Ro` will now make N parallel connections |    size by 8x. That means that `xbps-query -Ro` will now make N parallel connections | ||||||
|   | |||||||
| @@ -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(xbps_dictionary_t); | ||||||
| int	show_pkg_files_from_metadir(struct xbps_handle *, const char *); | int	show_pkg_files_from_metadir(struct xbps_handle *, const char *); | ||||||
| int	repo_show_pkg_files(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_info(struct xbps_handle *, const char *, const char *); | ||||||
| int 	repo_show_pkg_namedesc(struct xbps_handle *, xbps_object_t, void *, | int 	repo_show_pkg_namedesc(struct xbps_handle *, xbps_object_t, void *, | ||||||
| 		bool *); | 		bool *); | ||||||
|   | |||||||
| @@ -62,6 +62,7 @@ usage(bool fail) | |||||||
| 	    " -o --ownedby FILE        Search for package files by matching STRING or REGEX\n" | 	    " -o --ownedby FILE        Search for package files by matching STRING or REGEX\n" | ||||||
| 	    " -S --show PKG            Show information for PKG [default mode]\n" | 	    " -S --show PKG            Show information for PKG [default mode]\n" | ||||||
| 	    " -s --search PKG          Search for packages by matching PKG, STRING or REGEX\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" | 	    " -f --files PKG           Show package files for PKG\n" | ||||||
| 	    " -x --deps PKG            Show dependencies for PKG\n" | 	    " -x --deps PKG            Show dependencies for PKG\n" | ||||||
| 	    " -X --revdeps PKG         Show reverse 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' }, | 		{ "ownedby", required_argument, NULL, 'o' }, | ||||||
| 		{ "property", required_argument, NULL, 'p' }, | 		{ "property", required_argument, NULL, 'p' }, | ||||||
| 		{ "repository", optional_argument, NULL, 'R' }, | 		{ "repository", optional_argument, NULL, 'R' }, | ||||||
| 		{ "regex", no_argument, NULL, 0 }, |  | ||||||
| 		{ "rootdir", required_argument, NULL, 'r' }, | 		{ "rootdir", required_argument, NULL, 'r' }, | ||||||
| 		{ "show", required_argument, NULL, 'S' }, | 		{ "show", required_argument, NULL, 'S' }, | ||||||
| 		{ "search", required_argument, NULL, 's' }, | 		{ "search", required_argument, NULL, 's' }, | ||||||
| @@ -95,17 +95,19 @@ main(int argc, char **argv) | |||||||
| 		{ "files", required_argument, NULL, 'f' }, | 		{ "files", required_argument, NULL, 'f' }, | ||||||
| 		{ "deps", required_argument, NULL, 'x' }, | 		{ "deps", required_argument, NULL, 'x' }, | ||||||
| 		{ "revdeps", required_argument, NULL, 'X' }, | 		{ "revdeps", required_argument, NULL, 'X' }, | ||||||
|  | 		{ "regex", no_argument, NULL, 0 }, | ||||||
| 		{ "fulldeptree", no_argument, NULL, 1 }, | 		{ "fulldeptree", no_argument, NULL, 1 }, | ||||||
|  | 		{ "cat", required_argument, NULL, 2 }, | ||||||
| 		{ NULL, 0, NULL, 0 }, | 		{ NULL, 0, NULL, 0 }, | ||||||
| 	}; | 	}; | ||||||
| 	struct xbps_handle xh; | 	struct xbps_handle xh; | ||||||
| 	const char *pkg, *rootdir, *cachedir, *confdir, *props; | 	const char *pkg, *rootdir, *cachedir, *confdir, *props, *catfile; | ||||||
| 	int c, flags, rv; | 	int c, flags, rv; | ||||||
| 	bool list_pkgs, list_repos, orphans, own; | 	bool list_pkgs, list_repos, orphans, own; | ||||||
| 	bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps; | 	bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps; | ||||||
| 	bool show, pkg_search, regex, repo_mode, opmode, fulldeptree; | 	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; | 	flags = rv = c = 0; | ||||||
| 	list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false; | 	list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false; | ||||||
| 	list_manual = show_prop = show_files = false; | 	list_manual = show_prop = show_files = false; | ||||||
| @@ -195,6 +197,9 @@ main(int argc, char **argv) | |||||||
| 		case 1: | 		case 1: | ||||||
| 			fulldeptree = true; | 			fulldeptree = true; | ||||||
| 			break; | 			break; | ||||||
|  | 		case 2: | ||||||
|  | 			catfile = optarg; | ||||||
|  | 			break; | ||||||
| 		case '?': | 		case '?': | ||||||
| 			usage(true); | 			usage(true); | ||||||
| 			/* NOTREACHED */ | 			/* NOTREACHED */ | ||||||
| @@ -256,6 +261,10 @@ main(int argc, char **argv) | |||||||
| 		/* search mode */ | 		/* search mode */ | ||||||
| 		rv = search(&xh, repo_mode, pkg, props, regex); | 		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) { | 	} else if (show || show_prop) { | ||||||
| 		/* show mode */ | 		/* show mode */ | ||||||
| 		if (repo_mode) | 		if (repo_mode) | ||||||
|   | |||||||
| @@ -136,7 +136,7 @@ repo_match_cb(struct xbps_handle *xhp, | |||||||
|  |  | ||||||
| 	bfile = xbps_repository_pkg_path(xhp, obj); | 	bfile = xbps_repository_pkg_path(xhp, obj); | ||||||
| 	assert(bfile); | 	assert(bfile); | ||||||
| 	filesd = xbps_get_pkg_plist_from_binpkg(bfile, "./files.plist"); | 	filesd = xbps_binpkg_get_plist(bfile, "/files.plist"); | ||||||
| 	if (filesd == NULL) { | 	if (filesd == NULL) { | ||||||
| 		xbps_dbg_printf(xhp, "%s: couldn't fetch files.plist from %s: %s\n", | 		xbps_dbg_printf(xhp, "%s: couldn't fetch files.plist from %s: %s\n", | ||||||
| 		    pkgver, bfile, strerror(errno)); | 		    pkgver, bfile, strerror(errno)); | ||||||
|   | |||||||
| @@ -307,6 +307,31 @@ repo_show_pkg_info(struct xbps_handle *xhp, | |||||||
| 	return 0; | 	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 | int | ||||||
| repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg) | 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 | .Dt XBPS-QUERY 8 | ||||||
| .Sh NAME | .Sh NAME | ||||||
| .Nm xbps-query | .Nm xbps-query | ||||||
| @@ -211,6 +211,12 @@ If the | |||||||
| option is set, the matched | option is set, the matched | ||||||
| .Ar PKG | .Ar PKG | ||||||
| in repositories will be shown. | 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 | .El | ||||||
| .Sh ENVIRONMENT | .Sh ENVIRONMENT | ||||||
| .Bl -tag -width XBPS_TARGET_ARCH | .Bl -tag -width XBPS_TARGET_ARCH | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force | |||||||
| 		/* | 		/* | ||||||
| 		 * Read metadata props plist dictionary from binary package. | 		 * Read metadata props plist dictionary from binary package. | ||||||
| 		 */ | 		 */ | ||||||
| 		binpkgd = xbps_get_pkg_plist_from_binpkg(pkg, "./props.plist"); | 		binpkgd = xbps_binpkg_get_plist(pkg, "/props.plist"); | ||||||
| 		if (binpkgd == NULL) { | 		if (binpkgd == NULL) { | ||||||
| 			fprintf(stderr, "index: failed to read %s metadata for " | 			fprintf(stderr, "index: failed to read %s metadata for " | ||||||
| 			    "`%s', skipping!\n", XBPS_PKGPROPS, pkg); | 			    "`%s', skipping!\n", XBPS_PKGPROPS, pkg); | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ | |||||||
|  * |  * | ||||||
|  * This header documents the full API for the XBPS Library. |  * This header documents the full API for the XBPS Library. | ||||||
|  */ |  */ | ||||||
| #define XBPS_API_VERSION	"20141113-1" | #define XBPS_API_VERSION	"20141117" | ||||||
|  |  | ||||||
| #ifndef XBPS_VERSION | #ifndef XBPS_VERSION | ||||||
|  #define XBPS_VERSION		"UNSET" |  #define XBPS_VERSION		"UNSET" | ||||||
| @@ -1131,17 +1131,27 @@ int xbps_transaction_commit(struct xbps_handle *xhp); | |||||||
| /*@{*/ | /*@{*/ | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Internalizes a plist file in a binary package file stored locally or |  * Returns a buffer of a file stored in a binary package locally or | ||||||
|  * remotely as specified in \a fname. |  * remotely as specified in the url \a url. | ||||||
|  * |  * | ||||||
|  * @param[in] fname Full URL to binary package file (local or remote path). |  * @param[in] url Full URL to binary package file (local or remote path). | ||||||
|  * @param[in] plistf Plist file name to internalize. |  * @param[in] fname File name to match. | ||||||
|  |  * | ||||||
|  |  * @return A malloc(3)ed buffer with the contents of \a fname, NULL otherwise | ||||||
|  |  * and errno is set appropiately. | ||||||
|  |  */ | ||||||
|  | char *xbps_binpkg_get_file(const char *url, const char *fname); | ||||||
|  | /** | ||||||
|  |  * Internalizes a plist file in a binary package file stored locally or | ||||||
|  |  * remotely as specified in the url \a url. | ||||||
|  |  * | ||||||
|  |  * @param[in] url Full URL to binary package file (local or remote path). | ||||||
|  |  * @param[in] p Proplist file name to internalize as a dictionary. | ||||||
|  * |  * | ||||||
|  * @return An internalized proplib dictionary, otherwise NULL and |  * @return An internalized proplib dictionary, otherwise NULL and | ||||||
|  * errno is set appropiately. |  * errno is set appropiately. | ||||||
|  */ |  */ | ||||||
| xbps_dictionary_t xbps_get_pkg_plist_from_binpkg(const char *fname, | xbps_dictionary_t xbps_binpkg_get_plist(const char *url, const char *p); | ||||||
| 						 const char *plistf); |  | ||||||
|  |  | ||||||
| /*@}*/ | /*@}*/ | ||||||
|  |  | ||||||
| @@ -1410,17 +1420,6 @@ int xbps_repo_key_import(struct xbps_repo *repo); | |||||||
| /** @addtogroup archive_util */ | /** @addtogroup archive_util */ | ||||||
| /*@{*/ | /*@{*/ | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Returns a proplib dictionary if \a entry is matched in the \a ar archive. |  | ||||||
|  * |  | ||||||
|  * @param[in] ar The archive object. |  | ||||||
|  * @param[in] entry The archive_entry object (must be filled in properly). |  | ||||||
|  * |  | ||||||
|  * @return The internalized proplib dictionary, NULL otherwise. |  | ||||||
|  */ |  | ||||||
| xbps_dictionary_t xbps_archive_get_dictionary(struct archive *ar, |  | ||||||
| 				struct archive_entry *entry); |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Appends a file to the \a ar archive by using a memory buffer \a buf of |  * Appends a file to the \a ar archive by using a memory buffer \a buf of | ||||||
|  * size \a sizelen. |  * size \a sizelen. | ||||||
|   | |||||||
| @@ -96,166 +96,58 @@ | |||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @private |  * @private | ||||||
|  * From lib/external/dewey.c |  | ||||||
|  */ |  */ | ||||||
| int HIDDEN dewey_match(const char *, const char *); | int HIDDEN dewey_match(const char *, const char *); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/pkgdb.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_pkgdb_init(struct xbps_handle *); | int HIDDEN xbps_pkgdb_init(struct xbps_handle *); | ||||||
| void HIDDEN xbps_pkgdb_release(struct xbps_handle *); | void HIDDEN xbps_pkgdb_release(struct xbps_handle *); | ||||||
| int HIDDEN xbps_pkgdb_conversion(struct xbps_handle *); | int HIDDEN xbps_pkgdb_conversion(struct xbps_handle *); | ||||||
|  | int HIDDEN xbps_array_replace_dict_by_name(xbps_array_t, xbps_dictionary_t, | ||||||
| /** | 		const char *); | ||||||
|  * @private | int HIDDEN xbps_array_replace_dict_by_pattern(xbps_array_t, xbps_dictionary_t, | ||||||
|  * From lib/plist.c | 		const char *); | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_array_replace_dict_by_name(xbps_array_t, |  | ||||||
| 					   xbps_dictionary_t, |  | ||||||
| 					   const char *); |  | ||||||
| int HIDDEN xbps_array_replace_dict_by_pattern(xbps_array_t, |  | ||||||
| 					      xbps_dictionary_t, |  | ||||||
| 					       const char *); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/plist_remove.c |  | ||||||
|  */ |  | ||||||
| bool HIDDEN xbps_remove_pkg_from_array_by_name(xbps_array_t, const char *); | bool HIDDEN xbps_remove_pkg_from_array_by_name(xbps_array_t, const char *); | ||||||
| bool HIDDEN xbps_remove_pkg_from_array_by_pattern(xbps_array_t, const char *); | bool HIDDEN xbps_remove_pkg_from_array_by_pattern(xbps_array_t, const char *); | ||||||
| bool HIDDEN xbps_remove_pkg_from_array_by_pkgver(xbps_array_t, const char *); | bool HIDDEN xbps_remove_pkg_from_array_by_pkgver(xbps_array_t, const char *); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/download.c |  | ||||||
|  */ |  | ||||||
| void HIDDEN xbps_fetch_set_cache_connection(int, int); | void HIDDEN xbps_fetch_set_cache_connection(int, int); | ||||||
| void HIDDEN xbps_fetch_unset_cache_connection(void); | void HIDDEN xbps_fetch_unset_cache_connection(void); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/package_msg.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_cb_message(struct xbps_handle *, xbps_dictionary_t, const char *); | int HIDDEN xbps_cb_message(struct xbps_handle *, xbps_dictionary_t, const char *); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/package_config_files.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_entry_is_a_conf_file(xbps_dictionary_t, const char *); | int HIDDEN xbps_entry_is_a_conf_file(xbps_dictionary_t, const char *); | ||||||
| int HIDDEN xbps_entry_install_conf_file(struct xbps_handle *, | int HIDDEN xbps_entry_install_conf_file(struct xbps_handle *, xbps_dictionary_t, | ||||||
| 					xbps_dictionary_t, | 		xbps_dictionary_t, struct archive_entry *, const char *, | ||||||
| 					xbps_dictionary_t, | 		const char *); | ||||||
| 					struct archive_entry *, | int HIDDEN xbps_repository_find_deps(struct xbps_handle *, xbps_array_t, | ||||||
| 					const char *, | 		xbps_dictionary_t); | ||||||
| 					const char *); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/repo.c |  | ||||||
|  */ |  | ||||||
| void HIDDEN xbps_repo_invalidate(struct xbps_repo *); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/repo_pkgdeps.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_repository_find_deps(struct xbps_handle *, |  | ||||||
| 				     xbps_array_t, |  | ||||||
| 				     xbps_dictionary_t); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/plist_find.c |  | ||||||
|  */ |  | ||||||
| xbps_dictionary_t HIDDEN xbps_find_pkg_in_dict(xbps_dictionary_t, const char *); | xbps_dictionary_t HIDDEN xbps_find_pkg_in_dict(xbps_dictionary_t, const char *); | ||||||
| xbps_dictionary_t HIDDEN xbps_find_virtualpkg_in_dict(struct xbps_handle *, xbps_dictionary_t, const char *); | xbps_dictionary_t HIDDEN xbps_find_virtualpkg_in_dict(struct xbps_handle *, | ||||||
| xbps_dictionary_t HIDDEN xbps_find_pkg_in_array(xbps_array_t, const char *, const char *); | 		xbps_dictionary_t, const char *); | ||||||
| xbps_dictionary_t HIDDEN xbps_find_virtualpkg_in_array(struct xbps_handle *, xbps_array_t, const char *, const char *); | xbps_dictionary_t HIDDEN xbps_find_pkg_in_array(xbps_array_t, const char *, | ||||||
| /** | 		const char *); | ||||||
|  * @private | xbps_dictionary_t HIDDEN xbps_find_virtualpkg_in_array(struct xbps_handle *, | ||||||
|  * From lib/transaction_revdeps.c | 		xbps_array_t, const char *, const char *); | ||||||
|  */ |  | ||||||
| void HIDDEN xbps_transaction_revdeps(struct xbps_handle *, xbps_array_t); | void HIDDEN xbps_transaction_revdeps(struct xbps_handle *, xbps_array_t); | ||||||
|  | bool HIDDEN xbps_transaction_shlibs(struct xbps_handle *, xbps_array_t, | ||||||
| /** | 		xbps_array_t); | ||||||
|  * @privuate |  | ||||||
|  * From lib/transaction_shlibs.c |  | ||||||
|  */ |  | ||||||
| bool HIDDEN xbps_transaction_shlibs(struct xbps_handle *, xbps_array_t, xbps_array_t); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/transaction_dictionary.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_transaction_init(struct xbps_handle *); | int HIDDEN xbps_transaction_init(struct xbps_handle *); | ||||||
|  | int HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, | ||||||
| int HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, xbps_dictionary_t, bool); | 		xbps_dictionary_t, bool); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/repo_sync.c |  | ||||||
|  */ |  | ||||||
| char HIDDEN *xbps_get_remote_repo_string(const char *); | char HIDDEN *xbps_get_remote_repo_string(const char *); | ||||||
| int HIDDEN xbps_repo_sync(struct xbps_handle *, const char *); | int HIDDEN xbps_repo_sync(struct xbps_handle *, const char *); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/util_hash.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_file_hash_check_dictionary(struct xbps_handle *, | int HIDDEN xbps_file_hash_check_dictionary(struct xbps_handle *, | ||||||
| 					   xbps_dictionary_t d, | 		xbps_dictionary_t, const char *, const char *); | ||||||
| 					   const char *, |  | ||||||
| 					   const char *); |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/external/fexec.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_file_exec(struct xbps_handle *, const char *, ...); | int HIDDEN xbps_file_exec(struct xbps_handle *, const char *, ...); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/cb_util.c |  | ||||||
|  */ |  | ||||||
| void HIDDEN xbps_set_cb_fetch(struct xbps_handle *, off_t, off_t, off_t, | void HIDDEN xbps_set_cb_fetch(struct xbps_handle *, off_t, off_t, off_t, | ||||||
| 			      const char *, bool, bool, bool); | 		const char *, bool, bool, bool); | ||||||
| int HIDDEN xbps_set_cb_state(struct xbps_handle *, xbps_state_t, int, | int HIDDEN xbps_set_cb_state(struct xbps_handle *, xbps_state_t, int, | ||||||
| 			     const char *, const char *, ...); | 		const char *, const char *, ...); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/package_unpack.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_unpack_binary_pkg(struct xbps_handle *, xbps_dictionary_t); | int HIDDEN xbps_unpack_binary_pkg(struct xbps_handle *, xbps_dictionary_t); | ||||||
|  |  | ||||||
| int HIDDEN xbps_transaction_package_replace(struct xbps_handle *, xbps_array_t); | int HIDDEN xbps_transaction_package_replace(struct xbps_handle *, xbps_array_t); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/package_remove.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_remove_pkg(struct xbps_handle *, const char *, bool); | int HIDDEN xbps_remove_pkg(struct xbps_handle *, const char *, bool); | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/package_register.c |  | ||||||
|  */ |  | ||||||
| int HIDDEN xbps_register_pkg(struct xbps_handle *, xbps_dictionary_t); | int HIDDEN xbps_register_pkg(struct xbps_handle *, xbps_dictionary_t); | ||||||
|  | void HIDDEN xbps_pkg_find_conflicts(struct xbps_handle *, xbps_array_t, | ||||||
| /** | 		xbps_dictionary_t); | ||||||
|  * @private | char HIDDEN *xbps_archive_get_file(struct archive *, struct archive_entry *); | ||||||
|  * From lib/package_conflicts.c | xbps_dictionary_t HIDDEN xbps_archive_get_dictionary(struct archive *, | ||||||
|  */ | 		struct archive_entry *); | ||||||
| void HIDDEN xbps_pkg_find_conflicts(struct xbps_handle *, |  | ||||||
| 				    xbps_array_t, |  | ||||||
| 				    xbps_dictionary_t); |  | ||||||
| /** |  | ||||||
|  * @private |  | ||||||
|  * From lib/plist_find.c |  | ||||||
|  */ |  | ||||||
| const char HIDDEN *vpkg_user_conf(struct xbps_handle *, const char *, bool); | const char HIDDEN *vpkg_user_conf(struct xbps_handle *, const char *, bool); | ||||||
|  |  | ||||||
| #endif /* !_XBPS_API_IMPL_H_ */ | #endif /* !_XBPS_API_IMPL_H_ */ | ||||||
|   | |||||||
| @@ -31,10 +31,9 @@ | |||||||
|  |  | ||||||
| #include "xbps_api_impl.h" | #include "xbps_api_impl.h" | ||||||
|  |  | ||||||
| xbps_dictionary_t HIDDEN | char HIDDEN * | ||||||
| xbps_archive_get_dictionary(struct archive *ar, struct archive_entry *entry) | xbps_archive_get_file(struct archive *ar, struct archive_entry *entry) | ||||||
| { | { | ||||||
| 	xbps_dictionary_t d = NULL; |  | ||||||
| 	size_t buflen; | 	size_t buflen; | ||||||
| 	ssize_t nbytes = -1; | 	ssize_t nbytes = -1; | ||||||
| 	char *buf; | 	char *buf; | ||||||
| @@ -43,7 +42,7 @@ xbps_archive_get_dictionary(struct archive *ar, struct archive_entry *entry) | |||||||
| 	assert(entry != NULL); | 	assert(entry != NULL); | ||||||
|  |  | ||||||
| 	buflen = (size_t)archive_entry_size(entry); | 	buflen = (size_t)archive_entry_size(entry); | ||||||
| 	buf = malloc(buflen); | 	buf = malloc(buflen+1); | ||||||
| 	if (buf == NULL) | 	if (buf == NULL) | ||||||
| 		return NULL; | 		return NULL; | ||||||
|  |  | ||||||
| @@ -52,14 +51,23 @@ xbps_archive_get_dictionary(struct archive *ar, struct archive_entry *entry) | |||||||
| 		free(buf); | 		free(buf); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
|  | 	buf[buflen] = '\0'; | ||||||
|  | 	return buf; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | xbps_dictionary_t HIDDEN | ||||||
|  | xbps_archive_get_dictionary(struct archive *ar, struct archive_entry *entry) | ||||||
|  | { | ||||||
|  | 	xbps_dictionary_t d = NULL; | ||||||
|  | 	char *buf; | ||||||
|  |  | ||||||
|  | 	if ((buf = xbps_archive_get_file(ar, entry)) == NULL) | ||||||
|  | 		return NULL; | ||||||
|  |  | ||||||
| 	/* If blob is already a dictionary we are done */ | 	/* If blob is already a dictionary we are done */ | ||||||
| 	d = xbps_dictionary_internalize(buf); | 	d = xbps_dictionary_internalize(buf); | ||||||
| 	if (xbps_object_type(d) == XBPS_TYPE_DICTIONARY) { | 	free(buf); | ||||||
| 		free(buf); | 	return d; | ||||||
| 		return d; |  | ||||||
| 	} |  | ||||||
| 	return NULL; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /*- | /*- | ||||||
|  * Copyright (c) 2009-2013 Juan Romero Pardines. |  * Copyright (c) 2009-2014 Juan Romero Pardines. | ||||||
|  * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg (at) NetBSD.org> |  * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg (at) NetBSD.org> | ||||||
|  * All rights reserved. |  * All rights reserved. | ||||||
|  * |  * | ||||||
| @@ -139,51 +139,45 @@ open_archive(const char *url) | |||||||
| 	return a; | 	return a; | ||||||
| } | } | ||||||
|  |  | ||||||
| xbps_dictionary_t | char * | ||||||
| xbps_get_pkg_plist_from_binpkg(const char *fname, const char *plistf) | xbps_binpkg_get_file(const char *url, const char *fname) | ||||||
| { | { | ||||||
| 	xbps_dictionary_t plistd = NULL; |  | ||||||
| 	struct archive *a; | 	struct archive *a; | ||||||
| 	struct archive_entry *entry; | 	struct archive_entry *entry; | ||||||
| 	const char *comptype; | 	char *buf = NULL; | ||||||
| 	int i = 0; |  | ||||||
|  |  | ||||||
| 	assert(fname != NULL); | 	assert(url); | ||||||
| 	assert(plistf != NULL); | 	assert(fname); | ||||||
|  |  | ||||||
| 	if ((a = open_archive(fname)) == NULL) | 	if ((a = open_archive(url)) == NULL) | ||||||
| 		return NULL; | 		return NULL; | ||||||
|  |  | ||||||
| 	/* |  | ||||||
| 	 * Save compression type string for future use. |  | ||||||
| 	 */ |  | ||||||
| 	comptype = archive_compression_name(a); |  | ||||||
|  |  | ||||||
| 	while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) { | 	while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) { | ||||||
| 		if (strcmp(archive_entry_pathname(entry), plistf)) { | 		const char *bfile; | ||||||
| 			archive_read_data_skip(a); |  | ||||||
| 			if (i >= 3) { | 		bfile = archive_entry_pathname(entry); | ||||||
| 				/* | 		bfile++; /* skip first dot */ | ||||||
| 				 * Archive does not contain required | 		if (strcmp(bfile, fname) == 0) { | ||||||
| 				 * plist file, discard it completely. | 			buf = xbps_archive_get_file(a, entry); | ||||||
| 				 */ |  | ||||||
| 				errno = ENOENT; |  | ||||||
| 				break; |  | ||||||
| 			} |  | ||||||
| 			i++; |  | ||||||
| 			continue; |  | ||||||
| 		} |  | ||||||
| 		plistd = xbps_archive_get_dictionary(a, entry); |  | ||||||
| 		if (plistd == NULL) { |  | ||||||
| 			errno = EINVAL; |  | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		xbps_dictionary_set_cstring_nocopy(plistd, | 		archive_read_data_skip(a); | ||||||
| 		    "archive-compression-type", comptype); |  | ||||||
|  |  | ||||||
| 		break; |  | ||||||
| 	} | 	} | ||||||
| 	archive_read_finish(a); | 	archive_read_finish(a); | ||||||
|  |  | ||||||
| 	return plistd; | 	return buf; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | xbps_dictionary_t | ||||||
|  | xbps_binpkg_get_plist(const char *url, const char *plistf) | ||||||
|  | { | ||||||
|  | 	xbps_dictionary_t d; | ||||||
|  | 	char *buf; | ||||||
|  |  | ||||||
|  | 	if ((buf = xbps_binpkg_get_file(url, plistf)) == NULL) | ||||||
|  | 		return NULL; | ||||||
|  |  | ||||||
|  | 	d = xbps_dictionary_internalize(buf); | ||||||
|  | 	free(buf); | ||||||
|  | 	return d; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -277,7 +277,7 @@ xbps_repo_get_pkg_plist(struct xbps_handle *xhp, xbps_dictionary_t pkgd, | |||||||
| 	if (url == NULL) | 	if (url == NULL) | ||||||
| 		return NULL; | 		return NULL; | ||||||
|  |  | ||||||
| 	bpkgd = xbps_get_pkg_plist_from_binpkg(url, plist); | 	bpkgd = xbps_binpkg_get_plist(url, plist); | ||||||
| 	free(url); | 	free(url); | ||||||
| 	return bpkgd; | 	return bpkgd; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -315,7 +315,7 @@ xbps_rpool_get_pkg_plist(struct xbps_handle *xhp, | |||||||
| 		errno = EINVAL; | 		errno = EINVAL; | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	plistd = xbps_get_pkg_plist_from_binpkg(url, plistf); | 	plistd = xbps_binpkg_get_plist(url, plistf); | ||||||
| 	free(url); | 	free(url); | ||||||
|  |  | ||||||
| out: | out: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user