Skip to content
Newer
Older
100644 648 lines (555 sloc) 15.4 KB
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
1 #include <string.h>
584c433 @yanhan Initial commit.
authored May 24, 2011
2 #include <alpm.h>
3
4 #include "conf.h"
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
5 #include "curl.h"
584c433 @yanhan Initial commit.
authored May 24, 2011
6 #include "environment.h"
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
7 #include "graph.h"
bb1e229 @yanhan Shift pw_hashdb to its own file
authored Jun 7, 2011
8 #include "hashdb.h"
584c433 @yanhan Initial commit.
authored May 24, 2011
9 #include "package.h"
10 #include "powaur.h"
11 #include "query.h"
12 #include "util.h"
13
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
14 /* Removes version information from a package string like "glibc>=2.12" */
15 static void chompversion(char *str)
16 {
17 char *p;
18 p = strchr(str, '>');
19 if (p) {
20 *p = 0;
21 return;
22 }
23 p = strchr(str, '<');
24 if (p) {
25 *p = 0;
26 return;
27 }
28 p = strchr(str, '=');
29 if (p) {
30 *p = 0;
31 }
32 }
33
584c433 @yanhan Initial commit.
authored May 24, 2011
34 /* -Qi */
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
35 static int query_info(alpm_db_t *localdb, alpm_list_t *targets)
584c433 @yanhan Initial commit.
authored May 24, 2011
36 {
37 int ret, hits, found, pkgcount;
38 alpm_list_t *i, *k, *dbcache;
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
39 alpm_pkg_t *pkg;
584c433 @yanhan Initial commit.
authored May 24, 2011
40
41 ret = pkgcount = hits = found = 0;
42 dbcache = alpm_db_get_pkgcache(localdb);
43
44 for (i = targets; i; i = i->next, ++pkgcount) {
45 found = 0;
46 for (k = dbcache; k; k = k->next) {
47 pkg = k->data;
48 if (!strcmp(i->data, alpm_pkg_get_name(pkg))) {
49 if (hits++) {
50 printf("\n");
51 }
52
53 found = 1;
54 pacman_pkgdump(pkg, PKG_FROM_LOCAL);
55 break;
56 }
57 }
58
59 if (!found) {
60 if (pkgcount) {
61 printf("\n");
62 }
63
64 ret = -1;
65 pw_fprintf(PW_LOG_ERROR, stderr, "package %s not found\n", i->data);
66 }
67 }
68
69 return ret;
70 }
71
72 /* -Qs, only 1 target for now */
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
73 static int query_search(alpm_db_t *localdb, const char *pkgname)
584c433 @yanhan Initial commit.
authored May 24, 2011
74 {
75 int ret, found;
fdcc4cf @yanhan Introduce colorized output for -Q and -S
authored May 30, 2011
76 const char *repo;
584c433 @yanhan Initial commit.
authored May 24, 2011
77 alpm_list_t *i, *k, *dbcache, *groups;
fdcc4cf @yanhan Introduce colorized output for -Q and -S
authored May 30, 2011
78 alpm_list_t *syncdbs;
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
79 alpm_pkg_t *pkg;
584c433 @yanhan Initial commit.
authored May 24, 2011
80
81 dbcache = alpm_db_get_pkgcache(localdb);
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
82 syncdbs = alpm_option_get_syncdbs(config->handle);
584c433 @yanhan Initial commit.
authored May 24, 2011
83
84 for (k = dbcache; k; k = k->next) {
85 pkg = k->data;
fdcc4cf @yanhan Introduce colorized output for -Q and -S
authored May 30, 2011
86 groups = NULL;
584c433 @yanhan Initial commit.
authored May 24, 2011
87
fdcc4cf @yanhan Introduce colorized output for -Q and -S
authored May 30, 2011
88 if (!strcmp(pkgname, alpm_pkg_get_name(pkg))) {
89 repo = which_db(syncdbs, pkgname, &groups);
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
90 color_repo(repo);
91 printf("%s%s %s%s", color.bold, pkgname,
fdcc4cf @yanhan Introduce colorized output for -Q and -S
authored May 30, 2011
92 color.bgreen, alpm_pkg_get_version(pkg));
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
93 color_groups(groups);
94 printf("%s %s\n", TAB, alpm_pkg_get_desc(pkg));
584c433 @yanhan Initial commit.
authored May 24, 2011
95 found = 1;
96 }
97 }
98
99 return found ? 0: -1;
100 }
101
102 int powaur_query(alpm_list_t *targets)
103 {
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
104 alpm_db_t *localdb = alpm_option_get_localdb(config->handle);
b848e42 @yanhan Add error functions and wrapper functions
authored May 25, 2011
105 if (!localdb) {
106 return error(PW_ERR_INIT_LOCALDB);
107 }
584c433 @yanhan Initial commit.
authored May 24, 2011
108
109 alpm_list_t *dblist = NULL;
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
110 alpm_list_t *i, *j, *dbcache;
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
111 alpm_pkg_t *pkg, *spkg;
584c433 @yanhan Initial commit.
authored May 24, 2011
112 int ret = 0, found;
113
114 /* -i and -s conflicting options */
115 if (config->op_q_info && config->op_q_search) {
116 pw_fprintf(PW_LOG_ERROR, stderr, "-i (info) and -s (search) are "
117 "mutually exclusive.\n");
118 return -1;
119 }
120
121 /* No targets */
122 if (targets == NULL) {
123 dblist = alpm_list_add(dblist, localdb);
124
125 if (config->op_q_info) {
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
126 /* -Qi, detailed info */
127 ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_INFO);
584c433 @yanhan Initial commit.
authored May 24, 2011
128 } else if (config->op_q_search) {
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
129 /* -Qs
130 * repo/pkg ver (grp)
131 * desc
132 */
133 ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_SEARCH);
584c433 @yanhan Initial commit.
authored May 24, 2011
134 } else {
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
135 /* -Q
136 * repo/pkg ver (grp)
137 */
138 ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q);
584c433 @yanhan Initial commit.
authored May 24, 2011
139 }
140
141 alpm_list_free(dblist);
142 return ret;
143 }
144
145 if (config->op_q_info) {
146 ret = query_info(localdb, targets);
147 } else if (config->op_q_search) {
148 ret = query_search(localdb, targets->data);
149 } else {
150 /* Plain -Q */
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
151 alpm_list_t *sdbs = alpm_option_get_syncdbs(config->handle);
584c433 @yanhan Initial commit.
authored May 24, 2011
152 dbcache = alpm_db_get_pkgcache(localdb);
153
154 for (i = targets; i; i = i->next) {
155 found = 0;
156 for (j = dbcache; j; j = j->next) {
157 pkg = j->data;
158 if (!strcmp(i->data, alpm_pkg_get_name(pkg))) {
25865b4 @yanhan Colorized output for -Q and -S
authored May 30, 2011
159 print_pkg_pretty(sdbs, pkg, DUMP_Q);
584c433 @yanhan Initial commit.
authored May 24, 2011
160 found = 1;
161 break;
162 }
163 }
164
165 if (!found) {
166 printf("package \"%s\" not found\n", i->data);
167 ret = -1;
168 }
169 }
170 }
171
172 return ret;
173 }
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
174
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
175 /* Change provided package to a package which provides it.
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
176 * For AUR packages, this also downloads and extracts PKGBUILD in cwd.
177 * In addition, the "normalized" packages will be cached in hashdb->pkg_from
178 *
179 * @param curl curl handle
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
180 * @param hashdb hash database
181 * @param pkg package name
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
182 * @param resolve_lvl level of dep resolution. RESOLVE_THOROUGH forces
183 * downloading of AUR PKGBUILDs
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
184 *
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
185 * returns the "normalized" package if present, NULL on failure
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
186 */
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
187 static const char *normalize_package(CURL *curl, struct pw_hashdb *hashdb,
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
188 const char *pkgname, int resolve_lvl)
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
189 {
190 const char *provided = NULL;
191 struct pkgpair pkgpair;
192 struct pkgpair *pkgptr;
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
193 enum pkgfrom_t *pkgfrom;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
194
195 pkgpair.pkgname = pkgname;
196 pkgpair.pkg = NULL;
197
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
198 /* If we know where pkg is from and it's not AUR / it's from AUR and
199 * already downloaded, done */
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
200 pkgfrom = hashmap_search(hashdb->pkg_from, (void *) pkgname);
201 if (pkgfrom) {
202 if (*pkgfrom != PKG_FROM_AUR ||
203 hash_search(hashdb->aur_downloaded, (void *) pkgname)) {
204 return pkgname;
205 }
206
207 goto search_aur;
208 }
209
210 /* If it's in local db and not AUR, done */
211 if (hash_search(hashdb->local, &pkgpair)) {
212 if (hash_search(hashdb->aur, &pkgpair)) {
213 goto search_aur;
214 }
215 hashmap_insert(hashdb->pkg_from, (void *) pkgname, &hashdb->pkg_from_local);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
216 return pkgname;
217 }
218
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
219 /* Search provides cache */
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
220 provided = hashmap_search(hashdb->provides_cache, (void *) pkgname);
221 if (provided) {
222 return provided;
223 }
224
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
225 /* Search local provides */
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
226 pkgptr = hashbst_tree_search(hashdb->local_provides, (void *) pkgname,
227 hashdb->local, provides_search);
228 if (pkgptr) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
229 /* Cache in provides and pkg_from */
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
230 hashmap_insert(hashdb->provides_cache, (void *) pkgname,
231 (void *) pkgptr->pkgname);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
232 hashmap_insert(hashdb->pkg_from, (void *) pkgptr->pkgname, &hashdb->pkg_from_local);
233 return pkgptr->pkgname;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
234 }
235
305baf1 @yanhan Improved -G dependency resolution
authored Jun 10, 2011
236 /* Search sync provides tree in local db
237 * TODO: Is there a meaning to this?
238 * local provides are obtained from local packages.
239 * sync provides are obtained from sync packages.
240 * So searching for sync provides in local database is kind of...
241 */
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
242 pkgptr = hashbst_tree_search(hashdb->sync_provides, (void *) pkgname,
243 hashdb->local, provides_search);
244
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
245 if (pkgptr) {
246 /* Cache in pkg_from */
247 hashmap_insert(hashdb->pkg_from, (void *) pkgptr->pkgname, &hashdb->pkg_from_local);
248 return pkgptr->pkgname;
249 }
250
251 /* Search sync db */
252 if (hash_search(hashdb->sync, &pkgpair)) {
253 hashmap_insert(hashdb->pkg_from, (void *) pkgname, &hashdb->pkg_from_sync);
254 return pkgname;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
255 }
256
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
257 /* Sync provides */
258 pkgptr = hashbst_tree_search(hashdb->sync_provides, (void *) pkgname,
259 hashdb->sync, provides_search);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
260 if (pkgptr) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
261 hashmap_insert(hashdb->pkg_from, (void *) pkgptr->pkgname,
262 &hashdb->pkg_from_sync);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
263 hashmap_insert(hashdb->provides_cache, (void *) pkgname, (void *) pkgptr->pkgname);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
264 return pkgptr->pkgname;
265 }
266
267 search_aur:
268 pkgpair.pkgname = pkgname;
269 pkgpair.pkg = NULL;
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
270
271 /* For non RESOLVE_THOROUGH, don't bother downloading PKGBUILD of updated
272 * AUR packages
273 */
274 if (resolve_lvl != RESOLVE_THOROUGH) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
275 if (hash_search(hashdb->aur, &pkgpair) &&
276 !hash_search(hashdb->aur_outdated, (void *) pkgname)) {
277 goto done;
278 }
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
279 }
280
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
281 /* Download and extract from AUR */
afd1711 @yanhan Disable downloading messages for --crawl
authored Jun 9, 2011
282 if (dl_extract_single_package(curl, pkgname, NULL, 0)) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
283 return NULL;
284 }
285
286 hash_insert(hashdb->aur_downloaded, (void *) pkgname);
287 hashmap_insert(hashdb->pkg_from, (void *) pkgname, &hashdb->pkg_from_aur);
288
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
289 done:
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
290 return pkgname;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
291 }
292
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
293 /* Resolve dependencies for a given package
294 * @param curl curl handle
295 * @param hashdb hash database
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
296 * @param curpkg current package we are resolving
297 * @param dep_list pointer to list to store resulting dependencies
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
298 * @param resolve_lvl level of dep resolution. RESOLVE_THOROUGH forces
299 * downloading of AUR PKGBUILDs
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
300 *
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
301 * returns -1 on error, 0 on success
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
302 */
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
303 static int crawl_resolve(CURL *curl, struct pw_hashdb *hashdb, struct pkgpair *curpkg,
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
304 alpm_list_t **dep_list, int resolve_lvl)
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
305 {
306 alpm_list_t *i, *depmod_list, *deps = NULL;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
307 struct pkgpair *pkgpair;
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
308 struct pkgpair tmppkg;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
309 void *pkg_provides;
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
310 void *memlist_ptr;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
311 const char *cache_result;
312 const char *depname, *final_pkgname;
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
313 char cwd[PATH_MAX];
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
314 char buf[PATH_MAX];
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
315
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
316 /* Normalize package before doing anything else */
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
317 final_pkgname = normalize_package(curl, hashdb, curpkg->pkgname, resolve_lvl);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
318 if (!final_pkgname) {
319 return -1;
320 }
321
322 enum pkgfrom_t *from = hashmap_search(hashdb->pkg_from, (void *) final_pkgname);
323 if (!from) {
324 die("Failed to find out where package \"%s\" is from!\n", final_pkgname);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
325 }
326
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
327 switch (*from) {
328 case PKG_FROM_LOCAL:
329 tmppkg.pkgname = final_pkgname;
330 pkgpair = hash_search(hashdb->local, &tmppkg);
331 goto get_deps;
332 case PKG_FROM_SYNC:
333 tmppkg.pkgname = final_pkgname;
334 pkgpair = hash_search(hashdb->sync, &tmppkg);
335 goto get_deps;
336 default:
337 goto aur_deps;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
338 }
339
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
340 aur_uptodate:
341 tmppkg.pkgname = final_pkgname;
342 tmppkg.pkg = NULL;
343 pkgpair = hash_search(hashdb->aur, &tmppkg);
344
345 get_deps:
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
346 if (!pkgpair) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
347 /* Shouldn't happen */
348 die("Unable to find package \"%s\" in local/sync db!", final_pkgname);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
349 }
350
351 depmod_list = alpm_pkg_get_depends(pkgpair->pkg);
352 for (i = depmod_list; i; i = i->next) {
2c2c8ac @yanhan Updated to use libalpm 7
authored Jan 24, 2012
353 char *s = alpm_dep_compute_string(i->data);
354 strncpy(buf, s, sizeof(buf));
355 free(s);
356 chompversion(buf);
357 depname = normalize_package(curl, hashdb, buf, resolve_lvl);
00b165a @yanhan Check for return value of normalize_package
authored Jun 9, 2011
358 /* Possibility of normalize_package fail due to AUR download failing */
359 if (!depname) {
360 alpm_list_free(deps);
361 return -1;
362 }
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
363 deps = alpm_list_add(deps, (void *) depname);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
364 }
365
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
366 if (dep_list) {
367 *dep_list = deps;
368 } else {
369 alpm_list_free(deps);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
370 }
371
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
372 return 0;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
373
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
374 aur_deps:
375 tmppkg.pkgname = final_pkgname;
376 tmppkg.pkg = NULL;
377
378 /* For installed AUR packages which are up to date */
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
379 if (resolve_lvl != RESOLVE_THOROUGH) {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
380 if (hash_search(hashdb->aur, &tmppkg) &&
381 !hash_search(hashdb->aur_outdated, (void *) final_pkgname)) {
382 /* NOTE: top goto ! */
383 goto aur_uptodate;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
384 }
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
385 }
386
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
387 /* RESOLVE_THOROUGH / out to date AUR package.
388 * Download pkgbuild and extract deps */
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
389 if (!getcwd(cwd, PATH_MAX)) {
390 return error(PW_ERR_GETCWD);
391 }
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
392
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
393 if (chdir(final_pkgname)) {
394 return error(PW_ERR_CHDIR);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
395 }
396
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
397 deps = grab_dependencies("PKGBUILD");
398 if (chdir(cwd)) {
399 alpm_list_free(deps);
400 return error(PW_ERR_RESTORECWD);
401 }
402
403 if (dep_list) {
404 const char *normdep;
405 alpm_list_t *new_deps = NULL;
406
407 /* Transfer control to memlist and normalize packages */
408 for (i = deps; i; i = i->next) {
409 memlist_ptr = memlist_add(hashdb->strpool, &i->data);
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
410 normdep = normalize_package(curl, hashdb, memlist_ptr, resolve_lvl);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
411 new_deps = alpm_list_add(new_deps, (void *) normdep);
412 }
413
414 *dep_list = new_deps;
415 }
416
417 alpm_list_free(deps);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
418 return 0;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
419 }
420
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
421 /* Depending on resolve_lvl, decide if we want to continue resolving the package
422 *
423 * If resolve_lvl is RESOLVE_IMMEDIATE, only out of date / new AUR packages
424 * will be resolved.
425 */
426 static void should_we_continue_resolving(CURL *curl,
427 struct pw_hashdb *hashdb,
428 struct stack *st,
429 struct pkgpair *deppkg,
430 int resolve_lvl)
431 {
432 if (resolve_lvl == RESOLVE_THOROUGH) {
433 stack_push(st, deppkg);
434 return;
435 }
436
437 /* RESOLVE_IMMEDIATE. Normalize package. Only continue resolving
438 * new AUR packages
439 */
440 const char *pkgname;
441 pkgname = normalize_package(curl, hashdb, deppkg->pkgname, resolve_lvl);
442
443 /* Continue resolving for new AUR packages */
444 if (hash_search(hashdb->aur_downloaded, (void *) pkgname)) {
445 stack_push(st, deppkg);
446 }
447 }
448
452b554 @yanhan Print immediate dependencies for -S
authored Jun 26, 2011
449 /* Adds immediate dependencies to hashdb->immediate_deps
450 * This enables us to print the immediate deps instead of the entire huge
451 * dependency graph.
452 */
453 static void add_immediate_deps(struct pw_hashdb *hashdb, const char *pkgname,
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
454 alpm_list_t *deps, struct hash_table *immediate)
452b554 @yanhan Print immediate dependencies for -S
authored Jun 26, 2011
455 {
456 enum pkgfrom_t *from = NULL;
457 alpm_list_t *i;
458 struct pkgpair pkgpair;
459
460 from = hashmap_search(hashdb->pkg_from, (void *) pkgname);
461 if (!from) {
462 return;
463 } else if (*from == PKG_FROM_AUR) {
464 pkgpair.pkgname = pkgname;
465 /* Applies to new AUR packages and outdated AUR packages */
466 if (!hash_search(hashdb->aur, &pkgpair) ||
467 hash_search(hashdb->aur_outdated, (void *) pkgname)) {
468 for (i = deps; i; i = i->next) {
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
469 if (!hash_search(immediate, (void *) i->data)) {
470 hashdb->immediate_deps = alpm_list_add(hashdb->immediate_deps, i->data);
471 hash_insert(immediate, (void *) i->data);
472 }
452b554 @yanhan Print immediate dependencies for -S
authored Jun 26, 2011
473 }
474 }
475 }
476 }
477
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
478 void build_dep_graph(struct graph **graph, struct pw_hashdb *hashdb,
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
479 alpm_list_t *targets, int resolve_lvl)
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
480 {
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
481 if (!graph) {
482 return;
483 }
484
485 if (!*graph) {
486 *graph = graph_new((pw_hash_fn) sdbm, (pw_hashcmp_fn) strcmp);
487 }
488
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
489 struct stack *st = stack_new(sizeof(struct pkgpair));
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
490 struct hash_table *resolved = hash_new(HASH_TABLE, (pw_hash_fn) sdbm,
491 (pw_hashcmp_fn) strcmp);
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
492 struct hash_table *immediate = hash_new(HASH_TABLE, (pw_hash_fn) sdbm,
493 (pw_hashcmp_fn) strcmp);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
494 int ret;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
495 struct pkgpair pkgpair, deppkg;
496 alpm_list_t *i;
497 alpm_list_t *deps;
498
499 CURL *curl;
afa537d @yanhan Change curl_easy_init to use curl_easy_new
authored Jun 15, 2011
500 curl = curl_easy_new();
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
501 if (!curl) {
502 error(PW_ERR_CURL_INIT);
503 return;
504 }
505
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
506 /* Push all packages down stack */
507 for (i = targets; i; i = i->next) {
508 pkgpair.pkgname = i->data;
509 pkgpair.pkg = NULL;
510 stack_push(st, &pkgpair);
511 }
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
512
513 while (!stack_empty(st)) {
514 stack_pop(st, &pkgpair);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
515 deps = NULL;
516
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
517 if (hash_search(resolved, (void *) pkgpair.pkgname)) {
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
518 goto cleanup_deps;
519 }
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
520
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
521 ret = crawl_resolve(curl, hashdb, &pkgpair, &deps, resolve_lvl);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
522 if (ret) {
523 pw_fprintf(PW_LOG_ERROR, stderr, "Error in resolving packages.\n");
524 goto cleanup;
525 }
526
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
527 for (i = deps; i; i = i->next) {
528 deppkg.pkgname = i->data;
529 deppkg.pkg = NULL;
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
530
531 /* immediate vs thorough resolve */
532 should_we_continue_resolving(curl, hashdb, st, &deppkg, resolve_lvl);
533
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
534 /* dep --> current */
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
535 graph_add_edge(*graph, i->data, (void *) pkgpair.pkgname);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
536 }
537
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
538 hash_insert(resolved, (void *) pkgpair.pkgname);
452b554 @yanhan Print immediate dependencies for -S
authored Jun 26, 2011
539
540 /* Add immediate dependencies, for pretty printing purposes */
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
541 add_immediate_deps(hashdb, pkgpair.pkgname, deps, immediate);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
542 cleanup_deps:
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
543 alpm_list_free(deps);
544 }
545
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
546 cleanup:
547 hash_free(resolved);
152566f @yanhan -S: Only resolve new / outdated AUR packages
authored Jun 28, 2011
548 hash_free(immediate);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
549 stack_free(st);
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
550 curl_easy_cleanup(curl);
551 }
552
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
553 void print_topo_order(struct graph *graph, struct stack *topost)
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
554 {
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
555 int idx;
556 int cnt = 0;
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
557 const char *curpkg;
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
558
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
559 while (!stack_empty(topost)) {
560 stack_pop(topost, &idx);
561 curpkg = graph_get_vertex_data(graph, idx);
562 if (!curpkg) {
563 continue;
564 }
565
566 if (cnt++ > 0) {
567 printf(" -> %s", curpkg);
568 } else {
569 printf("%s", curpkg);
570 }
571 }
572
573 printf("\n");
574 }
575
576 int powaur_crawl(alpm_list_t *targets)
577 {
de78568 @yanhan Change --crawl to use powaur_dir
authored Jun 10, 2011
578 int ret = 0;
579 char cwd[PATH_MAX];
580 if (!getcwd(cwd, PATH_MAX)) {
581 return error(PW_ERR_GETCWD);
582 }
583
584 if (chdir(powaur_dir)) {
585 return error(PW_ERR_CHDIR, powaur_dir);
586 }
587
bb1e229 @yanhan Shift pw_hashdb to its own file
authored Jun 7, 2011
588 struct pw_hashdb *hashdb = build_hashdb();
589 if (!hashdb) {
590 pw_fprintf(PW_LOG_ERROR, stderr, "Unable to build hash database!\n");
de78568 @yanhan Change --crawl to use powaur_dir
authored Jun 9, 2011
591 ret = -1;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
592 }
593
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
594 alpm_list_t *i, *target_pkgs;
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
595 struct graph *graph;
596 struct stack *topost = stack_new(sizeof(int));
597 int have_cycles;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
598 for (i = targets; i; i = i->next) {
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
599 stack_reset(topost);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
600 graph = NULL;
601 target_pkgs = alpm_list_add(NULL, i->data);
8f276db @yanhan Change FORCE_DL and NOFORCE
authored Jun 28, 2011
602 build_dep_graph(&graph, hashdb, target_pkgs, RESOLVE_THOROUGH);
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
603 if (have_cycles) {
604 printf("Cyclic dependencies for package \"%s\"\n", i->data);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
605 }
606
607 graph_toposort(graph, topost);
608 if (stack_empty(topost)) {
609 printf("Package \"%s\" has no dependencies.\n", i->data);
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
610 } else {
611 printf("\n");
612 pw_printf(PW_LOG_INFO, "\"%s\" topological order: ", i->data);
613 print_topo_order(graph, topost);
614 }
615
616 graph_free(graph);
c2c1ee1 @yanhan Complete partial dep resolution for -Su
authored Jun 9, 2011
617 alpm_list_free(target_pkgs);
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
618 }
619
b31fc30 @yanhan Factor out dep resolution
authored Jun 7, 2011
620 stack_free(topost);
f60d87d @yanhan Enhance provides resolution
authored Jun 7, 2011
621 hashdb_free(hashdb);
de78568 @yanhan Change --crawl to use powaur_dir
authored Jun 9, 2011
622
623 if (chdir(cwd)) {
624 return error(PW_ERR_RESTORECWD);
625 }
626 return ret;
d4befbe @yanhan New --crawl option
authored Jun 5, 2011
627 }
23d7fbe @yanhan Add --list-aur option
authored Jun 25, 2011
628
be9faff @yanhan Change pkgpair_print to pkgpair_print_color
authored Jun 28, 2011
629 void pkgpair_print_color(void *p)
630 {
631 struct pkgpair *pkgpair_ptr = p;
632 printf("%s%s%s %s%s%s\n", color.bold, pkgpair_ptr->pkgname, color.nocolor,
633 color.bgreen, alpm_pkg_get_version(pkgpair_ptr->pkg), color.nocolor);
634 }
635
23d7fbe @yanhan Add --list-aur option
authored Jun 24, 2011
636 int powaur_list_aur(void)
637 {
638 struct pw_hashdb *hashdb = build_hashdb();
639 if (!hashdb) {
640 pw_fprintf(PW_LOG_ERROR, stderr, "Failed to build hashdb!\n");
641 return -1;
642 }
643
be9faff @yanhan Change pkgpair_print to pkgpair_print_color
authored Jun 28, 2011
644 hash_walk(hashdb->aur, pkgpair_print_color);
23d7fbe @yanhan Add --list-aur option
authored Jun 24, 2011
645 hashdb_free(hashdb);
646 return 0;
647 }
Something went wrong with that request. Please try again.