Share transaction callbacks for xbps-{bin,repo}, reposync cb support.
This commit is contained in:
@@ -4,7 +4,7 @@ TOPDIR = ../..
|
||||
BIN = xbps-bin
|
||||
OBJS = check.o install.o main.o remove.o show-deps.o
|
||||
OBJS += show-info-files.o util.o find-files.o
|
||||
OBJS += question.o fetch.o
|
||||
OBJS += question.o fetch_cb.o trans_cb.o
|
||||
MAN = $(BIN).8
|
||||
|
||||
include $(TOPDIR)/prog.mk
|
||||
|
@@ -44,8 +44,6 @@ int update_pkg(const char *);
|
||||
int autoupdate_pkgs(bool, bool);
|
||||
int autoremove_pkgs(bool, bool);
|
||||
int exec_transaction(bool, bool);
|
||||
void transaction_cb(struct xbps_transaction_cb_data *);
|
||||
void transaction_err_cb(struct xbps_transaction_cb_data *);
|
||||
|
||||
int remove_installed_pkgs(int, char **, bool, bool, bool, bool);
|
||||
|
||||
@@ -68,9 +66,13 @@ int find_files_in_packages(const char *);
|
||||
bool yesno(const char *, ...);
|
||||
bool noyes(const char *, ...);
|
||||
|
||||
/* from fetch.c */
|
||||
/* from fetch_cb.c */
|
||||
void fetch_file_progress_cb(struct xbps_fetch_cb_data *);
|
||||
|
||||
/* from trans_cb.c */
|
||||
void transaction_cb(struct xbps_transaction_cb_data *);
|
||||
void transaction_err_cb(struct xbps_transaction_cb_data *);
|
||||
|
||||
/* From util.c */
|
||||
int show_pkg_files(prop_dictionary_t);
|
||||
void show_pkg_info(prop_dictionary_t);
|
||||
|
@@ -283,87 +283,6 @@ update_pkg(const char *pkgname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
transaction_cb(struct xbps_transaction_cb_data *xtcd)
|
||||
{
|
||||
if (xtcd->desc != NULL && xtcd->pkgver == NULL) {
|
||||
printf("\n%s ...\n", xtcd->desc);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (xtcd->state) {
|
||||
case XBPS_TRANS_STATE_DOWNLOAD:
|
||||
printf("Downloading `%s' (from %s) ...\n",
|
||||
xtcd->pkgver, xtcd->binpkg_repourl);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_VERIFY:
|
||||
printf("Checking `%s' integrity ...\n", xtcd->binpkg_fname);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REMOVE:
|
||||
printf("Removing `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_PURGE:
|
||||
printf("Purging `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_CONFIGURE:
|
||||
printf("Configuring `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REGISTER:
|
||||
case XBPS_TRANS_STATE_INSTALL:
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UPDATE:
|
||||
printf("Updating `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UNPACK:
|
||||
printf("Unpacking `%s' (from ../%s) ...\n",
|
||||
xtcd->pkgver, xtcd->binpkg_fname);
|
||||
break;
|
||||
default:
|
||||
xbps_dbg_printf("%s: unknown transaction state %d %s\n",
|
||||
xtcd->pkgver, xtcd->state, xtcd->desc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
transaction_err_cb(struct xbps_transaction_cb_data *xtcd)
|
||||
{
|
||||
const char *state_descr = NULL;
|
||||
|
||||
switch (xtcd->state) {
|
||||
case XBPS_TRANS_STATE_DOWNLOAD:
|
||||
state_descr = "failed to download binary package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_VERIFY:
|
||||
state_descr = "failed to verify binary package SHA256";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REMOVE:
|
||||
state_descr = "failed to remove package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_PURGE:
|
||||
state_descr = "failed to purge package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_CONFIGURE:
|
||||
state_descr = "failed to configure package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UPDATE:
|
||||
state_descr = "failed to update package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UNPACK:
|
||||
state_descr = "failed to unpack binary package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REGISTER:
|
||||
state_descr = "failed to register package";
|
||||
break;
|
||||
default:
|
||||
state_descr = "unknown transaction state";
|
||||
break;
|
||||
}
|
||||
|
||||
xbps_error_printf("%s: %s: %s\n",
|
||||
xtcd->pkgver, state_descr, strerror(xtcd->err));
|
||||
}
|
||||
|
||||
int
|
||||
exec_transaction(bool yes, bool show_download_urls)
|
||||
{
|
||||
|
117
bin/xbps-bin/trans_cb.c
Normal file
117
bin/xbps-bin/trans_cb.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*-
|
||||
* Copyright (c) 2011 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
void
|
||||
transaction_cb(struct xbps_transaction_cb_data *xtcd)
|
||||
{
|
||||
if (xtcd->desc != NULL && xtcd->pkgver == NULL) {
|
||||
printf("\n%s ...\n", xtcd->desc);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (xtcd->state) {
|
||||
case XBPS_TRANS_STATE_DOWNLOAD:
|
||||
printf("Downloading `%s' (from %s) ...\n",
|
||||
xtcd->pkgver, xtcd->repourl);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_VERIFY:
|
||||
printf("Checking `%s' integrity ...\n", xtcd->binpkg_fname);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REMOVE:
|
||||
printf("Removing `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_PURGE:
|
||||
printf("Purging `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_CONFIGURE:
|
||||
printf("Configuring `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REGISTER:
|
||||
case XBPS_TRANS_STATE_INSTALL:
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UPDATE:
|
||||
printf("Updating `%s' ...\n", xtcd->pkgver);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UNPACK:
|
||||
printf("Unpacking `%s' (from ../%s) ...\n",
|
||||
xtcd->pkgver, xtcd->binpkg_fname);
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REPOSYNC:
|
||||
printf("Syncing repository pkg-index for `%s' ...\n",
|
||||
xtcd->repourl);
|
||||
break;
|
||||
default:
|
||||
xbps_dbg_printf("%s: unknown transaction state %d %s\n",
|
||||
xtcd->pkgver, xtcd->state, xtcd->desc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
transaction_err_cb(struct xbps_transaction_cb_data *xtcd)
|
||||
{
|
||||
const char *state_descr = NULL;
|
||||
|
||||
switch (xtcd->state) {
|
||||
case XBPS_TRANS_STATE_DOWNLOAD:
|
||||
state_descr = "failed to download binary package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_VERIFY:
|
||||
state_descr = "failed to verify binary package SHA256";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REMOVE:
|
||||
state_descr = "failed to remove package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_PURGE:
|
||||
state_descr = "failed to purge package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_CONFIGURE:
|
||||
state_descr = "failed to configure package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UPDATE:
|
||||
state_descr = "failed to update package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_UNPACK:
|
||||
state_descr = "failed to unpack binary package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REGISTER:
|
||||
state_descr = "failed to register package";
|
||||
break;
|
||||
case XBPS_TRANS_STATE_REPOSYNC:
|
||||
xbps_error_printf("Failed to sync pkg-index: %s\n",
|
||||
xtcd->err);
|
||||
return;
|
||||
default:
|
||||
state_descr = "unknown transaction state";
|
||||
break;
|
||||
}
|
||||
|
||||
xbps_error_printf("%s: %s: %s\n",
|
||||
xtcd->pkgver, state_descr, strerror(xtcd->err));
|
||||
}
|
Reference in New Issue
Block a user