~ubuntu-branches/ubuntu/raring/reprepro/raring

« back to all changes in this revision

Viewing changes to checkindsc.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernhard R. Link
  • Date: 2011-05-05 16:34:23 UTC
  • mfrom: (21.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110505163423-x49kbdijyoubai4x
Tags: 4.6.0-1
* new release
- general cleanup
- new FilterSrcList
* increase Standards-Version, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
  before the pgp-end-block.(in case someone
56
56
  missed the newline there))
57
57
 
58
 
* check to have source,version,maintainer,
 
58
* check to have source, version, maintainer,
59
59
  standards-version, files. And also look
60
 
  at binary,architecture and build*, as
 
60
  at binary, architecture and build*, as
61
61
  described in policy 5.4
62
62
 
63
63
* Get overwrite information, ecspecially
84
84
        /* things to be set by dsc_read: */
85
85
        struct dsc_headers dsc;
86
86
        /* things that will still be NULL then: */
87
 
        component_t component_atom;
 
87
        component_t component;
88
88
        /* Things that may be calculated by dsc_calclocations: */
89
89
        struct strlist filekeys;
90
90
};
91
91
 
92
92
static void dsc_free(/*@only@*/struct dscpackage *pkg) {
93
 
        if( pkg != NULL ) {
 
93
        if (pkg != NULL) {
94
94
                sources_done(&pkg->dsc);
95
95
                strlist_done(&pkg->filekeys);
96
96
                free(pkg);
103
103
        bool broken;
104
104
 
105
105
 
106
 
        dsc = calloc(1,sizeof(struct dscpackage));
 
106
        dsc = zNEW(struct dscpackage);
 
107
        if (FAILEDTOALLOC(dsc))
 
108
                return RET_ERROR_OOM;
107
109
 
108
110
        r = sources_readdsc(&dsc->dsc, filename, filename, &broken);
109
 
        if( RET_IS_OK(r) && broken && !IGNORING_(brokensignatures,
 
111
        if (RET_IS_OK(r) && broken && !IGNORING(brokensignatures,
110
112
"'%s' contains only broken signatures.\n"
111
113
"This most likely means the file was damaged or edited improperly\n",
112
 
                                filename) )
 
114
                                filename))
113
115
                r = RET_ERROR;
114
 
        if( RET_IS_OK(r) )
 
116
        if (RET_IS_OK(r))
115
117
                r = propersourcename(dsc->dsc.name);
116
 
        if( RET_IS_OK(r) )
 
118
        if (RET_IS_OK(r))
117
119
                r = properversion(dsc->dsc.version);
118
 
        if( RET_IS_OK(r) )
 
120
        if (RET_IS_OK(r))
119
121
                r = properfilenames(&dsc->dsc.files.names);
120
 
        if( RET_WAS_ERROR(r) ) {
 
122
        if (RET_WAS_ERROR(r)) {
121
123
                dsc_free(dsc);
122
124
                return r;
123
125
        }
124
 
        dsc->component_atom = atom_unknown;
 
126
        dsc->component = atom_unknown;
125
127
        *pkg = dsc;
126
128
 
127
129
        return RET_OK;
128
130
}
129
131
 
130
 
retvalue dsc_addprepared(struct database *database, const struct dsc_headers *dsc, component_t component, const struct strlist *filekeys, struct distribution *distribution, struct trackingdata *trackingdata){
 
132
retvalue dsc_addprepared(const struct dsc_headers *dsc, component_t component, const struct strlist *filekeys, struct distribution *distribution, struct trackingdata *trackingdata){
131
133
        retvalue r;
132
134
        struct target *t = distribution_getpart(distribution,
133
135
                        component, architecture_source, pt_dsc);
134
136
 
135
 
        assert( logger_isprepared(distribution->logger) );
 
137
        assert (logger_isprepared(distribution->logger));
136
138
 
137
139
        /* finally put it into the source distribution */
138
 
        r = target_initpackagesdb(t, database, READWRITE);
139
 
        if( !RET_WAS_ERROR(r) ) {
 
140
        r = target_initpackagesdb(t, READWRITE);
 
141
        if (!RET_WAS_ERROR(r)) {
140
142
                retvalue r2;
141
 
                if( interrupted() )
 
143
                if (interrupted())
142
144
                        r = RET_ERROR_INTERRUPTED;
143
145
                else
144
 
                        r = target_addpackage(t, distribution->logger, database,
 
146
                        r = target_addpackage(t, distribution->logger,
145
147
                                        dsc->name, dsc->version,
146
148
                                        dsc->control, filekeys,
147
149
                                        false, trackingdata,
148
150
                                        architecture_source,
149
151
                                        NULL, NULL);
150
152
                r2 = target_closepackagesdb(t);
151
 
                RET_ENDUPDATE(r,r2);
 
153
                RET_ENDUPDATE(r, r2);
152
154
        }
153
155
        RET_UPDATE(distribution->status, r);
154
156
        return r;
159
161
 * If basename, filekey and directory are != NULL, then they are used instead
160
162
 * of being newly calculated.
161
163
 * (And all files are expected to already be in the pool). */
162
 
retvalue dsc_add(struct database *database, component_t forcecomponent, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *dscfilename, int delete, trackingdb tracks){
 
164
retvalue dsc_add(component_t forcecomponent, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *dscfilename, int delete, trackingdb tracks){
163
165
        retvalue r;
164
166
        struct dscpackage *pkg;
165
167
        struct trackingdata trackingdata;
172
174
 
173
175
        /* First make sure this distribution has a source section at all,
174
176
         * for which it has to be listed in the "Architectures:"-field ;-) */
175
 
        if( !atomlist_in(&distribution->architectures, architecture_source) ) {
 
177
        if (!atomlist_in(&distribution->architectures, architecture_source)) {
176
178
                fprintf(stderr,
177
179
"Cannot put a source package into Distribution '%s' not having 'source' in its 'Architectures:'-field!\n",
178
180
                        distribution->codename);
182
184
        }
183
185
 
184
186
        r = dsc_read(&pkg, dscfilename);
185
 
        if( RET_WAS_ERROR(r) ) {
 
187
        if (RET_WAS_ERROR(r)) {
186
188
                return r;
187
189
        }
188
190
 
189
 
        oinfo = override_search(distribution->overrides.dsc,pkg->dsc.name);
190
 
        if( forcesection == NULL ) {
191
 
                forcesection = override_get(oinfo,SECTION_FIELDNAME);
 
191
        oinfo = override_search(distribution->overrides.dsc, pkg->dsc.name);
 
192
        if (forcesection == NULL) {
 
193
                forcesection = override_get(oinfo, SECTION_FIELDNAME);
192
194
        }
193
 
        if( forcepriority == NULL ) {
194
 
                forcepriority = override_get(oinfo,PRIORITY_FIELDNAME);
 
195
        if (forcepriority == NULL) {
 
196
                forcepriority = override_get(oinfo, PRIORITY_FIELDNAME);
195
197
        }
196
198
 
197
 
        if( forcesection != NULL ) {
 
199
        if (forcesection != NULL) {
198
200
                free(pkg->dsc.section);
199
201
                pkg->dsc.section = strdup(forcesection);
200
 
                if( pkg->dsc.section == NULL ) {
 
202
                if (FAILEDTOALLOC(pkg->dsc.section)) {
201
203
                        dsc_free(pkg);
202
204
                        return RET_ERROR_OOM;
203
205
                }
204
206
        }
205
 
        if( forcepriority != NULL ) {
 
207
        if (forcepriority != NULL) {
206
208
                free(pkg->dsc.priority);
207
209
                pkg->dsc.priority = strdup(forcepriority);
208
 
                if( pkg->dsc.priority == NULL ) {
 
210
                if (FAILEDTOALLOC(pkg->dsc.priority)) {
209
211
                        dsc_free(pkg);
210
212
                        return RET_ERROR_OOM;
211
213
                }
212
214
        }
213
215
 
214
216
        r = dirs_getdirectory(dscfilename, &origdirectory);
215
 
        if( RET_WAS_ERROR(r) ) {
 
217
        if (RET_WAS_ERROR(r)) {
216
218
                dsc_free(pkg);
217
219
                return r;
218
220
        }
219
221
 
220
 
        if( pkg->dsc.section == NULL || pkg->dsc.priority == NULL ) {
 
222
        if (pkg->dsc.section == NULL || pkg->dsc.priority == NULL) {
221
223
                struct sourceextraction *extraction;
222
224
 
223
225
                extraction = sourceextraction_init(
224
226
                        (pkg->dsc.section == NULL)?&pkg->dsc.section:NULL,
225
227
                        (pkg->dsc.priority == NULL)?&pkg->dsc.priority:NULL);
226
 
                if( FAILEDTOALLOC(extraction) ) {
 
228
                if (FAILEDTOALLOC(extraction)) {
227
229
                        free(origdirectory);
228
230
                        dsc_free(pkg);
229
231
                        return RET_ERROR_OOM;
230
232
                }
231
 
                for( i = 0 ; i < pkg->dsc.files.names.count ; i ++ )
 
233
                for (i = 0 ; i < pkg->dsc.files.names.count ; i ++)
232
234
                        sourceextraction_setpart(extraction, i,
233
235
                                        pkg->dsc.files.names.values[i]);
234
 
                while( sourceextraction_needs(extraction, &i) ) {
 
236
                while (sourceextraction_needs(extraction, &i)) {
235
237
                        char *fullfilename = calc_dirconcat(origdirectory,
236
238
                                        pkg->dsc.files.names.values[i]);
237
 
                        if( FAILEDTOALLOC(fullfilename) ) {
 
239
                        if (FAILEDTOALLOC(fullfilename)) {
238
240
                                free(origdirectory);
239
241
                                dsc_free(pkg);
240
242
                                return RET_ERROR_OOM;
246
248
                        // TODO: but if forcecomponent is set it might be possible.
247
249
                        r = sourceextraction_analyse(extraction, fullfilename);
248
250
                        free(fullfilename);
249
 
                        if( RET_WAS_ERROR(r) ) {
 
251
                        if (RET_WAS_ERROR(r)) {
250
252
                                free(origdirectory);
251
253
                                dsc_free(pkg);
252
254
                                sourceextraction_abort(extraction);
254
256
                        }
255
257
                }
256
258
                r = sourceextraction_finish(extraction);
257
 
                if( RET_WAS_ERROR(r) ) {
 
259
                if (RET_WAS_ERROR(r)) {
258
260
                        free(origdirectory);
259
261
                        dsc_free(pkg);
260
262
                        return r;
261
263
                }
262
264
        }
263
265
 
264
 
        if( pkg->dsc.section == NULL && pkg->dsc.priority == NULL ) {
265
 
                fprintf(stderr, "No section and no priority for '%s', skipping.\n",
266
 
                                pkg->dsc.name);
267
 
                free(origdirectory);
268
 
                dsc_free(pkg);
269
 
                return RET_ERROR;
270
 
        }
271
 
        if( pkg->dsc.section == NULL ) {
272
 
                fprintf(stderr, "No section for '%s', skipping.\n", pkg->dsc.name);
273
 
                free(origdirectory);
274
 
                dsc_free(pkg);
275
 
                return RET_ERROR;
276
 
        }
277
 
        if( pkg->dsc.priority == NULL ) {
278
 
                fprintf(stderr, "No priority for '%s', skipping.\n", pkg->dsc.name);
279
 
                free(origdirectory);
280
 
                dsc_free(pkg);
281
 
                return RET_ERROR;
282
 
        }
283
 
        if( !atom_defined(forcecomponent) ) {
 
266
        if (pkg->dsc.section == NULL && pkg->dsc.priority == NULL) {
 
267
                fprintf(stderr,
 
268
"No section and no priority for '%s', skipping.\n",
 
269
                                pkg->dsc.name);
 
270
                free(origdirectory);
 
271
                dsc_free(pkg);
 
272
                return RET_ERROR;
 
273
        }
 
274
        if (pkg->dsc.section == NULL) {
 
275
                fprintf(stderr, "No section for '%s', skipping.\n",
 
276
                                pkg->dsc.name);
 
277
                free(origdirectory);
 
278
                dsc_free(pkg);
 
279
                return RET_ERROR;
 
280
        }
 
281
        if (pkg->dsc.priority == NULL) {
 
282
                fprintf(stderr, "No priority for '%s', skipping.\n",
 
283
                                pkg->dsc.name);
 
284
                free(origdirectory);
 
285
                dsc_free(pkg);
 
286
                return RET_ERROR;
 
287
        }
 
288
        if (!atom_defined(forcecomponent)) {
284
289
                const char *fc;
285
290
 
286
291
                fc = override_get(oinfo, "$Component");
287
 
                if( fc != NULL ) {
 
292
                if (fc != NULL) {
288
293
                        forcecomponent = component_find(fc);
289
 
                        if( !atom_defined(forcecomponent) ) {
 
294
                        if (!atom_defined(forcecomponent)) {
290
295
                                fprintf(stderr,
291
296
"Unparseable component '%s' in $Component override of '%s'\n",
292
297
                                        fc, pkg->dsc.name);
299
304
 
300
305
        r = guess_component(distribution->codename, &distribution->components,
301
306
                        pkg->dsc.name, pkg->dsc.section, forcecomponent,
302
 
                        &pkg->component_atom);
303
 
        if( RET_WAS_ERROR(r) ) {
 
307
                        &pkg->component);
 
308
        if (RET_WAS_ERROR(r)) {
304
309
                free(origdirectory);
305
310
                dsc_free(pkg);
306
311
                return r;
307
312
        }
308
 
        if( verbose > 0 && !atom_defined(forcecomponent) ) {
 
313
        if (verbose > 0 && !atom_defined(forcecomponent)) {
309
314
                fprintf(stderr, "%s: component guessed as '%s'\n", dscfilename,
310
 
                                atoms_components[pkg->component_atom]);
 
315
                                atoms_components[pkg->component]);
311
316
        }
312
317
 
313
318
        {       char *dscbasename, *dscfilekey;
314
319
                struct checksums *dscchecksums;
315
320
 
316
321
                dscbasename = calc_source_basename(pkg->dsc.name, pkg->dsc.version);
317
 
                destdirectory = calc_sourcedir(pkg->component_atom, pkg->dsc.name);
 
322
                destdirectory = calc_sourcedir(pkg->component, pkg->dsc.name);
318
323
                /* Calculate the filekeys: */
319
 
                if( destdirectory != NULL )
 
324
                if (destdirectory != NULL)
320
325
                        r = calc_dirconcats(destdirectory,
321
326
                                        &pkg->dsc.files.names,
322
327
                                        &pkg->filekeys);
323
 
                if( dscbasename == NULL || destdirectory == NULL || RET_WAS_ERROR(r) ) {
 
328
                if (dscbasename == NULL || destdirectory == NULL || RET_WAS_ERROR(r)) {
324
329
                        free(dscbasename);
325
330
                        free(destdirectory); free(origdirectory);
326
331
                        dsc_free(pkg);
328
333
                }
329
334
                dscfilekey = calc_dirconcat(destdirectory, dscbasename);
330
335
                dscchecksums = NULL;
331
 
                if( dscfilename == NULL )
 
336
                if (FAILEDTOALLOC(dscfilename))
332
337
                        r = RET_ERROR_OOM;
333
338
                else
334
339
                        /* then look if we already have this, or copy it in */
335
 
                        r = files_preinclude(database,
 
340
                        r = files_preinclude(
336
341
                                        dscfilename, dscfilekey,
337
342
                                        &dscchecksums);
338
343
 
339
 
                if( !RET_WAS_ERROR(r) ) {
340
 
                        /* Add the dsc-file to basenames,filekeys and md5sums,
 
344
                if (!RET_WAS_ERROR(r)) {
 
345
                        /* Add the dsc-file to basenames, filekeys and md5sums,
341
346
                         * so that it will be listed in the Sources.gz */
342
347
 
343
348
                        r = checksumsarray_include(&pkg->dsc.files,
344
349
                                        dscbasename, dscchecksums);
345
 
                        if( RET_IS_OK(r) )
 
350
                        if (RET_IS_OK(r))
346
351
                                r = strlist_include(&pkg->filekeys, dscfilekey);
347
352
                        else
348
353
                                free(dscfilekey);
353
358
                checksums_free(dscchecksums);
354
359
        }
355
360
 
356
 
        assert( pkg->dsc.files.names.count == pkg->filekeys.count );
357
 
        for( i = 1 ; i < pkg->dsc.files.names.count ; i ++ ) {
358
 
                if( !RET_WAS_ERROR(r) ) {
359
 
                        r = files_checkincludefile(database, origdirectory,
 
361
        assert (pkg->dsc.files.names.count == pkg->filekeys.count);
 
362
        for (i = 1 ; i < pkg->dsc.files.names.count ; i ++) {
 
363
                if (!RET_WAS_ERROR(r)) {
 
364
                        r = files_checkincludefile(origdirectory,
360
365
                                        pkg->dsc.files.names.values[i],
361
366
                                        pkg->filekeys.values[i],
362
367
                                        &pkg->dsc.files.checksums[i]);
365
370
 
366
371
        /* Calculate the chunk to include: */
367
372
 
368
 
        if( !RET_WAS_ERROR(r) )
 
373
        if (!RET_WAS_ERROR(r))
369
374
                r = sources_complete(&pkg->dsc, destdirectory, oinfo,
370
375
                                pkg->dsc.section, pkg->dsc.priority, &control);
371
376
        free(destdirectory);
372
 
        if( RET_IS_OK(r) ) {
 
377
        if (RET_IS_OK(r)) {
373
378
                free(pkg->dsc.control);
374
379
                pkg->dsc.control = control;
375
380
        } else {
378
383
                return r;
379
384
        }
380
385
 
381
 
        if( interrupted() ) {
 
386
        if (interrupted()) {
382
387
                dsc_free(pkg);
383
388
                free(origdirectory);
384
389
                return RET_ERROR_INTERRUPTED;
385
390
        }
386
391
 
387
 
        if( tracks != NULL ) {
388
 
                r = trackingdata_summon(tracks,pkg->dsc.name,pkg->dsc.version,&trackingdata);
389
 
                if( RET_WAS_ERROR(r) ) {
 
392
        if (tracks != NULL) {
 
393
                r = trackingdata_summon(tracks, pkg->dsc.name,
 
394
                                pkg->dsc.version, &trackingdata);
 
395
                if (RET_WAS_ERROR(r)) {
390
396
                        free(origdirectory);
391
397
                        dsc_free(pkg);
392
398
                        return r;
393
399
                }
394
400
        }
395
401
 
396
 
        r = dsc_addprepared(database, &pkg->dsc, pkg->component_atom,
 
402
        r = dsc_addprepared(&pkg->dsc, pkg->component,
397
403
                        &pkg->filekeys, distribution,
398
404
                        (tracks!=NULL)?&trackingdata:NULL);
399
405
 
400
406
        /* delete source files, if they are to be */
401
 
        if( ( RET_IS_OK(r) && delete >= D_MOVE ) ||
402
 
                        ( r == RET_NOTHING && delete >= D_DELETE ) ) {
 
407
        if ((RET_IS_OK(r) && delete >= D_MOVE) ||
 
408
                        (r == RET_NOTHING && delete >= D_DELETE)) {
403
409
                char *fullfilename;
404
410
 
405
 
                for( i = 0 ; i < pkg->dsc.files.names.count ; i++ ) {
 
411
                for (i = 0 ; i < pkg->dsc.files.names.count ; i++) {
406
412
                        fullfilename = calc_dirconcat(origdirectory,
407
413
                                        pkg->dsc.files.names.values[i]);
408
 
                        if( fullfilename == NULL ) {
 
414
                        if (FAILEDTOALLOC(fullfilename)) {
409
415
                                r = RET_ERROR_OOM;
410
416
                                break;
411
417
                        }
412
 
                        if( isregularfile(fullfilename) )
 
418
                        if (isregularfile(fullfilename))
413
419
                                deletefile(fullfilename);
414
420
                        free(fullfilename);
415
421
                }
417
423
        free(origdirectory);
418
424
        dsc_free(pkg);
419
425
 
420
 
        if( tracks != NULL ) {
 
426
        if (tracks != NULL) {
421
427
                retvalue r2;
422
 
                r2 = trackingdata_finish(tracks, &trackingdata, database);
423
 
                RET_ENDUPDATE(r,r2);
 
428
                r2 = trackingdata_finish(tracks, &trackingdata);
 
429
                RET_ENDUPDATE(r, r2);
424
430
        }
425
431
        return r;
426
432
}