4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include <alpm_list.h>
38 #define CLBUF_SIZE 4096
40 /** Turn a depends list into a text list.
41 * @param deps a list with items of type alpm_depend_t
42 * @return a string list, must be freed
44 static void deplist_display(const char *title
,
47 alpm_list_t
*i
, *text
= NULL
;
48 for(i
= deps
; i
; i
= alpm_list_next(i
)) {
49 alpm_depend_t
*dep
= alpm_list_getdata(i
);
50 text
= alpm_list_add(text
, alpm_dep_compute_string(dep
));
52 list_display(title
, text
);
57 * Display the details of a package.
58 * Extra information entails 'required by' info for sync packages and backup
59 * files info for local packages.
60 * @param pkg package to display information for
61 * @param from the type of package we are dealing with
62 * @param extra should we show extra information
64 void dump_pkg_full(alpm_pkg_t
*pkg
, int extra
)
68 char bdatestr
[50] = "", idatestr
[50] = "";
71 alpm_list_t
*requiredby
= NULL
;
74 from
= alpm_pkg_get_origin(pkg
);
76 /* set variables here, do all output below */
77 bdate
= alpm_pkg_get_builddate(pkg
);
79 strftime(bdatestr
, 50, "%c", localtime(&bdate
));
81 idate
= alpm_pkg_get_installdate(pkg
);
83 strftime(idatestr
, 50, "%c", localtime(&idate
));
86 switch((long)alpm_pkg_get_reason(pkg
)) {
87 case ALPM_PKG_REASON_EXPLICIT
:
88 reason
= _("Explicitly installed");
90 case ALPM_PKG_REASON_DEPEND
:
91 reason
= _("Installed as a dependency for another package");
94 reason
= _("Unknown");
98 if(extra
|| from
== PKG_FROM_LOCALDB
) {
99 /* compute this here so we don't get a pause in the middle of output */
100 requiredby
= alpm_pkg_compute_requiredby(pkg
);
104 if(from
== PKG_FROM_SYNCDB
) {
105 string_display(_("Repository :"),
106 alpm_db_get_name(alpm_pkg_get_db(pkg
)));
108 string_display(_("Name :"), alpm_pkg_get_name(pkg
));
109 string_display(_("Version :"), alpm_pkg_get_version(pkg
));
110 string_display(_("URL :"), alpm_pkg_get_url(pkg
));
111 list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg
));
112 list_display(_("Groups :"), alpm_pkg_get_groups(pkg
));
113 deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg
));
114 deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg
));
115 list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg
));
116 if(extra
|| from
== PKG_FROM_LOCALDB
) {
117 list_display(_("Required By :"), requiredby
);
119 deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg
));
120 deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg
));
122 size
= humanize_size(alpm_pkg_get_size(pkg
), 'K', &label
);
123 if(from
== PKG_FROM_SYNCDB
) {
124 printf(_("Download Size : %6.2f %s\n"), size
, label
);
125 } else if(from
== PKG_FROM_FILE
) {
126 printf(_("Compressed Size: %6.2f %s\n"), size
, label
);
129 size
= humanize_size(alpm_pkg_get_isize(pkg
), 'K', &label
);
130 printf(_("Installed Size : %6.2f %s\n"), size
, label
);
132 string_display(_("Packager :"), alpm_pkg_get_packager(pkg
));
133 string_display(_("Architecture :"), alpm_pkg_get_arch(pkg
));
134 string_display(_("Build Date :"), bdatestr
);
135 if(from
== PKG_FROM_LOCALDB
) {
136 string_display(_("Install Date :"), idatestr
);
137 string_display(_("Install Reason :"), reason
);
139 if(from
== PKG_FROM_FILE
|| from
== PKG_FROM_LOCALDB
) {
140 string_display(_("Install Script :"),
141 alpm_pkg_has_scriptlet(pkg
) ? _("Yes") : _("No"));
144 if(from
== PKG_FROM_SYNCDB
) {
145 string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg
));
146 string_display(_("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg
));
147 string_display(_("Signatures :"),
148 alpm_pkg_get_base64_sig(pkg
) ? _("Yes") : _("None"));
150 if(from
== PKG_FROM_FILE
) {
151 alpm_siglist_t siglist
;
152 int err
= alpm_pkg_check_pgp_signature(pkg
, &siglist
);
153 if(err
&& alpm_errno(config
->handle
) == ALPM_ERR_SIG_MISSING
) {
154 string_display(_("Signatures :"), _("None"));
156 string_display(_("Signatures :"),
157 alpm_strerror(alpm_errno(config
->handle
)));
159 signature_display(_("Signatures :"), &siglist
);
161 alpm_siglist_cleanup(&siglist
);
163 string_display(_("Description :"), alpm_pkg_get_desc(pkg
));
165 /* Print additional package info if info flag passed more than once */
166 if(from
== PKG_FROM_LOCALDB
&& extra
) {
167 dump_pkg_backups(pkg
);
170 /* final newline to separate packages */
173 FREELIST(requiredby
);
176 static const char *get_backup_file_status(const char *root
,
177 const alpm_backup_t
*backup
)
182 snprintf(path
, PATH_MAX
, "%s%s", root
, backup
->name
);
184 /* if we find the file, calculate checksums, otherwise it is missing */
185 if(access(path
, R_OK
) == 0) {
186 char *md5sum
= alpm_compute_md5sum(path
);
189 pm_fprintf(stderr
, ALPM_LOG_ERROR
,
190 _("could not calculate checksums for %s\n"), path
);
194 /* if checksums don't match, file has been modified */
195 if(strcmp(md5sum
, backup
->hash
) != 0) {
216 /* Display list of backup files and their modification states
218 void dump_pkg_backups(alpm_pkg_t
*pkg
)
221 const char *root
= alpm_option_get_root(config
->handle
);
222 printf(_("Backup Files:\n"));
223 if(alpm_pkg_get_backup(pkg
)) {
224 /* package has backup files, so print them */
225 for(i
= alpm_pkg_get_backup(pkg
); i
; i
= alpm_list_next(i
)) {
226 const alpm_backup_t
*backup
= alpm_list_getdata(i
);
231 value
= get_backup_file_status(root
, backup
);
232 printf("%s\t%s%s\n", value
, root
, backup
->name
);
235 /* package had no backup files */
236 printf(_("(none)\n"));
240 /* List all files contained in a package
242 void dump_pkg_files(alpm_pkg_t
*pkg
, int quiet
)
244 const char *pkgname
, *root
;
245 alpm_filelist_t
*pkgfiles
;
248 pkgname
= alpm_pkg_get_name(pkg
);
249 pkgfiles
= alpm_pkg_get_files(pkg
);
250 root
= alpm_option_get_root(config
->handle
);
252 for(i
= 0; i
< pkgfiles
->count
; i
++) {
253 const alpm_file_t
*file
= pkgfiles
->files
+ i
;
255 fprintf(stdout
, "%s %s%s\n", pkgname
, root
, file
->name
);
257 fprintf(stdout
, "%s%s\n", root
, file
->name
);
264 /* Display the changelog of a package
266 void dump_pkg_changelog(alpm_pkg_t
*pkg
)
270 if((fp
= alpm_pkg_changelog_open(pkg
)) == NULL
) {
271 pm_fprintf(stderr
, ALPM_LOG_ERROR
, _("no changelog available for '%s'.\n"),
272 alpm_pkg_get_name(pkg
));
275 /* allocate a buffer to get the changelog back in chunks */
276 char buf
[CLBUF_SIZE
];
278 while((ret
= alpm_pkg_changelog_read(buf
, CLBUF_SIZE
, pkg
, fp
))) {
279 if(ret
< CLBUF_SIZE
) {
280 /* if we hit the end of the file, we need to add a null terminator */
285 alpm_pkg_changelog_close(pkg
, fp
);
290 /* vim: set ts=2 sw=2 noet: */