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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user