1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <alpm.h>
#include <alpm_list.h>
#include "package.h"
#include "util.h"
#include "conf.h"
#define CLBUF_SIZE 4096
static void deplist_display(const char *title,
alpm_list_t *deps)
{
alpm_list_t *i, *text = NULL;
for(i = deps; i; i = alpm_list_next(i)) {
alpm_depend_t *dep = alpm_list_getdata(i);
text = alpm_list_add(text, alpm_dep_compute_string(dep));
}
list_display(title, text);
FREELIST(text);
}
void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
{
const char *reason;
time_t bdate, idate;
char bdatestr[50] = "", idatestr[50] = "";
const char *label;
double size;
alpm_list_t *requiredby = NULL;
if(pkg == NULL) {
return;
}
bdate = alpm_pkg_get_builddate(pkg);
if(bdate) {
strftime(bdatestr, 50, "%c", localtime(&bdate));
}
idate = alpm_pkg_get_installdate(pkg);
if(idate) {
strftime(idatestr, 50, "%c", localtime(&idate));
}
switch((long)alpm_pkg_get_reason(pkg)) {
case ALPM_PKG_REASON_EXPLICIT:
reason = _("Explicitly installed");
break;
case ALPM_PKG_REASON_DEPEND:
reason = _("Installed as a dependency for another package");
break;
default:
reason = _("Unknown");
break;
}
if(extra || from == PKG_FROM_LOCALDB) {
requiredby = alpm_pkg_compute_requiredby(pkg);
}
if(from == PKG_FROM_SYNCDB) {
string_display(_("Repository :"),
alpm_db_get_name(alpm_pkg_get_db(pkg)));
}
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));
list_display(_("Groups :"), alpm_pkg_get_groups(pkg));
deplist_display(_("Provides :"), alpm_pkg_get_provides(pkg));
deplist_display(_("Depends On :"), alpm_pkg_get_depends(pkg));
list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg));
if(extra || from == PKG_FROM_LOCALDB) {
list_display(_("Required By :"), requiredby);
}
deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
size = humanize_size(alpm_pkg_get_size(pkg), 'K', &label);
if(from == PKG_FROM_SYNCDB) {
printf(_("Download Size : %6.2f %s\n"), size, label);
} else if(from == PKG_FROM_FILE) {
printf(_("Compressed Size: %6.2f %s\n"), size, label);
}
size = humanize_size(alpm_pkg_get_isize(pkg), 'K', &label);
printf(_("Installed Size : %6.2f %s\n"), size, label);
string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
string_display(_("Build Date :"), bdatestr);
if(from == PKG_FROM_LOCALDB) {
string_display(_("Install Date :"), idatestr);
string_display(_("Install Reason :"), reason);
}
if(from == PKG_FROM_FILE || from == PKG_FROM_LOCALDB) {
string_display(_("Install Script :"),
alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"));
}
if(from == PKG_FROM_SYNCDB) {
string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
string_display(_("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg));
string_display(_("Signatures :"),
alpm_pkg_get_base64_sig(pkg) ? _("Yes") : _("None"));
}
if(from == PKG_FROM_FILE) {
alpm_sigresult_t result;
int err = alpm_pkg_check_pgp_signature(pkg, &result);
if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
string_display(_("Signatures :"), _("None"));
} else if(err) {
string_display(_("Signatures :"),
alpm_strerror(alpm_errno(config->handle)));
} else {
signature_display(_("Signatures :"), &result);
}
alpm_sigresult_cleanup(&result);
}
string_display(_("Description :"), alpm_pkg_get_desc(pkg));
if(from == PKG_FROM_LOCALDB && extra) {
dump_pkg_backups(pkg);
}
printf("\n");
FREELIST(requiredby);
}
static const char *get_backup_file_status(const char *root,
const alpm_backup_t *backup)
{
char path[PATH_MAX];
const char *ret;
snprintf(path, PATH_MAX, "%s%s", root, backup->name);
if(access(path, R_OK) == 0) {
char *md5sum = alpm_compute_md5sum(path);
if(md5sum == NULL) {
pm_fprintf(stderr, ALPM_LOG_ERROR,
_("could not calculate checksums for %s\n"), path);
return NULL;
}
if(strcmp(md5sum, backup->hash) != 0) {
ret = "MODIFIED";
} else {
ret = "UNMODIFIED";
}
free(md5sum);
} else {
switch(errno) {
case EACCES:
ret = "UNREADABLE";
break;
case ENOENT:
ret = "MISSING";
break;
default:
ret = "UNKNOWN";
}
}
return ret;
}
void dump_pkg_backups(alpm_pkg_t *pkg)
{
alpm_list_t *i;
const char *root = alpm_option_get_root(config->handle);
printf(_("Backup Files:\n"));
if(alpm_pkg_get_backup(pkg)) {
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
const alpm_backup_t *backup = alpm_list_getdata(i);
const char *value;
if(!backup->hash) {
continue;
}
value = get_backup_file_status(root, backup);
printf("%s\t%s%s\n", value, root, backup->name);
}
} else {
printf(_("(none)\n"));
}
}
void dump_pkg_files(alpm_pkg_t *pkg, int quiet)
{
const char *pkgname, *root;
alpm_filelist_t *pkgfiles;
size_t i;
pkgname = alpm_pkg_get_name(pkg);
pkgfiles = alpm_pkg_get_files(pkg);
root = alpm_option_get_root(config->handle);
for(i = 0; i < pkgfiles->count; i++) {
const alpm_file_t *file = pkgfiles->files + i;
if(!quiet) {
fprintf(stdout, "%s %s%s\n", pkgname, root, file->name);
} else {
fprintf(stdout, "%s%s\n", root, file->name);
}
}
fflush(stdout);
}
void dump_pkg_changelog(alpm_pkg_t *pkg)
{
void *fp = NULL;
if((fp = alpm_pkg_changelog_open(pkg)) == NULL) {
pm_fprintf(stderr, ALPM_LOG_ERROR, _("no changelog available for '%s'.\n"),
alpm_pkg_get_name(pkg));
return;
} else {
char buf[CLBUF_SIZE];
size_t ret = 0;
while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) {
if(ret < CLBUF_SIZE) {
*(buf + ret) = '\0';
}
printf("%s", buf);
}
alpm_pkg_changelog_close(pkg, fp);
printf("\n");
}
}
|