2005-03-19 04:00:40 -05:00
|
|
|
/*
|
|
|
|
* trans.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2005-03-19 04:00:40 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2006-05-14 22:19:57 -04:00
|
|
|
#include <libintl.h>
|
2007-03-03 04:43:16 -05:00
|
|
|
#include <wchar.h>
|
2005-03-19 04:00:40 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
/* pacman */
|
2005-10-10 16:42:48 -04:00
|
|
|
#include "util.h"
|
2005-03-19 04:00:40 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "trans.h"
|
2006-02-22 15:39:24 -05:00
|
|
|
#include "conf.h"
|
2005-03-19 04:00:40 -05:00
|
|
|
|
2005-04-02 15:31:40 -05:00
|
|
|
#define LOG_STR_LEN 256
|
|
|
|
|
2006-02-22 15:39:24 -05:00
|
|
|
extern config_t *config;
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2007-01-18 11:52:57 -05:00
|
|
|
static int prevpercent=0; /* for less progressbar output */
|
2006-02-22 15:39:24 -05:00
|
|
|
|
2005-03-19 04:00:40 -05:00
|
|
|
/* Callback to handle transaction events
|
|
|
|
*/
|
2007-01-23 22:02:53 -05:00
|
|
|
void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
|
2005-03-19 04:00:40 -05:00
|
|
|
{
|
2005-04-02 15:31:40 -05:00
|
|
|
char str[LOG_STR_LEN] = "";
|
2005-03-19 04:00:40 -05:00
|
|
|
|
|
|
|
switch(event) {
|
2005-04-02 15:31:40 -05:00
|
|
|
case PM_TRANS_EVT_CHECKDEPS_START:
|
2007-02-09 11:02:01 -05:00
|
|
|
MSG(NL, _("checking dependencies... "));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-04-02 15:31:40 -05:00
|
|
|
case PM_TRANS_EVT_FILECONFLICTS_START:
|
2006-10-15 19:54:43 -04:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(NL, _("checking for file conflicts... "));
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
|
|
|
case PM_TRANS_EVT_CLEANUP_START:
|
2007-02-09 11:02:01 -05:00
|
|
|
MSG(NL, _("cleaning up... "));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-04-02 15:31:40 -05:00
|
|
|
case PM_TRANS_EVT_RESOLVEDEPS_START:
|
2007-02-09 11:02:01 -05:00
|
|
|
MSG(NL, _("resolving dependencies... "));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-04-13 15:59:04 -04:00
|
|
|
case PM_TRANS_EVT_INTERCONFLICTS_START:
|
2007-02-09 11:02:01 -05:00
|
|
|
MSG(NL, _("looking for inter-conflicts... "));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-04-02 15:31:40 -05:00
|
|
|
case PM_TRANS_EVT_FILECONFLICTS_DONE:
|
2006-10-15 19:54:43 -04:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(CL, _("done.\n"));
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 19:54:43 -04:00
|
|
|
case PM_TRANS_EVT_CHECKDEPS_DONE:
|
2007-01-23 22:02:53 -05:00
|
|
|
case PM_TRANS_EVT_CLEANUP_DONE:
|
2005-04-02 15:31:40 -05:00
|
|
|
case PM_TRANS_EVT_RESOLVEDEPS_DONE:
|
2005-04-13 15:59:04 -04:00
|
|
|
case PM_TRANS_EVT_INTERCONFLICTS_DONE:
|
2007-02-09 11:02:01 -05:00
|
|
|
MSG(CL, _("done.\n"));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_EXTRACT_DONE:
|
2006-11-01 21:29:10 -05:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(CL, _("done.\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_ADD_START:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
2006-11-20 04:10:23 -05:00
|
|
|
MSG(NL, _("installing %s... "), alpm_pkg_get_name(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_ADD_DONE:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(CL, _("done.\n"));
|
|
|
|
}
|
2006-05-14 22:19:57 -04:00
|
|
|
snprintf(str, LOG_STR_LEN, _("installed %s (%s)"),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
|
|
|
alpm_pkg_get_version(data1));
|
2005-03-19 04:00:40 -05:00
|
|
|
alpm_logaction(str);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_REMOVE_START:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
2006-11-20 04:10:23 -05:00
|
|
|
MSG(NL, _("removing %s... "), alpm_pkg_get_name(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_REMOVE_DONE:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(CL, _("done.\n"));
|
|
|
|
}
|
2006-05-14 22:19:57 -04:00
|
|
|
snprintf(str, LOG_STR_LEN, _("removed %s (%s)"),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
|
|
|
alpm_pkg_get_version(data1));
|
2005-03-19 04:00:40 -05:00
|
|
|
alpm_logaction(str);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_UPGRADE_START:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
2006-11-20 04:10:23 -05:00
|
|
|
MSG(NL, _("upgrading %s... "), alpm_pkg_get_name(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
case PM_TRANS_EVT_UPGRADE_DONE:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noprogressbar) {
|
|
|
|
MSG(CL, _("done.\n"));
|
|
|
|
}
|
2006-05-14 22:19:57 -04:00
|
|
|
snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"),
|
2006-11-20 04:10:23 -05:00
|
|
|
(char *)alpm_pkg_get_name(data1),
|
|
|
|
(char *)alpm_pkg_get_version(data2),
|
|
|
|
(char *)alpm_pkg_get_version(data1));
|
2005-03-19 04:00:40 -05:00
|
|
|
alpm_logaction(str);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_INTEGRITY_START:
|
|
|
|
MSG(NL, _("checking package integrity... "));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_INTEGRITY_DONE:
|
|
|
|
MSG(CL, _("done.\n"));
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_SCRIPTLET_INFO:
|
|
|
|
MSG(NL, "%s\n", (char*)data1);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_SCRIPTLET_START:
|
|
|
|
MSG(NL, (char*)data1);
|
|
|
|
MSG(CL, "...");
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_SCRIPTLET_DONE:
|
|
|
|
if(!(long)data1) {
|
2007-02-08 15:44:47 -05:00
|
|
|
MSG(CL, _("done.\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
} else {
|
2007-02-08 15:44:47 -05:00
|
|
|
MSG(CL, _("failed.\n"));
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_PRINTURI:
|
2006-12-29 12:07:34 -05:00
|
|
|
MSG(NL, "%s/%s\n", (char*)data1, (char*)data2);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_EVT_RETRIEVE_START:
|
2006-11-01 21:29:10 -05:00
|
|
|
MSG(NL, _(":: Retrieving packages from %s...\n"), (char*)data1);
|
2006-10-15 15:34:52 -04:00
|
|
|
fflush(stdout);
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-03-19 04:00:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-23 22:02:53 -05:00
|
|
|
void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
|
|
|
|
void *data3, int *response)
|
2005-10-09 02:09:57 -04:00
|
|
|
{
|
|
|
|
char str[LOG_STR_LEN] = "";
|
|
|
|
|
|
|
|
switch(event) {
|
|
|
|
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_INSTALL_IGNOREPKG) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
2007-02-22 21:10:56 -05:00
|
|
|
} else if(data2) {
|
2006-10-15 15:34:52 -04:00
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
|
|
|
alpm_pkg_get_name(data2));
|
2006-10-15 15:34:52 -04:00
|
|
|
*response = yesno(str);
|
2007-02-22 21:10:56 -05:00
|
|
|
} else {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s is in IgnorePkg. Install anyway? [Y/n] "),
|
|
|
|
alpm_pkg_get_name(data1));
|
|
|
|
*response = yesno(str);
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_CONV_REMOVE_HOLDPKG:
|
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_REMOVE_HOLDPKG) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-23 22:02:53 -05:00
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
*response = yesno(str);
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-10-09 02:09:57 -04:00
|
|
|
case PM_TRANS_CONV_REPLACE_PKG:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_REPLACE_PKG) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
2006-10-15 15:34:52 -04:00
|
|
|
(char *)data3,
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data2));
|
2006-10-15 15:34:52 -04:00
|
|
|
*response = yesno(str);
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-12-26 01:40:29 -05:00
|
|
|
case PM_TRANS_CONV_CONFLICT_PKG:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_CONFLICT_PKG) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s conflicts with %s. Remove %s? [Y/n] "),
|
|
|
|
(char *)data1,
|
|
|
|
(char *)data2,
|
|
|
|
(char *)data2);
|
|
|
|
*response = yesno(str);
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-10-09 02:09:57 -04:00
|
|
|
case PM_TRANS_CONV_LOCAL_NEWER:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_LOCAL_NEWER) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!config->op_s_downloadonly) {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
|
|
|
alpm_pkg_get_version(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
*response = yesno(str);
|
|
|
|
} else {
|
|
|
|
*response = 1;
|
|
|
|
}
|
2006-02-22 15:39:24 -05:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-10-09 02:09:57 -04:00
|
|
|
case PM_TRANS_CONV_LOCAL_UPTODATE:
|
2006-10-15 15:34:52 -04:00
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_LOCAL_UPTODATE) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!config->op_s_downloadonly) {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "),
|
2006-11-20 04:10:23 -05:00
|
|
|
alpm_pkg_get_name(data1),
|
|
|
|
alpm_pkg_get_version(data1));
|
2006-10-15 15:34:52 -04:00
|
|
|
*response = yesno(str);
|
|
|
|
} else {
|
|
|
|
*response = 1;
|
|
|
|
}
|
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_CONV_CORRUPTED_PKG:
|
|
|
|
if(config->noask) {
|
|
|
|
if(config->ask & PM_TRANS_CONV_CORRUPTED_PKG) {
|
|
|
|
*response = 1;
|
|
|
|
} else {
|
|
|
|
*response = 0;
|
|
|
|
}
|
2006-02-22 15:39:24 -05:00
|
|
|
} else {
|
2006-10-15 15:34:52 -04:00
|
|
|
if(!config->noconfirm) {
|
|
|
|
snprintf(str, LOG_STR_LEN, _(":: Archive %s is corrupted. Do you want to delete it? [Y/n] "),
|
|
|
|
(char *)data1);
|
|
|
|
*response = yesno(str);
|
|
|
|
} else {
|
|
|
|
*response = 1;
|
|
|
|
}
|
2006-02-22 15:39:24 -05:00
|
|
|
}
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2005-10-09 02:09:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-03 03:13:59 -05:00
|
|
|
void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
|
|
|
|
int howmany, int remain)
|
2006-10-15 15:34:52 -04:00
|
|
|
{
|
2007-02-03 20:36:45 -05:00
|
|
|
float timediff;
|
|
|
|
|
2007-01-30 20:37:41 -05:00
|
|
|
/* size of line to allocate for text printing (e.g. not progressbar) */
|
|
|
|
const int infolen = 50;
|
2007-03-03 04:43:16 -05:00
|
|
|
int tmp, digits, oprlen, textlen, pkglen;
|
2007-02-14 14:35:41 -05:00
|
|
|
char *opr = NULL;
|
2007-03-03 04:43:16 -05:00
|
|
|
wchar_t *wcopr = NULL;
|
2006-10-15 15:34:52 -04:00
|
|
|
|
|
|
|
if(config->noprogressbar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-17 03:55:05 -05:00
|
|
|
/* XXX: big fat hack: due to the fact that we switch out printf/pm_fprintf,
|
|
|
|
* not everything honors our 'neednl' newline hackery. This forces a newline
|
|
|
|
* if we need one before drawing the progress bar */
|
|
|
|
MSG(NL,NULL);
|
|
|
|
|
2006-12-22 02:11:20 -05:00
|
|
|
if(percent == 0) {
|
|
|
|
set_output_padding(1); /* turn on output padding with ' ' */
|
2007-02-03 20:36:45 -05:00
|
|
|
timediff = get_update_timediff(1);
|
|
|
|
} else {
|
|
|
|
timediff = get_update_timediff(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(percent > 0 && percent < 100 && !timediff) {
|
|
|
|
/* only update the progress bar when
|
|
|
|
* a) we first start
|
|
|
|
* b) we end the progress
|
|
|
|
* c) it has been long enough since the last call
|
|
|
|
*/
|
|
|
|
return;
|
2006-12-22 02:11:20 -05:00
|
|
|
}
|
|
|
|
|
2007-01-30 20:37:41 -05:00
|
|
|
/* if no pkgname, percent is too high or unchanged, then return */
|
2007-02-03 20:36:45 -05:00
|
|
|
if(!pkgname || percent == prevpercent) {
|
2006-10-15 15:34:52 -04:00
|
|
|
return;
|
2007-01-30 20:37:41 -05:00
|
|
|
}
|
2006-10-15 15:34:52 -04:00
|
|
|
|
|
|
|
prevpercent=percent;
|
2007-03-03 04:43:16 -05:00
|
|
|
/* set text of message to display */
|
2006-10-15 15:34:52 -04:00
|
|
|
switch (event) {
|
|
|
|
case PM_TRANS_PROGRESS_ADD_START:
|
2007-02-14 14:35:41 -05:00
|
|
|
opr = _("installing");
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_PROGRESS_UPGRADE_START:
|
2007-02-14 14:35:41 -05:00
|
|
|
opr = _("upgrading");
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
case PM_TRANS_PROGRESS_REMOVE_START:
|
2007-02-14 14:35:41 -05:00
|
|
|
opr = _("removing");
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 19:54:43 -04:00
|
|
|
case PM_TRANS_PROGRESS_CONFLICTS_START:
|
2007-02-14 14:35:41 -05:00
|
|
|
opr = _("checking for file conflicts");
|
2007-01-23 22:02:53 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-03-03 04:43:16 -05:00
|
|
|
/* convert above strings to wide chars */
|
|
|
|
oprlen = strlen(opr);
|
|
|
|
wcopr = (wchar_t*)calloc(oprlen, sizeof(wchar_t));
|
|
|
|
if(!wcopr) {
|
|
|
|
fprintf(stderr, "malloc failure: could not allocate %d bytes\n",
|
|
|
|
strlen(opr) * sizeof(wchar_t));
|
|
|
|
}
|
|
|
|
oprlen = mbstowcs(wcopr, opr, oprlen);
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2007-01-30 20:37:41 -05:00
|
|
|
/* find # of digits in package counts to scale output */
|
|
|
|
digits = 1;
|
2007-03-03 04:43:16 -05:00
|
|
|
tmp = howmany;
|
|
|
|
while((tmp /= 10)) {
|
2007-01-30 20:37:41 -05:00
|
|
|
++digits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine room left for non-digits text [not ( 1/12) part] */
|
|
|
|
textlen = infolen - 3 - (2 * digits);
|
|
|
|
/* room left for package name */
|
2007-03-03 04:43:16 -05:00
|
|
|
pkglen = textlen - oprlen - 1;
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2006-10-15 19:54:43 -04:00
|
|
|
switch (event) {
|
2007-01-30 20:37:41 -05:00
|
|
|
case PM_TRANS_PROGRESS_ADD_START:
|
|
|
|
case PM_TRANS_PROGRESS_UPGRADE_START:
|
|
|
|
case PM_TRANS_PROGRESS_REMOVE_START:
|
2007-02-21 23:32:09 -05:00
|
|
|
printf("(%2$*1$d/%3$*1$d) %4$s %6$-*5$.*5$s", digits, remain, howmany,
|
|
|
|
opr, pkglen, pkgname);
|
2007-01-30 20:37:41 -05:00
|
|
|
break;
|
|
|
|
case PM_TRANS_PROGRESS_CONFLICTS_START:
|
2007-02-21 23:46:34 -05:00
|
|
|
printf("(%2$*1$d/%3$*1$d) %5$-*4$s", digits, remain, howmany,
|
2007-02-14 14:35:41 -05:00
|
|
|
textlen, opr);
|
2007-01-30 20:37:41 -05:00
|
|
|
break;
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2006-10-31 01:41:42 -05:00
|
|
|
|
2007-03-03 04:43:16 -05:00
|
|
|
free(wcopr);
|
|
|
|
|
2007-01-30 20:37:41 -05:00
|
|
|
/* call refactored fill progress function */
|
2007-02-03 20:36:45 -05:00
|
|
|
fill_progress(percent, getcols() - infolen);
|
|
|
|
|
|
|
|
if(percent >= 100) {
|
|
|
|
set_output_padding(0); /* restore padding */
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
|
|
|
|
2005-03-19 04:00:40 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|