]>
Commit | Line | Data |
---|---|---|
d04baaba JV |
1 | /* |
2 | * conf.c | |
23229097 | 3 | * |
1dd34058 | 4 | * Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> |
c72b4543 | 5 | * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> |
23229097 | 6 | * |
d04baaba JV |
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. | |
11 | * | |
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. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
9781d0d6 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d04baaba JV |
19 | */ |
20 | ||
bda208f8 | 21 | #include <errno.h> |
bda208f8 | 22 | #include <limits.h> |
62f82801 | 23 | #include <locale.h> /* setlocale */ |
95119d46 | 24 | #include <fcntl.h> /* open */ |
d04baaba JV |
25 | #include <stdlib.h> |
26 | #include <stdio.h> | |
c22e381a | 27 | #include <string.h> /* strdup */ |
bda208f8 | 28 | #include <sys/stat.h> |
95119d46 | 29 | #include <sys/types.h> |
bda208f8 DM |
30 | #include <sys/utsname.h> /* uname */ |
31 | #include <unistd.h> | |
d04baaba | 32 | |
d04baaba | 33 | /* pacman */ |
869e81e1 | 34 | #include "conf.h" |
3d2c8e1f | 35 | #include "ini.h" |
3c3cb001 | 36 | #include "util.h" |
bda208f8 | 37 | #include "pacman.h" |
4fdcf50d | 38 | #include "callback.h" |
d04baaba | 39 | |
86ca39d1 DM |
40 | /* global config variable */ |
41 | config_t *config = NULL; | |
42 | ||
6582f68c SG |
43 | #define NOCOLOR "\033[0m" |
44 | ||
d5c0f391 AG |
45 | #define BOLD "\033[0;1m" |
46 | ||
6582f68c SG |
47 | #define BLACK "\033[0;30m" |
48 | #define RED "\033[0;31m" | |
49 | #define GREEN "\033[0;32m" | |
50 | #define YELLOW "\033[0;33m" | |
51 | #define BLUE "\033[0;34m" | |
52 | #define MAGENTA "\033[0;35m" | |
53 | #define CYAN "\033[0;36m" | |
54 | #define WHITE "\033[0;37m" | |
55 | ||
56 | #define BOLDBLACK "\033[1;30m" | |
57 | #define BOLDRED "\033[1;31m" | |
58 | #define BOLDGREEN "\033[1;32m" | |
59 | #define BOLDYELLOW "\033[1;33m" | |
60 | #define BOLDBLUE "\033[1;34m" | |
61 | #define BOLDMAGENTA "\033[1;35m" | |
62 | #define BOLDCYAN "\033[1;36m" | |
63 | #define BOLDWHITE "\033[1;37m" | |
64 | ||
65 | void enable_colors(int colors) | |
66 | { | |
67 | colstr_t *colstr = &config->colstr; | |
68 | ||
69 | if(colors == PM_COLOR_ON) { | |
d5c0f391 AG |
70 | colstr->colon = BOLDBLUE "::" BOLD " "; |
71 | colstr->title = BOLD; | |
6582f68c SG |
72 | colstr->repo = BOLDMAGENTA; |
73 | colstr->version = BOLDGREEN; | |
74 | colstr->groups = BOLDBLUE; | |
75 | colstr->meta = BOLDCYAN; | |
76 | colstr->warn = BOLDYELLOW; | |
77 | colstr->err = BOLDRED; | |
78 | colstr->nocolor = NOCOLOR; | |
79 | } | |
80 | } | |
81 | ||
14606c30 | 82 | config_t *config_new(void) |
98df67cd | 83 | { |
2f0de317 DM |
84 | config_t *newconfig = calloc(1, sizeof(config_t)); |
85 | if(!newconfig) { | |
9e9ecf21 | 86 | pm_printf(ALPM_LOG_ERROR, |
3c3cb001 AM |
87 | _("malloc failure: could not allocate %zd bytes\n"), |
88 | sizeof(config_t)); | |
0303b26b | 89 | return NULL; |
97313ba3 | 90 | } |
c22e381a | 91 | /* defaults which may get overridden later */ |
2f0de317 | 92 | newconfig->op = PM_OP_MAIN; |
ca43fdd9 | 93 | newconfig->logmask = ALPM_LOG_ERROR | ALPM_LOG_WARNING; |
2f0de317 | 94 | newconfig->configfile = strdup(CONFFILE); |
b3612e9c | 95 | newconfig->deltaratio = 0.0; |
69694edd DM |
96 | if(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) { |
97 | newconfig->siglevel = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL | | |
98 | ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; | |
33b3b6d9 AM |
99 | newconfig->localfilesiglevel = ALPM_SIG_USE_DEFAULT; |
100 | newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT; | |
69694edd | 101 | } |
98df67cd | 102 | |
6582f68c SG |
103 | newconfig->colstr.colon = ":: "; |
104 | newconfig->colstr.title = ""; | |
105 | newconfig->colstr.repo = ""; | |
106 | newconfig->colstr.version = ""; | |
107 | newconfig->colstr.groups = ""; | |
108 | newconfig->colstr.meta = ""; | |
109 | newconfig->colstr.warn = ""; | |
110 | newconfig->colstr.err = ""; | |
111 | newconfig->colstr.nocolor = ""; | |
112 | ||
0303b26b | 113 | return newconfig; |
98df67cd AF |
114 | } |
115 | ||
2f0de317 | 116 | int config_free(config_t *oldconfig) |
98df67cd | 117 | { |
2f0de317 | 118 | if(oldconfig == NULL) { |
0303b26b | 119 | return -1; |
98df67cd AF |
120 | } |
121 | ||
7edeb276 DM |
122 | alpm_list_free(oldconfig->explicit_adds); |
123 | alpm_list_free(oldconfig->explicit_removes); | |
124 | ||
a888f377 | 125 | FREELIST(oldconfig->holdpkg); |
4fdcf50d DM |
126 | FREELIST(oldconfig->ignorepkg); |
127 | FREELIST(oldconfig->ignoregrp); | |
128 | FREELIST(oldconfig->noupgrade); | |
129 | FREELIST(oldconfig->noextract); | |
2f0de317 | 130 | free(oldconfig->configfile); |
4845207f DM |
131 | free(oldconfig->rootdir); |
132 | free(oldconfig->dbpath); | |
133 | free(oldconfig->logfile); | |
4fdcf50d DM |
134 | free(oldconfig->gpgdir); |
135 | FREELIST(oldconfig->cachedirs); | |
30c4d53c | 136 | free(oldconfig->xfercommand); |
d39b1dbe | 137 | free(oldconfig->print_format); |
4fdcf50d | 138 | free(oldconfig->arch); |
2f0de317 | 139 | free(oldconfig); |
98df67cd | 140 | |
0303b26b | 141 | return 0; |
98df67cd AF |
142 | } |
143 | ||
bda208f8 | 144 | /** Helper function for download_with_xfercommand() */ |
b5709b81 GEP |
145 | static char *get_filename(const char *url) |
146 | { | |
bda208f8 DM |
147 | char *filename = strrchr(url, '/'); |
148 | if(filename != NULL) { | |
149 | filename++; | |
150 | } | |
151 | return filename; | |
152 | } | |
153 | ||
154 | /** Helper function for download_with_xfercommand() */ | |
b5709b81 GEP |
155 | static char *get_destfile(const char *path, const char *filename) |
156 | { | |
bda208f8 DM |
157 | char *destfile; |
158 | /* len = localpath len + filename len + null */ | |
159 | size_t len = strlen(path) + strlen(filename) + 1; | |
160 | destfile = calloc(len, sizeof(char)); | |
161 | snprintf(destfile, len, "%s%s", path, filename); | |
162 | ||
163 | return destfile; | |
164 | } | |
165 | ||
166 | /** Helper function for download_with_xfercommand() */ | |
b5709b81 GEP |
167 | static char *get_tempfile(const char *path, const char *filename) |
168 | { | |
bda208f8 DM |
169 | char *tempfile; |
170 | /* len = localpath len + filename len + '.part' len + null */ | |
171 | size_t len = strlen(path) + strlen(filename) + 6; | |
172 | tempfile = calloc(len, sizeof(char)); | |
173 | snprintf(tempfile, len, "%s%s.part", path, filename); | |
174 | ||
175 | return tempfile; | |
176 | } | |
177 | ||
178 | /** External fetch callback */ | |
179 | static int download_with_xfercommand(const char *url, const char *localpath, | |
b5709b81 GEP |
180 | int force) |
181 | { | |
95119d46 | 182 | int ret = 0, retval; |
bda208f8 | 183 | int usepart = 0; |
95119d46 | 184 | int cwdfd; |
bda208f8 | 185 | struct stat st; |
e13a3bf5 | 186 | char *parsedcmd, *tempcmd; |
bda208f8 DM |
187 | char *destfile, *tempfile, *filename; |
188 | ||
189 | if(!config->xfercommand) { | |
190 | return -1; | |
191 | } | |
192 | ||
193 | filename = get_filename(url); | |
194 | if(!filename) { | |
195 | return -1; | |
196 | } | |
197 | destfile = get_destfile(localpath, filename); | |
198 | tempfile = get_tempfile(localpath, filename); | |
199 | ||
200 | if(force && stat(tempfile, &st) == 0) { | |
201 | unlink(tempfile); | |
202 | } | |
203 | if(force && stat(destfile, &st) == 0) { | |
204 | unlink(destfile); | |
205 | } | |
206 | ||
207 | tempcmd = strdup(config->xfercommand); | |
208 | /* replace all occurrences of %o with fn.part */ | |
209 | if(strstr(tempcmd, "%o")) { | |
210 | usepart = 1; | |
211 | parsedcmd = strreplace(tempcmd, "%o", tempfile); | |
212 | free(tempcmd); | |
213 | tempcmd = parsedcmd; | |
214 | } | |
215 | /* replace all occurrences of %u with the download URL */ | |
216 | parsedcmd = strreplace(tempcmd, "%u", url); | |
217 | free(tempcmd); | |
218 | ||
219 | /* save the cwd so we can restore it later */ | |
95119d46 DM |
220 | do { |
221 | cwdfd = open(".", O_RDONLY); | |
222 | } while(cwdfd == -1 && errno == EINTR); | |
223 | if(cwdfd < 0) { | |
ca43fdd9 | 224 | pm_printf(ALPM_LOG_ERROR, _("could not get current working directory\n")); |
bda208f8 DM |
225 | } |
226 | ||
227 | /* cwd to the download directory */ | |
228 | if(chdir(localpath)) { | |
ca43fdd9 | 229 | pm_printf(ALPM_LOG_WARNING, _("could not chdir to download directory %s\n"), localpath); |
bda208f8 DM |
230 | ret = -1; |
231 | goto cleanup; | |
232 | } | |
233 | /* execute the parsed command via /bin/sh -c */ | |
ca43fdd9 | 234 | pm_printf(ALPM_LOG_DEBUG, "running command: %s\n", parsedcmd); |
bda208f8 DM |
235 | retval = system(parsedcmd); |
236 | ||
237 | if(retval == -1) { | |
ca43fdd9 | 238 | pm_printf(ALPM_LOG_WARNING, _("running XferCommand: fork failed!\n")); |
bda208f8 DM |
239 | ret = -1; |
240 | } else if(retval != 0) { | |
241 | /* download failed */ | |
ca43fdd9 | 242 | pm_printf(ALPM_LOG_DEBUG, "XferCommand command returned non-zero status " |
bda208f8 DM |
243 | "code (%d)\n", retval); |
244 | ret = -1; | |
245 | } else { | |
246 | /* download was successful */ | |
07a12927 | 247 | ret = 0; |
bda208f8 | 248 | if(usepart) { |
07a12927 DM |
249 | if(rename(tempfile, destfile)) { |
250 | pm_printf(ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"), | |
251 | tempfile, destfile, strerror(errno)); | |
252 | ret = -1; | |
253 | } | |
bda208f8 | 254 | } |
bda208f8 DM |
255 | } |
256 | ||
257 | cleanup: | |
258 | /* restore the old cwd if we have it */ | |
95119d46 DM |
259 | if(cwdfd >= 0) { |
260 | if(fchdir(cwdfd) != 0) { | |
261 | pm_printf(ALPM_LOG_ERROR, _("could not restore working directory (%s)\n"), | |
262 | strerror(errno)); | |
263 | } | |
eb19d41d | 264 | close(cwdfd); |
bda208f8 DM |
265 | } |
266 | ||
267 | if(ret == -1) { | |
268 | /* hack to let an user the time to cancel a download */ | |
269 | sleep(2); | |
270 | } | |
271 | free(destfile); | |
272 | free(tempfile); | |
273 | free(parsedcmd); | |
274 | ||
275 | return ret; | |
276 | } | |
277 | ||
278 | ||
279 | int config_set_arch(const char *arch) | |
280 | { | |
281 | if(strcmp(arch, "auto") == 0) { | |
282 | struct utsname un; | |
283 | uname(&un); | |
4fdcf50d | 284 | config->arch = strdup(un.machine); |
bda208f8 | 285 | } else { |
4fdcf50d | 286 | config->arch = strdup(arch); |
bda208f8 | 287 | } |
ca43fdd9 | 288 | pm_printf(ALPM_LOG_DEBUG, "config: arch: %s\n", config->arch); |
4fdcf50d | 289 | return 0; |
bda208f8 DM |
290 | } |
291 | ||
b03b06cf DM |
292 | /** |
293 | * Parse a signature verification level line. | |
294 | * @param values the list of parsed option values | |
295 | * @param storage location to store the derived signature level; any existing | |
296 | * value here is used as a starting point | |
e4690232 DM |
297 | * @param file path to the config file |
298 | * @param linenum current line number in file | |
b03b06cf DM |
299 | * @return 0 on success, 1 on any parsing error |
300 | */ | |
e4690232 DM |
301 | static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, |
302 | const char *file, int linenum) | |
0fbdfd02 | 303 | { |
b03b06cf DM |
304 | alpm_siglevel_t level = *storage; |
305 | alpm_list_t *i; | |
306 | int ret = 0; | |
307 | ||
308 | /* Collapse the option names into a single bitmasked value */ | |
309 | for(i = values; i; i = alpm_list_next(i)) { | |
310 | const char *original = i->data, *value; | |
311 | int package = 0, database = 0; | |
312 | ||
3d4656c0 | 313 | if(strncmp(original, "Package", strlen("Package")) == 0) { |
b03b06cf DM |
314 | /* only packages are affected, don't flip flags for databases */ |
315 | value = original + strlen("Package"); | |
316 | package = 1; | |
3d4656c0 | 317 | } else if(strncmp(original, "Database", strlen("Database")) == 0) { |
b03b06cf DM |
318 | /* only databases are affected, don't flip flags for packages */ |
319 | value = original + strlen("Database"); | |
320 | database = 1; | |
321 | } else { | |
322 | /* no prefix, so anything found will affect both packages and dbs */ | |
323 | value = original; | |
324 | package = database = 1; | |
325 | } | |
326 | ||
327 | /* now parse out and store actual flag if it is valid */ | |
328 | if(strcmp(value, "Never") == 0) { | |
329 | if(package) { | |
330 | level &= ~ALPM_SIG_PACKAGE; | |
33b3b6d9 | 331 | level |= ALPM_SIG_PACKAGE_SET; |
b03b06cf DM |
332 | } |
333 | if(database) { | |
334 | level &= ~ALPM_SIG_DATABASE; | |
335 | } | |
336 | } else if(strcmp(value, "Optional") == 0) { | |
337 | if(package) { | |
338 | level |= ALPM_SIG_PACKAGE; | |
339 | level |= ALPM_SIG_PACKAGE_OPTIONAL; | |
33b3b6d9 | 340 | level |= ALPM_SIG_PACKAGE_SET; |
b03b06cf DM |
341 | } |
342 | if(database) { | |
343 | level |= ALPM_SIG_DATABASE; | |
344 | level |= ALPM_SIG_DATABASE_OPTIONAL; | |
345 | } | |
346 | } else if(strcmp(value, "Required") == 0) { | |
347 | if(package) { | |
348 | level |= ALPM_SIG_PACKAGE; | |
349 | level &= ~ALPM_SIG_PACKAGE_OPTIONAL; | |
33b3b6d9 | 350 | level |= ALPM_SIG_PACKAGE_SET; |
b03b06cf DM |
351 | } |
352 | if(database) { | |
353 | level |= ALPM_SIG_DATABASE; | |
354 | level &= ~ALPM_SIG_DATABASE_OPTIONAL; | |
355 | } | |
356 | } else if(strcmp(value, "TrustedOnly") == 0) { | |
357 | if(package) { | |
358 | level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK; | |
359 | level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK; | |
33b3b6d9 | 360 | level |= ALPM_SIG_PACKAGE_TRUST_SET; |
b03b06cf DM |
361 | } |
362 | if(database) { | |
363 | level &= ~ALPM_SIG_DATABASE_MARGINAL_OK; | |
364 | level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK; | |
365 | } | |
366 | } else if(strcmp(value, "TrustAll") == 0) { | |
367 | if(package) { | |
368 | level |= ALPM_SIG_PACKAGE_MARGINAL_OK; | |
369 | level |= ALPM_SIG_PACKAGE_UNKNOWN_OK; | |
33b3b6d9 | 370 | level |= ALPM_SIG_PACKAGE_TRUST_SET; |
b03b06cf DM |
371 | } |
372 | if(database) { | |
373 | level |= ALPM_SIG_DATABASE_MARGINAL_OK; | |
374 | level |= ALPM_SIG_DATABASE_UNKNOWN_OK; | |
375 | } | |
376 | } else { | |
e4690232 DM |
377 | pm_printf(ALPM_LOG_ERROR, |
378 | _("config file %s, line %d: invalid value for '%s' : '%s'\n"), | |
379 | file, linenum, "SigLevel", original); | |
b03b06cf DM |
380 | ret = 1; |
381 | } | |
382 | level &= ~ALPM_SIG_USE_DEFAULT; | |
0fbdfd02 | 383 | } |
b03b06cf | 384 | |
69694edd DM |
385 | /* ensure we have sig checking ability and are actually turning it on */ |
386 | if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) && | |
387 | level & (ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE)) { | |
e4690232 DM |
388 | pm_printf(ALPM_LOG_ERROR, |
389 | _("config file %s, line %d: '%s' option invalid, no signature support\n"), | |
390 | file, linenum, "SigLevel"); | |
69694edd DM |
391 | ret = 1; |
392 | } | |
393 | ||
b03b06cf DM |
394 | if(!ret) { |
395 | *storage = level; | |
396 | } | |
397 | return ret; | |
0fbdfd02 | 398 | } |
bda208f8 | 399 | |
33b3b6d9 AM |
400 | /** |
401 | * Merge the package entires of two signature verification levels. | |
402 | * @param base initial siglevel | |
403 | * @param over overridden siglevel, derived value is stored here | |
404 | */ | |
405 | static void merge_siglevel(alpm_siglevel_t *base, alpm_siglevel_t *over) | |
406 | { | |
407 | alpm_siglevel_t level = *over; | |
408 | if(level & ALPM_SIG_USE_DEFAULT) { | |
409 | level = *base; | |
410 | } else { | |
411 | if(!(level & ALPM_SIG_PACKAGE_SET)) { | |
412 | level |= *base & ALPM_SIG_PACKAGE; | |
413 | level |= *base & ALPM_SIG_PACKAGE_OPTIONAL; | |
414 | } | |
415 | if(!(level & ALPM_SIG_PACKAGE_TRUST_SET)) { | |
416 | level |= *base & ALPM_SIG_PACKAGE_MARGINAL_OK; | |
417 | level |= *base & ALPM_SIG_PACKAGE_UNKNOWN_OK; | |
418 | } | |
419 | } | |
420 | ||
421 | *over = level; | |
422 | } | |
423 | ||
e4690232 DM |
424 | static int process_cleanmethods(alpm_list_t *values, |
425 | const char *file, int linenum) | |
426 | { | |
4fdcf50d DM |
427 | alpm_list_t *i; |
428 | for(i = values; i; i = alpm_list_next(i)) { | |
429 | const char *value = i->data; | |
430 | if(strcmp(value, "KeepInstalled") == 0) { | |
431 | config->cleanmethod |= PM_CLEAN_KEEPINST; | |
432 | } else if(strcmp(value, "KeepCurrent") == 0) { | |
433 | config->cleanmethod |= PM_CLEAN_KEEPCUR; | |
434 | } else { | |
e4690232 DM |
435 | pm_printf(ALPM_LOG_ERROR, |
436 | _("config file %s, line %d: invalid value for '%s' : '%s'\n"), | |
437 | file, linenum, "CleanMethod", value); | |
4fdcf50d DM |
438 | return 1; |
439 | } | |
bda208f8 DM |
440 | } |
441 | return 0; | |
442 | } | |
443 | ||
444 | /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm | |
445 | * settings. Refactored out of the parseconfig code since all of them did | |
446 | * the exact same thing and duplicated code. | |
447 | * @param ptr a pointer to the start of the multiple options | |
448 | * @param option the string (friendly) name of the option, used for messages | |
4fdcf50d | 449 | * @param list the list to add the option to |
bda208f8 DM |
450 | */ |
451 | static void setrepeatingoption(char *ptr, const char *option, | |
4fdcf50d | 452 | alpm_list_t **list) |
bda208f8 | 453 | { |
16312553 AG |
454 | char *val, *saveptr; |
455 | ||
456 | val = strtok_r(ptr, " ", &saveptr); | |
457 | while(val) { | |
458 | *list = alpm_list_add(*list, strdup(val)); | |
459 | pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, val); | |
460 | val = strtok_r(NULL, " ", &saveptr); | |
bda208f8 | 461 | } |
bda208f8 DM |
462 | } |
463 | ||
464 | static int _parse_options(const char *key, char *value, | |
465 | const char *file, int linenum) | |
466 | { | |
467 | if(value == NULL) { | |
468 | /* options without settings */ | |
469 | if(strcmp(key, "UseSyslog") == 0) { | |
4fdcf50d | 470 | config->usesyslog = 1; |
ca43fdd9 | 471 | pm_printf(ALPM_LOG_DEBUG, "config: usesyslog\n"); |
bda208f8 DM |
472 | } else if(strcmp(key, "ILoveCandy") == 0) { |
473 | config->chomp = 1; | |
ca43fdd9 | 474 | pm_printf(ALPM_LOG_DEBUG, "config: chomp\n"); |
bda208f8 DM |
475 | } else if(strcmp(key, "VerbosePkgLists") == 0) { |
476 | config->verbosepkglists = 1; | |
ca43fdd9 | 477 | pm_printf(ALPM_LOG_DEBUG, "config: verbosepkglists\n"); |
bda208f8 | 478 | } else if(strcmp(key, "UseDelta") == 0) { |
b3612e9c DM |
479 | config->deltaratio = 0.7; |
480 | pm_printf(ALPM_LOG_DEBUG, "config: usedelta (default 0.7)\n"); | |
bda208f8 DM |
481 | } else if(strcmp(key, "TotalDownload") == 0) { |
482 | config->totaldownload = 1; | |
ca43fdd9 | 483 | pm_printf(ALPM_LOG_DEBUG, "config: totaldownload\n"); |
bda208f8 | 484 | } else if(strcmp(key, "CheckSpace") == 0) { |
4fdcf50d | 485 | config->checkspace = 1; |
c8c7a513 SG |
486 | } else if(strcmp(key, "Color") == 0) { |
487 | if(config->color == PM_COLOR_UNSET) { | |
488 | config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; | |
6582f68c | 489 | enable_colors(config->color); |
c8c7a513 | 490 | } |
bda208f8 | 491 | } else { |
ca43fdd9 | 492 | pm_printf(ALPM_LOG_WARNING, |
bda208f8 DM |
493 | _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), |
494 | file, linenum, key, "options"); | |
495 | } | |
496 | } else { | |
497 | /* options with settings */ | |
498 | if(strcmp(key, "NoUpgrade") == 0) { | |
4fdcf50d | 499 | setrepeatingoption(value, "NoUpgrade", &(config->noupgrade)); |
bda208f8 | 500 | } else if(strcmp(key, "NoExtract") == 0) { |
4fdcf50d | 501 | setrepeatingoption(value, "NoExtract", &(config->noextract)); |
bda208f8 | 502 | } else if(strcmp(key, "IgnorePkg") == 0) { |
4fdcf50d | 503 | setrepeatingoption(value, "IgnorePkg", &(config->ignorepkg)); |
bda208f8 | 504 | } else if(strcmp(key, "IgnoreGroup") == 0) { |
4fdcf50d | 505 | setrepeatingoption(value, "IgnoreGroup", &(config->ignoregrp)); |
bda208f8 | 506 | } else if(strcmp(key, "HoldPkg") == 0) { |
4fdcf50d | 507 | setrepeatingoption(value, "HoldPkg", &(config->holdpkg)); |
4fdcf50d DM |
508 | } else if(strcmp(key, "CacheDir") == 0) { |
509 | setrepeatingoption(value, "CacheDir", &(config->cachedirs)); | |
bda208f8 | 510 | } else if(strcmp(key, "Architecture") == 0) { |
4fdcf50d | 511 | if(!config->arch) { |
bda208f8 DM |
512 | config_set_arch(value); |
513 | } | |
b3612e9c DM |
514 | } else if(strcmp(key, "UseDelta") == 0) { |
515 | double ratio; | |
516 | char *endptr; | |
62f82801 DM |
517 | const char *oldlocale; |
518 | ||
769facca | 519 | /* set the locale to 'C' for consistent decimal parsing (0.7 and never |
62f82801 DM |
520 | * 0,7) from config files, then restore old setting when we are done */ |
521 | oldlocale = setlocale(LC_NUMERIC, NULL); | |
522 | setlocale(LC_NUMERIC, "C"); | |
b3612e9c | 523 | ratio = strtod(value, &endptr); |
62f82801 DM |
524 | setlocale(LC_NUMERIC, oldlocale); |
525 | ||
b3612e9c DM |
526 | if(*endptr != '\0' || ratio < 0.0 || ratio > 2.0) { |
527 | pm_printf(ALPM_LOG_ERROR, | |
528 | _("config file %s, line %d: invalid value for '%s' : '%s'\n"), | |
529 | file, linenum, "UseDelta", value); | |
530 | return 1; | |
531 | } | |
532 | config->deltaratio = ratio; | |
533 | pm_printf(ALPM_LOG_DEBUG, "config: usedelta = %f\n", ratio); | |
bda208f8 DM |
534 | } else if(strcmp(key, "DBPath") == 0) { |
535 | /* don't overwrite a path specified on the command line */ | |
536 | if(!config->dbpath) { | |
537 | config->dbpath = strdup(value); | |
ca43fdd9 | 538 | pm_printf(ALPM_LOG_DEBUG, "config: dbpath: %s\n", value); |
bda208f8 | 539 | } |
bda208f8 DM |
540 | } else if(strcmp(key, "RootDir") == 0) { |
541 | /* don't overwrite a path specified on the command line */ | |
542 | if(!config->rootdir) { | |
543 | config->rootdir = strdup(value); | |
ca43fdd9 | 544 | pm_printf(ALPM_LOG_DEBUG, "config: rootdir: %s\n", value); |
bda208f8 DM |
545 | } |
546 | } else if(strcmp(key, "GPGDir") == 0) { | |
547 | if(!config->gpgdir) { | |
548 | config->gpgdir = strdup(value); | |
ca43fdd9 | 549 | pm_printf(ALPM_LOG_DEBUG, "config: gpgdir: %s\n", value); |
bda208f8 DM |
550 | } |
551 | } else if(strcmp(key, "LogFile") == 0) { | |
552 | if(!config->logfile) { | |
553 | config->logfile = strdup(value); | |
ca43fdd9 | 554 | pm_printf(ALPM_LOG_DEBUG, "config: logfile: %s\n", value); |
bda208f8 DM |
555 | } |
556 | } else if(strcmp(key, "XferCommand") == 0) { | |
557 | config->xfercommand = strdup(value); | |
ca43fdd9 | 558 | pm_printf(ALPM_LOG_DEBUG, "config: xfercommand: %s\n", value); |
bda208f8 | 559 | } else if(strcmp(key, "CleanMethod") == 0) { |
4fdcf50d DM |
560 | alpm_list_t *methods = NULL; |
561 | setrepeatingoption(value, "CleanMethod", &methods); | |
e4690232 | 562 | if(process_cleanmethods(methods, file, linenum)) { |
4fdcf50d DM |
563 | FREELIST(methods); |
564 | return 1; | |
565 | } | |
566 | FREELIST(methods); | |
b03b06cf DM |
567 | } else if(strcmp(key, "SigLevel") == 0) { |
568 | alpm_list_t *values = NULL; | |
569 | setrepeatingoption(value, "SigLevel", &values); | |
e4690232 | 570 | if(process_siglevel(values, &config->siglevel, file, linenum)) { |
b03b06cf | 571 | FREELIST(values); |
bda208f8 DM |
572 | return 1; |
573 | } | |
b03b06cf | 574 | FREELIST(values); |
33b3b6d9 AM |
575 | } else if(strcmp(key, "LocalFileSigLevel") == 0) { |
576 | alpm_list_t *values = NULL; | |
577 | setrepeatingoption(value, "LocalFileSigLevel", &values); | |
578 | if(process_siglevel(values, &config->localfilesiglevel, file, linenum)) { | |
579 | FREELIST(values); | |
580 | return 1; | |
581 | } | |
582 | FREELIST(values); | |
583 | } else if(strcmp(key, "RemoteFileSigLevel") == 0) { | |
584 | alpm_list_t *values = NULL; | |
585 | setrepeatingoption(value, "RemoteFileSigLevel", &values); | |
586 | if(process_siglevel(values, &config->remotefilesiglevel, file, linenum)) { | |
587 | FREELIST(values); | |
588 | return 1; | |
589 | } | |
590 | FREELIST(values); | |
bda208f8 | 591 | } else { |
ca43fdd9 | 592 | pm_printf(ALPM_LOG_WARNING, |
bda208f8 DM |
593 | _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), |
594 | file, linenum, key, "options"); | |
595 | } | |
596 | ||
597 | } | |
598 | return 0; | |
599 | } | |
600 | ||
939d5a95 | 601 | static int _add_mirror(alpm_db_t *db, char *value) |
bda208f8 DM |
602 | { |
603 | const char *dbname = alpm_db_get_name(db); | |
604 | /* let's attempt a replacement for the current repo */ | |
605 | char *temp = strreplace(value, "$repo", dbname); | |
606 | /* let's attempt a replacement for the arch */ | |
4fdcf50d | 607 | const char *arch = config->arch; |
bda208f8 DM |
608 | char *server; |
609 | if(arch) { | |
610 | server = strreplace(temp, "$arch", arch); | |
611 | free(temp); | |
612 | } else { | |
613 | if(strstr(temp, "$arch")) { | |
614 | free(temp); | |
ca58e326 | 615 | pm_printf(ALPM_LOG_ERROR, |
e4690232 | 616 | _("mirror '%s' contains the '%s' variable, but no '%s' is defined.\n"), |
ca58e326 | 617 | value, "$arch", "Architecture"); |
bda208f8 DM |
618 | return 1; |
619 | } | |
620 | server = temp; | |
621 | } | |
622 | ||
42ab639b | 623 | if(alpm_db_add_server(db, server) != 0) { |
bda208f8 | 624 | /* pm_errno is set by alpm_db_setserver */ |
ca43fdd9 | 625 | pm_printf(ALPM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"), |
e2aa9526 | 626 | dbname, server, alpm_strerror(alpm_errno(config->handle))); |
bda208f8 DM |
627 | free(server); |
628 | return 1; | |
629 | } | |
630 | ||
631 | free(server); | |
632 | return 0; | |
633 | } | |
634 | ||
4fdcf50d | 635 | /** Sets up libalpm global stuff in one go. Called after the command line |
769facca | 636 | * and initial config file parsing. Once this is complete, we can see if any |
bda208f8 DM |
637 | * paths were defined. If a rootdir was defined and nothing else, we want all |
638 | * of our paths to live under the rootdir that was specified. Safe to call | |
639 | * multiple times (will only do anything the first time). | |
640 | */ | |
4fdcf50d | 641 | static int setup_libalpm(void) |
bda208f8 | 642 | { |
73c74355 | 643 | int ret = 0; |
a3f93992 | 644 | alpm_errno_t err; |
64c1cf79 | 645 | alpm_handle_t *handle; |
4fdcf50d | 646 | |
ca43fdd9 | 647 | pm_printf(ALPM_LOG_DEBUG, "setup_libalpm called\n"); |
73c74355 | 648 | |
73c74355 DM |
649 | /* Configure root path first. If it is set and dbpath/logfile were not |
650 | * set, then set those as well to reside under the root. */ | |
651 | if(config->rootdir) { | |
652 | char path[PATH_MAX]; | |
73c74355 | 653 | if(!config->dbpath) { |
4fdcf50d | 654 | snprintf(path, PATH_MAX, "%s/%s", config->rootdir, DBPATH + 1); |
73c74355 | 655 | config->dbpath = strdup(path); |
bda208f8 | 656 | } |
73c74355 | 657 | if(!config->logfile) { |
4fdcf50d | 658 | snprintf(path, PATH_MAX, "%s/%s", config->rootdir, LOGFILE + 1); |
73c74355 | 659 | config->logfile = strdup(path); |
bda208f8 | 660 | } |
4fdcf50d DM |
661 | } else { |
662 | config->rootdir = strdup(ROOTDIR); | |
663 | if(!config->dbpath) { | |
664 | config->dbpath = strdup(DBPATH); | |
bda208f8 | 665 | } |
73c74355 | 666 | } |
4fdcf50d DM |
667 | |
668 | /* initialize library */ | |
17a6ac56 DM |
669 | handle = alpm_initialize(config->rootdir, config->dbpath, &err); |
670 | if(!handle) { | |
48861f50 AM |
671 | pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library\n(%s: %s)\n"), |
672 | alpm_strerror(err), config->dbpath); | |
afc96f2a | 673 | if(err == ALPM_ERR_DB_VERSION) { |
ca43fdd9 | 674 | pm_printf(ALPM_LOG_ERROR, _(" try running pacman-db-upgrade\n")); |
1150d9e1 | 675 | } |
4fdcf50d DM |
676 | return -1; |
677 | } | |
17a6ac56 | 678 | config->handle = handle; |
4fdcf50d | 679 | |
17a6ac56 DM |
680 | alpm_option_set_logcb(handle, cb_log); |
681 | alpm_option_set_dlcb(handle, cb_dl_progress); | |
98fdfa19 DM |
682 | alpm_option_set_eventcb(handle, cb_event); |
683 | alpm_option_set_questioncb(handle, cb_question); | |
684 | alpm_option_set_progresscb(handle, cb_progress); | |
4fdcf50d DM |
685 | |
686 | config->logfile = config->logfile ? config->logfile : strdup(LOGFILE); | |
17a6ac56 | 687 | ret = alpm_option_set_logfile(handle, config->logfile); |
4fdcf50d | 688 | if(ret != 0) { |
ca43fdd9 | 689 | pm_printf(ALPM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), |
db3b86e7 | 690 | config->logfile, alpm_strerror(alpm_errno(handle))); |
4fdcf50d | 691 | return ret; |
73c74355 | 692 | } |
bda208f8 | 693 | |
73c74355 DM |
694 | /* Set GnuPG's home directory. This is not relative to rootdir, even if |
695 | * rootdir is defined. Reasoning: gpgdir contains configuration data. */ | |
4fdcf50d | 696 | config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR); |
1cd6515a | 697 | ret = alpm_option_set_gpgdir(handle, config->gpgdir); |
4fdcf50d | 698 | if(ret != 0) { |
ca43fdd9 | 699 | pm_printf(ALPM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), |
db3b86e7 | 700 | config->gpgdir, alpm_strerror(alpm_errno(handle))); |
4fdcf50d | 701 | return ret; |
bda208f8 | 702 | } |
73c74355 DM |
703 | |
704 | /* add a default cachedir if one wasn't specified */ | |
4fdcf50d | 705 | if(config->cachedirs == NULL) { |
17a6ac56 | 706 | alpm_option_add_cachedir(handle, CACHEDIR); |
4fdcf50d | 707 | } else { |
17a6ac56 | 708 | alpm_option_set_cachedirs(handle, config->cachedirs); |
4fdcf50d DM |
709 | } |
710 | ||
33f25185 | 711 | alpm_option_set_default_siglevel(handle, config->siglevel); |
4fdcf50d | 712 | |
33b3b6d9 AM |
713 | merge_siglevel(&config->siglevel, &config->localfilesiglevel); |
714 | merge_siglevel(&config->siglevel, &config->remotefilesiglevel); | |
715 | alpm_option_set_local_file_siglevel(handle, config->localfilesiglevel); | |
716 | alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel); | |
717 | ||
4fdcf50d | 718 | if(config->xfercommand) { |
17a6ac56 | 719 | alpm_option_set_fetchcb(handle, download_with_xfercommand); |
361ed6a6 DM |
720 | } else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER)) { |
721 | pm_printf(ALPM_LOG_WARNING, _("no '%s' configured"), "XferCommand"); | |
73c74355 | 722 | } |
4fdcf50d DM |
723 | |
724 | if(config->totaldownload) { | |
17a6ac56 | 725 | alpm_option_set_totaldlcb(handle, cb_dl_total); |
4fdcf50d DM |
726 | } |
727 | ||
17a6ac56 DM |
728 | alpm_option_set_arch(handle, config->arch); |
729 | alpm_option_set_checkspace(handle, config->checkspace); | |
730 | alpm_option_set_usesyslog(handle, config->usesyslog); | |
b3612e9c | 731 | alpm_option_set_deltaratio(handle, config->deltaratio); |
4fdcf50d | 732 | |
17a6ac56 | 733 | alpm_option_set_ignorepkgs(handle, config->ignorepkg); |
f1bb56ce | 734 | alpm_option_set_ignoregroups(handle, config->ignoregrp); |
17a6ac56 DM |
735 | alpm_option_set_noupgrades(handle, config->noupgrade); |
736 | alpm_option_set_noextracts(handle, config->noextract); | |
4fdcf50d | 737 | |
73c74355 | 738 | return 0; |
bda208f8 DM |
739 | } |
740 | ||
a7755309 DM |
741 | /** |
742 | * Allows parsing in advance of an entire config section before we start | |
743 | * calling library methods. | |
744 | */ | |
745 | struct section_t { | |
746 | /* useful for all sections */ | |
26da037f | 747 | const char *name; |
a7755309 | 748 | int is_options; |
74c89436 | 749 | int parse_options; |
a7755309 | 750 | /* db section option gathering */ |
7af0ab1c | 751 | alpm_siglevel_t siglevel; |
a7755309 | 752 | alpm_list_t *servers; |
c0ee7137 | 753 | alpm_db_usage_t usage; |
a7755309 DM |
754 | }; |
755 | ||
c0ee7137 DR |
756 | static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage, |
757 | const char *file, int linenum) | |
758 | { | |
759 | alpm_list_t *i; | |
760 | alpm_db_usage_t level = *usage; | |
761 | int ret = 0; | |
762 | ||
763 | for(i = values; i; i = i->next) { | |
764 | char *key = i->data; | |
765 | ||
766 | if(strcmp(key, "Sync") == 0) { | |
767 | level |= ALPM_DB_USAGE_SYNC; | |
768 | } else if(strcmp(key, "Search") == 0) { | |
769 | level |= ALPM_DB_USAGE_SEARCH; | |
770 | } else if(strcmp(key, "Install") == 0) { | |
771 | level |= ALPM_DB_USAGE_INSTALL; | |
772 | } else if(strcmp(key, "Upgrade") == 0) { | |
773 | level |= ALPM_DB_USAGE_UPGRADE; | |
774 | } else if(strcmp(key, "All") == 0) { | |
775 | level |= ALPM_DB_USAGE_ALL; | |
776 | } else { | |
777 | pm_printf(ALPM_LOG_ERROR, | |
778 | _("config file %s, line %d: '%s' option '%s' not recognized\n"), | |
779 | file, linenum, "Usage", key); | |
780 | ret = 1; | |
781 | } | |
782 | } | |
783 | ||
784 | *usage = level; | |
785 | ||
786 | return ret; | |
787 | } | |
788 | ||
789 | ||
36f702ba AG |
790 | static int _parse_repo(const char *key, char *value, const char *file, |
791 | int line, struct section_t *section) | |
792 | { | |
793 | int ret = 0; | |
794 | ||
795 | if(strcmp(key, "Server") == 0) { | |
796 | if(!value) { | |
797 | pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), | |
798 | file, line, key); | |
799 | ret = 1; | |
800 | } else { | |
801 | section->servers = alpm_list_add(section->servers, strdup(value)); | |
802 | } | |
803 | } else if(strcmp(key, "SigLevel") == 0) { | |
804 | if(!value) { | |
805 | pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), | |
806 | file, line, key); | |
807 | } else { | |
808 | alpm_list_t *values = NULL; | |
809 | setrepeatingoption(value, "SigLevel", &values); | |
810 | if(values) { | |
811 | if(section->siglevel == ALPM_SIG_USE_DEFAULT) { | |
812 | section->siglevel = config->siglevel; | |
813 | } | |
814 | ret = process_siglevel(values, §ion->siglevel, file, line); | |
815 | FREELIST(values); | |
816 | } | |
817 | } | |
c0ee7137 DR |
818 | } else if(strcmp(key, "Usage") == 0) { |
819 | alpm_list_t *values = NULL; | |
820 | setrepeatingoption(value, "Usage", &values); | |
821 | if(values) { | |
822 | if(process_usage(values, §ion->usage, file, line)) { | |
823 | FREELIST(values); | |
824 | return 1; | |
825 | } | |
826 | FREELIST(values); | |
827 | } | |
36f702ba AG |
828 | } else { |
829 | pm_printf(ALPM_LOG_WARNING, | |
830 | _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), | |
831 | file, line, key, section->name); | |
832 | } | |
833 | ||
834 | return ret; | |
835 | } | |
836 | ||
a7755309 DM |
837 | /** |
838 | * Wrap up a section once we have reached the end of it. This should be called | |
839 | * when a subsequent section is encountered, or when we have reached the end of | |
840 | * the root config file. Once called, all existing saved config pieces on the | |
841 | * section struct are freed. | |
842 | * @param section the current parsed and saved section data | |
843 | * @param parse_options whether we are parsing options or repo data | |
844 | * @return 0 on success, 1 on failure | |
845 | */ | |
74c89436 | 846 | static int finish_section(struct section_t *section) |
a7755309 DM |
847 | { |
848 | int ret = 0; | |
849 | alpm_list_t *i; | |
939d5a95 | 850 | alpm_db_t *db; |
a7755309 | 851 | |
ca43fdd9 | 852 | pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name); |
a7755309 DM |
853 | |
854 | /* parsing options (or nothing)- nothing to do except free the pieces */ | |
74c89436 | 855 | if(!section->name || section->parse_options || section->is_options) { |
a7755309 DM |
856 | goto cleanup; |
857 | } | |
858 | ||
859 | /* if we are not looking at options sections only, register a db */ | |
b488f229 | 860 | db = alpm_register_syncdb(config->handle, section->name, section->siglevel); |
a7755309 | 861 | if(db == NULL) { |
ca43fdd9 | 862 | pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"), |
a7755309 DM |
863 | section->name, alpm_strerror(alpm_errno(config->handle))); |
864 | ret = 1; | |
865 | goto cleanup; | |
866 | } | |
867 | ||
c0ee7137 DR |
868 | pm_printf(ALPM_LOG_DEBUG, |
869 | "setting usage of %d for %s repoistory\n", | |
870 | section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage, | |
871 | section->name); | |
872 | alpm_db_set_usage(db, section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage); | |
873 | ||
a7755309 | 874 | for(i = section->servers; i; i = alpm_list_next(i)) { |
6be492d2 | 875 | char *value = i->data; |
a7755309 | 876 | if(_add_mirror(db, value) != 0) { |
ca43fdd9 | 877 | pm_printf(ALPM_LOG_ERROR, |
a7755309 DM |
878 | _("could not add mirror '%s' to database '%s' (%s)\n"), |
879 | value, section->name, alpm_strerror(alpm_errno(config->handle))); | |
880 | ret = 1; | |
881 | goto cleanup; | |
882 | } | |
883 | free(value); | |
884 | } | |
885 | ||
886 | cleanup: | |
887 | alpm_list_free(section->servers); | |
888 | section->servers = NULL; | |
7af0ab1c | 889 | section->siglevel = ALPM_SIG_USE_DEFAULT; |
a7755309 | 890 | section->name = NULL; |
c0ee7137 | 891 | section->usage = 0; |
a7755309 DM |
892 | return ret; |
893 | } | |
bda208f8 | 894 | |
26da037f | 895 | static int _parse_directive(const char *file, int linenum, const char *name, |
ab84249a | 896 | char *key, char *value, void *data) |
8287312c | 897 | { |
ab84249a | 898 | struct section_t *section = data; |
26da037f AG |
899 | if(!key && !value) { |
900 | int ret = finish_section(section); | |
901 | pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name); | |
902 | section->name = name; | |
903 | if(name && strcmp(name, "options") == 0) { | |
904 | section->is_options = 1; | |
905 | } else { | |
906 | section->is_options = 0; | |
907 | } | |
908 | return ret; | |
909 | } | |
910 | ||
8287312c AG |
911 | if(section->name == NULL) { |
912 | pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: All directives must belong to a section.\n"), | |
913 | file, linenum); | |
914 | return 1; | |
915 | } | |
916 | ||
917 | if(section->parse_options && section->is_options) { | |
918 | /* we are either in options ... */ | |
919 | return _parse_options(key, value, file, linenum); | |
920 | } else if(!section->parse_options && !section->is_options) { | |
921 | /* ... or in a repo section */ | |
922 | return _parse_repo(key, value, file, linenum, section); | |
923 | } | |
26da037f | 924 | |
8287312c AG |
925 | return 0; |
926 | } | |
927 | ||
bda208f8 | 928 | /** Parse a configuration file. |
c730ca59 | 929 | * @param file path to the config file |
bda208f8 DM |
930 | * @return 0 on success, non-zero on error |
931 | */ | |
932 | int parseconfig(const char *file) | |
933 | { | |
73c74355 | 934 | int ret; |
a7755309 DM |
935 | struct section_t section; |
936 | memset(§ion, 0, sizeof(struct section_t)); | |
7af0ab1c | 937 | section.siglevel = ALPM_SIG_USE_DEFAULT; |
c0ee7137 | 938 | section.usage = 0; |
73c74355 DM |
939 | /* the config parse is a two-pass affair. We first parse the entire thing for |
940 | * the [options] section so we can get all default and path options set. | |
941 | * Next, we go back and parse everything but [options]. */ | |
942 | ||
bda208f8 | 943 | /* call the real parseconfig function with a null section & db argument */ |
ca43fdd9 | 944 | pm_printf(ALPM_LOG_DEBUG, "parseconfig: options pass\n"); |
74c89436 | 945 | section.parse_options = 1; |
3d2c8e1f | 946 | if((ret = parse_ini(file, _parse_directive, §ion))) { |
73c74355 DM |
947 | return ret; |
948 | } | |
4fdcf50d | 949 | if((ret = setup_libalpm())) { |
73c74355 DM |
950 | return ret; |
951 | } | |
952 | /* second pass, repo section parsing */ | |
ca43fdd9 | 953 | pm_printf(ALPM_LOG_DEBUG, "parseconfig: repo pass\n"); |
74c89436 | 954 | section.parse_options = 0; |
3d2c8e1f | 955 | return parse_ini(file, _parse_directive, §ion); |
bda208f8 DM |
956 | } |
957 | ||
d04baaba | 958 | /* vim: set ts=2 sw=2 noet: */ |