2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* package.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2005-03-20 17:03:30 -05:00
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
2006-05-14 22:19:57 -04:00
|
|
|
#include <libintl.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-22 03:46:12 -05:00
|
|
|
#include <alpm_list.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2005-03-20 17:03:30 -05:00
|
|
|
#include "log.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
|
|
|
#include "package.h"
|
|
|
|
|
|
|
|
/* Display the content of an installed package
|
|
|
|
*/
|
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
|
|
|
{
|
2007-01-17 00:25:32 -05:00
|
|
|
const char *bdate, *type, *idate, *reason;
|
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);
|
2006-11-20 04:10:23 -05:00
|
|
|
type = alpm_pkg_get_buildtype(pkg);
|
2007-01-17 00:25:32 -05:00
|
|
|
idate = alpm_pkg_get_installdate(pkg);
|
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-01-17 00:25:32 -05:00
|
|
|
/* actual output */
|
|
|
|
printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
|
|
|
|
printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg));
|
2007-01-19 04:28:44 -05:00
|
|
|
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
|
2007-01-17 00:25:32 -05:00
|
|
|
printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg));
|
|
|
|
printf(_("URL : %s\n"), (char *)alpm_pkg_get_url(pkg));
|
2007-01-19 04:28:44 -05:00
|
|
|
list_display(_("License :"), alpm_pkg_get_licenses(pkg));
|
2007-01-17 00:25:32 -05:00
|
|
|
printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg));
|
|
|
|
printf(_("Installed Size : %ld\n"), (long int)alpm_pkg_get_size(pkg));
|
|
|
|
printf(_("Build Date : %s %s\n"), bdate, strlen(bdate) ? "UTC" : "");
|
|
|
|
printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown"));
|
|
|
|
/* TODO only applicable if querying installed package, not a file */
|
|
|
|
printf(_("Install Date : %s %s\n"), idate, strlen(idate) ? "UTC" : "");
|
|
|
|
printf(_("Install Script : %s\n"), alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
|
|
|
|
printf(_("Reason : %s\n"), reason);
|
2007-01-19 04:28:44 -05:00
|
|
|
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
|
|
|
|
list_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
|
|
|
|
list_display(_("Removes :"), alpm_pkg_get_removes(pkg));
|
2007-01-17 00:25:32 -05:00
|
|
|
/* TODO only applicable if querying installed package, not a file */
|
2007-01-19 04:28:44 -05:00
|
|
|
list_display(_("Required By :"), alpm_pkg_get_requiredby(pkg));
|
|
|
|
list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-05-14 22:19:57 -04:00
|
|
|
printf(_("Description : "));
|
2006-11-20 04:10:23 -05:00
|
|
|
indentprint(alpm_pkg_get_desc(pkg), 17);
|
2005-03-14 20:51:43 -05:00
|
|
|
printf("\n");
|
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
/* Print additional package info if info flag passed more than once */
|
|
|
|
/* TODO only applicable if querying installed package, not a file */
|
2005-04-24 15:42:51 -04:00
|
|
|
if(level > 1) {
|
2007-01-17 00:25:32 -05:00
|
|
|
/* call new backup function */
|
|
|
|
dump_pkg_backups(pkg);
|
2005-03-20 17:03:30 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2007-01-17 00:25:32 -05:00
|
|
|
char *md5sum, *sha1sum;
|
2005-03-14 20:51:43 -05:00
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-17 00:25:32 -05:00
|
|
|
md5sum = (char *)alpm_pkg_get_md5sum(pkg);
|
|
|
|
sha1sum = (char *)alpm_pkg_get_sha1sum(pkg);
|
|
|
|
|
|
|
|
printf(_("Repository : %s\n"), treename);
|
|
|
|
printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));
|
|
|
|
printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg));
|
2007-01-19 04:28:44 -05:00
|
|
|
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
|
|
|
|
list_display(_("Provides :"), alpm_pkg_get_provides(pkg));
|
|
|
|
list_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
|
|
|
|
list_display(_("Removes :"), alpm_pkg_get_removes(pkg));
|
|
|
|
list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
|
|
|
|
list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
|
2007-01-17 00:25:32 -05:00
|
|
|
printf(_("Download Size : %ld\n"), (long)alpm_pkg_get_size(pkg));
|
|
|
|
printf(_("Installed Size : %ld\n"), (long)alpm_pkg_get_isize(pkg));
|
|
|
|
|
|
|
|
printf(_("Description : "));
|
|
|
|
indentprint(alpm_pkg_get_desc(pkg), 17);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (md5sum != NULL && md5sum[0] != '\0') {
|
|
|
|
printf(_("MD5 Sum : %s"), md5sum);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-01-17 00:25:32 -05:00
|
|
|
if (sha1sum != NULL && sha1sum[0] != '\0') {
|
|
|
|
printf(_("SHA1 Sum : %s"), sha1sum);
|
2006-10-15 15:34:52 -04:00
|
|
|
}
|
|
|
|
printf("\n");
|
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();
|
|
|
|
printf("\nBackup Files :\n");
|
2007-01-19 04:28:44 -05:00
|
|
|
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
|
2007-01-17 00:25:32 -05:00
|
|
|
struct stat buf;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char *str = strdup(alpm_list_getdata(i));
|
|
|
|
char *ptr = index(str, '\t');
|
|
|
|
if(ptr == NULL) {
|
|
|
|
FREE(str);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*ptr = '\0';
|
|
|
|
ptr++;
|
|
|
|
snprintf(path, PATH_MAX-1, "%s%s", root, str);
|
|
|
|
/* if we find the file, calculate checksums, otherwise it is missing */
|
|
|
|
if(!stat(path, &buf)) {
|
|
|
|
char *sum;
|
|
|
|
char *md5sum = alpm_get_md5sum(path);
|
|
|
|
char *sha1sum = alpm_get_sha1sum(path);
|
|
|
|
|
|
|
|
if(md5sum == NULL || sha1sum == NULL) {
|
|
|
|
ERR(NL, _("error calculating checksums for %s\n"), path);
|
|
|
|
FREE(str);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* TODO Is this a good way to check type of backup stored?
|
|
|
|
* We aren't storing it anywhere in the database. */
|
|
|
|
if (strlen(ptr) == 32) {
|
|
|
|
sum = md5sum;
|
|
|
|
} else { /*if (strlen(ptr) == 40) */
|
|
|
|
sum = sha1sum;
|
|
|
|
}
|
|
|
|
/* if checksums don't match, file has been modified */
|
|
|
|
if (strcmp(sum, ptr)) {
|
|
|
|
printf(_("MODIFIED\t%s\n"), path);
|
|
|
|
} else {
|
|
|
|
printf(_("Not Modified\t%s\n"), path);
|
|
|
|
}
|
|
|
|
FREE(md5sum);
|
|
|
|
FREE(sha1sum);
|
|
|
|
} else {
|
|
|
|
printf(_("MISSING\t\t%s\n"), path);
|
|
|
|
}
|
|
|
|
FREE(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* List all files contained in a package
|
|
|
|
*/
|
2006-11-20 04:10:23 -05:00
|
|
|
void dump_pkg_files(pmpkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-11-20 04:10:23 -05:00
|
|
|
const char *pkgname;
|
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);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
for(i = pkgfiles; i; i = alpm_list_next(i)) {
|
2006-10-15 15:34:52 -04:00
|
|
|
fprintf(stdout, "%s %s\n", (char *)pkgname, (char *)alpm_list_getdata(i));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:34:52 -04:00
|
|
|
/* Display the changelog of an installed package
|
|
|
|
*/
|
2006-11-20 04:10:23 -05:00
|
|
|
void dump_pkg_changelog(char *clfile, const char *pkgname)
|
2006-10-15 15:34:52 -04:00
|
|
|
{
|
|
|
|
FILE* fp = NULL;
|
|
|
|
char line[PATH_MAX+1];
|
|
|
|
|
|
|
|
if((fp = fopen(clfile, "r")) == NULL)
|
|
|
|
{
|
|
|
|
ERR(NL, _("No changelog available for '%s'.\n"), pkgname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(!feof(fp))
|
|
|
|
{
|
2007-01-18 11:52:57 -05:00
|
|
|
fgets(line, (int)PATH_MAX, fp);
|
2006-10-15 15:34:52 -04:00
|
|
|
printf("%s", line);
|
|
|
|
line[0] = '\0';
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|