2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2015-01-28 22:36:58 +05:30
|
|
|
* Copyright (c) 2008-2015 Juan Romero Pardines.
|
2012-11-02 19:34:25 +05:30
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <sys/ioctl.h>
|
2014-10-30 15:53:10 +05:30
|
|
|
#include <assert.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
|
|
|
|
2013-06-12 13:34:10 +05:30
|
|
|
int
|
2012-11-02 19:34:25 +05:30
|
|
|
get_maxcols(void)
|
|
|
|
{
|
|
|
|
struct winsize ws;
|
|
|
|
|
2016-04-24 17:32:52 +05:30
|
|
|
if (!isatty(STDOUT_FILENO)) {
|
2015-04-15 22:10:34 +05:30
|
|
|
/* not a TTY, don't use any limit */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1) {
|
|
|
|
/* 80x24 terminal */
|
|
|
|
return 80;
|
|
|
|
}
|
|
|
|
/* TTY columns */
|
|
|
|
return ws.ws_col;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-22 15:39:21 +05:30
|
|
|
print_package_line(const char *str, size_t maxcols, bool reset)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2020-02-22 15:39:21 +05:30
|
|
|
static size_t cols;
|
2012-11-02 19:34:25 +05:30
|
|
|
static bool first;
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
cols = 0;
|
|
|
|
first = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cols += strlen(str) + 4;
|
|
|
|
if (cols <= maxcols) {
|
|
|
|
if (first == false) {
|
|
|
|
printf(" ");
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("\n ");
|
|
|
|
cols = strlen(str) + 4;
|
|
|
|
}
|
|
|
|
printf("%s ", str);
|
|
|
|
}
|
2014-10-30 15:53:10 +05:30
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
find_longest_pkgname(struct transaction *trans)
|
|
|
|
{
|
|
|
|
xbps_object_t obj;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgname;
|
2020-02-22 15:39:21 +05:30
|
|
|
size_t len = 0, max = 0;
|
2014-10-30 15:53:10 +05:30
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname))
|
|
|
|
continue;
|
2014-10-30 15:53:10 +05:30
|
|
|
len = strlen(pkgname);
|
|
|
|
if (max == 0 || len > max)
|
|
|
|
max = len;
|
|
|
|
}
|
|
|
|
xbps_object_iterator_reset(trans->iter);
|
|
|
|
return max+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-02-22 15:39:21 +05:30
|
|
|
print_trans_colmode(struct transaction *trans, size_t cols)
|
2014-10-30 15:53:10 +05:30
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_t ipkgd;
|
2014-10-30 15:53:10 +05:30
|
|
|
xbps_object_t obj;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t ttype;
|
|
|
|
const char *pkgver, *pkgname, *ipkgver, *ver, *iver, *tract;
|
2014-10-30 15:53:10 +05:30
|
|
|
char size[8];
|
2020-02-21 13:38:22 +05:30
|
|
|
uint64_t dlsize = 0;
|
2020-02-22 15:39:21 +05:30
|
|
|
size_t x, blen, pnamelen, hdrlen;
|
2014-10-30 15:53:10 +05:30
|
|
|
|
|
|
|
pnamelen = find_longest_pkgname(trans);
|
|
|
|
/* header length */
|
2014-12-09 17:03:58 +05:30
|
|
|
hdrlen = pnamelen + 61;
|
2014-10-30 15:53:10 +05:30
|
|
|
if (cols <= hdrlen)
|
|
|
|
return false;
|
|
|
|
|
2014-12-09 17:03:58 +05:30
|
|
|
printf("\nName ");
|
|
|
|
if (pnamelen < 5)
|
|
|
|
pnamelen = 5;
|
|
|
|
|
|
|
|
for (x = 5; x < pnamelen; x++)
|
2014-10-30 15:53:10 +05:30
|
|
|
printf(" ");
|
2014-12-09 17:03:58 +05:30
|
|
|
|
2014-11-05 14:46:57 +05:30
|
|
|
printf("Action Version New version Download size\n");
|
2014-10-30 15:53:10 +05:30
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
bool dload = false;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
pkgver = pkgname = ipkgver = ver = iver = NULL;
|
2014-10-30 15:53:10 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
2014-10-30 15:53:10 +05:30
|
|
|
xbps_dictionary_get_uint64(obj, "filename-size", &dlsize);
|
|
|
|
xbps_dictionary_get_bool(obj, "download", &dload);
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = xbps_transaction_pkg_type(obj);
|
2014-10-30 15:53:10 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
tract = "unknown";
|
2020-01-25 17:35:46 +05:30
|
|
|
if (trans->xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
|
|
|
tract = "download";
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (ttype == XBPS_TRANS_INSTALL) {
|
2014-11-05 14:46:57 +05:30
|
|
|
trans->inst_pkgcnt++;
|
2020-02-21 13:38:22 +05:30
|
|
|
tract = "install";
|
|
|
|
} else if (ttype == XBPS_TRANS_REINSTALL) {
|
|
|
|
trans->inst_pkgcnt++;
|
|
|
|
tract = "reinstall";
|
|
|
|
} else if (ttype == XBPS_TRANS_UPDATE) {
|
2014-11-05 14:46:57 +05:30
|
|
|
trans->up_pkgcnt++;
|
2020-02-21 13:38:22 +05:30
|
|
|
tract = "update";
|
|
|
|
} else if (ttype == XBPS_TRANS_REMOVE) {
|
2014-11-05 14:46:57 +05:30
|
|
|
trans->rm_pkgcnt++;
|
2020-02-21 13:38:22 +05:30
|
|
|
tract = "remove";
|
|
|
|
} else if (ttype == XBPS_TRANS_CONFIGURE) {
|
2014-11-05 14:46:57 +05:30
|
|
|
trans->cf_pkgcnt++;
|
2020-02-21 13:38:22 +05:30
|
|
|
tract = "configure";
|
|
|
|
} else if (ttype == XBPS_TRANS_HOLD) {
|
|
|
|
tract = "hold";
|
|
|
|
} else if (ttype == XBPS_TRANS_DOWNLOAD) {
|
|
|
|
tract = "download";
|
|
|
|
}
|
|
|
|
if (dload) {
|
|
|
|
trans->dl_pkgcnt++;
|
2014-11-05 14:46:57 +05:30
|
|
|
}
|
2020-01-25 17:35:46 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname);
|
2019-06-21 19:56:08 +05:30
|
|
|
if (trans->xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
2020-01-25 17:35:46 +05:30
|
|
|
ipkgd = NULL;
|
2019-06-21 19:56:08 +05:30
|
|
|
}
|
2015-01-29 14:28:32 +05:30
|
|
|
if (ipkgd) {
|
2014-10-30 15:53:10 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
|
|
|
|
iver = xbps_pkg_version(ipkgver);
|
|
|
|
}
|
|
|
|
ver = xbps_pkg_version(pkgver);
|
2015-01-29 14:28:32 +05:30
|
|
|
if (iver) {
|
|
|
|
int rv = xbps_cmpver(iver, ver);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (rv == 1 && ttype != XBPS_TRANS_HOLD)
|
2015-01-29 14:28:32 +05:30
|
|
|
tract = "downgrade";
|
|
|
|
}
|
2014-10-30 15:53:10 +05:30
|
|
|
/* print pkgname and some blanks */
|
|
|
|
blen = pnamelen - strlen(pkgname);
|
|
|
|
printf("%s", pkgname);
|
|
|
|
for (x = 0; x < blen; x++)
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
/* print action */
|
|
|
|
printf("%s ", tract);
|
2014-11-05 14:46:57 +05:30
|
|
|
for (x = strlen(tract); x < 9; x++)
|
2014-10-30 15:53:10 +05:30
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
/* print installed version */
|
|
|
|
if (iver == NULL)
|
|
|
|
iver = "-";
|
|
|
|
|
|
|
|
/* print new version */
|
|
|
|
printf("%s ", iver);
|
2014-11-05 14:46:57 +05:30
|
|
|
for (x = strlen(iver); x < 17; x++)
|
2014-10-30 15:53:10 +05:30
|
|
|
printf(" ");
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (ttype == XBPS_TRANS_REMOVE) {
|
2014-10-30 15:53:10 +05:30
|
|
|
ver = "-";
|
|
|
|
}
|
|
|
|
if (dload)
|
|
|
|
(void)xbps_humanize_number(size, (int64_t)dlsize);
|
|
|
|
else {
|
|
|
|
size[0] = '-';
|
|
|
|
size[1] = '\0';
|
|
|
|
}
|
|
|
|
printf("%s ", ver);
|
2014-11-05 14:46:57 +05:30
|
|
|
for (x = strlen(ver); x < 22; x++)
|
2014-10-30 15:53:10 +05:30
|
|
|
printf(" ");
|
|
|
|
/* print download size */
|
|
|
|
printf("%s ", size);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
xbps_object_iterator_reset(trans->iter);
|
|
|
|
return true;
|
|
|
|
}
|