forked from NetBSDfr/pkgin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary.c
739 lines (596 loc) · 17.1 KB
/
summary.c
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/* $Id: summary.c,v 1.33 2012/07/15 17:36:34 imilh Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emile "iMil" Heitor <imil@NetBSD.org> .
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/**
* Import pkg_summary to SQLite database
*/
#include "tools.h"
#include "pkgin.h"
static const struct Summary {
const int type;
const char *tbl_name;
const char *deps;
const char *conflicts;
const char *requires;
const char *provides;
const char *end;
} sumsw[] = {
[LOCAL_SUMMARY] = {
LOCAL_SUMMARY,
"LOCAL_PKG",
"LOCAL_DEPS",
"LOCAL_CONFLICTS",
"LOCAL_REQUIRES",
"LOCAL_PROVIDES",
NULL
},
[REMOTE_SUMMARY] = {
REMOTE_SUMMARY,
"REMOTE_PKG",
"REMOTE_DEPS",
"REMOTE_CONFLICTS",
"REMOTE_REQUIRES",
"REMOTE_PROVIDES",
NULL
},
};
struct Columns {
int num;
char **name;
} cols;
typedef struct Insertlist {
char *field;
char *value;
SLIST_ENTRY(Insertlist) next;
} Insertlist;
SLIST_HEAD(, Insertlist) inserthead;
static char **fetch_summary(char *url);
static void freecols(void);
static void free_insertlist(void);
static void prepare_insert(int, struct Summary, char *);
int colnames(void *, int, char **, char **);
char *env_repos, **pkg_repos;
char **commit_list = NULL;
int commit_idx = 0;
int query_size = BUFSIZ;
/* column count for table fields, given by colnames callback */
int colcount = 0;
/* force pkg_summary reload */
int force_fetch = 0;
static const char *const sumexts[] = { "bz2", "gz", NULL };
/**
* remote summary fetch
*/
static char **
fetch_summary(char *cur_repo)
{
/* from pkg_install/files/admin/audit.c */
Dlfile *file = NULL;
char *decompressed_input;
size_t decompressed_len;
time_t sum_mtime;
int i;
char **out, buf[BUFSIZ];
for (i = 0; sumexts[i] != NULL; i++) { /* try all extensions */
if (!force_fetch && !force_update)
sum_mtime = pkg_sum_mtime(cur_repo);
else
sum_mtime = 0; /* 0 sumtime == force reload */
snprintf(buf, BUFSIZ, "%s/%s.%s",
cur_repo, PKG_SUMMARY, sumexts[i]);
if ((file = download_file(buf, &sum_mtime)) != NULL)
break; /* pkg_summary found and not up-to-date */
if (sum_mtime < 0) /* pkg_summary found, but up-to-date */
return NULL;
}
if (file == NULL)
errx(EXIT_FAILURE, MSG_COULDNT_FETCH, buf);
snprintf(buf, BUFSIZ,
UPDATE_REPO_MTIME, (long long)sum_mtime, cur_repo);
pkgindb_doquery(buf, NULL, NULL);
if (decompress_buffer(file->buf, file->size, &decompressed_input,
&decompressed_len)) {
out = splitstr(decompressed_input, "\n");
XFREE(file->buf);
XFREE(file);
return out;
}
XFREE(file->buf);
XFREE(file);
return NULL;
}
/**
* progress percentage
*/
static void
progress(char c)
{
const char *alnum = ALNUM;
int i, alnumlen = strlen(alnum);
float percent = 0;
for (i = 0; i < alnumlen; i++)
if (c == alnum[i])
percent = ((float)(i + 1)/ (float)alnumlen) * 100;
printf(MSG_UPDATING_DB_PCT, (int)percent);
fflush(stdout);
}
/**
* check if the field is PKGNAME
*/
static int
chk_pkgname(char *field, char *last_field)
{
if (strncmp(field, "PKGNAME=", 8) == 0)
return 1;
/* in some very rare cases, CONFLICTS appears *after* PKGNAME */
if (strncmp(last_field, "PKGNAME=", 8) != 0 &&
/* never seen many CONFLICTS after PKGNAME, but just in case... */
strncmp(last_field, "CONFLICTS=", 10) != 0 &&
strncmp(field, "CONFLICTS=", 10) == 0)
return 1;
return 0;
}
/**
* returns value for given field
*/
static char *
field_record(const char *field, char *line)
{
char *pfield;
if (strncmp(field, line, strlen(field)) == 0) {
pfield = strchr(line, '=');
trimcr(pfield++);
/* weird buggy packages with empty fields, like LICENSE= */
if (*pfield != '\0')
return pfield;
}
return NULL;
}
static void
freecols()
{
int i;
for (i = 0; i < cols.num; i++)
XFREE(cols.name[i]);
XFREE(cols.name);
}
static void
free_insertlist()
{
Insertlist *pi;
while (!SLIST_EMPTY(&inserthead)) {
pi = SLIST_FIRST(&inserthead);
SLIST_REMOVE_HEAD(&inserthead, next);
XFREE(pi->field);
XFREE(pi->value);
XFREE(pi);
}
}
/**
* sqlite callback, fill cols.name[] with available columns names
*/
int
colnames(void *unused, int argc, char **argv, char **colname)
{
int i = 0;
colcount++;
cols.num = colcount;
XREALLOC(cols.name, colcount * sizeof(char *));
for (i = 0; i < argc; i++)
if (argv[i] != NULL && strncmp(colname[i], "name", 4) == 0)
XSTRDUP(cols.name[colcount - 1], argv[i]);
return PDB_OK;
}
/**
* for now, values are located on a SLIST, build INSERT line with them
*/
static void
prepare_insert(int pkgid, struct Summary sum, char *cur_repo)
{
char *commit_query;
Insertlist *pi;
if (sum.type == REMOTE_SUMMARY)
query_size = (query_size + strlen(cur_repo)) * sizeof(char);
XMALLOC(commit_query, query_size);
snprintf(commit_query, BUFSIZ, "INSERT INTO %s ( PKG_ID,", sum.tbl_name);
/* insert fields */
SLIST_FOREACH(pi, &inserthead, next)
XSNPRINTF(commit_query, query_size,
"%s\"%s\",", commit_query, pi->field);
/* insert REPOSITORY field */
if (sum.type == REMOTE_SUMMARY)
XSNPRINTF(commit_query, query_size, "%s\"REPOSITORY\")", commit_query);
else
commit_query[strlen(commit_query) - 1] = ')';
XSNPRINTF(commit_query, query_size, "%s VALUES ( %d, ",
commit_query, pkgid);
/* insert values */
SLIST_FOREACH(pi, &inserthead, next)
XSNPRINTF(commit_query, query_size,
"%s\"%s\",", commit_query, pi->value);
/* insert repository URL if it's a remote pkg_summary */
if (sum.type == REMOTE_SUMMARY) {
XSNPRINTF(commit_query, query_size, "%s\"%s\");",
commit_query, cur_repo);
} else {
commit_query[strlen(commit_query) - 1] = ')';
strcat(commit_query, ";");
}
/* append query to commit list */
commit_idx++;
XREALLOC(commit_list, (commit_idx + 1) * sizeof(char *));
commit_list[commit_idx] = commit_query;
}
/**
* add item to the main SLIST
*/
static void
add_to_slist(const char *field, const char *value)
{
Insertlist *insert;
XMALLOC(insert, sizeof(Insertlist));
XSTRDUP(insert->field, field);
XSTRDUP(insert->value, value);
SLIST_INSERT_HEAD(&inserthead, insert, next);
}
/**
* fill-in secondary tables
*/
static void
child_table(const char *fmt, ...)
{
char buf[BUFSIZ];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
/* append query to commit_list */
commit_idx++;
XREALLOC(commit_list, (commit_idx + 1) * sizeof(char *));
XSTRDUP(commit_list[commit_idx], buf);
}
static void
update_col(struct Summary sum, int pkgid, char *line)
{
static uint8_t said = 0;
int i;
char *val, *p, buf[BUFSIZ];
/* check MACHINE_ARCH */
if (!said && (val = field_record("MACHINE_ARCH", line)) != NULL) {
if (strncmp(CHECK_MACHINE_ARCH,
val, strlen(CHECK_MACHINE_ARCH))) {
printf(MSG_ARCH_DONT_MATCH, val, CHECK_MACHINE_ARCH);
if (!check_yesno(DEFAULT_NO))
exit(EXIT_FAILURE);
said = 1;
printf("\r"MSG_UPDATING_DB);
}
}
/* DEPENDS */
if ((val = field_record("DEPENDS", line)) != NULL) {
if ((p = get_pkgname_from_depend(val)) != NULL) {
child_table(INSERT_DEPENDS_VALUES,
sum.deps, sum.deps, sum.deps,
pkgid, p, val);
XFREE(p);
} else
printf(MSG_COULD_NOT_GET_PKGNAME, val);
}
/* REQUIRES */
if ((val = field_record("REQUIRES", line)) != NULL)
child_table(INSERT_SINGLE_VALUE, \
sum.requires, sum.requires, pkgid, val);
/* PROVIDES */
if ((val = field_record("PROVIDES", line)) != NULL)
child_table(INSERT_SINGLE_VALUE, \
sum.provides, sum.provides, pkgid, val);
for (i = 0; i < cols.num; i++) {
snprintf(buf, BUFSIZ, "%s=", cols.name[i]);
val = field_record(cols.name[i], line);
/* XXX: handle that later */
if (strncmp(cols.name[i], "DESCRIPTION", 11) == 0)
continue;
if (val != NULL && strncmp(buf, line, strlen(buf)) == 0) {
/* nasty little hack to prevent double quotes */
if (strchr(line, '"') != NULL)
for (p = line; *p != '\0'; p++)
if (*p == '"')
*p = '`';
add_to_slist(cols.name[i], val);
/* update query size */
query_size += strlen(cols.name[i]) + strlen(val) + 5;
/* 5 = strlen(\"\",) */
}
}
}
/* default version for (rare and buggy) packages with a version */
#define NOVERSION "-0.0"
static void
insert_summary(struct Summary sum, char **summary, char *cur_repo)
{
int i;
static int pkgid = 1;
char *pkgname, *pkgvers, **psum;
char query[BUFSIZ], tmpname[BUFSIZ];
const char *alnum = ALNUM;
if (summary == NULL) {
pkgindb_close();
errx(EXIT_FAILURE, "could not read summary");
}
snprintf(query, BUFSIZ, "PRAGMA table_info(%s);", sum.tbl_name);
/* record columns names to cols */
pkgindb_doquery(query, colnames, NULL);
SLIST_INIT(&inserthead);
XMALLOC(commit_list, sizeof(char *));
/* begin transaction */
XSTRDUP(commit_list[0], "BEGIN;");
printf(MSG_UPDATING_DB);
fflush(stdout);
psum = summary;
/* main pkg_summary analysis loop */
while (*psum != NULL) {
/* CONFLICTS may appear before PKGNAME... */
if ((pkgname = field_record("CONFLICTS", *psum)) != NULL) {
snprintf(query, BUFSIZ,
"INSERT INTO %s (PKG_ID,%s_PKGNAME) VALUES (%d,\"%s\");",
sum.conflicts, sum.conflicts, pkgid, pkgname);
/* append query to commit_list */
commit_idx++;
XREALLOC(commit_list, (commit_idx + 1) * sizeof(char *));
XSTRDUP(commit_list[commit_idx], query);
psum++;
continue; /* there may be more */
}
/* PKGNAME record, should always be true */
if ((pkgname = field_record("PKGNAME", *psum)) != NULL) {
/* some rare packages have no version */
if (!exact_pkgfmt(pkgname)) {
snprintf(tmpname, BUFSIZ, "%s%s", pkgname, NOVERSION);
pkgname = tmpname;
}
add_to_slist("FULLPKGNAME", pkgname);
/* split PKGNAME and VERSION */
pkgvers = strrchr(pkgname, '-');
*pkgvers++ = '\0';
add_to_slist("PKGNAME", pkgname);
add_to_slist("PKGVERS", pkgvers);
/* nice little counter */
progress(pkgname[0]);
}
psum++;
/* browse entries following PKGNAME and build the SQL query */
while (*psum != NULL && !chk_pkgname(*psum, *(psum - 1))) {
update_col(sum, pkgid, *psum);
psum++;
}
/* build INSERT query */
prepare_insert(pkgid, sum, cur_repo);
/* next PKG_ID */
pkgid++;
/* free the SLIST containing this package's key/vals */
free_insertlist();
/* reset max query size */
query_size = BUFSIZ;
} /* while *psum != NULL */
commit_idx++;
XREALLOC(commit_list, (commit_idx + 2) * sizeof(char *));
XSTRDUP(commit_list[commit_idx], "COMMIT;");
commit_list[commit_idx + 1] = NULL;
/* do the insert */
for (i = 0; commit_list[i] != NULL; i++)
pkgindb_doquery(commit_list[i], NULL, NULL);
progress(alnum[strlen(alnum) - 1]); /* XXX: nasty. */
free_list(commit_list);
commit_idx = 0;
/* reset pkgid */
if (sum.type == LOCAL_SUMMARY)
pkgid = 1;
printf("\n");
}
static void
delete_remote_tbl(struct Summary sum, char *repo)
{
char buf[BUFSIZ];
const char **arr;
/*
* delete repository related tables
* loop through sumsw structure to record table name
* and call associated SQL query
*/
/* (REMOTE[LOCAL)_PKG is first -> skip */
for (arr = &(sum.tbl_name) + 1; *arr != NULL; ++arr) {
snprintf(buf, BUFSIZ, DELETE_REMOTE,
*arr, *arr, *arr, *arr, *arr, repo, *arr);
pkgindb_doquery(buf, NULL, NULL);
}
snprintf(buf, BUFSIZ,
"DELETE FROM REMOTE_PKG WHERE REPOSITORY = '%s';", repo);
pkgindb_doquery(buf, NULL, NULL);
}
static void
update_localdb(char **pkgkeep)
{
char **summary = NULL, buf[BUFSIZ];
Plistnumbered *keeplisthead, *nokeeplisthead;
Pkglist *pkglist;
/* has the pkgdb (pkgsrc) changed ? if not, continue */
if (!pkg_db_mtime() || !pkgdb_open(ReadWrite))
return;
/* just checking */
pkgdb_close();
/* record the keep list */
keeplisthead = rec_pkglist(KEEP_LOCAL_PKGS);
/* delete local pkg table (faster than updating) */
pkgindb_doquery(DELETE_LOCAL, NULL, NULL);
printf(MSG_READING_LOCAL_SUMMARY);
/* generate summary locally */
summary = exec_list(PKGTOOLS "/pkg_info -Xa", NULL);
printf(MSG_PROCESSING_LOCAL_SUMMARY);
/* insert the summary to the database */
insert_summary(sumsw[LOCAL_SUMMARY], summary, NULL);
/* re-read local packages list as it may have changed */
free_global_pkglists();
init_global_pkglists();
/* restore keep-list */
if (keeplisthead != NULL) {
SLIST_FOREACH(pkglist, keeplisthead->P_Plisthead, next) {
snprintf(buf, BUFSIZ, KEEP_PKG, pkglist->name);
pkgindb_doquery(buf, NULL, NULL);
}
free_pkglist(&keeplisthead->P_Plisthead, LIST);
free(keeplisthead);
/*
* packages are installed "manually" by pkgin_install()
* they are recorded as "non-automatic" in pkgdb, we
* need to mark unkeeps as "automatic"
*/
if ((nokeeplisthead =
rec_pkglist(NOKEEP_LOCAL_PKGS)) != NULL) {
SLIST_FOREACH(pkglist, nokeeplisthead->P_Plisthead, next) {
mark_as_automatic_installed(pkglist->full, 1);
}
free_pkglist(&nokeeplisthead->P_Plisthead, LIST);
free(nokeeplisthead);
}
} else { /* empty keep list */
/*
* no packages are marked as keep in pkgin's db
* probably a fresh install or a rebuild
* restore keep flags with pkgdb informations
*/
SLIST_FOREACH(pkglist, &l_plisthead, next) {
if (!is_automatic_installed(pkglist->full)) {
snprintf(buf, BUFSIZ, KEEP_PKG, pkglist->name);
pkgindb_doquery(buf, NULL, NULL);
}
}
}
/* insert new keep list if there's any */
if (pkgkeep != NULL)
/* installation: mark the packages as "keep" */
pkg_keep(KEEP, pkgkeep);
free_list(summary);
}
static int
pdb_clean_remote(void *param, int argc, char **argv, char **colname)
{
int i;
size_t repolen;
char **repos = pkg_repos, query[BUFSIZ];
if (argv == NULL)
return PDB_ERR;
for (i = 0; repos[i] != NULL; i++) {
repolen = strlen(repos[i]);
if (repolen == strlen(argv[0]) &&
strncmp(repos[i], argv[0], repolen) == 0 &&
!force_update)
return PDB_OK;
}
/* did not find argv[0] (db repository) in pkg_repos */
printf(MSG_CLEANING_DB_FROM_REPO, argv[0]);
delete_remote_tbl(sumsw[REMOTE_SUMMARY], argv[0]);
snprintf(query, BUFSIZ,
"DELETE FROM REPOS WHERE REPO_URL = \'%s\';", argv[0]);
pkgindb_doquery(query, NULL, NULL);
/* force pkg_summary reload for available repository */
force_fetch = 1;
return PDB_OK;
}
static void
update_remotedb(void)
{
char **summary = NULL, **prepos;
uint8_t cleaned = 0;
/* loop through PKG_REPOS */
for (prepos = pkg_repos; *prepos != NULL; prepos++) {
/* load remote pkg_summary */
if ((summary = fetch_summary(*prepos)) == NULL) {
printf(MSG_DB_IS_UP_TO_DATE, *prepos);
continue;
}
/*
* do not cleanup repos before being sure new repo is reachable
*/
if (!cleaned) {
/* delete unused repositories */
pkgindb_doquery("SELECT REPO_URL FROM REPOS;",
pdb_clean_remote, NULL);
cleaned = 1;
}
printf(MSG_PROCESSING_REMOTE_SUMMARY, *prepos);
/* delete remote* associated to this repository */
delete_remote_tbl(sumsw[REMOTE_SUMMARY], *prepos);
/* update remote* table for this repository */
insert_summary(sumsw[REMOTE_SUMMARY], summary, *prepos);
free_list(summary);
}
/* remove empty rows (duplicates) */
pkgindb_doquery(DELETE_EMPTY_ROWS, NULL, NULL);
}
int
update_db(int which, char **pkgkeep)
{
if (!have_enough_rights())
return EXIT_FAILURE;
/* always check for LOCAL_SUMMARY updates */
update_localdb(pkgkeep);
if (which == REMOTE_SUMMARY)
update_remotedb();
/* columns name not needed anymore */
if (cols.name != NULL) {
/* reset colums count */
colcount = 0;
freecols();
}
return EXIT_SUCCESS;
}
void
split_repos(void)
{
int repocount;
char *p;
XSTRDUP(env_repos, getenv("PKG_REPOS"));
if (env_repos == NULL)
if ((env_repos = read_repos()) == NULL)
errx(EXIT_FAILURE, MSG_MISSING_PKG_REPOS);
repocount = 2; /* 1st elm + NULL */
XMALLOC(pkg_repos, repocount * sizeof(char *));
*pkg_repos = env_repos;
p = env_repos;
while((p = strchr(p, ' ')) != NULL) {
*p = '\0';
p++;
XREALLOC(pkg_repos, ++repocount * sizeof(char *));
pkg_repos[repocount - 2] = p;
}
/* NULL last element */
pkg_repos[repocount - 1] = NULL;
repo_record(pkg_repos);
}