]> git.pld-linux.org Git - packages/poldek.git/blame - poldek-split64.patch
- release 3 for Th.
[packages/poldek.git] / poldek-split64.patch
CommitLineData
340d66c8
AM
1Index: cli/op_split.c
2===================================================================
3RCS file: /cvsroot/installer/poldek/cli/op_split.c,v
4retrieving revision 1.10
5retrieving revision 1.11
6diff -u -r1.10 -r1.11
7--- cli/op_split.c 10 Jul 2005 13:30:17 -0000 1.10
8+++ cli/op_split.c 3 Oct 2005 19:57:05 -0000 1.11
9@@ -7,7 +7,7 @@
10 */
11
12 /*
13- $Id$
14+ $Id$
15 */
16
17 #ifdef HAVE_CONFIG_H
18@@ -167,9 +167,6 @@
19 logn(LOGERR, _("first free space bigger than chunk size"));
20 return 0;
21 }
22-
23- arg_s->size *= 1024 * 1024;
24- arg_s->first_free_space *= 1024 * 1024;
25
26 return poldek_split(ctx, arg_s->size, arg_s->first_free_space,
27 arg_s->prefix);
28Index: split.c
29===================================================================
30RCS file: /cvsroot/installer/poldek/split.c,v
31retrieving revision 1.22
32retrieving revision 1.23
33diff -u -r1.22 -r1.23
34--- split.c 5 Jul 2005 21:11:12 -0000 1.22
35+++ split.c 3 Oct 2005 19:57:04 -0000 1.23
36@@ -11,7 +11,7 @@
37 */
38
39 /*
40- $Id$
41+ $Id$
42 */
43
44 #include <ctype.h>
45@@ -39,8 +39,8 @@
46
47 struct chunk {
48 int no;
49- unsigned size;
50- unsigned maxsize;
51+ uint64_t size;
52+ uint64_t maxsize;
53 int items;
54 tn_array *pkgs;
55 };
56@@ -50,7 +50,7 @@
57 char mask[0];
58 };
59
60-static struct chunk *chunk_new(int no, int maxsize)
61+static struct chunk *chunk_new(int no, uint64_t maxsize)
62 {
63 struct chunk *chunk;
64
65@@ -241,7 +241,7 @@
66
67
68 static
69-int try_package(int deep, unsigned *chunk_size, unsigned maxsize,
70+int try_package(int deep, uint64_t *chunk_size, uint64_t maxsize,
71 struct pkg *pkg, tn_array *stack)
72 {
73 int i, rc = 1;
74@@ -256,7 +256,7 @@
75 n_array_push(stack, pkg_link(pkg));
76 *chunk_size += pkg->fsize;
77
78- DBGF("trying %s: %d (%d) > %d\n", pkg_snprintf_s(pkg), *chunk_size,
79+ DBGF("trying %s: %lld (%d) > %lld\n", pkg_snprintf_s(pkg), *chunk_size,
80 pkg->fsize, maxsize);
81
82 if (*chunk_size > maxsize)
83@@ -281,7 +281,7 @@
84 int chunk_add(struct chunk *chunk, struct pkg *pkg)
85 {
86 int i, rc = 0;
87- int chunk_size = 0;
88+ uint64_t chunk_size = 0;
89 tn_array *stack = NULL;
90
91
92@@ -320,9 +320,46 @@
93 return rc;
94 }
95
96+static
97+int snprintf_size64(char *buf, int bufsize, uint64_t nbytes,
98+ int ndigits, int longunit)
99+{
100+ char unit[3], fmt[32];
101+ double nb;
102+
103+
104+ nb = nbytes;
105+ unit[0] = 'B';
106+ unit[1] = unit[2] = '\0';
107+
108+ if (nb > 1024) {
109+ nb /= 1024.0;
110+
111+ unit[0] = 'K';
112+ unit[1] = 'B';
113+
114+ if (nb > 1024) {
115+ nb /= 1024;
116+ unit[0] = 'M';
117+ }
118+
119+ if (nb > 1024) {
120+ nb /= 1024;
121+ unit[0] = 'G';
122+ }
123+ }
124+
125+ n_snprintf(fmt, sizeof(fmt), "%%.%df%%s", ndigits);
126+ if (!longunit)
127+ unit[1] = '\0';
128+
129+ return n_snprintf(buf, bufsize, fmt, nb, unit);
130+}
131+
132+
133
134 static
135-int make_chunks(tn_array *pkgs, unsigned split_size, unsigned first_free_space,
136+int make_chunks(tn_array *pkgs, uint64_t split_size, uint64_t first_free_space,
137 const char *outprefix)
138 {
139 int i, chunk_no = 0, rc = 1;
140@@ -356,7 +393,7 @@
141 }
142
143 for (i=0; i < n_array_size(chunks); i++) {
144- struct vfile *vf;
145+ FILE *stream;
146 char path[PATH_MAX], strsize[128];
147 struct chunk *chunk;
148 struct pkg *pkg;
149@@ -373,21 +410,21 @@
150 pri_max = pkg->pri;
151
152 snprintf(path, sizeof(path), "%s.%.2d", outprefix, chunk->no);
153- snprintf_size(strsize, sizeof(strsize), chunk->size, 2, 0);
154- msgn(0, _("Writing %s (%4d packages, %s, "
155+ snprintf_size64(strsize, sizeof(strsize), chunk->size, 2, 0);
156+ msgn(0, _("Writing %s (%4d packages, %s (%lldb), "
157 "pri min, max = %d, %d)"),
158- path, chunk->items, strsize, pri_min, pri_max);
159+ path, chunk->items, strsize, chunk->size, pri_min, pri_max);
160
161
162- if ((vf = vfile_open(path, VFT_STDIO, VFM_RW)) == NULL)
163+ if ((stream = fopen(path, "w")) == NULL)
164 return 0;
165
166 #if 0
167- fprintf(vf->vf_stream, "# chunk #%d: %d packages, %d bytes\n",
168+ fprintf(vf->vf_stream, "# chunk #%d: %d packages, %lld bytes\n",
169 i, chunk->items, chunk->size);
170 #endif
171- chunk_dump(chunk, vf->vf_stream);
172- vfile_close(vf);
173+ chunk_dump(chunk, stream);
174+ fclose(stream);
175 }
176
177 l_end:
178@@ -444,12 +481,18 @@
179 }
180
181 static
182-int packages_split(const tn_array *pkgs, unsigned split_size,
183- unsigned first_free_space, const char *outprefix)
184+int packages_split(const tn_array *pkgs, unsigned split_size_mb,
185+ unsigned first_free_space_mb, const char *outprefix)
186 {
187 tn_array *packages = NULL, *ordered_pkgs = NULL;
188 int i, rc = 1;
189+ uint64_t split_size, first_free_space;
190+
191+ split_size = (uint64_t)split_size_mb * 1024L * 1024L;
192+ first_free_space = (uint64_t)first_free_space_mb * 1024L * 1024L;
193
194+ DBGF("%dM (%lld), %dM %lld\n", split_size_mb, split_size,
195+ first_free_space_mb, first_free_space);
196
197 packages = n_array_dup(pkgs, (tn_fn_dup)pkg_link);
198 // pre-sort packages with pkg_cmp_pri_name_evr_rev()
199@@ -482,8 +525,8 @@
200 return rc;
201 }
202
203-int poldek_split(const struct poldek_ctx *ctx, unsigned size,
204- unsigned first_free_space, const char *outprefix)
205+int poldek_split(const struct poldek_ctx *ctx, unsigned size_mb,
206+ unsigned first_free_space_mb, const char *outprefix)
207 {
208 if (outprefix == NULL)
209 outprefix = "packages.chunk";
210@@ -492,6 +535,7 @@
211 logn(LOGERR, "split: %s", _("no available packages found"));
212 return 0;
213 }
214-
215- return packages_split(ctx->ps->pkgs, size, first_free_space, outprefix);
216+
217+ return packages_split(ctx->ps->pkgs, size_mb, first_free_space_mb,
218+ outprefix);
219 }
This page took 0.051751 seconds and 4 git commands to generate.