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
|
#include <alpm.h>
#include <alpm_list.h>
#include "pacman.h"
#include "util.h"
#include "conf.h"
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
int ret = 0;
alpm_list_t *t;
for(t = targets; t; t = alpm_list_next(t)) {
char *filename = NULL, *f;
int found = 0;
alpm_list_t *s;
size_t len;
if((filename = strdup(t->data)) == NULL) {
goto notfound;
}
len = strlen(filename);
f = filename;
while(len > 1 && f[0] == '/') {
f = f + 1;
len--;
}
for(s = syncs; s; s = alpm_list_next(s)) {
alpm_list_t *p;
alpm_db_t *repo = s->data;
alpm_list_t *packages = alpm_db_get_pkgcache(repo);
for(p = packages; p; p = alpm_list_next(p)) {
alpm_pkg_t *pkg = p->data;
alpm_filelist_t *files = alpm_pkg_get_files(pkg);
if(alpm_filelist_contains(files, f)) {
if(!config->quiet) {
printf(_("%s is owned by %s/%s %s\n"), filename,
alpm_db_get_name(repo), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
} else {
printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
}
found = 1;
}
}
}
free(filename);
notfound:
if(!found) {
ret++;
}
}
return 0;
}
static int files_search(alpm_list_t __attribute__((unused)) *syncs, alpm_list_t __attribute__((unused)) *targets) {
return 0;
}
static int files_list(alpm_list_t __attribute__((unused)) *syncs, alpm_list_t __attribute__((unused)) *targets) {
return 0;
}
int pacman_files(alpm_list_t *targets)
{
alpm_list_t *files_dbs = NULL;
if(check_syncdbs(1, 0)) {
return 1;
}
files_dbs = alpm_get_syncdbs(config->handle);
if(config->op_s_sync) {
colon_printf(_("Synchronizing package databases...\n"));
alpm_logaction(config->handle, PACMAN_CALLER_PREFIX,
"synchronizing package lists\n");
if(!sync_syncdbs(config->op_s_sync, files_dbs)) {
return 1;
}
}
if(targets == NULL && (config->op_s_search || config->op_q_owns)) {
pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
return 1;
}
if(config->op_q_owns) {
return files_fileowner(files_dbs, targets);
}
if(config->op_s_search) {
return files_search(files_dbs, targets);
}
if(config->op_q_list) {
return files_list(files_dbs, targets);
}
return 0;
}
|