Introduce struct xbps_handle and use it for xbps_init().
This structure sets up function callbacks for fetching files and unpacking binary packages, as well as setting the debug boolean. This way the affected functions (xbps_fetch_file() and xbps_unpack_binary_pkg()) do not need to accept the fn cb pointers and data as arguments. Bump XBPS_RELVER.
This commit is contained in:
parent
0bd533f8a9
commit
22ae7aa2e8
@ -94,7 +94,6 @@ static int
|
||||
download_package_list(prop_object_iterator_t iter, bool only_show)
|
||||
{
|
||||
prop_object_t obj;
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
const char *pkgver, *repoloc, *filename, *cachedir, *sha256;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
@ -147,8 +146,7 @@ again:
|
||||
return errno;
|
||||
}
|
||||
printf("Downloading %s binary package ...\n", pkgver);
|
||||
rv = xbps_fetch_file(binfile, cachedir, false, NULL,
|
||||
fetch_file_progress_cb, &xfpd);
|
||||
rv = xbps_fetch_file(binfile, cachedir, false, NULL);
|
||||
if (rv == -1) {
|
||||
xbps_error_printf("xbps-bin: couldn't download `%s'\n",
|
||||
filename);
|
||||
@ -373,45 +371,11 @@ xbps_update_pkg(const char *pkgname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb_verbose(void *data)
|
||||
{
|
||||
struct xbps_unpack_progress_data *xpd = data;
|
||||
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "Extracted %sfile `%s' (%" PRIi64 " bytes)\n",
|
||||
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
|
||||
xpd->entry_size);
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb_percentage(void *data)
|
||||
{
|
||||
struct xbps_unpack_progress_data *xpd = data;
|
||||
double percent = 0;
|
||||
|
||||
if (xpd->entry_is_metadata)
|
||||
return;
|
||||
|
||||
percent =
|
||||
(double)((xpd->entry_extract_count * 100.0) / xpd->entry_total_count);
|
||||
if (percent > 100.0 ||
|
||||
xpd->entry_extract_count >= xpd->entry_total_count)
|
||||
percent = 100.0;
|
||||
|
||||
printf("\033[s(%3.2f%%)\033[u", percent);
|
||||
}
|
||||
|
||||
static int
|
||||
exec_transaction(struct transaction *trans)
|
||||
{
|
||||
prop_dictionary_t instpkgd;
|
||||
prop_object_t obj;
|
||||
struct xbps_unpack_progress_data xpd;
|
||||
const char *pkgname, *version, *pkgver, *instver, *filen, *tract;
|
||||
int flags = xbps_get_flags(), rv = 0;
|
||||
bool update, preserve, autoinst;
|
||||
@ -528,15 +492,7 @@ exec_transaction(struct transaction *trans)
|
||||
* Unpack binary package.
|
||||
*/
|
||||
printf("Unpacking `%s' (from ../%s) ... ", pkgver, filen);
|
||||
if (flags & XBPS_FLAG_VERBOSE) {
|
||||
rv = xbps_unpack_binary_pkg(obj,
|
||||
unpack_progress_cb_verbose, &xpd);
|
||||
printf("\n");
|
||||
} else {
|
||||
rv = xbps_unpack_binary_pkg(obj,
|
||||
unpack_progress_cb_percentage, &xpd);
|
||||
}
|
||||
if (rv != 0) {
|
||||
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
|
||||
xbps_error_printf("xbps-bin: error unpacking %s "
|
||||
"(%s)\n", pkgver, strerror(rv));
|
||||
return rv;
|
||||
|
@ -149,10 +149,46 @@ cleanup(int signum)
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb_verbose(void *data)
|
||||
{
|
||||
struct xbps_unpack_progress_data *xpd = data;
|
||||
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "Extracted %sfile `%s' (%" PRIi64 " bytes)\n",
|
||||
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
|
||||
xpd->entry_size);
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb_percentage(void *data)
|
||||
{
|
||||
struct xbps_unpack_progress_data *xpd = data;
|
||||
double percent = 0;
|
||||
|
||||
if (xpd->entry_is_metadata)
|
||||
return;
|
||||
|
||||
percent =
|
||||
(double)((xpd->entry_extract_count * 100.0) / xpd->entry_total_count);
|
||||
if (percent > 100.0 ||
|
||||
xpd->entry_extract_count >= xpd->entry_total_count)
|
||||
percent = 100.0;
|
||||
|
||||
printf("\033[s(%3.2f%%)\033[u", percent);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
struct xbps_handle xh;
|
||||
struct xbps_unpack_progress_data xupd;
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
struct list_pkgver_cb lpc;
|
||||
struct sigaction sa;
|
||||
int i , c, flags, rv;
|
||||
@ -225,7 +261,16 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Initialize stuff for libxbps.
|
||||
*/
|
||||
xbps_init(with_debug);
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.with_debug = with_debug;
|
||||
xh.xbps_fetch_cb = fetch_file_progress_cb;
|
||||
xh.xfpd = &xfpd;
|
||||
if (flags & XBPS_FLAG_VERBOSE)
|
||||
xh.xbps_unpack_cb = unpack_progress_cb_verbose;
|
||||
else
|
||||
xh.xbps_unpack_cb = unpack_progress_cb_percentage;
|
||||
xh.xupd = &xupd;
|
||||
xbps_init(&xh);
|
||||
|
||||
if ((dict = xbps_regpkgdb_dictionary_get()) == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
|
@ -77,6 +77,8 @@ repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
prop_dictionary_t pkgd;
|
||||
char *root;
|
||||
int c, rv = 0;
|
||||
@ -110,7 +112,14 @@ main(int argc, char **argv)
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
xbps_init(with_debug);
|
||||
/*
|
||||
* Initialize the function callbacks and debug in libxbps.
|
||||
*/
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.with_debug = with_debug;
|
||||
xh.xbps_fetch_cb = fetch_file_progress_cb;
|
||||
xh.xfpd = &xfpd;
|
||||
xbps_init(&xh);
|
||||
|
||||
if ((rv = xbps_repository_pool_init()) != 0) {
|
||||
if (rv != ENOENT) {
|
||||
|
@ -164,7 +164,6 @@ int
|
||||
register_repository(const char *uri)
|
||||
{
|
||||
struct repoinfo *rpi = NULL;
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
const char *idxstr = NULL;
|
||||
char *metadir, *plist;
|
||||
int rv = 0;
|
||||
@ -174,8 +173,7 @@ register_repository(const char *uri)
|
||||
|
||||
if (xbps_check_is_repository_uri_remote(idxstr)) {
|
||||
printf("Fetching remote package index at %s...\n", idxstr);
|
||||
rv = xbps_repository_sync_pkg_index(idxstr,
|
||||
fetch_file_progress_cb, &xfpd);
|
||||
rv = xbps_repository_sync_pkg_index(idxstr);
|
||||
if (rv == -1) {
|
||||
xbps_error_printf("xbps-repo: couldn't fetch pkg-index"
|
||||
"file: %s.\n", xbps_fetch_error_string());
|
||||
@ -295,7 +293,6 @@ show_pkg_deps_from_repolist(const char *pkgname)
|
||||
static int
|
||||
repo_sync_pkg_index_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
{
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
struct repoinfo *rp;
|
||||
char *plist;
|
||||
int rv = 0;
|
||||
@ -307,8 +304,7 @@ repo_sync_pkg_index_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
return 0;
|
||||
|
||||
printf("Syncing package index from: %s\n", rpi->rpi_uri);
|
||||
rv = xbps_repository_sync_pkg_index(rpi->rpi_uri,
|
||||
fetch_file_progress_cb, &xfpd);
|
||||
rv = xbps_repository_sync_pkg_index(rpi->rpi_uri);
|
||||
if (rv == -1) {
|
||||
xbps_error_printf("xbps-repo: failed to sync `%s': %s\n",
|
||||
rpi->rpi_uri, xbps_fetch_error_string());
|
||||
|
@ -106,6 +106,7 @@ usage(void)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
struct xbps_fetch_progress_data xfpd;
|
||||
prop_dictionary_t dict;
|
||||
const char *version;
|
||||
@ -137,7 +138,14 @@ main(int argc, char **argv)
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
xbps_init(debug);
|
||||
/*
|
||||
* Initialize the callbacks and debug in libxbps.
|
||||
*/
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.with_debug = debug;
|
||||
xh.xbps_fetch_cb = fetch_file_progress_cb;
|
||||
xh.xfpd = &xfpd;
|
||||
xbps_init(&xh);
|
||||
|
||||
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(),
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
@ -336,8 +344,7 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
rv = xbps_fetch_file(argv[i], ".", false, "v",
|
||||
fetch_file_progress_cb, &xfpd);
|
||||
rv = xbps_fetch_file(argv[i], ".", false, "v");
|
||||
if (rv == -1) {
|
||||
printf("%s: %s\n", argv[1],
|
||||
xbps_fetch_error_string());
|
||||
|
@ -53,7 +53,7 @@
|
||||
* @def XBPS_RELVER
|
||||
* Current library release date.
|
||||
*/
|
||||
#define XBPS_RELVER "20110218"
|
||||
#define XBPS_RELVER "20110221"
|
||||
|
||||
/**
|
||||
* @def XBPS_META_PATH
|
||||
@ -128,16 +128,61 @@ void xbps_warn_printf(const char *, ...);
|
||||
/** @addtogroup initend */
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* @struct xbps_handle xbps_api.h "xbps_api.h"
|
||||
* @brief Structure to be passed to xbps_init() and xbps_end() functions.
|
||||
*
|
||||
* This structure sets some global properties for libxbps, to set some
|
||||
* function callbacks and data to the fetch and unpack functions.
|
||||
*/
|
||||
struct xbps_handle {
|
||||
/**
|
||||
* @var xbps_unpack_cb
|
||||
*
|
||||
* Pointer to the supplied function callback to be used in
|
||||
* xbps_unpack_binary_pkg().
|
||||
*/
|
||||
void (*xbps_unpack_cb)(void *);
|
||||
/**
|
||||
* @var xupd
|
||||
*
|
||||
* Pointer to a xbps_unpack_progress_data structure to be passed
|
||||
* as argument to the \a xbps_unpack_cb function callback.
|
||||
*/
|
||||
struct xbps_unpack_progress_data *xupd;
|
||||
/**
|
||||
* @var xbps_fetch_cb
|
||||
*
|
||||
* Pointer to the supplied function callback to be used in
|
||||
* xbps_fetch_file().
|
||||
*/
|
||||
void (*xbps_fetch_cb)(void *);
|
||||
/**
|
||||
* @var xfpd
|
||||
*
|
||||
* Pointer to a xbps_fetch_progress_data structure to be passed
|
||||
* as argument to the \a xbps_fetch_cb function callback.
|
||||
*/
|
||||
struct xbps_fetch_progress_data *xfpd;
|
||||
/**
|
||||
* @var with_debug
|
||||
*
|
||||
* Set to true to enable debugging messages to stderr.
|
||||
*/
|
||||
bool with_debug;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the XBPS library with the following steps:
|
||||
*
|
||||
* - Sets the function callbacks for fetching and unpacking.
|
||||
* - Sets default cache connections for libfetch.
|
||||
*
|
||||
* - Initializes the debug printfs.
|
||||
*
|
||||
* @param[in] debug If true, debugging output will be shown to stderr.
|
||||
* @param[in] xh Pointer to an xbps_handle structure. It's
|
||||
* assumed that this pointer is not NULL.
|
||||
*/
|
||||
void xbps_init(bool debug);
|
||||
void xbps_init(struct xbps_handle *xh);
|
||||
|
||||
/**
|
||||
* Releases all resources used by the XBPS library.
|
||||
@ -295,10 +340,6 @@ struct xbps_fetch_progress_data {
|
||||
* @param[in] refetch If true and local/remote size/mtime do not match,
|
||||
* fetch the file from scratch.
|
||||
* @param[in] flags Flags passed to libfetch's fetchXget().
|
||||
* @param[in] progress_cb Pointer to a function callback to update the
|
||||
* the fetch progress.
|
||||
* @param[in] xfpd Pointer to a xbps_fetch_progress_data struct to be
|
||||
* passed to the \a progress_cb callback as its argument.
|
||||
*
|
||||
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
|
||||
* do not match) and 1 if downloaded successfully.
|
||||
@ -306,9 +347,7 @@ struct xbps_fetch_progress_data {
|
||||
int xbps_fetch_file(const char *uri,
|
||||
const char *outputdir,
|
||||
bool refetch,
|
||||
const char *flags,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd);
|
||||
const char *flags);
|
||||
|
||||
/**
|
||||
* Returns last error string reported by xbps_fetch_file().
|
||||
@ -995,18 +1034,12 @@ prop_dictionary_t
|
||||
* by the \a uri argument (if necessary).
|
||||
*
|
||||
* @param[in] uri URI to a remote repository.
|
||||
* @param[in] progress_cb Pointer to a function callback to update the
|
||||
* the fetch progress.
|
||||
* @param[in] xfpd Pointer to a xbps_fetch_progress_data struct to be
|
||||
* passed to the \a progress_cb callback as its argument.
|
||||
*
|
||||
* @return -1 on error (errno is set appropiately), 0 if transfer was
|
||||
* not necessary (local/remote size/mtime matched) or 1 if
|
||||
* downloaded successfully.
|
||||
*/
|
||||
int xbps_repository_sync_pkg_index(const char *uri,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd);
|
||||
int xbps_repository_sync_pkg_index(const char *uri);
|
||||
|
||||
/*@}*/
|
||||
|
||||
@ -1142,16 +1175,10 @@ struct xbps_unpack_progress_data {
|
||||
*
|
||||
* @param[in] trans_pkg_dict Package proplib dictionary as stored in the
|
||||
* \a packages array returned by the transaction dictionary.
|
||||
* @param[in] progress_cb Pointer to a function callback to update progress data
|
||||
* while extracting files in package (optional).
|
||||
* @param[in] xupd Pointer to a struct xbps_unpack_progress_data to be passed to
|
||||
* the function callback \a progress_cb.
|
||||
*
|
||||
* @return 0 on success, otherwise an errno value.
|
||||
*/
|
||||
int xbps_unpack_binary_pkg(prop_dictionary_t trans_pkg_dict,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_unpack_progress_data *xupd);
|
||||
int xbps_unpack_binary_pkg(prop_dictionary_t trans_pkg_dict);
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
@ -76,18 +76,15 @@ __BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Sets the libfetch's cache connection limits.
|
||||
*
|
||||
* @param[in] global Number of global cached connections, if set to 0
|
||||
* by default it's set to XBPS_FETCH_CACHECONN.
|
||||
* @param[in] per_host Number of per host cached connections, if set to 0
|
||||
* by default it's set to XBPS_FETCH_CACHECONN_HOST.
|
||||
* From lib/initend.c
|
||||
*/
|
||||
void HIDDEN xbps_fetch_set_cache_connection(int global, int per_host);
|
||||
struct xbps_handle HIDDEN *xbps_handle_get(void);
|
||||
|
||||
/**
|
||||
* Destroys the libfetch's cache connection established.
|
||||
* @private
|
||||
* From lib/download.c
|
||||
*/
|
||||
void HIDDEN xbps_fetch_set_cache_connection(int global, int per_host);
|
||||
void HIDDEN xbps_fetch_unset_cache_connection(void);
|
||||
|
||||
/**
|
||||
@ -102,16 +99,7 @@ int HIDDEN xbps_entry_install_conf_file(prop_dictionary_t,
|
||||
const char *);
|
||||
/**
|
||||
* @private
|
||||
* From lib/plist_archive_entry.c
|
||||
*
|
||||
* Finds a proplib dictionary in an archive, matching a specific
|
||||
* entry on it.
|
||||
*
|
||||
* @param[in] ar Pointer to an archive object, as returned by libarchive.
|
||||
* @param[in] entry Pointer to an archive entry object, as returned by libarchive.
|
||||
*
|
||||
* @return The proplib dictionary associated with entry, NULL otherwise
|
||||
* and errno is set appropiately.
|
||||
* From lib/plist_entry.c
|
||||
*/
|
||||
prop_dictionary_t HIDDEN
|
||||
xbps_read_dict_from_archive_entry(struct archive *ar,
|
||||
@ -152,44 +140,16 @@ prop_dictionary_t HIDDEN xbps_transaction_dictionary_get(void);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* From lib/repository_sync_index.c
|
||||
*/
|
||||
char HIDDEN *xbps_get_remote_repo_string(const char *);
|
||||
|
||||
/**
|
||||
* Forks and executes a command in the current working directory
|
||||
* with an arbitrary number of arguments.
|
||||
*
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, the last
|
||||
* argument must be NULL.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
* @private
|
||||
* From lib/fexec.c
|
||||
*/
|
||||
int HIDDEN xbps_file_exec(const char *arg, ...);
|
||||
|
||||
/**
|
||||
* Forks and executes a command in the current working directory
|
||||
* with an arbitrary number of arguments.
|
||||
*
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, does not need
|
||||
* to be terminated with a NULL argument.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
*/
|
||||
int HIDDEN xbps_file_exec_skipempty(const char *arg, ...);
|
||||
|
||||
/**
|
||||
* Forks and executes a command with an arbitrary number of arguments
|
||||
* in a specified path.
|
||||
*
|
||||
* If uid==0 and /bin/sh (relative to path) exists, a chroot(2) call
|
||||
* will be done, otherwise chdir(2) to path.
|
||||
*
|
||||
* @param[in] path Destination path to chroot(2) or chdir(2).
|
||||
* @param[in] arg Arguments passed to execvp(3) when forked, the last
|
||||
* argument must be NULL.
|
||||
*
|
||||
* @return 0 on success, -1 on error and errno set appropiately.
|
||||
*/
|
||||
int HIDDEN xbps_file_chdir_exec(const char *path, const char *arg, ...);
|
||||
|
||||
/**
|
||||
@ -201,7 +161,7 @@ int HIDDEN xbps_repository_pkg_replaces(prop_dictionary_t,
|
||||
|
||||
/**
|
||||
* @private
|
||||
* From lib/plist.c
|
||||
* From lib/plist_find.c
|
||||
*/
|
||||
prop_dictionary_t HIDDEN
|
||||
xbps_find_virtualpkg_user_in_dict_by_name(prop_dictionary_t,
|
||||
|
@ -89,10 +89,9 @@ int
|
||||
xbps_fetch_file(const char *uri,
|
||||
const char *outputdir,
|
||||
bool refetch,
|
||||
const char *flags,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd)
|
||||
const char *flags)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
struct stat st;
|
||||
struct url *url = NULL;
|
||||
struct url_stat url_st;
|
||||
@ -110,6 +109,7 @@ xbps_fetch_file(const char *uri,
|
||||
fetchLastErrCode = 0;
|
||||
fetchTimeout = 30; /* 30 seconds of timeout */
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
/*
|
||||
* Get the filename specified in URI argument.
|
||||
*/
|
||||
@ -257,15 +257,15 @@ xbps_fetch_file(const char *uri,
|
||||
* and let the user know that the transfer is going to start
|
||||
* immediately.
|
||||
*/
|
||||
if (progress_cb != NULL && xfpd != NULL) {
|
||||
xfpd->file_name = filename;
|
||||
xfpd->file_size = url_st.size;
|
||||
xfpd->file_offset = url->offset;
|
||||
xfpd->file_dloaded = -1;
|
||||
xfpd->cb_start = true;
|
||||
xfpd->cb_update = false;
|
||||
xfpd->cb_end = false;
|
||||
progress_cb(xfpd);
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfpd != NULL) {
|
||||
xhp->xfpd->file_name = filename;
|
||||
xhp->xfpd->file_size = url_st.size;
|
||||
xhp->xfpd->file_offset = url->offset;
|
||||
xhp->xfpd->file_dloaded = -1;
|
||||
xhp->xfpd->cb_start = true;
|
||||
xhp->xfpd->cb_update = false;
|
||||
xhp->xfpd->cb_end = false;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
}
|
||||
/*
|
||||
* Start fetching requested file.
|
||||
@ -282,11 +282,12 @@ xbps_fetch_file(const char *uri,
|
||||
* Let the fetch progress callback know that
|
||||
* we are sucking more bytes from it.
|
||||
*/
|
||||
if (progress_cb != NULL && xfpd != NULL) {
|
||||
xfpd->file_dloaded = bytes_dload;
|
||||
xfpd->cb_start = false;
|
||||
xfpd->cb_update = true;
|
||||
progress_cb(xfpd);
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL &&
|
||||
xhp->xfpd != NULL) {
|
||||
xhp->xfpd->file_dloaded = bytes_dload;
|
||||
xhp->xfpd->cb_start = false;
|
||||
xhp->xfpd->cb_update = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
}
|
||||
|
||||
}
|
||||
@ -294,10 +295,10 @@ xbps_fetch_file(const char *uri,
|
||||
* Let the fetch progress callback know that the file
|
||||
* has been fetched.
|
||||
*/
|
||||
if (progress_cb != NULL && xfpd != NULL) {
|
||||
xfpd->cb_update = false;
|
||||
xfpd->cb_end = true;
|
||||
progress_cb(xfpd);
|
||||
if (xhp != NULL && xhp->xbps_fetch_cb != NULL && xhp->xfpd != NULL) {
|
||||
xhp->xfpd->cb_update = false;
|
||||
xhp->xfpd->cb_end = true;
|
||||
xhp->xbps_fetch_cb(xhp->xfpd);
|
||||
}
|
||||
if (bytes_read == -1) {
|
||||
xbps_error_printf("IO error while fetching %s: %s\n", filename,
|
||||
|
@ -40,14 +40,18 @@
|
||||
* Use these functions to initialize some parameters before starting
|
||||
* using libxbps and finalize usage to release resources at the end.
|
||||
*/
|
||||
static bool with_debug;
|
||||
static bool debug;
|
||||
static struct xbps_handle *xhp;
|
||||
|
||||
void
|
||||
xbps_init(bool debug)
|
||||
xbps_init(struct xbps_handle *xh)
|
||||
{
|
||||
assert(xh != NULL);
|
||||
|
||||
xhp = xh;
|
||||
debug = xhp->with_debug;
|
||||
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN,
|
||||
XBPS_FETCH_CACHECONN_HOST);
|
||||
with_debug = debug;
|
||||
}
|
||||
|
||||
void
|
||||
@ -56,6 +60,13 @@ xbps_end(void)
|
||||
xbps_regpkgdb_dictionary_release();
|
||||
xbps_repository_pool_release();
|
||||
xbps_fetch_unset_cache_connection();
|
||||
xhp = NULL;
|
||||
}
|
||||
|
||||
struct xbps_handle HIDDEN *
|
||||
xbps_handle_get(void)
|
||||
{
|
||||
return xhp;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -72,7 +83,7 @@ xbps_dbg_printf_append(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (!with_debug)
|
||||
if (!debug)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
@ -85,7 +96,7 @@ xbps_dbg_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (!with_debug)
|
||||
if (!debug)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
@ -149,10 +149,10 @@ remove_metafile(const char *file, const char *pkgname, const char *version)
|
||||
* archive_read_set_progress_callback() from libarchive(3) cannot be used
|
||||
* here because sometimes it misses some entries by unknown reasons.
|
||||
*/
|
||||
#define RUN_PROGRESS_CB() \
|
||||
do { \
|
||||
if (progress_cb != NULL && xupd != NULL) \
|
||||
(*progress_cb)(xupd); \
|
||||
#define RUN_PROGRESS_CB() \
|
||||
do { \
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xupd != NULL) \
|
||||
(*xhp->xbps_unpack_cb)(xhp->xupd); \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
@ -160,8 +160,7 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
struct archive *ar,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_unpack_progress_data *xupd)
|
||||
struct xbps_handle *xhp)
|
||||
{
|
||||
prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL;
|
||||
prop_array_t array;
|
||||
@ -212,11 +211,12 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||
entry_pname = archive_entry_pathname(entry);
|
||||
set_extract_flags(&flags, update);
|
||||
if (progress_cb != NULL && xupd != NULL) {
|
||||
xupd->entry = entry_pname;
|
||||
xupd->entry_size = archive_entry_size(entry);
|
||||
xupd->entry_is_metadata = false;
|
||||
xupd->entry_is_conf = false;
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL &&
|
||||
xhp->xupd != NULL) {
|
||||
xhp->xupd->entry = entry_pname;
|
||||
xhp->xupd->entry_size = archive_entry_size(entry);
|
||||
xhp->xupd->entry_is_metadata = false;
|
||||
xhp->xupd->entry_is_conf = false;
|
||||
}
|
||||
|
||||
if (strcmp("./INSTALL", entry_pname) == 0) {
|
||||
@ -246,9 +246,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xupd != NULL) {
|
||||
xupd->entry_is_metadata = true;
|
||||
xupd->entry_extract_count++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@ -260,9 +260,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
|
||||
nmetadata++;
|
||||
if (xupd != NULL) {
|
||||
xupd->entry_is_metadata = true;
|
||||
xupd->entry_extract_count++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@ -279,9 +279,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xupd != NULL) {
|
||||
xupd->entry_is_metadata = true;
|
||||
xupd->entry_extract_count++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@ -299,9 +299,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
goto out;
|
||||
}
|
||||
nmetadata++;
|
||||
if (xupd != NULL) {
|
||||
xupd->entry_is_metadata = true;
|
||||
xupd->entry_extract_count++;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_is_metadata = true;
|
||||
xhp->xupd->entry_extract_count++;
|
||||
}
|
||||
RUN_PROGRESS_CB();
|
||||
continue;
|
||||
@ -330,16 +330,16 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
* Compute total entries in progress data, if set.
|
||||
* total_entries = metadata + files + conf_files + links.
|
||||
*/
|
||||
if (xupd != NULL) {
|
||||
xupd->entry_total_count = nmetadata;
|
||||
if (xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_total_count = nmetadata;
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
xupd->entry_total_count +=
|
||||
xhp->xupd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
array = prop_dictionary_get(filesd, "conf_files");
|
||||
xupd->entry_total_count +=
|
||||
xhp->xupd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
array = prop_dictionary_get(filesd, "links");
|
||||
xupd->entry_total_count +=
|
||||
xhp->xupd->entry_total_count +=
|
||||
(ssize_t)prop_array_count(array);
|
||||
}
|
||||
|
||||
@ -354,8 +354,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
/* error */
|
||||
goto out;
|
||||
} else if (rv == 1) {
|
||||
if (xupd != NULL)
|
||||
xupd->entry_is_conf = true;
|
||||
if (xhp->xupd != NULL)
|
||||
xhp->xupd->entry_is_conf = true;
|
||||
|
||||
rv = xbps_entry_install_conf_file(filesd,
|
||||
entry, entry_pname, pkgname, version);
|
||||
@ -397,8 +397,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (xupd != NULL)
|
||||
xupd->entry_extract_count++;
|
||||
if (xhp->xupd != NULL)
|
||||
xhp->xupd->entry_extract_count++;
|
||||
|
||||
RUN_PROGRESS_CB();
|
||||
}
|
||||
@ -461,10 +461,9 @@ out:
|
||||
#undef RUN_PROGRESS_CB
|
||||
|
||||
int
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_unpack_progress_data *xupd)
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
struct archive *ar;
|
||||
const char *pkgname, *version, *repoloc;
|
||||
char *bpkg;
|
||||
@ -503,15 +502,15 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod,
|
||||
/*
|
||||
* Set extract progress callback if specified.
|
||||
*/
|
||||
if (progress_cb != NULL && xupd != NULL) {
|
||||
xupd->entry_extract_count = 0;
|
||||
xupd->entry_total_count = 0;
|
||||
xhp = xbps_handle_get();
|
||||
if (xhp != NULL && xhp->xbps_unpack_cb != NULL && xhp->xupd != NULL) {
|
||||
xhp->xupd->entry_extract_count = 0;
|
||||
xhp->xupd->entry_total_count = 0;
|
||||
}
|
||||
/*
|
||||
* Extract archive files.
|
||||
*/
|
||||
rv = unpack_archive(pkg_repod, ar, pkgname, version,
|
||||
progress_cb, xupd);
|
||||
rv = unpack_archive(pkg_repod, ar, pkgname, version, xhp);
|
||||
if (rv != 0) {
|
||||
xbps_error_printf("failed to unpack `%s' binpkg: %s\n",
|
||||
bpkg, strerror(rv));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2011 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -82,9 +82,7 @@ xbps_get_remote_repo_string(const char *uri)
|
||||
* size and/or mtime match) and 1 if downloaded successfully.
|
||||
*/
|
||||
int
|
||||
xbps_repository_sync_pkg_index(const char *uri,
|
||||
void (*progress_cb)(void *),
|
||||
struct xbps_fetch_progress_data *xfpd)
|
||||
xbps_repository_sync_pkg_index(const char *uri)
|
||||
{
|
||||
struct url *url = NULL;
|
||||
struct utsname un;
|
||||
@ -163,8 +161,7 @@ xbps_repository_sync_pkg_index(const char *uri,
|
||||
/*
|
||||
* Download pkg-index.plist file from repository.
|
||||
*/
|
||||
rv = xbps_fetch_file(rpidx, fetch_outputdir, true, NULL,
|
||||
progress_cb, xfpd);
|
||||
rv = xbps_fetch_file(rpidx, fetch_outputdir, true, NULL);
|
||||
if (rv == -1) {
|
||||
(void)remove(tmp_metafile);
|
||||
goto out;
|
||||
|
Loading…
Reference in New Issue
Block a user