|
krh@15
|
1 |
#define _GNU_SOURCE
|
|
krh@15
|
2 |
|
|
krh@0
|
3 |
#include <stdlib.h>
|
|
krh@19
|
4 |
#include <stddef.h>
|
|
krh@0
|
5 |
#include <stdio.h>
|
|
krh@0
|
6 |
#include <string.h>
|
|
krh@0
|
7 |
#include <sys/types.h>
|
|
krh@0
|
8 |
#include <sys/stat.h>
|
|
krh@0
|
9 |
#include <sys/mman.h>
|
|
krh@0
|
10 |
#include <unistd.h>
|
|
krh@0
|
11 |
#include <fcntl.h>
|
|
krh@15
|
12 |
#include <errno.h>
|
|
krh@0
|
13 |
|
|
krh@0
|
14 |
#include <expat.h>
|
|
krh@0
|
15 |
#include "sha1.h"
|
|
krh@0
|
16 |
|
|
krh@19
|
17 |
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
krh@19
|
18 |
|
|
krh@6
|
19 |
struct array {
|
|
krh@6
|
20 |
void *data;
|
|
krh@6
|
21 |
int size, alloc;
|
|
krh@6
|
22 |
};
|
|
krh@6
|
23 |
|
|
krh@13
|
24 |
static void
|
|
krh@13
|
25 |
array_init(struct array *array)
|
|
krh@13
|
26 |
{
|
|
krh@13
|
27 |
memset(array, 0, sizeof *array);
|
|
krh@13
|
28 |
}
|
|
krh@13
|
29 |
|
|
krh@13
|
30 |
static void
|
|
krh@13
|
31 |
array_release(struct array *array)
|
|
krh@13
|
32 |
{
|
|
krh@13
|
33 |
free(array->data);
|
|
krh@13
|
34 |
}
|
|
krh@13
|
35 |
|
|
krh@6
|
36 |
static void *
|
|
krh@6
|
37 |
array_add(struct array *array, int size)
|
|
krh@6
|
38 |
{
|
|
krh@6
|
39 |
int alloc;
|
|
krh@6
|
40 |
void *data, *p;
|
|
krh@6
|
41 |
|
|
krh@6
|
42 |
if (array->alloc > 0)
|
|
krh@6
|
43 |
alloc = array->alloc;
|
|
krh@6
|
44 |
else
|
|
krh@10
|
45 |
alloc = 16;
|
|
krh@6
|
46 |
|
|
krh@6
|
47 |
while (alloc < array->size + size)
|
|
krh@6
|
48 |
alloc *= 2;
|
|
krh@6
|
49 |
|
|
krh@6
|
50 |
if (array->alloc < alloc) {
|
|
krh@6
|
51 |
data = realloc(array->data, alloc);
|
|
krh@6
|
52 |
if (data == NULL)
|
|
krh@6
|
53 |
return 0;
|
|
krh@6
|
54 |
array->data = data;
|
|
krh@6
|
55 |
array->alloc = alloc;
|
|
krh@6
|
56 |
}
|
|
krh@6
|
57 |
|
|
krh@6
|
58 |
p = array->data + array->size;
|
|
krh@6
|
59 |
array->size += size;
|
|
krh@6
|
60 |
|
|
krh@6
|
61 |
return p;
|
|
krh@6
|
62 |
}
|
|
krh@6
|
63 |
|
|
krh@0
|
64 |
static int
|
|
krh@0
|
65 |
write_to_fd(int fd, void *p, size_t size)
|
|
krh@0
|
66 |
{
|
|
krh@0
|
67 |
int rest, len;
|
|
krh@0
|
68 |
|
|
krh@0
|
69 |
rest = size;
|
|
krh@0
|
70 |
while (rest > 0) {
|
|
krh@0
|
71 |
len = write(fd, p, rest);
|
|
krh@0
|
72 |
if (len < 0)
|
|
krh@0
|
73 |
return -1;
|
|
krh@0
|
74 |
rest -= len;
|
|
krh@0
|
75 |
}
|
|
krh@0
|
76 |
|
|
krh@0
|
77 |
return 0;
|
|
krh@0
|
78 |
}
|
|
krh@0
|
79 |
|
|
krh@0
|
80 |
static int
|
|
krh@0
|
81 |
write_to_file(const char *filename, void *p, size_t size)
|
|
krh@0
|
82 |
{
|
|
krh@0
|
83 |
int fd, err;
|
|
krh@0
|
84 |
|
|
krh@0
|
85 |
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
|
|
krh@0
|
86 |
if (fd < 0)
|
|
krh@0
|
87 |
return -1;
|
|
krh@0
|
88 |
err = write_to_fd(fd, p, size);
|
|
krh@0
|
89 |
close(fd);
|
|
krh@0
|
90 |
|
|
krh@0
|
91 |
return err;
|
|
krh@0
|
92 |
}
|
|
krh@0
|
93 |
|
|
krh@0
|
94 |
static void *
|
|
krh@0
|
95 |
zalloc(size_t size)
|
|
krh@0
|
96 |
{
|
|
krh@0
|
97 |
void *p;
|
|
krh@0
|
98 |
|
|
krh@0
|
99 |
p = malloc(size);
|
|
krh@0
|
100 |
memset(p, 0, size);
|
|
krh@0
|
101 |
|
|
krh@0
|
102 |
return p;
|
|
krh@0
|
103 |
}
|
|
krh@0
|
104 |
|
|
krh@19
|
105 |
struct razor_set_section {
|
|
krh@19
|
106 |
unsigned int type;
|
|
krh@19
|
107 |
unsigned int offset;
|
|
krh@19
|
108 |
unsigned int size;
|
|
krh@19
|
109 |
};
|
|
krh@19
|
110 |
|
|
krh@4
|
111 |
struct razor_set_header {
|
|
krh@4
|
112 |
unsigned int magic;
|
|
krh@4
|
113 |
unsigned int version;
|
|
krh@19
|
114 |
struct razor_set_section sections[0];
|
|
krh@4
|
115 |
};
|
|
krh@4
|
116 |
|
|
krh@4
|
117 |
#define RAZOR_MAGIC 0x7a7a7a7a
|
|
krh@4
|
118 |
#define RAZOR_VERSION 1
|
|
krh@8
|
119 |
|
|
krh@19
|
120 |
#define RAZOR_PACKAGES 0
|
|
krh@19
|
121 |
#define RAZOR_REQUIRES 1
|
|
krh@19
|
122 |
#define RAZOR_PROVIDES 2
|
|
krh@19
|
123 |
#define RAZOR_STRING_POOL 3
|
|
krh@19
|
124 |
#define RAZOR_PROPERTY_POOL 4
|
|
krh@4
|
125 |
|
|
krh@4
|
126 |
struct razor_package {
|
|
krh@4
|
127 |
unsigned long name;
|
|
krh@4
|
128 |
unsigned long version;
|
|
krh@10
|
129 |
unsigned long requires;
|
|
krh@10
|
130 |
unsigned long provides;
|
|
krh@4
|
131 |
};
|
|
krh@4
|
132 |
|
|
krh@8
|
133 |
struct razor_property {
|
|
krh@7
|
134 |
unsigned long name;
|
|
krh@7
|
135 |
unsigned long version;
|
|
krh@9
|
136 |
unsigned long packages;
|
|
krh@7
|
137 |
};
|
|
krh@7
|
138 |
|
|
krh@4
|
139 |
struct razor_set {
|
|
krh@6
|
140 |
struct array buckets;
|
|
krh@6
|
141 |
struct array string_pool;
|
|
krh@10
|
142 |
struct array property_pool;
|
|
krh@7
|
143 |
struct array packages;
|
|
krh@8
|
144 |
struct array requires;
|
|
krh@7
|
145 |
struct array provides;
|
|
krh@4
|
146 |
struct razor_set_header *header;
|
|
krh@4
|
147 |
};
|
|
krh@4
|
148 |
|
|
krh@19
|
149 |
struct razor_set_section razor_sections[] = {
|
|
krh@19
|
150 |
{ RAZOR_PACKAGES, offsetof(struct razor_set, packages) },
|
|
krh@19
|
151 |
{ RAZOR_REQUIRES, offsetof(struct razor_set, requires) },
|
|
krh@19
|
152 |
{ RAZOR_PROVIDES, offsetof(struct razor_set, provides) },
|
|
krh@19
|
153 |
{ RAZOR_STRING_POOL, offsetof(struct razor_set, string_pool) },
|
|
krh@19
|
154 |
{ RAZOR_PROPERTY_POOL, offsetof(struct razor_set, property_pool) },
|
|
krh@19
|
155 |
};
|
|
krh@19
|
156 |
|
|
krh@4
|
157 |
struct razor_set *
|
|
krh@4
|
158 |
razor_set_create(void)
|
|
krh@0
|
159 |
{
|
|
krh@18
|
160 |
return zalloc(sizeof(struct razor_set));
|
|
krh@0
|
161 |
}
|
|
krh@0
|
162 |
|
|
krh@4
|
163 |
struct razor_set *
|
|
krh@4
|
164 |
razor_set_open(const char *filename)
|
|
krh@0
|
165 |
{
|
|
krh@4
|
166 |
struct razor_set *set;
|
|
krh@19
|
167 |
struct razor_set_section *s;
|
|
krh@0
|
168 |
struct stat stat;
|
|
krh@19
|
169 |
struct array *array;
|
|
krh@19
|
170 |
int fd;
|
|
krh@0
|
171 |
|
|
krh@4
|
172 |
set = zalloc(sizeof *set);
|
|
krh@0
|
173 |
fd = open(filename, O_RDONLY);
|
|
krh@0
|
174 |
if (fstat(fd, &stat) < 0)
|
|
krh@0
|
175 |
return NULL;
|
|
krh@4
|
176 |
set->header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
krh@4
|
177 |
if (set->header == MAP_FAILED) {
|
|
krh@4
|
178 |
free(set);
|
|
krh@0
|
179 |
return NULL;
|
|
krh@0
|
180 |
}
|
|
krh@0
|
181 |
|
|
krh@19
|
182 |
for (s = set->header->sections; ~s->type; s++) {
|
|
krh@19
|
183 |
if (s->type >= ARRAY_SIZE(razor_sections))
|
|
krh@19
|
184 |
continue;
|
|
krh@19
|
185 |
if (s->type != razor_sections[s->type].type)
|
|
krh@19
|
186 |
continue;
|
|
krh@19
|
187 |
array = (void *) set + razor_sections[s->type].offset;
|
|
krh@19
|
188 |
array->data = (void *) set->header + s->offset;
|
|
krh@19
|
189 |
array->size = s->size;
|
|
krh@19
|
190 |
array->alloc = s->size;
|
|
krh@0
|
191 |
}
|
|
krh@0
|
192 |
close(fd);
|
|
krh@0
|
193 |
|
|
krh@4
|
194 |
return set;
|
|
krh@0
|
195 |
}
|
|
krh@0
|
196 |
|
|
krh@0
|
197 |
void
|
|
krh@4
|
198 |
razor_set_destroy(struct razor_set *set)
|
|
krh@0
|
199 |
{
|
|
krh@0
|
200 |
unsigned int size;
|
|
krh@19
|
201 |
struct array *a;
|
|
krh@0
|
202 |
int i;
|
|
krh@0
|
203 |
|
|
krh@4
|
204 |
if (set->header) {
|
|
krh@4
|
205 |
for (i = 0; set->header->sections[i].type; i++)
|
|
krh@0
|
206 |
;
|
|
krh@4
|
207 |
size = set->header->sections[i].type;
|
|
krh@4
|
208 |
munmap(set->header, size);
|
|
krh@17
|
209 |
free(set->buckets.data);
|
|
krh@0
|
210 |
} else {
|
|
krh@19
|
211 |
for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
|
|
krh@19
|
212 |
a = (void *) set + razor_sections[i].offset;
|
|
krh@19
|
213 |
free(a->data);
|
|
krh@19
|
214 |
}
|
|
krh@6
|
215 |
free(set->buckets.data);
|
|
krh@0
|
216 |
}
|
|
krh@0
|
217 |
|
|
krh@4
|
218 |
free(set);
|
|
krh@0
|
219 |
}
|
|
krh@0
|
220 |
|
|
krh@0
|
221 |
static int
|
|
krh@4
|
222 |
razor_set_write(struct razor_set *set, const char *filename)
|
|
krh@0
|
223 |
{
|
|
krh@0
|
224 |
char data[4096];
|
|
krh@4
|
225 |
struct razor_set_header *header = (struct razor_set_header *) data;
|
|
krh@19
|
226 |
struct array *a;
|
|
krh@17
|
227 |
unsigned long offset;
|
|
krh@17
|
228 |
int i, fd;
|
|
krh@0
|
229 |
|
|
krh@0
|
230 |
memset(data, 0, sizeof data);
|
|
krh@4
|
231 |
header->magic = RAZOR_MAGIC;
|
|
krh@4
|
232 |
header->version = RAZOR_VERSION;
|
|
krh@17
|
233 |
offset = sizeof data;
|
|
krh@0
|
234 |
|
|
krh@19
|
235 |
for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
|
|
krh@19
|
236 |
if (razor_sections[i].type != i)
|
|
krh@19
|
237 |
continue;
|
|
krh@19
|
238 |
a = (void *) set + razor_sections[i].offset;
|
|
krh@19
|
239 |
header->sections[i].type = i;
|
|
krh@17
|
240 |
header->sections[i].offset = offset;
|
|
krh@19
|
241 |
header->sections[i].size = a->size;
|
|
krh@19
|
242 |
offset += (a->size + 4095) & ~4095;
|
|
krh@17
|
243 |
}
|
|
krh@0
|
244 |
|
|
krh@19
|
245 |
header->sections[i].type = ~0;
|
|
krh@17
|
246 |
header->sections[i].offset = 0;
|
|
krh@17
|
247 |
header->sections[i].size = 0;
|
|
krh@10
|
248 |
|
|
krh@0
|
249 |
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
|
|
krh@0
|
250 |
if (fd < 0)
|
|
krh@0
|
251 |
return -1;
|
|
krh@0
|
252 |
|
|
krh@0
|
253 |
write_to_fd(fd, data, sizeof data);
|
|
krh@19
|
254 |
for (i = 0; i < ARRAY_SIZE(razor_sections); i++) {
|
|
krh@19
|
255 |
if (razor_sections[i].type != i)
|
|
krh@19
|
256 |
continue;
|
|
krh@19
|
257 |
a = (void *) set + razor_sections[i].offset;
|
|
krh@19
|
258 |
write_to_fd(fd, a->data, (a->size + 4095) & ~4095);
|
|
krh@19
|
259 |
}
|
|
krh@17
|
260 |
|
|
krh@17
|
261 |
close(fd);
|
|
krh@0
|
262 |
|
|
krh@0
|
263 |
return 0;
|
|
krh@0
|
264 |
}
|
|
krh@0
|
265 |
|
|
krh@0
|
266 |
static unsigned int
|
|
krh@0
|
267 |
hash_string(const char *key)
|
|
krh@0
|
268 |
{
|
|
krh@0
|
269 |
const char *p;
|
|
krh@0
|
270 |
unsigned int hash = 0;
|
|
krh@0
|
271 |
|
|
krh@0
|
272 |
for (p = key; *p; p++)
|
|
krh@9
|
273 |
hash = (hash * 617) ^ *p;
|
|
krh@0
|
274 |
|
|
krh@0
|
275 |
return hash;
|
|
krh@0
|
276 |
}
|
|
krh@0
|
277 |
|
|
krh@0
|
278 |
unsigned long
|
|
krh@4
|
279 |
razor_set_lookup(struct razor_set *set, const char *key)
|
|
krh@0
|
280 |
{
|
|
krh@6
|
281 |
unsigned int mask, start, i;
|
|
krh@6
|
282 |
unsigned long *b;
|
|
krh@6
|
283 |
char *pool;
|
|
krh@0
|
284 |
|
|
krh@6
|
285 |
pool = set->string_pool.data;
|
|
krh@6
|
286 |
mask = set->buckets.alloc - 1;
|
|
krh@6
|
287 |
start = hash_string(key) * sizeof(unsigned long);
|
|
krh@0
|
288 |
|
|
krh@6
|
289 |
for (i = 0; i < set->buckets.alloc; i += sizeof *b) {
|
|
krh@6
|
290 |
b = set->buckets.data + ((start + i) & mask);
|
|
krh@6
|
291 |
|
|
krh@6
|
292 |
if (*b == 0)
|
|
krh@0
|
293 |
return 0;
|
|
krh@0
|
294 |
|
|
krh@6
|
295 |
if (strcmp(key, &pool[*b]) == 0)
|
|
krh@6
|
296 |
return *b;
|
|
krh@6
|
297 |
}
|
|
krh@0
|
298 |
|
|
krh@0
|
299 |
return 0;
|
|
krh@0
|
300 |
}
|
|
krh@0
|
301 |
|
|
krh@0
|
302 |
static unsigned long
|
|
krh@4
|
303 |
add_to_string_pool(struct razor_set *set, const char *key)
|
|
krh@0
|
304 |
{
|
|
krh@6
|
305 |
int len;
|
|
krh@6
|
306 |
char *p;
|
|
krh@0
|
307 |
|
|
krh@0
|
308 |
len = strlen(key) + 1;
|
|
krh@6
|
309 |
p = array_add(&set->string_pool, len);
|
|
krh@6
|
310 |
memcpy(p, key, len);
|
|
krh@0
|
311 |
|
|
krh@6
|
312 |
return p - (char *) set->string_pool.data;
|
|
krh@0
|
313 |
}
|
|
krh@0
|
314 |
|
|
krh@10
|
315 |
static unsigned long
|
|
krh@10
|
316 |
add_to_property_pool(struct razor_set *set, struct array *properties)
|
|
krh@10
|
317 |
{
|
|
krh@10
|
318 |
unsigned long *p;
|
|
krh@10
|
319 |
|
|
krh@10
|
320 |
p = array_add(properties, sizeof *p);
|
|
krh@18
|
321 |
*p = ~0ul;
|
|
krh@10
|
322 |
p = array_add(&set->property_pool, properties->size);
|
|
krh@10
|
323 |
memcpy(p, properties->data, properties->size);
|
|
krh@10
|
324 |
|
|
krh@10
|
325 |
return p - (unsigned long *) set->property_pool.data;
|
|
krh@10
|
326 |
}
|
|
krh@10
|
327 |
|
|
krh@0
|
328 |
static void
|
|
krh@4
|
329 |
do_insert(struct razor_set *set, unsigned long value)
|
|
krh@0
|
330 |
{
|
|
krh@6
|
331 |
unsigned int mask, start, i;
|
|
krh@6
|
332 |
unsigned long *b;
|
|
krh@0
|
333 |
const char *key;
|
|
krh@0
|
334 |
|
|
krh@6
|
335 |
key = (char *) set->string_pool.data + value;
|
|
krh@6
|
336 |
mask = set->buckets.alloc - 1;
|
|
krh@6
|
337 |
start = hash_string(key) * sizeof(unsigned long);
|
|
krh@6
|
338 |
|
|
krh@6
|
339 |
for (i = 0; i < set->buckets.alloc; i += sizeof *b) {
|
|
krh@6
|
340 |
b = set->buckets.data + ((start + i) & mask);
|
|
krh@6
|
341 |
if (*b == 0) {
|
|
krh@6
|
342 |
*b = value;
|
|
krh@0
|
343 |
break;
|
|
krh@0
|
344 |
}
|
|
krh@6
|
345 |
}
|
|
krh@0
|
346 |
}
|
|
krh@0
|
347 |
|
|
krh@0
|
348 |
unsigned long
|
|
krh@4
|
349 |
razor_set_insert(struct razor_set *set, const char *key)
|
|
krh@0
|
350 |
{
|
|
krh@6
|
351 |
unsigned long value, *buckets, *b, *end;
|
|
krh@6
|
352 |
int alloc;
|
|
krh@0
|
353 |
|
|
krh@6
|
354 |
alloc = set->buckets.alloc;
|
|
krh@6
|
355 |
array_add(&set->buckets, 4 * sizeof *buckets);
|
|
krh@6
|
356 |
if (alloc != set->buckets.alloc) {
|
|
krh@6
|
357 |
end = set->buckets.data + alloc;
|
|
krh@6
|
358 |
memset(end, 0, set->buckets.alloc - alloc);
|
|
krh@6
|
359 |
for (b = set->buckets.data; b < end; b++) {
|
|
krh@6
|
360 |
value = *b;
|
|
krh@6
|
361 |
if (value != 0) {
|
|
krh@6
|
362 |
*b = 0;
|
|
krh@4
|
363 |
do_insert(set, value);
|
|
krh@6
|
364 |
}
|
|
krh@0
|
365 |
}
|
|
krh@0
|
366 |
}
|
|
krh@0
|
367 |
|
|
krh@4
|
368 |
value = add_to_string_pool(set, key);
|
|
krh@4
|
369 |
do_insert (set, value);
|
|
krh@0
|
370 |
|
|
krh@0
|
371 |
return value;
|
|
krh@0
|
372 |
}
|
|
krh@0
|
373 |
|
|
krh@0
|
374 |
unsigned long
|
|
krh@4
|
375 |
razor_set_tokenize(struct razor_set *set, const char *string)
|
|
krh@0
|
376 |
{
|
|
krh@0
|
377 |
unsigned long token;
|
|
krh@0
|
378 |
|
|
krh@13
|
379 |
if (string == NULL)
|
|
krh@18
|
380 |
return razor_set_tokenize(set, "");
|
|
krh@13
|
381 |
|
|
krh@4
|
382 |
token = razor_set_lookup(set, string);
|
|
krh@0
|
383 |
if (token != 0)
|
|
krh@0
|
384 |
return token;
|
|
krh@0
|
385 |
|
|
krh@4
|
386 |
return razor_set_insert(set, string);
|
|
krh@0
|
387 |
}
|
|
krh@0
|
388 |
|
|
krh@13
|
389 |
struct import_property_context {
|
|
krh@25
|
390 |
struct array *all;
|
|
krh@10
|
391 |
struct array package;
|
|
krh@10
|
392 |
};
|
|
krh@10
|
393 |
|
|
krh@9
|
394 |
struct import_context {
|
|
krh@4
|
395 |
struct razor_set *set;
|
|
krh@13
|
396 |
struct import_property_context requires;
|
|
krh@13
|
397 |
struct import_property_context provides;
|
|
krh@25
|
398 |
struct razor_package *package;
|
|
krh@10
|
399 |
unsigned long *requires_map;
|
|
krh@10
|
400 |
unsigned long *provides_map;
|
|
krh@10
|
401 |
};
|
|
krh@10
|
402 |
|
|
krh@0
|
403 |
static void
|
|
krh@13
|
404 |
import_context_add_package(struct import_context *ctx,
|
|
krh@13
|
405 |
const char *name, const char *version)
|
|
krh@13
|
406 |
{
|
|
krh@25
|
407 |
struct razor_package *p;
|
|
krh@13
|
408 |
|
|
krh@25
|
409 |
p = array_add(&ctx->set->packages, sizeof *p);
|
|
krh@13
|
410 |
p->name = razor_set_tokenize(ctx->set, name);
|
|
krh@13
|
411 |
p->version = razor_set_tokenize(ctx->set, version);
|
|
krh@13
|
412 |
|
|
krh@18
|
413 |
ctx->package = p;
|
|
krh@13
|
414 |
array_init(&ctx->requires.package);
|
|
krh@13
|
415 |
array_init(&ctx->provides.package);
|
|
krh@13
|
416 |
}
|
|
krh@13
|
417 |
|
|
krh@13
|
418 |
void
|
|
krh@13
|
419 |
import_context_finish_package(struct import_context *ctx)
|
|
krh@13
|
420 |
{
|
|
krh@25
|
421 |
struct razor_package *p;
|
|
krh@13
|
422 |
|
|
krh@18
|
423 |
p = ctx->package;
|
|
krh@13
|
424 |
p->requires = add_to_property_pool(ctx->set, &ctx->requires.package);
|
|
krh@13
|
425 |
p->provides = add_to_property_pool(ctx->set, &ctx->provides.package);
|
|
krh@13
|
426 |
|
|
krh@13
|
427 |
array_release(&ctx->requires.package);
|
|
krh@13
|
428 |
array_release(&ctx->provides.package);
|
|
krh@13
|
429 |
}
|
|
krh@13
|
430 |
|
|
krh@13
|
431 |
static void
|
|
krh@13
|
432 |
import_context_add_property(struct import_context *ctx,
|
|
krh@13
|
433 |
struct import_property_context *pctx,
|
|
krh@13
|
434 |
const char *name, const char *version)
|
|
krh@13
|
435 |
{
|
|
krh@25
|
436 |
struct razor_property *p;
|
|
krh@13
|
437 |
unsigned long *r;
|
|
krh@13
|
438 |
|
|
krh@25
|
439 |
p = array_add(pctx->all, sizeof *p);
|
|
krh@13
|
440 |
p->name = razor_set_tokenize(ctx->set, name);
|
|
krh@13
|
441 |
p->version = razor_set_tokenize(ctx->set, version);
|
|
krh@25
|
442 |
p->packages = ctx->package -
|
|
krh@25
|
443 |
(struct razor_package *) ctx->set->packages.data;
|
|
krh@13
|
444 |
|
|
krh@13
|
445 |
r = array_add(&pctx->package, sizeof *r);
|
|
krh@25
|
446 |
*r = p - (struct razor_property *) pctx->all->data;
|
|
krh@13
|
447 |
}
|
|
krh@13
|
448 |
|
|
krh@13
|
449 |
static void
|
|
krh@9
|
450 |
parse_package(struct import_context *ctx, const char **atts, void *data)
|
|
krh@3
|
451 |
{
|
|
krh@13
|
452 |
const char *name = NULL, *version = NULL;
|
|
krh@3
|
453 |
int i;
|
|
krh@3
|
454 |
|
|
krh@3
|
455 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@3
|
456 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@13
|
457 |
name = atts[i + 1];
|
|
krh@3
|
458 |
else if (strcmp(atts[i], "version") == 0)
|
|
krh@13
|
459 |
version = atts[i + 1];
|
|
krh@3
|
460 |
}
|
|
krh@3
|
461 |
|
|
krh@13
|
462 |
if (name == NULL || version == NULL) {
|
|
krh@3
|
463 |
fprintf(stderr, "invalid package tag, "
|
|
krh@3
|
464 |
"missing name or version attributes\n");
|
|
krh@3
|
465 |
return;
|
|
krh@3
|
466 |
}
|
|
krh@3
|
467 |
|
|
krh@13
|
468 |
import_context_add_package(ctx, name, version);
|
|
krh@3
|
469 |
}
|
|
krh@3
|
470 |
|
|
krh@3
|
471 |
static void
|
|
krh@9
|
472 |
parse_property(struct import_context *ctx, const char **atts, void *data)
|
|
krh@8
|
473 |
{
|
|
krh@13
|
474 |
const char *name = NULL, *version = NULL;
|
|
krh@8
|
475 |
int i;
|
|
krh@8
|
476 |
|
|
krh@8
|
477 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@8
|
478 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@13
|
479 |
name = atts[i + 1];
|
|
krh@9
|
480 |
if (strcmp(atts[i], "version") == 0)
|
|
krh@13
|
481 |
version = atts[i + 1];
|
|
krh@8
|
482 |
}
|
|
krh@8
|
483 |
|
|
krh@13
|
484 |
if (name == NULL) {
|
|
krh@9
|
485 |
fprintf(stderr, "invalid tag, missing name attribute\n");
|
|
krh@8
|
486 |
return;
|
|
krh@8
|
487 |
}
|
|
krh@8
|
488 |
|
|
krh@13
|
489 |
import_context_add_property(ctx, data, name, version);
|
|
krh@7
|
490 |
}
|
|
krh@7
|
491 |
|
|
krh@7
|
492 |
static void
|
|
krh@0
|
493 |
start_element(void *data, const char *name, const char **atts)
|
|
krh@0
|
494 |
{
|
|
krh@9
|
495 |
struct import_context *ctx = data;
|
|
krh@0
|
496 |
|
|
krh@3
|
497 |
if (strcmp(name, "package") == 0)
|
|
krh@9
|
498 |
parse_package(ctx, atts, NULL);
|
|
krh@8
|
499 |
else if (strcmp(name, "requires") == 0)
|
|
krh@9
|
500 |
parse_property(ctx, atts, &ctx->requires);
|
|
krh@7
|
501 |
else if (strcmp(name, "provides") == 0)
|
|
krh@9
|
502 |
parse_property(ctx, atts, &ctx->provides);
|
|
krh@0
|
503 |
}
|
|
krh@0
|
504 |
|
|
krh@0
|
505 |
static void
|
|
krh@0
|
506 |
end_element (void *data, const char *name)
|
|
krh@0
|
507 |
{
|
|
krh@9
|
508 |
struct import_context *ctx = data;
|
|
krh@4
|
509 |
|
|
krh@13
|
510 |
if (strcmp(name, "package") == 0)
|
|
krh@13
|
511 |
import_context_finish_package(ctx);
|
|
krh@0
|
512 |
}
|
|
krh@0
|
513 |
|
|
krh@0
|
514 |
static char *
|
|
krh@0
|
515 |
sha1_to_hex(const unsigned char *sha1)
|
|
krh@0
|
516 |
{
|
|
krh@0
|
517 |
static int bufno;
|
|
krh@0
|
518 |
static char hexbuffer[4][50];
|
|
krh@0
|
519 |
static const char hex[] = "0123456789abcdef";
|
|
krh@0
|
520 |
char *buffer = hexbuffer[3 & ++bufno], *buf = buffer;
|
|
krh@0
|
521 |
int i;
|
|
krh@0
|
522 |
|
|
krh@0
|
523 |
for (i = 0; i < 20; i++) {
|
|
krh@0
|
524 |
unsigned int val = *sha1++;
|
|
krh@0
|
525 |
*buf++ = hex[val >> 4];
|
|
krh@0
|
526 |
*buf++ = hex[val & 0xf];
|
|
krh@0
|
527 |
}
|
|
krh@0
|
528 |
*buf = '\0';
|
|
krh@0
|
529 |
|
|
krh@0
|
530 |
return buffer;
|
|
krh@0
|
531 |
}
|
|
krh@0
|
532 |
|
|
krh@9
|
533 |
static void
|
|
krh@13
|
534 |
razor_prepare_import(struct import_context *ctx)
|
|
krh@9
|
535 |
{
|
|
krh@9
|
536 |
memset(ctx, 0, sizeof *ctx);
|
|
krh@13
|
537 |
ctx->set = razor_set_create();
|
|
krh@25
|
538 |
ctx->requires.all = &ctx->set->requires;
|
|
krh@25
|
539 |
ctx->provides.all = &ctx->set->provides;
|
|
krh@9
|
540 |
}
|
|
krh@9
|
541 |
|
|
krh@0
|
542 |
static int
|
|
krh@13
|
543 |
razor_import(struct import_context *ctx, const char *filename)
|
|
krh@0
|
544 |
{
|
|
krh@0
|
545 |
SHA_CTX sha1;
|
|
krh@0
|
546 |
XML_Parser parser;
|
|
krh@0
|
547 |
int fd;
|
|
krh@0
|
548 |
void *p;
|
|
krh@0
|
549 |
struct stat stat;
|
|
krh@0
|
550 |
char buf[128];
|
|
krh@0
|
551 |
unsigned char hash[20];
|
|
krh@0
|
552 |
|
|
krh@0
|
553 |
fd = open(filename, O_RDONLY);
|
|
krh@0
|
554 |
if (fstat(fd, &stat) < 0)
|
|
krh@0
|
555 |
return -1;
|
|
krh@0
|
556 |
p = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
krh@0
|
557 |
if (p == MAP_FAILED)
|
|
krh@0
|
558 |
return -1;
|
|
krh@0
|
559 |
|
|
krh@0
|
560 |
parser = XML_ParserCreate(NULL);
|
|
krh@9
|
561 |
XML_SetUserData(parser, ctx);
|
|
krh@0
|
562 |
XML_SetElementHandler(parser, start_element, end_element);
|
|
krh@0
|
563 |
if (XML_Parse(parser, p, stat.st_size, 1) == XML_STATUS_ERROR) {
|
|
krh@0
|
564 |
fprintf(stderr,
|
|
krh@0
|
565 |
"%s at line %d, %s\n",
|
|
krh@0
|
566 |
XML_ErrorString(XML_GetErrorCode(parser)),
|
|
krh@0
|
567 |
XML_GetCurrentLineNumber(parser),
|
|
krh@0
|
568 |
filename);
|
|
krh@0
|
569 |
return 1;
|
|
krh@0
|
570 |
}
|
|
krh@0
|
571 |
|
|
krh@0
|
572 |
XML_ParserFree(parser);
|
|
krh@0
|
573 |
|
|
krh@0
|
574 |
SHA1_Init(&sha1);
|
|
krh@0
|
575 |
SHA1_Update(&sha1, p, stat.st_size);
|
|
krh@0
|
576 |
SHA1_Final(hash, &sha1);
|
|
krh@0
|
577 |
|
|
krh@0
|
578 |
close(fd);
|
|
krh@0
|
579 |
|
|
krh@0
|
580 |
snprintf(buf, sizeof buf, "set/%s", sha1_to_hex(hash));
|
|
krh@0
|
581 |
if (write_to_file(buf, p, stat.st_size) < 0)
|
|
krh@0
|
582 |
return -1;
|
|
krh@0
|
583 |
munmap(p, stat.st_size);
|
|
krh@0
|
584 |
|
|
krh@0
|
585 |
return 0;
|
|
krh@0
|
586 |
}
|
|
krh@0
|
587 |
|
|
krh@22
|
588 |
typedef int (*compare_with_data_func_t)(const void *p1,
|
|
krh@22
|
589 |
const void *p,
|
|
krh@22
|
590 |
void *data);
|
|
krh@22
|
591 |
|
|
krh@25
|
592 |
struct qsort_context {
|
|
krh@25
|
593 |
size_t size;
|
|
krh@25
|
594 |
compare_with_data_func_t compare;
|
|
krh@25
|
595 |
void *data;
|
|
krh@25
|
596 |
};
|
|
krh@25
|
597 |
|
|
krh@22
|
598 |
static void
|
|
krh@22
|
599 |
qsort_swap(void *p1, void *p2, size_t size)
|
|
krh@22
|
600 |
{
|
|
krh@22
|
601 |
char buffer[size];
|
|
krh@22
|
602 |
|
|
krh@22
|
603 |
memcpy(buffer, p1, size);
|
|
krh@22
|
604 |
memcpy(p1, p2, size);
|
|
krh@22
|
605 |
memcpy(p2, buffer, size);
|
|
krh@22
|
606 |
}
|
|
krh@22
|
607 |
|
|
krh@25
|
608 |
static void
|
|
krh@25
|
609 |
__qsort_with_data(void *base, size_t nelem, unsigned long *map,
|
|
krh@25
|
610 |
struct qsort_context *ctx)
|
|
krh@22
|
611 |
{
|
|
krh@22
|
612 |
void *p, *start, *end, *pivot;
|
|
krh@25
|
613 |
unsigned long *mp, *mstart, *mend, tmp;
|
|
krh@22
|
614 |
int left, right, result;
|
|
krh@25
|
615 |
size_t size = ctx->size;
|
|
krh@22
|
616 |
|
|
krh@22
|
617 |
p = base;
|
|
krh@22
|
618 |
start = base;
|
|
krh@22
|
619 |
end = base + nelem * size;
|
|
krh@25
|
620 |
mp = map;
|
|
krh@25
|
621 |
mstart = map;
|
|
krh@25
|
622 |
mend = map + nelem;
|
|
krh@22
|
623 |
pivot = base + (random() % nelem) * size;
|
|
krh@25
|
624 |
|
|
krh@22
|
625 |
while (p < end) {
|
|
krh@25
|
626 |
result = ctx->compare(p, pivot, ctx->data);
|
|
krh@22
|
627 |
if (result < 0) {
|
|
krh@22
|
628 |
qsort_swap(p, start, size);
|
|
krh@25
|
629 |
tmp = *mp;
|
|
krh@25
|
630 |
*mp = *mstart;
|
|
krh@25
|
631 |
*mstart = tmp;
|
|
krh@22
|
632 |
if (start == pivot)
|
|
krh@22
|
633 |
pivot = p;
|
|
krh@22
|
634 |
start += size;
|
|
krh@25
|
635 |
mstart++;
|
|
krh@22
|
636 |
p += size;
|
|
krh@22
|
637 |
} else if (result == 0) {
|
|
krh@22
|
638 |
p += size;
|
|
krh@25
|
639 |
mp++;
|
|
krh@22
|
640 |
} else {
|
|
krh@22
|
641 |
end -= size;
|
|
krh@25
|
642 |
mend--;
|
|
krh@22
|
643 |
qsort_swap(p, end, size);
|
|
krh@25
|
644 |
tmp = *mp;
|
|
krh@25
|
645 |
*mp = *mstart;
|
|
krh@25
|
646 |
*mstart = tmp;
|
|
krh@22
|
647 |
if (end == pivot)
|
|
krh@22
|
648 |
pivot = p;
|
|
krh@22
|
649 |
}
|
|
krh@22
|
650 |
}
|
|
krh@22
|
651 |
|
|
krh@22
|
652 |
left = (start - base) / size;
|
|
krh@22
|
653 |
right = (base + nelem * size - end) / size;
|
|
krh@22
|
654 |
if (left > 1)
|
|
krh@25
|
655 |
__qsort_with_data(base, left, map, ctx);
|
|
krh@22
|
656 |
if (right > 1)
|
|
krh@25
|
657 |
__qsort_with_data(end, right, mend, ctx);
|
|
krh@25
|
658 |
}
|
|
krh@25
|
659 |
|
|
krh@25
|
660 |
unsigned long *
|
|
krh@25
|
661 |
qsort_with_data(void *base, size_t nelem, size_t size,
|
|
krh@25
|
662 |
compare_with_data_func_t compare, void *data)
|
|
krh@25
|
663 |
{
|
|
krh@25
|
664 |
struct qsort_context ctx;
|
|
krh@25
|
665 |
unsigned long *map;
|
|
krh@25
|
666 |
int i;
|
|
krh@25
|
667 |
|
|
krh@25
|
668 |
ctx.size = size;
|
|
krh@25
|
669 |
ctx.compare = compare;
|
|
krh@25
|
670 |
ctx.data = data;
|
|
krh@25
|
671 |
|
|
krh@25
|
672 |
map = malloc(nelem * sizeof (unsigned long));
|
|
krh@25
|
673 |
for (i = 0; i < nelem; i++)
|
|
krh@25
|
674 |
map[i] = i;
|
|
krh@25
|
675 |
|
|
krh@25
|
676 |
__qsort_with_data(base, nelem, map, &ctx);
|
|
krh@25
|
677 |
|
|
krh@25
|
678 |
return map;
|
|
krh@22
|
679 |
}
|
|
krh@9
|
680 |
|
|
krh@9
|
681 |
static int
|
|
krh@22
|
682 |
compare_packages(const void *p1, const void *p2, void *data)
|
|
krh@9
|
683 |
{
|
|
krh@25
|
684 |
const struct razor_package *pkg1 = p1, *pkg2 = p2;
|
|
krh@22
|
685 |
struct razor_set *set = data;
|
|
krh@22
|
686 |
char *pool = set->string_pool.data;
|
|
krh@9
|
687 |
|
|
krh@23
|
688 |
if (pkg1->name == pkg2->name)
|
|
krh@23
|
689 |
return 0;
|
|
krh@23
|
690 |
else
|
|
krh@23
|
691 |
return strcmp(&pool[pkg1->name], &pool[pkg2->name]);
|
|
krh@9
|
692 |
}
|
|
krh@9
|
693 |
|
|
krh@9
|
694 |
static int
|
|
krh@22
|
695 |
compare_properties(const void *p1, const void *p2, void *data)
|
|
krh@9
|
696 |
{
|
|
krh@25
|
697 |
const struct razor_property *prop1 = p1, *prop2 = p2;
|
|
krh@22
|
698 |
struct razor_set *set = data;
|
|
krh@22
|
699 |
char *pool = set->string_pool.data;
|
|
krh@9
|
700 |
|
|
krh@23
|
701 |
if (prop1->name == prop2->name)
|
|
krh@12
|
702 |
return strcmp(&pool[prop1->version], &pool[prop2->version]);
|
|
krh@12
|
703 |
else
|
|
krh@23
|
704 |
return strcmp(&pool[prop1->name], &pool[prop2->name]);
|
|
krh@9
|
705 |
}
|
|
krh@9
|
706 |
|
|
krh@10
|
707 |
static unsigned long *
|
|
krh@25
|
708 |
uniqueify_properties(struct razor_set *set, struct array *properties)
|
|
krh@9
|
709 |
{
|
|
krh@25
|
710 |
struct razor_property *rp, *up, *rp_end;
|
|
krh@18
|
711 |
struct array *pkgs, *p;
|
|
krh@25
|
712 |
unsigned long *map, *rmap, *r;
|
|
krh@18
|
713 |
int i, count, unique;
|
|
krh@9
|
714 |
|
|
krh@25
|
715 |
count = properties->size / sizeof(struct razor_property);
|
|
krh@25
|
716 |
map = qsort_with_data(properties->data,
|
|
krh@25
|
717 |
count,
|
|
krh@25
|
718 |
sizeof(struct razor_property),
|
|
krh@25
|
719 |
compare_properties,
|
|
krh@25
|
720 |
set);
|
|
krh@9
|
721 |
|
|
krh@25
|
722 |
rp_end = properties->data + properties->size;
|
|
krh@25
|
723 |
rmap = malloc(count * sizeof *map);
|
|
krh@25
|
724 |
pkgs = zalloc(count * sizeof *pkgs);
|
|
krh@25
|
725 |
for (rp = properties->data, up = rp, i = 0; rp < rp_end; rp++, i++) {
|
|
krh@25
|
726 |
if (rp->name != up->name || rp->version != up->version) {
|
|
krh@25
|
727 |
up++;
|
|
krh@25
|
728 |
up->name = rp->name;
|
|
krh@25
|
729 |
up->version = rp->version;
|
|
krh@10
|
730 |
}
|
|
krh@25
|
731 |
|
|
krh@25
|
732 |
unique = up - (struct razor_property *) properties->data;
|
|
krh@25
|
733 |
rmap[map[i]] = unique;
|
|
krh@25
|
734 |
r = array_add(&pkgs[unique], sizeof *r);
|
|
krh@25
|
735 |
*r = rp->packages;
|
|
krh@10
|
736 |
}
|
|
krh@25
|
737 |
free(map);
|
|
krh@9
|
738 |
|
|
krh@25
|
739 |
up++;
|
|
krh@25
|
740 |
properties->size = (void *) up - properties->data;
|
|
krh@25
|
741 |
rp_end = up;
|
|
krh@25
|
742 |
for (rp = properties->data, p = pkgs; rp < rp_end; rp++, p++) {
|
|
krh@25
|
743 |
rp->packages = add_to_property_pool(set, p);
|
|
krh@25
|
744 |
array_release(p);
|
|
krh@18
|
745 |
}
|
|
krh@18
|
746 |
|
|
krh@18
|
747 |
free(pkgs);
|
|
krh@18
|
748 |
|
|
krh@25
|
749 |
return rmap;
|
|
krh@10
|
750 |
}
|
|
krh@10
|
751 |
|
|
krh@10
|
752 |
static void
|
|
krh@18
|
753 |
remap_package_links(struct import_context *ctx)
|
|
krh@10
|
754 |
{
|
|
krh@25
|
755 |
struct razor_package *p, *end;
|
|
krh@10
|
756 |
unsigned long *pool, *r;
|
|
krh@10
|
757 |
|
|
krh@10
|
758 |
pool = ctx->set->property_pool.data;
|
|
krh@25
|
759 |
end = ctx->set->packages.data + ctx->set->packages.size;
|
|
krh@25
|
760 |
for (p = ctx->set->packages.data; p < end; p++) {
|
|
krh@18
|
761 |
for (r = &pool[p->requires]; ~*r; r++)
|
|
krh@10
|
762 |
*r = ctx->requires_map[*r];
|
|
krh@18
|
763 |
for (r = &pool[p->provides]; ~*r; r++)
|
|
krh@10
|
764 |
*r = ctx->provides_map[*r];
|
|
krh@9
|
765 |
}
|
|
krh@18
|
766 |
}
|
|
krh@10
|
767 |
|
|
krh@18
|
768 |
static void
|
|
krh@25
|
769 |
remap_property_links(struct import_context *ctx, unsigned long *map)
|
|
krh@18
|
770 |
{
|
|
krh@18
|
771 |
struct razor_property *p, *end;
|
|
krh@25
|
772 |
struct razor_package *rp;
|
|
krh@25
|
773 |
unsigned long *pool, *r, *rmap;
|
|
krh@18
|
774 |
int i, count;
|
|
krh@18
|
775 |
|
|
krh@18
|
776 |
pool = ctx->set->property_pool.data;
|
|
krh@25
|
777 |
count = ctx->set->packages.size / sizeof(struct razor_package);
|
|
krh@25
|
778 |
rmap = malloc(count * sizeof *map);
|
|
krh@25
|
779 |
rp = ctx->set->packages.data;
|
|
krh@18
|
780 |
for (i = 0; i < count; i++)
|
|
krh@25
|
781 |
rmap[map[i]] = i;
|
|
krh@18
|
782 |
|
|
krh@18
|
783 |
/* FIXME: This will break if we implement package list sharing
|
|
krh@18
|
784 |
* for all properties, since we'll remap those lists more than
|
|
krh@18
|
785 |
* once. We should just have a separate pool for property
|
|
krh@18
|
786 |
* lists and a separate pool for package lists and remap it as
|
|
krh@18
|
787 |
* a flat pool. Right now, as property lists and package
|
|
krh@18
|
788 |
* lists are mixed, we can't do that. */
|
|
krh@18
|
789 |
|
|
krh@18
|
790 |
end = ctx->set->requires.data + ctx->set->requires.size;
|
|
krh@18
|
791 |
for (p = ctx->set->requires.data; p < end; p++)
|
|
krh@18
|
792 |
for (r = &pool[p->packages]; ~*r; r++)
|
|
krh@25
|
793 |
*r = rmap[*r];
|
|
krh@18
|
794 |
|
|
krh@18
|
795 |
end = ctx->set->provides.data + ctx->set->provides.size;
|
|
krh@18
|
796 |
for (p = ctx->set->provides.data; p < end; p++)
|
|
krh@18
|
797 |
for (r = &pool[p->packages]; ~*r; r++)
|
|
krh@25
|
798 |
*r = rmap[*r];
|
|
krh@18
|
799 |
|
|
krh@25
|
800 |
free(rmap);
|
|
krh@9
|
801 |
}
|
|
krh@9
|
802 |
|
|
krh@13
|
803 |
static struct razor_set *
|
|
krh@13
|
804 |
razor_finish_import(struct import_context *ctx)
|
|
krh@9
|
805 |
{
|
|
krh@25
|
806 |
unsigned long *map;
|
|
krh@25
|
807 |
int count;
|
|
krh@18
|
808 |
|
|
krh@25
|
809 |
ctx->requires_map = uniqueify_properties(ctx->set, ctx->requires.all);
|
|
krh@25
|
810 |
ctx->provides_map = uniqueify_properties(ctx->set, ctx->provides.all);
|
|
krh@18
|
811 |
remap_package_links(ctx);
|
|
krh@10
|
812 |
free(ctx->requires_map);
|
|
krh@10
|
813 |
free(ctx->provides_map);
|
|
krh@25
|
814 |
|
|
krh@25
|
815 |
count = ctx->set->packages.size / sizeof(struct razor_package);
|
|
krh@25
|
816 |
map = qsort_with_data(ctx->set->packages.data,
|
|
krh@25
|
817 |
count,
|
|
krh@25
|
818 |
sizeof(struct razor_package),
|
|
krh@25
|
819 |
compare_packages,
|
|
krh@25
|
820 |
ctx->set);
|
|
krh@25
|
821 |
remap_property_links(ctx, map);
|
|
krh@25
|
822 |
free(map);
|
|
krh@13
|
823 |
|
|
krh@13
|
824 |
return ctx->set;
|
|
krh@9
|
825 |
}
|
|
krh@9
|
826 |
|
|
krh@15
|
827 |
/* Import a yum filelist as a razor package set. */
|
|
krh@15
|
828 |
|
|
krh@15
|
829 |
enum {
|
|
krh@15
|
830 |
YUM_STATE_BEGIN,
|
|
krh@15
|
831 |
YUM_STATE_PACKAGE_NAME
|
|
krh@15
|
832 |
};
|
|
krh@15
|
833 |
|
|
krh@15
|
834 |
struct yum_context {
|
|
krh@15
|
835 |
struct import_context ctx;
|
|
krh@15
|
836 |
struct import_property_context *current_property_context;
|
|
krh@15
|
837 |
char *name;
|
|
krh@15
|
838 |
int state;
|
|
krh@15
|
839 |
};
|
|
krh@15
|
840 |
|
|
krh@15
|
841 |
static void
|
|
krh@15
|
842 |
yum_start_element(void *data, const char *name, const char **atts)
|
|
krh@15
|
843 |
{
|
|
krh@15
|
844 |
struct yum_context *ctx = data;
|
|
krh@15
|
845 |
const char *n, *version;
|
|
krh@15
|
846 |
int i;
|
|
krh@15
|
847 |
|
|
krh@15
|
848 |
if (strcmp(name, "name") == 0) {
|
|
krh@15
|
849 |
ctx->state = YUM_STATE_PACKAGE_NAME;
|
|
krh@15
|
850 |
} else if (strcmp(name, "version") == 0) {
|
|
krh@24
|
851 |
version = NULL;
|
|
krh@15
|
852 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@15
|
853 |
if (strcmp(atts[i], "ver") == 0)
|
|
krh@15
|
854 |
version = atts[i + 1];
|
|
krh@15
|
855 |
}
|
|
krh@15
|
856 |
import_context_add_package(&ctx->ctx, ctx->name, version);
|
|
krh@15
|
857 |
} else if (strcmp(name, "rpm:requires") == 0) {
|
|
krh@15
|
858 |
ctx->current_property_context = &ctx->ctx.requires;
|
|
krh@15
|
859 |
} else if (strcmp(name, "rpm:provides") == 0) {
|
|
krh@15
|
860 |
ctx->current_property_context = &ctx->ctx.provides;
|
|
krh@15
|
861 |
} else if (strcmp(name, "rpm:entry") == 0 &&
|
|
krh@15
|
862 |
ctx->current_property_context != NULL) {
|
|
krh@15
|
863 |
n = NULL;
|
|
krh@15
|
864 |
version = NULL;
|
|
krh@15
|
865 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@15
|
866 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@15
|
867 |
n = atts[i + 1];
|
|
krh@15
|
868 |
else if (strcmp(atts[i], "ver") == 0)
|
|
krh@15
|
869 |
version = atts[i + 1];
|
|
krh@15
|
870 |
}
|
|
krh@15
|
871 |
|
|
krh@15
|
872 |
if (n == NULL) {
|
|
krh@15
|
873 |
fprintf(stderr, "invalid rpm:entry, "
|
|
krh@15
|
874 |
"missing name or version attributes\n");
|
|
krh@15
|
875 |
return;
|
|
krh@15
|
876 |
}
|
|
krh@15
|
877 |
|
|
krh@15
|
878 |
import_context_add_property(&ctx->ctx,
|
|
krh@15
|
879 |
ctx->current_property_context,
|
|
krh@15
|
880 |
n, version);
|
|
krh@15
|
881 |
}
|
|
krh@15
|
882 |
}
|
|
krh@15
|
883 |
|
|
krh@15
|
884 |
static void
|
|
krh@15
|
885 |
yum_end_element (void *data, const char *name)
|
|
krh@15
|
886 |
{
|
|
krh@15
|
887 |
struct yum_context *ctx = data;
|
|
krh@15
|
888 |
|
|
krh@15
|
889 |
if (strcmp(name, "package") == 0) {
|
|
krh@15
|
890 |
free(ctx->name);
|
|
krh@15
|
891 |
import_context_finish_package(&ctx->ctx);
|
|
krh@15
|
892 |
} else if (strcmp(name, "name") == 0) {
|
|
krh@15
|
893 |
ctx->state = 0;
|
|
krh@15
|
894 |
} else if (strcmp(name, "rpm:requires") == 0) {
|
|
krh@15
|
895 |
ctx->current_property_context = NULL;
|
|
krh@15
|
896 |
} else if (strcmp(name, "rpm:provides") == 0) {
|
|
krh@15
|
897 |
ctx->current_property_context = NULL;
|
|
krh@15
|
898 |
}
|
|
krh@15
|
899 |
}
|
|
krh@15
|
900 |
|
|
krh@15
|
901 |
static void
|
|
krh@15
|
902 |
yum_character_data (void *data, const XML_Char *s, int len)
|
|
krh@15
|
903 |
{
|
|
krh@15
|
904 |
struct yum_context *ctx = data;
|
|
krh@15
|
905 |
|
|
krh@15
|
906 |
if (ctx->state == YUM_STATE_PACKAGE_NAME)
|
|
krh@15
|
907 |
ctx->name = strndup(s, len);
|
|
krh@15
|
908 |
}
|
|
krh@15
|
909 |
|
|
krh@15
|
910 |
static struct razor_set *
|
|
krh@15
|
911 |
razor_set_create_from_yum_filelist(int fd)
|
|
krh@15
|
912 |
{
|
|
krh@15
|
913 |
struct yum_context ctx;
|
|
krh@15
|
914 |
XML_Parser parser;
|
|
krh@15
|
915 |
char buf[4096];
|
|
krh@15
|
916 |
int len;
|
|
krh@15
|
917 |
|
|
krh@15
|
918 |
razor_prepare_import(&ctx.ctx);
|
|
krh@15
|
919 |
|
|
krh@15
|
920 |
parser = XML_ParserCreate(NULL);
|
|
krh@15
|
921 |
XML_SetUserData(parser, &ctx);
|
|
krh@15
|
922 |
XML_SetElementHandler(parser, yum_start_element, yum_end_element);
|
|
krh@15
|
923 |
XML_SetCharacterDataHandler(parser, yum_character_data);
|
|
krh@15
|
924 |
|
|
krh@15
|
925 |
while (1) {
|
|
krh@15
|
926 |
len = read(fd, buf, sizeof buf);
|
|
krh@15
|
927 |
if (len < 0) {
|
|
krh@15
|
928 |
fprintf(stderr,
|
|
krh@15
|
929 |
"couldn't read input: %s\n", strerror(errno));
|
|
krh@15
|
930 |
return NULL;
|
|
krh@15
|
931 |
} else if (len == 0)
|
|
krh@15
|
932 |
break;
|
|
krh@15
|
933 |
|
|
krh@15
|
934 |
if (XML_Parse(parser, buf, len, 0) == XML_STATUS_ERROR) {
|
|
krh@15
|
935 |
fprintf(stderr,
|
|
krh@15
|
936 |
"%s at line %d\n",
|
|
krh@15
|
937 |
XML_ErrorString(XML_GetErrorCode(parser)),
|
|
krh@15
|
938 |
XML_GetCurrentLineNumber(parser));
|
|
krh@15
|
939 |
return NULL;
|
|
krh@15
|
940 |
}
|
|
krh@15
|
941 |
}
|
|
krh@15
|
942 |
|
|
krh@15
|
943 |
XML_ParserFree(parser);
|
|
krh@15
|
944 |
|
|
krh@15
|
945 |
return razor_finish_import(&ctx.ctx);
|
|
krh@15
|
946 |
}
|
|
krh@15
|
947 |
|
|
krh@0
|
948 |
void
|
|
krh@4
|
949 |
razor_set_list(struct razor_set *set)
|
|
krh@3
|
950 |
{
|
|
krh@6
|
951 |
struct razor_package *p, *end;
|
|
krh@6
|
952 |
char *pool;
|
|
krh@3
|
953 |
|
|
krh@6
|
954 |
pool = set->string_pool.data;
|
|
krh@6
|
955 |
end = set->packages.data + set->packages.size;
|
|
krh@14
|
956 |
for (p = set->packages.data; p < end; p++)
|
|
krh@6
|
957 |
printf("%s %s\n", &pool[p->name], &pool[p->version]);
|
|
krh@3
|
958 |
}
|
|
krh@3
|
959 |
|
|
krh@16
|
960 |
struct razor_set *bsearch_set;
|
|
krh@16
|
961 |
|
|
krh@16
|
962 |
static int
|
|
krh@16
|
963 |
compare_package_name(const void *key, const void *data)
|
|
krh@16
|
964 |
{
|
|
krh@16
|
965 |
const struct razor_package *p = data;
|
|
krh@16
|
966 |
char *pool;
|
|
krh@16
|
967 |
|
|
krh@16
|
968 |
pool = bsearch_set->string_pool.data;
|
|
krh@16
|
969 |
|
|
krh@16
|
970 |
return strcmp(key, &pool[p->name]);
|
|
krh@16
|
971 |
}
|
|
krh@16
|
972 |
|
|
krh@10
|
973 |
struct razor_package *
|
|
krh@10
|
974 |
razor_set_get_package(struct razor_set *set, const char *package)
|
|
krh@10
|
975 |
{
|
|
krh@16
|
976 |
bsearch_set = set;
|
|
krh@16
|
977 |
return bsearch(package, set->packages.data,
|
|
krh@16
|
978 |
set->packages.size / sizeof(struct razor_package),
|
|
krh@16
|
979 |
sizeof(struct razor_package), compare_package_name);
|
|
krh@10
|
980 |
}
|
|
krh@10
|
981 |
|
|
krh@18
|
982 |
static int
|
|
krh@18
|
983 |
compare_property_name(const void *key, const void *data)
|
|
krh@18
|
984 |
{
|
|
krh@18
|
985 |
const struct razor_property *p = data;
|
|
krh@18
|
986 |
char *pool;
|
|
krh@18
|
987 |
|
|
krh@18
|
988 |
pool = bsearch_set->string_pool.data;
|
|
krh@18
|
989 |
|
|
krh@18
|
990 |
return strcmp(key, &pool[p->name]);
|
|
krh@18
|
991 |
}
|
|
krh@18
|
992 |
|
|
krh@18
|
993 |
struct razor_property *
|
|
krh@18
|
994 |
razor_set_get_property(struct razor_set *set,
|
|
krh@18
|
995 |
struct array *properties,
|
|
krh@18
|
996 |
const char *property)
|
|
krh@18
|
997 |
{
|
|
krh@18
|
998 |
struct razor_property *p, *start;
|
|
krh@18
|
999 |
|
|
krh@18
|
1000 |
bsearch_set = set;
|
|
krh@18
|
1001 |
p = bsearch(property, properties->data,
|
|
krh@18
|
1002 |
properties->size / sizeof(struct razor_property),
|
|
krh@18
|
1003 |
sizeof(struct razor_property), compare_property_name);
|
|
krh@18
|
1004 |
|
|
krh@18
|
1005 |
start = properties->data;
|
|
krh@18
|
1006 |
while (p > start && (p - 1)->name == p->name)
|
|
krh@18
|
1007 |
p--;
|
|
krh@18
|
1008 |
|
|
krh@18
|
1009 |
return p;
|
|
krh@18
|
1010 |
}
|
|
krh@18
|
1011 |
|
|
krh@10
|
1012 |
static void
|
|
krh@10
|
1013 |
razor_set_list_all_properties(struct razor_set *set, struct array *properties)
|
|
krh@8
|
1014 |
{
|
|
krh@8
|
1015 |
struct razor_property *p, *end;
|
|
krh@8
|
1016 |
char *pool;
|
|
krh@8
|
1017 |
|
|
krh@8
|
1018 |
pool = set->string_pool.data;
|
|
krh@10
|
1019 |
end = properties->data + properties->size;
|
|
krh@14
|
1020 |
for (p = properties->data; p < end; p++)
|
|
krh@8
|
1021 |
printf("%s %s\n", &pool[p->name], &pool[p->version]);
|
|
krh@8
|
1022 |
}
|
|
krh@8
|
1023 |
|
|
krh@8
|
1024 |
void
|
|
krh@10
|
1025 |
razor_set_list_requires(struct razor_set *set, const char *name)
|
|
krh@7
|
1026 |
{
|
|
krh@10
|
1027 |
struct razor_property *p, *requires;
|
|
krh@10
|
1028 |
struct razor_package *package;
|
|
krh@10
|
1029 |
unsigned long *r;
|
|
krh@7
|
1030 |
char *pool;
|
|
krh@7
|
1031 |
|
|
krh@10
|
1032 |
if (name) {
|
|
krh@10
|
1033 |
package = razor_set_get_package(set, name);
|
|
krh@10
|
1034 |
r = (unsigned long *) set->property_pool.data +
|
|
krh@10
|
1035 |
package->requires;
|
|
krh@10
|
1036 |
requires = set->requires.data;
|
|
krh@10
|
1037 |
pool = set->string_pool.data;
|
|
krh@18
|
1038 |
while (~*r) {
|
|
krh@10
|
1039 |
p = &requires[*r++];
|
|
krh@10
|
1040 |
printf("%s %s\n", &pool[p->name], &pool[p->version]);
|
|
krh@10
|
1041 |
}
|
|
krh@10
|
1042 |
} else
|
|
krh@10
|
1043 |
razor_set_list_all_properties(set, &set->requires);
|
|
krh@10
|
1044 |
}
|
|
krh@10
|
1045 |
|
|
krh@10
|
1046 |
void
|
|
krh@10
|
1047 |
razor_set_list_provides(struct razor_set *set, const char *name)
|
|
krh@10
|
1048 |
{
|
|
krh@10
|
1049 |
struct razor_property *p, *provides;
|
|
krh@10
|
1050 |
struct razor_package *package;
|
|
krh@10
|
1051 |
unsigned long *r;
|
|
krh@10
|
1052 |
char *pool;
|
|
krh@10
|
1053 |
|
|
krh@10
|
1054 |
if (name) {
|
|
krh@10
|
1055 |
package = razor_set_get_package(set, name);
|
|
krh@10
|
1056 |
r = (unsigned long *) set->property_pool.data +
|
|
krh@10
|
1057 |
package->provides;
|
|
krh@10
|
1058 |
provides = set->provides.data;
|
|
krh@10
|
1059 |
pool = set->string_pool.data;
|
|
krh@18
|
1060 |
while (~*r) {
|
|
krh@10
|
1061 |
p = &provides[*r++];
|
|
krh@10
|
1062 |
printf("%s %s\n", &pool[p->name], &pool[p->version]);
|
|
krh@10
|
1063 |
}
|
|
krh@10
|
1064 |
} else
|
|
krh@10
|
1065 |
razor_set_list_all_properties(set, &set->provides);
|
|
krh@7
|
1066 |
}
|
|
krh@7
|
1067 |
|
|
krh@7
|
1068 |
void
|
|
krh@18
|
1069 |
razor_set_list_property_packages(struct razor_set *set,
|
|
krh@18
|
1070 |
struct array *properties,
|
|
krh@20
|
1071 |
const char *name,
|
|
krh@20
|
1072 |
const char *version)
|
|
krh@18
|
1073 |
{
|
|
krh@18
|
1074 |
struct razor_property *property, *end;
|
|
krh@18
|
1075 |
struct razor_package *p, *packages;
|
|
krh@18
|
1076 |
unsigned long *r;
|
|
krh@18
|
1077 |
char *pool;
|
|
krh@18
|
1078 |
|
|
krh@18
|
1079 |
if (name == NULL)
|
|
krh@18
|
1080 |
return;
|
|
krh@18
|
1081 |
|
|
krh@18
|
1082 |
property = razor_set_get_property(set, properties, name);
|
|
krh@18
|
1083 |
packages = set->packages.data;
|
|
krh@18
|
1084 |
pool = set->string_pool.data;
|
|
krh@18
|
1085 |
end = properties->data + properties->size;
|
|
krh@18
|
1086 |
while (property < end && strcmp(name, &pool[property->name]) == 0) {
|
|
krh@20
|
1087 |
if (version && strcmp(version, &pool[property->version]) != 0)
|
|
krh@20
|
1088 |
goto next;
|
|
krh@18
|
1089 |
r = (unsigned long *)
|
|
krh@18
|
1090 |
set->property_pool.data + property->packages;
|
|
krh@18
|
1091 |
while (~*r) {
|
|
krh@18
|
1092 |
p = &packages[*r++];
|
|
krh@18
|
1093 |
printf("%s %s\n",
|
|
krh@18
|
1094 |
&pool[p->name], &pool[p->version]);
|
|
krh@18
|
1095 |
}
|
|
krh@20
|
1096 |
next:
|
|
krh@18
|
1097 |
property++;
|
|
krh@18
|
1098 |
}
|
|
krh@18
|
1099 |
}
|
|
krh@18
|
1100 |
|
|
krh@18
|
1101 |
void
|
|
krh@21
|
1102 |
razor_set_validate(struct razor_set *set, struct array *unsatisfied)
|
|
krh@21
|
1103 |
{
|
|
krh@21
|
1104 |
struct razor_property *r, *p, *rend, *pend;
|
|
krh@21
|
1105 |
unsigned long *u;
|
|
krh@21
|
1106 |
char *pool;
|
|
krh@21
|
1107 |
|
|
krh@21
|
1108 |
r = set->requires.data;
|
|
krh@21
|
1109 |
p = set->provides.data;
|
|
krh@21
|
1110 |
rend = set->requires.data + set->requires.size;
|
|
krh@21
|
1111 |
pend = set->provides.data + set->provides.size;
|
|
krh@21
|
1112 |
pool = set->string_pool.data;
|
|
krh@21
|
1113 |
|
|
krh@21
|
1114 |
while (r < rend) {
|
|
krh@21
|
1115 |
while (p < pend && strcmp(&pool[r->name], &pool[p->name]) > 0)
|
|
krh@21
|
1116 |
p++;
|
|
krh@21
|
1117 |
if (p == pend || strcmp(&pool[r->name], &pool[p->name]) != 0) {
|
|
krh@21
|
1118 |
u = array_add(unsatisfied, sizeof *u);
|
|
krh@21
|
1119 |
*u = r - (struct razor_property *) set->requires.data;
|
|
krh@21
|
1120 |
}
|
|
krh@21
|
1121 |
r++;
|
|
krh@21
|
1122 |
}
|
|
krh@21
|
1123 |
}
|
|
krh@21
|
1124 |
|
|
krh@21
|
1125 |
void
|
|
krh@21
|
1126 |
razor_set_list_unsatisfied(struct razor_set *set)
|
|
krh@21
|
1127 |
{
|
|
krh@21
|
1128 |
struct array unsatisfied;
|
|
krh@21
|
1129 |
struct razor_property *requires, *r;
|
|
krh@21
|
1130 |
unsigned long *u, *end;
|
|
krh@21
|
1131 |
char *pool;
|
|
krh@21
|
1132 |
|
|
krh@21
|
1133 |
array_init(&unsatisfied);
|
|
krh@21
|
1134 |
razor_set_validate(set, &unsatisfied);
|
|
krh@21
|
1135 |
|
|
krh@21
|
1136 |
end = unsatisfied.data + unsatisfied.size;
|
|
krh@21
|
1137 |
requires = set->requires.data;
|
|
krh@21
|
1138 |
pool = set->string_pool.data;
|
|
krh@21
|
1139 |
|
|
krh@21
|
1140 |
for (u = unsatisfied.data; u < end; u++) {
|
|
krh@21
|
1141 |
r = requires + *u;
|
|
krh@21
|
1142 |
printf("%s %s not satisfied\n",
|
|
krh@21
|
1143 |
&pool[r->name], &pool[r->version]);
|
|
krh@21
|
1144 |
}
|
|
krh@21
|
1145 |
|
|
krh@21
|
1146 |
array_release(&unsatisfied);
|
|
krh@21
|
1147 |
}
|
|
krh@21
|
1148 |
|
|
krh@21
|
1149 |
void
|
|
krh@4
|
1150 |
razor_set_info(struct razor_set *set)
|
|
krh@3
|
1151 |
{
|
|
krh@3
|
1152 |
unsigned int offset, size;
|
|
krh@3
|
1153 |
int i;
|
|
krh@3
|
1154 |
|
|
krh@4
|
1155 |
for (i = 0; i < set->header->sections[i].type; i++) {
|
|
krh@4
|
1156 |
offset = set->header->sections[i].offset;
|
|
krh@18
|
1157 |
size = set->header->sections[i].size;
|
|
krh@3
|
1158 |
|
|
krh@4
|
1159 |
switch (set->header->sections[i].type) {
|
|
krh@4
|
1160 |
case RAZOR_PACKAGES:
|
|
krh@3
|
1161 |
printf("package section:\t%dkb\n", size / 1024);
|
|
krh@3
|
1162 |
break;
|
|
krh@8
|
1163 |
case RAZOR_REQUIRES:
|
|
krh@8
|
1164 |
printf("requires section:\t%dkb\n", size / 1024);
|
|
krh@8
|
1165 |
break;
|
|
krh@7
|
1166 |
case RAZOR_PROVIDES:
|
|
krh@7
|
1167 |
printf("provides section:\t%dkb\n", size / 1024);
|
|
krh@7
|
1168 |
break;
|
|
krh@19
|
1169 |
case RAZOR_STRING_POOL:
|
|
krh@19
|
1170 |
printf("string pool:\t\t%dkb\n", size / 1024);
|
|
krh@19
|
1171 |
break;
|
|
krh@19
|
1172 |
case RAZOR_PROPERTY_POOL:
|
|
krh@18
|
1173 |
printf("properties section:\t%dkb\n", size / 1024);
|
|
krh@18
|
1174 |
break;
|
|
krh@3
|
1175 |
}
|
|
krh@3
|
1176 |
}
|
|
krh@0
|
1177 |
}
|
|
krh@0
|
1178 |
|
|
krh@0
|
1179 |
static int
|
|
krh@0
|
1180 |
usage(void)
|
|
krh@0
|
1181 |
{
|
|
krh@7
|
1182 |
printf("usage: razor [ import FILES | lookup <key> | "
|
|
krh@15
|
1183 |
"list | list-requires | list-provides | eat-yum | info ]\n");
|
|
krh@0
|
1184 |
exit(1);
|
|
krh@0
|
1185 |
}
|
|
krh@0
|
1186 |
|
|
krh@15
|
1187 |
static const char *repo_filename = "system.repo";
|
|
krh@15
|
1188 |
static const char rawhide_repo_filename[] = "rawhide.repo";
|
|
krh@0
|
1189 |
|
|
krh@0
|
1190 |
int
|
|
krh@0
|
1191 |
main(int argc, char *argv[])
|
|
krh@0
|
1192 |
{
|
|
krh@0
|
1193 |
int i;
|
|
krh@4
|
1194 |
struct razor_set *set;
|
|
krh@0
|
1195 |
struct stat statbuf;
|
|
krh@9
|
1196 |
struct import_context ctx;
|
|
krh@15
|
1197 |
char *repo;
|
|
krh@15
|
1198 |
|
|
krh@15
|
1199 |
repo = getenv("RAZOR_REPO");
|
|
krh@15
|
1200 |
if (repo != NULL)
|
|
krh@15
|
1201 |
repo_filename = repo;
|
|
krh@0
|
1202 |
|
|
krh@3
|
1203 |
if (argc < 2) {
|
|
krh@0
|
1204 |
usage();
|
|
krh@0
|
1205 |
} else if (strcmp(argv[1], "import") == 0) {
|
|
krh@0
|
1206 |
if (stat("set", &statbuf) && mkdir("set", 0777)) {
|
|
krh@0
|
1207 |
fprintf(stderr, "could not create directory 'set'\n");
|
|
krh@0
|
1208 |
exit(-1);
|
|
krh@0
|
1209 |
}
|
|
krh@0
|
1210 |
|
|
krh@13
|
1211 |
razor_prepare_import(&ctx);
|
|
krh@9
|
1212 |
|
|
krh@0
|
1213 |
for (i = 2; i < argc; i++) {
|
|
krh@13
|
1214 |
if (razor_import(&ctx, argv[i]) < 0) {
|
|
krh@0
|
1215 |
fprintf(stderr, "failed to import %s\n",
|
|
krh@0
|
1216 |
argv[i]);
|
|
krh@0
|
1217 |
exit(-1);
|
|
krh@0
|
1218 |
}
|
|
krh@0
|
1219 |
}
|
|
krh@0
|
1220 |
|
|
krh@13
|
1221 |
set = razor_finish_import(&ctx);
|
|
krh@6
|
1222 |
|
|
krh@6
|
1223 |
printf("bucket allocation: %d\n", set->buckets.alloc);
|
|
krh@6
|
1224 |
printf("pool size: %d\n", set->string_pool.size);
|
|
krh@6
|
1225 |
printf("pool allocation: %d\n", set->string_pool.alloc);
|
|
krh@7
|
1226 |
printf("packages: %d\n",
|
|
krh@7
|
1227 |
set->packages.size / sizeof(struct razor_package));
|
|
krh@8
|
1228 |
printf("requires: %d\n",
|
|
krh@8
|
1229 |
set->requires.size / sizeof(struct razor_property));
|
|
krh@7
|
1230 |
printf("provides: %d\n",
|
|
krh@8
|
1231 |
set->provides.size / sizeof(struct razor_property));
|
|
krh@0
|
1232 |
|
|
krh@4
|
1233 |
razor_set_write(set, repo_filename);
|
|
krh@0
|
1234 |
|
|
krh@4
|
1235 |
razor_set_destroy(set);
|
|
krh@0
|
1236 |
} else if (strcmp(argv[1], "lookup") == 0) {
|
|
krh@4
|
1237 |
set = razor_set_open(repo_filename);
|
|
krh@0
|
1238 |
printf("%s is %lu\n", argv[2],
|
|
krh@4
|
1239 |
razor_set_lookup(set, argv[2]));
|
|
krh@4
|
1240 |
razor_set_destroy(set);
|
|
krh@3
|
1241 |
} else if (strcmp(argv[1], "list") == 0) {
|
|
krh@4
|
1242 |
set = razor_set_open(repo_filename);
|
|
krh@4
|
1243 |
razor_set_list(set);
|
|
krh@4
|
1244 |
razor_set_destroy(set);
|
|
krh@8
|
1245 |
} else if (strcmp(argv[1], "list-requires") == 0) {
|
|
krh@8
|
1246 |
set = razor_set_open(repo_filename);
|
|
krh@10
|
1247 |
razor_set_list_requires(set, argv[2]);
|
|
krh@8
|
1248 |
razor_set_destroy(set);
|
|
krh@7
|
1249 |
} else if (strcmp(argv[1], "list-provides") == 0) {
|
|
krh@7
|
1250 |
set = razor_set_open(repo_filename);
|
|
krh@10
|
1251 |
razor_set_list_provides(set, argv[2]);
|
|
krh@7
|
1252 |
razor_set_destroy(set);
|
|
krh@18
|
1253 |
} else if (strcmp(argv[1], "what-requires") == 0) {
|
|
krh@18
|
1254 |
set = razor_set_open(repo_filename);
|
|
krh@20
|
1255 |
razor_set_list_property_packages(set, &set->requires,
|
|
krh@20
|
1256 |
argv[2], argv[3]);
|
|
krh@18
|
1257 |
razor_set_destroy(set);
|
|
krh@18
|
1258 |
} else if (strcmp(argv[1], "what-provides") == 0) {
|
|
krh@18
|
1259 |
set = razor_set_open(repo_filename);
|
|
krh@20
|
1260 |
razor_set_list_property_packages(set, &set->provides,
|
|
krh@20
|
1261 |
argv[2], argv[3]);
|
|
krh@18
|
1262 |
razor_set_destroy(set);
|
|
krh@3
|
1263 |
} else if (strcmp(argv[1], "info") == 0) {
|
|
krh@4
|
1264 |
set = razor_set_open(repo_filename);
|
|
krh@4
|
1265 |
razor_set_info(set);
|
|
krh@4
|
1266 |
razor_set_destroy(set);
|
|
krh@15
|
1267 |
} else if (strcmp(argv[1], "eat-yum") == 0) {
|
|
krh@15
|
1268 |
set = razor_set_create_from_yum_filelist(STDIN_FILENO);
|
|
krh@15
|
1269 |
if (set == NULL)
|
|
krh@15
|
1270 |
return 1;
|
|
krh@15
|
1271 |
razor_set_write(set, rawhide_repo_filename);
|
|
krh@15
|
1272 |
razor_set_destroy(set);
|
|
krh@18
|
1273 |
printf("wrote %s\n", rawhide_repo_filename);
|
|
krh@21
|
1274 |
} else if (strcmp(argv[1], "validate") == 0) {
|
|
krh@21
|
1275 |
set = razor_set_open(repo_filename);
|
|
krh@21
|
1276 |
if (set == NULL)
|
|
krh@21
|
1277 |
return 1;
|
|
krh@21
|
1278 |
razor_set_list_unsatisfied(set);
|
|
krh@21
|
1279 |
razor_set_destroy(set);
|
|
krh@0
|
1280 |
} else {
|
|
krh@0
|
1281 |
usage();
|
|
krh@0
|
1282 |
}
|
|
krh@0
|
1283 |
|
|
krh@0
|
1284 |
return 0;
|
|
krh@0
|
1285 |
}
|