2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* package.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2007-12-10 23:55:22 -05:00
|
|
|
* Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2008-06-15 20:15:36 -04:00
|
|
|
#include <unistd.h>
|
2005-03-20 17:03:30 -05:00
|
|
|
#include <limits.h>
|
2008-02-23 00:47:03 -05:00
|
|
|
#include <wchar.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-22 03:46:12 -05:00
|
|
|
#include <alpm_list.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "package.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
|
|
|
|
2007-12-09 00:42:04 -05:00
|
|
|
#define CLBUF_SIZE 4096
|
|
|
|
|
2007-11-23 16:32:40 -05:00
|
|
|
/* Display the content of a package
|
2007-01-29 23:15:14 -05:00
|
|
|
*
|
2007-11-23 16:32:40 -05:00
|
|
|
* level: <0 - sync package [-Si]
|
|
|
|
* =0 - file query [-Qip]
|
|
|
|
* 1 - localdb query, normal level [-Qi]
|
|
|
|
* >1 - localdb query, extra information (backup files) [-Qii]
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
2006-11-20 04:10:23 -05:00
|
|
|
void dump_pkg_full(pmpkg_t *pkg, int level)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2008-07-31 07:38:30 -04:00
|
|
|
const char *reason;
|
2007-09-19 01:21:56 -04:00
|
|
|
time_t bdate, idate;
|
2007-11-23 16:32:40 -05:00
|
|
|
char bdatestr[50] = "", idatestr[50] = "";
|
2007-11-13 01:37:11 -05:00
|
|
|
const alpm_list_t *i;
|
2007-11-29 17:16:13 -05:00
|
|
|
alpm_list_t *requiredby = NULL, *depstrings = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* set variables here, do all output below */
|
|
|
|
bdate = alpm_pkg_get_builddate(pkg);
|
2007-11-23 16:32:40 -05:00
|
|
|
if(bdate) {
|
|
|
|
strftime(bdatestr, 50, "%c", localtime(&bdate));
|
|
|
|
}
|
2007-01-17 00:25:32 -05:00
|
|
|
idate = alpm_pkg_get_installdate(pkg);
|
2007-11-23 16:32:40 -05:00
|
|
|
if(idate) {
|
|
|
|
strftime(idatestr, 50, "%c", localtime(&idate));
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
switch((long)alpm_pkg_get_reason(pkg)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
case PM_PKG_REASON_EXPLICIT:
|
2007-01-22 03:52:18 -05:00
|
|
|
reason = _("Explicitly installed");
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
|
|
|
case PM_PKG_REASON_DEPEND:
|
2007-01-22 03:52:18 -05:00
|
|
|
reason = _("Installed as a dependency for another package");
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
|
|
|
default:
|
2007-01-22 03:52:18 -05:00
|
|
|
reason = _("Unknown");
|
2005-03-14 20:51:43 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-13 01:37:11 -05:00
|
|
|
/* turn depends list into a text list */
|
|
|
|
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
|
|
|
|
pmdepend_t *dep = (pmdepend_t*)alpm_list_getdata(i);
|
2008-08-26 06:57:08 -04:00
|
|
|
depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep));
|
2007-11-13 01:37:11 -05:00
|
|
|
}
|
|
|
|
|
2007-11-29 17:16:13 -05:00
|
|
|
if(level>0) {
|
|
|
|
/* compute this here so we don't get a puase in the middle of output */
|
|
|
|
requiredby = alpm_pkg_compute_requiredby(pkg);
|
|
|
|
}
|
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* actual output */
|
2007-11-23 16:32:40 -05:00
|
|
|
string_display(_("Name :"), alpm_pkg_get_name(pkg));
|
|
|
|
string_display(_("Version :"), alpm_pkg_get_version(pkg));
|
|
|
|
string_display(_("URL :"), alpm_pkg_get_url(pkg));
|
|
|
|
list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg));
|
2007-01-25 21:13:16 -05:00
|
|
|
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
|
|
|
|
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
|
2007-11-13 01:37:11 -05:00
|
|
|
list_display(_("Depends On :"), depstrings);
|
2008-07-31 09:58:25 -04:00
|
|
|
list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
|
2007-01-29 23:15:14 -05:00
|
|
|
/* Only applicable if installed */
|
|
|
|
if(level > 0) {
|
2007-11-12 20:40:08 -05:00
|
|
|
list_display(_("Required By :"), requiredby);
|
|
|
|
FREELIST(requiredby);
|
2007-01-29 23:15:14 -05:00
|
|
|
}
|
2007-01-25 21:13:16 -05:00
|
|
|
list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
|
2007-04-04 21:01:55 -04:00
|
|
|
list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
|
2007-11-23 16:32:40 -05:00
|
|
|
if(level < 0) {
|
|
|
|
printf(_("Download Size : %6.2f K\n"),
|
|
|
|
(float)alpm_pkg_get_size(pkg) / 1024.0);
|
|
|
|
}
|
|
|
|
if(level == 0) {
|
|
|
|
printf(_("Compressed Size: %6.2f K\n"),
|
|
|
|
(float)alpm_pkg_get_size(pkg) / 1024.0);
|
|
|
|
}
|
|
|
|
|
2007-11-11 16:02:33 -05:00
|
|
|
printf(_("Installed Size : %6.2f K\n"),
|
|
|
|
(float)alpm_pkg_get_isize(pkg) / 1024.0);
|
2007-11-23 16:32:40 -05:00
|
|
|
string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
|
|
|
|
string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
|
|
|
|
string_display(_("Build Date :"), bdatestr);
|
2007-01-29 23:15:14 -05:00
|
|
|
if(level > 0) {
|
2007-11-23 16:32:40 -05:00
|
|
|
string_display(_("Install Date :"), idatestr);
|
|
|
|
string_display(_("Install Reason :"), reason);
|
|
|
|
}
|
|
|
|
if(level >= 0) {
|
|
|
|
string_display(_("Install Script :"),
|
|
|
|
alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MD5 Sum for sync package */
|
|
|
|
if(level < 0) {
|
|
|
|
string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
|
2007-01-29 23:15:14 -05:00
|
|
|
}
|
2008-07-31 07:38:30 -04:00
|
|
|
string_display(_("Description :"), alpm_pkg_get_desc(pkg));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* Print additional package info if info flag passed more than once */
|
2005-04-24 15:42:51 -04:00
|
|
|
if(level > 1) {
|
2007-02-07 20:12:48 -05:00
|
|
|
dump_pkg_backups(pkg);
|
2005-03-20 17:03:30 -05:00
|
|
|
}
|
2007-11-13 01:37:11 -05:00
|
|
|
|
2008-08-28 14:55:26 -04:00
|
|
|
/* final newline to separate packages */
|
|
|
|
printf("\n");
|
|
|
|
|
2007-11-13 01:37:11 -05:00
|
|
|
FREELIST(depstrings);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Display the content of a sync package
|
|
|
|
*/
|
2007-01-19 04:28:44 -05:00
|
|
|
void dump_pkg_sync(pmpkg_t *pkg, const char *treename)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-23 16:32:40 -05:00
|
|
|
string_display(_("Repository :"), treename);
|
|
|
|
dump_pkg_full(pkg, -1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* Display list of backup files and their modification states
|
|
|
|
*/
|
|
|
|
void dump_pkg_backups(pmpkg_t *pkg)
|
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i;
|
2007-01-17 00:25:32 -05:00
|
|
|
const char *root = alpm_option_get_root();
|
2007-02-19 21:14:27 -05:00
|
|
|
printf(_("Backup Files:\n"));
|
|
|
|
if(alpm_pkg_get_backup(pkg)) {
|
|
|
|
/* package has backup files, so print them */
|
|
|
|
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char *str = strdup(alpm_list_getdata(i));
|
|
|
|
char *ptr = index(str, '\t');
|
|
|
|
if(ptr == NULL) {
|
2007-04-25 17:24:23 -04:00
|
|
|
free(str);
|
2007-01-17 00:25:32 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-19 21:14:27 -05:00
|
|
|
*ptr = '\0';
|
|
|
|
ptr++;
|
|
|
|
snprintf(path, PATH_MAX-1, "%s%s", root, str);
|
|
|
|
/* if we find the file, calculate checksums, otherwise it is missing */
|
2008-06-15 20:15:36 -04:00
|
|
|
if(access(path, R_OK) == 0) {
|
2008-08-26 06:57:08 -04:00
|
|
|
char *md5sum = alpm_compute_md5sum(path);
|
2007-02-19 21:14:27 -05:00
|
|
|
|
2007-07-25 17:35:29 -04:00
|
|
|
if(md5sum == NULL) {
|
2008-05-10 23:30:27 -04:00
|
|
|
pm_fprintf(stderr, PM_LOG_ERROR,
|
|
|
|
_("could not calculate checksums for %s\n"), path);
|
2007-04-25 17:24:23 -04:00
|
|
|
free(str);
|
2007-02-19 21:14:27 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-25 17:35:29 -04:00
|
|
|
|
2007-02-19 21:14:27 -05:00
|
|
|
/* if checksums don't match, file has been modified */
|
2007-07-25 17:35:29 -04:00
|
|
|
if (strcmp(md5sum, ptr)) {
|
2007-02-19 21:14:27 -05:00
|
|
|
printf(_("MODIFIED\t%s\n"), path);
|
|
|
|
} else {
|
|
|
|
printf(_("Not Modified\t%s\n"), path);
|
|
|
|
}
|
2007-04-25 17:24:23 -04:00
|
|
|
free(md5sum);
|
2007-01-17 00:25:32 -05:00
|
|
|
} else {
|
2007-02-19 21:14:27 -05:00
|
|
|
printf(_("MISSING\t\t%s\n"), path);
|
2007-01-17 00:25:32 -05:00
|
|
|
}
|
2007-04-25 17:24:23 -04:00
|
|
|
free(str);
|
2007-01-17 00:25:32 -05:00
|
|
|
}
|
2007-02-19 21:14:27 -05:00
|
|
|
} else {
|
|
|
|
/* package had no backup files */
|
|
|
|
printf(_("(none)\n"));
|
2007-01-17 00:25:32 -05:00
|
|
|
}
|
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* List all files contained in a package
|
|
|
|
*/
|
2009-05-10 16:41:29 -04:00
|
|
|
void dump_pkg_files(pmpkg_t *pkg, int quiet)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-02-28 23:51:24 -05:00
|
|
|
const char *pkgname, *root, *filestr;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *i, *pkgfiles;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
pkgname = alpm_pkg_get_name(pkg);
|
|
|
|
pkgfiles = alpm_pkg_get_files(pkg);
|
2007-02-28 23:51:24 -05:00
|
|
|
root = alpm_option_get_root();
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
for(i = pkgfiles; i; i = alpm_list_next(i)) {
|
2008-05-04 20:15:49 -04:00
|
|
|
filestr = alpm_list_getdata(i);
|
2009-05-10 16:41:29 -04:00
|
|
|
if(!quiet){
|
|
|
|
fprintf(stdout, "%s %s%s\n", pkgname, root, filestr);
|
|
|
|
} else {
|
|
|
|
fprintf(stdout, "%s%s\n", root, filestr);
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2007-12-09 00:42:04 -05:00
|
|
|
/* Display the changelog of a package
|
2006-10-15 15:34:52 -04:00
|
|
|
*/
|
2007-12-09 00:42:04 -05:00
|
|
|
void dump_pkg_changelog(pmpkg_t *pkg)
|
2006-10-15 15:34:52 -04:00
|
|
|
{
|
2007-12-09 00:42:04 -05:00
|
|
|
void *fp = NULL;
|
2006-10-15 15:34:52 -04:00
|
|
|
|
2007-12-09 00:42:04 -05:00
|
|
|
if((fp = alpm_pkg_changelog_open(pkg)) == NULL) {
|
2008-05-10 23:30:27 -04:00
|
|
|
pm_fprintf(stderr, PM_LOG_ERROR, _("no changelog available for '%s'.\n"),
|
2007-12-09 00:42:04 -05:00
|
|
|
alpm_pkg_get_name(pkg));
|
2006-10-15 15:34:52 -04:00
|
|
|
return;
|
2007-12-09 00:42:04 -05:00
|
|
|
} else {
|
|
|
|
/* allocate a buffer to get the changelog back in chunks */
|
|
|
|
char buf[CLBUF_SIZE];
|
|
|
|
int ret = 0;
|
|
|
|
while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) {
|
|
|
|
if(ret < CLBUF_SIZE) {
|
|
|
|
/* if we hit the end of the file, we need to add a null terminator */
|
|
|
|
*(buf + ret) = '\0';
|
|
|
|
}
|
|
|
|
printf("%s", buf);
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
2007-12-09 00:42:04 -05:00
|
|
|
alpm_pkg_changelog_close(pkg, fp);
|
|
|
|
printf("\n");
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|