-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgset-load.c
149 lines (112 loc) · 4.25 KB
/
pkgset-load.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
/*
Copyright (C) 2000 - 2008 Pawel A. Gajda <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2 as
published by the Free Software Foundation (see file COPYING for details).
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <trurl/nassert.h>
#include <vfile/vfile.h>
#include "compiler.h"
#include "pkgset.h"
#include "pkgdir/pkgdir.h"
#include "pkgdir/pkgdir_intern.h"
#include "log.h"
#include "misc.h"
#include "i18n.h"
#include "depdirs.h"
int pkgset_load(struct pkgset *ps, int ldflags, tn_array *sources)
{
int i, j;
unsigned openflags = 0;
n_array_isort_ex(sources, (tn_fn_cmp)source_cmp_pri);
if (ldflags & PKGDIR_LD_ALLDESC)
openflags |= PKGDIR_OPEN_ALLDESC;
for (i=0; i < n_array_size(sources); i++) {
struct source *src = n_array_nth(sources, i);
struct pkgdir *pkgdir = NULL;
if (src->flags & PKGSOURCE_NOAUTO)
continue;
if (src->type == NULL)
source_set_type(src, poldek_conf_PKGDIR_DEFAULT_TYPE);
pkgdir = pkgdir_srcopen(src, openflags);
/* trying dir */
if (pkgdir == NULL && !source_is_type(src, "dir") &&
util__isdir(src->path)) {
logn(LOGNOTICE, _("trying to scan directory %s..."), src->path);
source_set_type(src, "dir");
pkgdir = pkgdir_srcopen(src, openflags);
}
if (pkgdir == NULL) {
if (n_array_size(sources) > 1)
logn(LOGWARN, _("%s: load failed, skipped"),
vf_url_slim_s(src->path, 0));
continue;
}
n_array_push(ps->pkgdirs, pkgdir);
MEMINF("after open %s", pkgdir_idstr(pkgdir));
}
/* merge pkgdis depdirs into ps->depdirs */
for (i=0; i < n_array_size(ps->pkgdirs); i++) {
struct pkgdir *pkgdir = n_array_nth(ps->pkgdirs, i);
if (pkgdir->depdirs) {
for (j=0; j < n_array_size(pkgdir->depdirs); j++)
n_array_push(ps->depdirs, n_array_nth(pkgdir->depdirs, j));
}
}
n_array_sort(ps->depdirs);
n_array_uniq(ps->depdirs);
for (i=0; i < n_array_size(ps->pkgdirs); i++) {
struct pkgdir *pkgdir = n_array_nth(ps->pkgdirs, i);
if ((pkgdir->flags & PKGDIR_LOADED) == 0) {
if (!pkgdir_load(pkgdir, ps->depdirs, ldflags)) {
logn(LOGERR, _("%s: load failed"), pkgdir->idxpath);
}
}
MEMINF("after load %s", pkgdir_idstr(pkgdir));
}
/* merge pkgdirs packages into ps->pkgs */
for (i=0; i < n_array_size(ps->pkgdirs); i++) {
struct pkgdir *pkgdir = n_array_nth(ps->pkgdirs, i);
for (j=0; j < n_array_size(pkgdir->pkgs); j++) {
struct pkg *pkg = n_array_nth(pkgdir->pkgs, j);
//pkg->recno = ps->_recno++; TOFIX another field is needed
if (pkg_is_scored(pkg, PKG_IGNORED))
continue;
n_array_push(ps->pkgs, pkg_link(pkg));
}
}
init_depdirs(ps->depdirs);
if (n_array_size(ps->pkgs)) {
int n = n_array_size(ps->pkgs);
msgn(1, ngettext("%d package read",
"%d packages read", n), n);
}
return n_array_size(ps->pkgs);
}
int pkgset_add_pkgdir(struct pkgset *ps, struct pkgdir *pkgdir)
{
int i;
n_array_push(ps->depdirs, pkgdir);
if (pkgdir->depdirs) {
for (i=0; i < n_array_size(pkgdir->depdirs); i++)
n_array_push(ps->depdirs, n_array_nth(pkgdir->depdirs, i));
}
n_array_sort(ps->depdirs);
n_array_uniq(ps->depdirs);
for (i=0; i < n_array_size(pkgdir->pkgs); i++) {
struct pkg *pkg = n_array_nth(pkgdir->pkgs, i);
//pkg->recno = ps->_recno++; TOFIX see comment in pkgset_load()
n_array_push(ps->pkgs, pkg_link(pkg));
}
n_array_push(ps->pkgdirs, pkgdir);
return 1;
}