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.
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.
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
32
#include "distribution.h"
36
#include "configparser.h"
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};
43
static const struct constant contentsflags[] = {
48
{"nodebs", cf_nodebs},
51
{".", cf_uncompressed},
56
distribution->contents.flags.enabled = true;
58
memset(flags, 0, sizeof(flags));
59
r = config_getflags(iter, "Contents", contentsflags, flags,
60
IGNORABLE(unknownfield), "");
61
if( r == RET_ERROR_UNKNOWNFIELD )
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) )
67
if( flags[cf_dummy] ) {
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] ) {
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;
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;
90
distribution->contents.compressions = 0;
91
if( flags[cf_uncompressed] )
92
distribution->contents.compressions |= IC_FLAG(ic_uncompressed);
94
distribution->contents.compressions |= IC_FLAG(ic_gzip);
97
distribution->contents.compressions |= IC_FLAG(ic_bzip2);
99
distribution->contents.flags.udebs = flags[cf_udebs];
100
distribution->contents.flags.nodebs = flags[cf_nodebs];
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;
108
char *section, *filekey;
110
r = chunk_getvalue(chunk,"Section",§ion);
111
/* Ignoring packages without section, as they should not exist anyway */
114
r = chunk_getvalue(chunk,"Filename",&filekey);
115
/* dito with filekey */
116
if( !RET_IS_OK(r) ) {
120
r = filelist_addpackage(contents, database,
121
packagename, section, filekey);
128
static retvalue genarchcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) {
130
char *contentsfilename;
131
struct filetorelease *file;
132
struct filelist_list *contents;
133
const struct atomlist *components;
135
if( distribution->contents_components_set )
136
components = &distribution->contents_components;
138
components = &distribution->components;
140
if( components->count == 0 )
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) )
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,
164
if( !RET_IS_OK(r) ) {
165
free(contentsfilename);
169
printf(" generating %s...\n",contentsfilename);
171
free(contentsfilename);
173
r = filelist_init(&contents);
174
if( RET_WAS_ERROR(r) ) {
175
release_abortfile(file);
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);
186
r = release_finishfile(release,file);
187
filelist_free(contents);
191
static retvalue genarchudebcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) {
193
char *contentsfilename;
194
struct filetorelease *file;
195
struct filelist_list *contents;
196
const struct atomlist *components;
198
if( distribution->contents_ucomponents_set )
199
components = &distribution->contents_ucomponents;
201
components = &distribution->udebcomponents;
203
if( components->count == 0 )
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) )
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,
227
if( !RET_IS_OK(r) ) {
228
free(contentsfilename);
232
printf(" generating %s...\n",contentsfilename);
234
free(contentsfilename);
235
r = filelist_init(&contents);
236
if( RET_WAS_ERROR(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);
246
r = release_finishfile(release,file);
247
filelist_free(contents);
251
retvalue contents_generate(struct database *database, struct distribution *distribution, struct release *release, bool onlyneeded) {
254
const struct atomlist *architectures;
256
if( distribution->contents.compressions == 0 )
257
distribution->contents.compressions = IC_FLAG(ic_gzip);
259
result = RET_NOTHING;
260
if( distribution->contents_architectures_set ) {
261
architectures = &distribution->contents_architectures;
263
architectures = &distribution->architectures;
265
for( i = 0 ; i < architectures->count ; i++ ) {
266
architecture_t architecture = architectures->atoms[i];
268
if( architecture == architecture_source )
271
if( !distribution->contents.flags.nodebs ) {
272
r = genarchcontents(database, distribution,
273
architecture, release, onlyneeded);
274
RET_UPDATE(result,r);
276
if( distribution->contents.flags.udebs ) {
277
r = genarchudebcontents(database, distribution,
278
architecture, release, onlyneeded);
279
RET_UPDATE(result,r);