Introduce install/remove iterators.
These iterator constructors lets you pass in two sets and creates
an iterator for the packages to remove or the packages to install.
The iterators will step through the packages in a sequence that respects
the pre, post, preun and postun modifiers.
Right now, the install order isn't actually implemented, this patch just
implements the API changes and updates the applications.
9 #include "razor-internal.h"
12 razor_create_dir(const char *root, const char *path)
14 char buffer[PATH_MAX], *p;
15 const char *slash, *next;
18 /* Create all sub-directories in dir. We know root exists and
19 * is a dir, root does not end in a '/', and path has a
23 p = buffer + strlen(buffer);
25 for (slash = path; *slash != '\0'; slash = next) {
26 next = strchr(slash + 1, '/');
30 memcpy(p, slash, next - slash);
34 if (stat(buffer, &buf) == 0) {
35 if (!S_ISDIR(buf.st_mode)) {
37 "%s exists but is not a directory\n",
41 } else if (mkdir(buffer, 0777) < 0) {
42 fprintf(stderr, "failed to make directory %s: %m\n",
47 /* FIXME: What to do about permissions for dirs we
48 * have to create but are not in the cpio archive? */
55 razor_write(int fd, const void *data, size_t size)
59 const unsigned char *p;
64 written = write(fd, p, rest);
66 fprintf(stderr, "write error: %m\n");
76 struct qsort_context {
78 razor_compare_with_data_func_t compare;
83 qsort_swap(void *p1, void *p2, size_t size)
87 memcpy(buffer, p1, size);
89 memcpy(p2, buffer, size);
93 __qsort_with_data(void *base, size_t nelem, uint32_t *map,
94 struct qsort_context *ctx)
96 void *p, *start, *end, *pivot;
97 uint32_t *mp, *mstart, *mend, tmp;
98 int left, right, result;
99 size_t size = ctx->size;
103 end = base + nelem * size;
107 pivot = base + (random() % nelem) * size;
110 result = ctx->compare(p, pivot, ctx->data);
112 qsort_swap(p, start, size);
122 } else if (result == 0) {
128 qsort_swap(p, end, size);
137 left = (start - base) / size;
138 right = (base + nelem * size - end) / size;
140 __qsort_with_data(base, left, map, ctx);
142 __qsort_with_data(end, right, mend, ctx);
146 razor_qsort_with_data(void *base, size_t nelem, size_t size,
147 razor_compare_with_data_func_t compare, void *data)
149 struct qsort_context ctx;
157 ctx.compare = compare;
160 map = malloc(nelem * sizeof (uint32_t));
161 for (i = 0; i < nelem; i++)
164 __qsort_with_data(base, nelem, map, &ctx);