~udienz/reprepro/reprepro.head

« back to all changes in this revision

Viewing changes to contents.c

  • Committer: Mahyuddin Susanto
  • Date: 2010-12-01 21:08:07 UTC
  • Revision ID: udienz@gmail.com-20101201210807-b9bgweyvsis408u2
- Remove all file/directory exept debian/
+ Adding get-orig-source at debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is part of "reprepro"
2
 
 *  Copyright (C) 2006,2007 Bernhard R. Link
3
 
 *  This program is free software; you can redistribute it and/or modify
4
 
 *  it under the terms of the GNU General Public License version 2 as
5
 
 *  published by the Free Software Foundation.
6
 
 *
7
 
 *  This program is distributed in the hope that it will be useful,
8
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
 *  GNU General Public License for more details.
11
 
 *
12
 
 *  You should have received a copy of the GNU General Public License
13
 
 *  along with this program; if not, write to the Free Software
14
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1301  USA
15
 
 */
16
 
#include <config.h>
17
 
 
18
 
#include <errno.h>
19
 
#include <limits.h>
20
 
#include <assert.h>
21
 
#include <stdio.h>
22
 
#include <stdlib.h>
23
 
#include <malloc.h>
24
 
#include <string.h>
25
 
#include <ctype.h>
26
 
#include "error.h"
27
 
#include "mprintf.h"
28
 
#include "chunks.h"
29
 
#include "dirs.h"
30
 
#include "names.h"
31
 
#include "release.h"
32
 
#include "distribution.h"
33
 
#include "filelist.h"
34
 
#include "files.h"
35
 
#include "ignore.h"
36
 
#include "configparser.h"
37
 
 
38
 
/* options are zerroed when called, when error is returned contentsopions_done
39
 
 * is called by the caller */
40
 
retvalue contentsoptions_parse(struct distribution *distribution, struct configiterator *iter) {
41
 
        enum contentsflags { cf_disable, cf_dummy, cf_udebs, cf_nodebs, cf_uncompressed, cf_gz, cf_bz2, cf_COUNT};
42
 
        bool flags[cf_COUNT];
43
 
        static const struct constant contentsflags[] = {
44
 
                {"0", cf_disable},
45
 
                {"1", cf_dummy},
46
 
                {"2", cf_dummy},
47
 
                {"udebs", cf_udebs},
48
 
                {"nodebs", cf_nodebs},
49
 
                {".bz2", cf_bz2},
50
 
                {".gz", cf_gz},
51
 
                {".", cf_uncompressed},
52
 
                {NULL,  -1}
53
 
        };
54
 
        retvalue r;
55
 
 
56
 
        distribution->contents.flags.enabled = true;
57
 
 
58
 
        memset(flags, 0, sizeof(flags));
59
 
        r = config_getflags(iter, "Contents", contentsflags, flags,
60
 
                        IGNORABLE(unknownfield), "");
61
 
        if( r == RET_ERROR_UNKNOWNFIELD )
62
 
                (void)fputs(
63
 
"Note that the format of the Contents field has changed with reprepro 3.0.0.\n"
64
 
"There is no longer a number needed (nor possible) there.\n", stderr);
65
 
        if( RET_WAS_ERROR(r) )
66
 
                return r;
67
 
        if( flags[cf_dummy] ) {
68
 
                (void)fputs(
69
 
"Warning: Contents headers in conf/distribution no longer need an\n"
70
 
"rate argument. Ignoring the number there, this might cause a error\n"
71
 
"future versions.\n", stderr);
72
 
        } else if( flags[cf_disable] ) {
73
 
                (void)fputs(
74
 
"Warning: Contents headers in conf/distribution no longer need an\n"
75
 
"rate argument. Treating the '0' as sign to not activate Contents-\n"
76
 
"-generation, but it will cause an error in future version.\n", stderr);
77
 
                distribution->contents.flags.enabled = false;
78
 
        }
79
 
 
80
 
#ifndef HAVE_LIBBZ2
81
 
        if( flags[cf_bz2] ) {
82
 
                fprintf(stderr,
83
 
"Warning: Ignoring request to generate .bz2'ed Contents files.\n"
84
 
"(bzip2 support disabled at build time.)\n"
85
 
"Request was in %s in the Contents header ending in line %u\n",
86
 
                        config_filename(iter), config_line(iter));
87
 
                flags[cf_bz2] = false;
88
 
        }
89
 
#endif
90
 
        distribution->contents.compressions = 0;
91
 
        if( flags[cf_uncompressed] )
92
 
                distribution->contents.compressions |= IC_FLAG(ic_uncompressed);
93
 
        if( flags[cf_gz] )
94
 
                distribution->contents.compressions |= IC_FLAG(ic_gzip);
95
 
#ifdef HAVE_LIBBZ2
96
 
        if( flags[cf_bz2] )
97
 
                distribution->contents.compressions |= IC_FLAG(ic_bzip2);
98
 
#endif
99
 
        distribution->contents.flags.udebs = flags[cf_udebs];
100
 
        distribution->contents.flags.nodebs = flags[cf_nodebs];
101
 
 
102
 
        return RET_OK;
103
 
}
104
 
 
105
 
static retvalue addpackagetocontents(struct database *database, UNUSED(struct distribution *di), UNUSED(struct target *ta), const char *packagename, const char *chunk, void *data) {
106
 
        struct filelist_list *contents = data;
107
 
        retvalue r;
108
 
        char *section, *filekey;
109
 
 
110
 
        r = chunk_getvalue(chunk,"Section",&section);
111
 
        /* Ignoring packages without section, as they should not exist anyway */
112
 
        if( !RET_IS_OK(r) )
113
 
                return r;
114
 
        r = chunk_getvalue(chunk,"Filename",&filekey);
115
 
        /* dito with filekey */
116
 
        if( !RET_IS_OK(r) ) {
117
 
                free(section);
118
 
                return r;
119
 
        }
120
 
        r = filelist_addpackage(contents, database,
121
 
                        packagename, section, filekey);
122
 
 
123
 
        free(filekey);
124
 
        free(section);
125
 
        return r;
126
 
}
127
 
 
128
 
static retvalue genarchcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) {
129
 
        retvalue r;
130
 
        char *contentsfilename;
131
 
        struct filetorelease *file;
132
 
        struct filelist_list *contents;
133
 
        const struct atomlist *components;
134
 
 
135
 
        if( distribution->contents_components_set )
136
 
                components = &distribution->contents_components;
137
 
        else
138
 
                components = &distribution->components;
139
 
 
140
 
        if( components->count == 0 )
141
 
                return RET_NOTHING;
142
 
 
143
 
        if( onlyneeded ) {
144
 
                struct target *target;
145
 
                for( target=distribution->targets; target!=NULL;
146
 
                                target=target->next ) {
147
 
                        if( target->saved_wasmodified
148
 
                                && target->architecture_atom == architecture
149
 
                                && target->packagetype_atom == pt_deb
150
 
                                && atomlist_in(components,
151
 
                                        target->component_atom) )
152
 
                                break;
153
 
                }
154
 
                if( target != NULL )
155
 
                        onlyneeded = false;
156
 
        }
157
 
 
158
 
        contentsfilename = mprintf("Contents-%s", atoms_architectures[architecture]);
159
 
        if( FAILEDTOALLOC(contentsfilename) )
160
 
                return RET_ERROR_OOM;
161
 
        r = release_startfile(release, contentsfilename,
162
 
                        distribution->contents.compressions,
163
 
                        onlyneeded, &file);
164
 
        if( !RET_IS_OK(r) ) {
165
 
                free(contentsfilename);
166
 
                return r;
167
 
        }
168
 
        if( verbose > 0 ) {
169
 
                printf(" generating %s...\n",contentsfilename);
170
 
        }
171
 
        free(contentsfilename);
172
 
 
173
 
        r = filelist_init(&contents);
174
 
        if( RET_WAS_ERROR(r) ) {
175
 
                release_abortfile(file);
176
 
                return r;
177
 
        }
178
 
        r = distribution_foreach_package_c(distribution, database,
179
 
                        components, architecture, pt_deb,
180
 
                        addpackagetocontents, contents);
181
 
        if( !RET_WAS_ERROR(r) )
182
 
                r = filelist_write(contents, file);
183
 
        if( RET_WAS_ERROR(r) )
184
 
                release_abortfile(file);
185
 
        else
186
 
                r = release_finishfile(release,file);
187
 
        filelist_free(contents);
188
 
        return r;
189
 
}
190
 
 
191
 
static retvalue genarchudebcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) {
192
 
        retvalue r;
193
 
        char *contentsfilename;
194
 
        struct filetorelease *file;
195
 
        struct filelist_list *contents;
196
 
        const struct atomlist *components;
197
 
 
198
 
        if( distribution->contents_ucomponents_set )
199
 
                components = &distribution->contents_ucomponents;
200
 
        else
201
 
                components = &distribution->udebcomponents;
202
 
 
203
 
        if( components->count == 0 )
204
 
                return RET_NOTHING;
205
 
 
206
 
        if( onlyneeded ) {
207
 
                struct target *target;
208
 
                for( target=distribution->targets; target!=NULL;
209
 
                                target=target->next ) {
210
 
                        if( target->saved_wasmodified
211
 
                                && target->architecture_atom == architecture
212
 
                                && target->packagetype_atom == pt_udeb
213
 
                                && atomlist_in(components,
214
 
                                        target->component_atom) )
215
 
                                break;
216
 
                }
217
 
                if( target != NULL )
218
 
                        onlyneeded = false;
219
 
        }
220
 
 
221
 
        contentsfilename = mprintf("uContents-%s", atoms_architectures[architecture]);
222
 
        if( FAILEDTOALLOC(contentsfilename) )
223
 
                return RET_ERROR_OOM;
224
 
        r = release_startfile(release, contentsfilename,
225
 
                        distribution->contents.compressions,
226
 
                        onlyneeded, &file);
227
 
        if( !RET_IS_OK(r) ) {
228
 
                free(contentsfilename);
229
 
                return r;
230
 
        }
231
 
        if( verbose > 0 ) {
232
 
                printf(" generating %s...\n",contentsfilename);
233
 
        }
234
 
        free(contentsfilename);
235
 
        r = filelist_init(&contents);
236
 
        if( RET_WAS_ERROR(r) )
237
 
                return r;
238
 
        r = distribution_foreach_package_c(distribution, database,
239
 
                        components, architecture, pt_udeb,
240
 
                        addpackagetocontents, contents);
241
 
        if( !RET_WAS_ERROR(r) )
242
 
                r = filelist_write(contents, file);
243
 
        if( RET_WAS_ERROR(r) )
244
 
                release_abortfile(file);
245
 
        else
246
 
                r = release_finishfile(release,file);
247
 
        filelist_free(contents);
248
 
        return r;
249
 
}
250
 
 
251
 
retvalue contents_generate(struct database *database, struct distribution *distribution, struct release *release, bool onlyneeded) {
252
 
        retvalue result,r;
253
 
        int i;
254
 
        const struct atomlist *architectures;
255
 
 
256
 
        if( distribution->contents.compressions == 0 )
257
 
                distribution->contents.compressions = IC_FLAG(ic_gzip);
258
 
 
259
 
        result = RET_NOTHING;
260
 
        if( distribution->contents_architectures_set ) {
261
 
                architectures = &distribution->contents_architectures;
262
 
        } else {
263
 
                architectures = &distribution->architectures;
264
 
        }
265
 
        for( i = 0 ; i < architectures->count ; i++ ) {
266
 
                architecture_t architecture = architectures->atoms[i];
267
 
 
268
 
                if( architecture == architecture_source )
269
 
                        continue;
270
 
 
271
 
                if( !distribution->contents.flags.nodebs ) {
272
 
                        r = genarchcontents(database, distribution,
273
 
                                        architecture, release, onlyneeded);
274
 
                        RET_UPDATE(result,r);
275
 
                }
276
 
                if( distribution->contents.flags.udebs ) {
277
 
                        r = genarchudebcontents(database, distribution,
278
 
                                        architecture, release, onlyneeded);
279
 
                        RET_UPDATE(result,r);
280
 
                }
281
 
        }
282
 
        return result;
283
 
}