1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
/* This file is part of "reprepro"
* Copyright (C) 2003,2004,2005,2006,2007,2009 Bernhard R. Link
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include <config.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#include "error.h"
#include "ignore.h"
#include "filecntl.h"
#include "strlist.h"
#include "checksums.h"
#include "names.h"
#include "checkindeb.h"
#include "reference.h"
#include "binaries.h"
#include "files.h"
#include "guesscomponent.h"
#include "tracking.h"
#include "override.h"
#include "log.h"
/* This file includes the code to include binaries, i.e.
to create the chunk for the Packages.gz-file and
to put it in the various databases.
Things to do with .deb's checkin by hand: (by comparison with apt-ftparchive)
- extract the control file (that's the hard part -> extractcontrol.c )
- check for Package, Version, Architecture, Maintainer, Description
- apply overwrite if neccesary (section,priority and perhaps maintainer).
- add Size, MD5sum, Filename, Priority, Section
- remove Status (warning if existant?)
- check for Optional-field and reject then..
*/
struct debpackage {
/* things to be set by deb_read: */
struct deb_headers deb;
/* things that will still be NULL then: */
component_t component_atom;
/* with deb_calclocations: */
const char *filekey;
struct strlist filekeys;
};
void deb_free(/*@only@*/struct debpackage *pkg) {
if( pkg != NULL ) {
binaries_debdone(&pkg->deb);
if( pkg->filekey != NULL )
strlist_done(&pkg->filekeys);
}
free(pkg);
}
/* read the data from a .deb, make some checks and extract some data */
static retvalue deb_read(/*@out@*/struct debpackage **pkg, const char *filename, bool needssourceversion) {
retvalue r;
struct debpackage *deb;
deb = calloc(1,sizeof(struct debpackage));
r = binaries_readdeb(&deb->deb, filename, needssourceversion);
if( RET_IS_OK(r) )
r = properpackagename(deb->deb.name);
if( RET_IS_OK(r) )
r = propersourcename(deb->deb.source);
if( RET_IS_OK(r) && needssourceversion )
r = properversion(deb->deb.sourceversion);
if( RET_IS_OK(r) )
r = properversion(deb->deb.version);
if( RET_WAS_ERROR(r) ) {
deb_free(deb);
return r;
}
*pkg = deb;
return RET_OK;
}
static retvalue deb_preparelocation(struct debpackage *pkg, component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, packagetype_t packagetype, struct distribution *distribution, const struct overridedata **oinfo_ptr, const char *debfilename){
const struct atomlist *components;
const struct overridefile *binoverride;
const struct overridedata *oinfo;
retvalue r;
if( packagetype == pt_udeb ) {
binoverride = distribution->overrides.udeb;
components = &distribution->udebcomponents;
} else {
binoverride = distribution->overrides.deb;
components = &distribution->components;
}
oinfo = override_search(binoverride,pkg->deb.name);
*oinfo_ptr = oinfo;
if( forcesection == NULL ) {
forcesection = override_get(oinfo,SECTION_FIELDNAME);
}
if( forcepriority == NULL ) {
forcepriority = override_get(oinfo,PRIORITY_FIELDNAME);
}
if( !atom_defined(forcecomponent) ) {
const char *fc;
fc = override_get(oinfo, "$Component");
if( fc != NULL ) {
forcecomponent = component_find(fc);
if( !atom_defined(forcecomponent) ) {
fprintf(stderr,
"Unparseable component '%s' in $Component override of '%s'\n",
fc, pkg->deb.name);
return RET_ERROR;
}
}
}
if( forcesection != NULL ) {
free(pkg->deb.section);
pkg->deb.section = strdup(forcesection);
if( pkg->deb.section == NULL ) {
return RET_ERROR_OOM;
}
}
if( forcepriority != NULL ) {
free(pkg->deb.priority);
pkg->deb.priority = strdup(forcepriority);
if( pkg->deb.priority == NULL ) {
return RET_ERROR_OOM;
}
}
if( pkg->deb.section == NULL ) {
fprintf(stderr, "No section given for '%s', skipping.\n",
pkg->deb.name);
return RET_ERROR;
}
if( pkg->deb.priority == NULL ) {
fprintf(stderr, "No priority given for '%s', skipping.\n",
pkg->deb.name);
return RET_ERROR;
}
/* decide where it has to go */
r = guess_component(distribution->codename, components,
pkg->deb.name, pkg->deb.section,
forcecomponent, &pkg->component_atom);
if( RET_WAS_ERROR(r) )
return r;
if( verbose > 0 && !atom_defined(forcecomponent) ) {
fprintf(stderr, "%s: component guessed as '%s'\n", debfilename,
atoms_components[pkg->component_atom]);
}
/* some sanity checks: */
if( forcearchitectures != NULL &&
pkg->deb.architecture_atom != architecture_all &&
!atomlist_in(forcearchitectures,
pkg->deb.architecture_atom) ) {
fprintf(stderr, "Cannot add '%s', as it is architecture '%s' and you specified to only include ",
debfilename,
atoms_architectures[pkg->deb.architecture_atom]);
atomlist_fprint(stderr, at_architecture, forcearchitectures);
fputs(".\n", stderr);
return RET_ERROR;
} else if( pkg->deb.architecture_atom != architecture_all &&
!atomlist_in(&distribution->architectures,
pkg->deb.architecture_atom)) {
(void)fprintf(stderr,
"Error looking at '%s': '%s' is not one of the valid architectures: '",
debfilename,
atoms_architectures[pkg->deb.architecture_atom]);
(void)atomlist_fprint(stderr, at_architecture,
&distribution->architectures);
(void)fputs("'\n",stderr);
return RET_ERROR;
}
if( !atomlist_in(components, pkg->component_atom) ) {
fprintf(stderr,
"Error looking at %s': Would be placed in unavailable component '%s'!\n",
debfilename,
atoms_components[pkg->component_atom]);
/* this cannot be ignored as there is not data structure available*/
return RET_ERROR;
}
r = binaries_calcfilekeys(pkg->component_atom, &pkg->deb,
packagetype, &pkg->filekeys);
if( RET_WAS_ERROR(r) )
return r;
pkg->filekey = pkg->filekeys.values[0];
return RET_OK;
}
retvalue deb_prepare(/*@out@*/struct debpackage **deb, component_t forcecomponent, architecture_t forcearchitecture, const char *forcesection, const char *forcepriority, packagetype_t packagetype, struct distribution *distribution, const char *debfilename, const char * const givenfilekey, const struct checksums * checksums, const struct strlist *allowed_binaries, const char *expectedsourcepackage, const char *expectedsourceversion){
retvalue r;
struct debpackage *pkg;
const struct overridedata *oinfo;
char *control;
struct atomlist forcearchitectures;
assert( givenfilekey != NULL );
assert( checksums != NULL );
assert( allowed_binaries != NULL );
assert( expectedsourcepackage != NULL );
assert( expectedsourceversion != NULL );
/* First taking a closer look in the file: */
r = deb_read(&pkg,debfilename, true);
if( RET_WAS_ERROR(r) ) {
return r;
}
if( !strlist_in(allowed_binaries, pkg->deb.name) &&
!IGNORING_(surprisingbinary,
"'%s' has packagename '%s' not listed in the .changes file!\n",
debfilename, pkg->deb.name)) {
deb_free(pkg);
return RET_ERROR;
}
if( strcmp(pkg->deb.source, expectedsourcepackage) != 0 ) {
/* this cannot be ignored easily, as it determines
* the directory this file is stored into */
fprintf(stderr,
"'%s' lists source package '%s', but .changes says it is '%s'!\n",
debfilename, pkg->deb.source,
expectedsourcepackage);
deb_free(pkg);
return RET_ERROR;
}
if( strcmp(pkg->deb.sourceversion, expectedsourceversion) != 0 &&
!IGNORING_(wrongsourceversion,
"'%s' lists source version '%s', but .changes says it is '%s'!\n",
debfilename, pkg->deb.sourceversion,
expectedsourceversion)) {
deb_free(pkg);
return RET_ERROR;
}
forcearchitectures.count = 1;
forcearchitectures.size = 1;
forcearchitectures.atoms = &forcearchitecture;
r = deb_preparelocation(pkg, forcecomponent, &forcearchitectures, forcesection, forcepriority, packagetype, distribution, &oinfo, debfilename);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
if( strcmp(givenfilekey,pkg->filekey) != 0 ) {
fprintf(stderr,
"Name mismatch: .changes indicates '%s', but the file itself says '%s'!\n",
givenfilekey, pkg->filekey);
deb_free(pkg);
return RET_ERROR;
}
/* Prepare everything that can be prepared beforehand */
r = binaries_complete(&pkg->deb, pkg->filekey, checksums, oinfo,
pkg->deb.section, pkg->deb.priority, &control);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
free(pkg->deb.control); pkg->deb.control = control;
*deb = pkg;
return RET_OK;
}
retvalue deb_addprepared(const struct debpackage *pkg, struct database *database, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata) {
return binaries_adddeb(&pkg->deb, database, forcearchitectures,
packagetype, distribution, trackingdata,
pkg->component_atom, &pkg->filekeys,
pkg->deb.control);
}
/* insert the given .deb into the mirror in <component> in the <distribution>
* putting things with architecture of "all" into <d->architectures> (and also
* causing error, if it is not one of them otherwise)
* if component is NULL, guessing it from the section. */
retvalue deb_add(struct database *database, component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, packagetype_t packagetype, struct distribution *distribution, const char *debfilename, int delete, /*@null@*/trackingdb tracks) {
struct debpackage *pkg;
retvalue r;
struct trackingdata trackingdata;
const struct overridedata *oinfo;
char *control;
struct checksums *checksums;
causingfile = debfilename;
r = deb_read(&pkg, debfilename, tracks != NULL );
if( RET_WAS_ERROR(r) ) {
return r;
}
r = deb_preparelocation(pkg, forcecomponent, forcearchitectures, forcesection, forcepriority, packagetype, distribution, &oinfo, debfilename);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
r = files_preinclude(database, debfilename, pkg->filekey, &checksums);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
/* Prepare everything that can be prepared beforehand */
r = binaries_complete(&pkg->deb, pkg->filekey, checksums, oinfo,
pkg->deb.section, pkg->deb.priority, &control);
checksums_free(checksums);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
free(pkg->deb.control); pkg->deb.control = control;
if( tracks != NULL ) {
assert(pkg->deb.sourceversion != NULL);
r = trackingdata_summon(tracks,
pkg->deb.source, pkg->deb.sourceversion,
&trackingdata);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
}
r = binaries_adddeb(&pkg->deb, database, forcearchitectures,
packagetype, distribution,
(tracks!=NULL)?&trackingdata:NULL,
pkg->component_atom, &pkg->filekeys,
pkg->deb.control);
RET_UPDATE(distribution->status, r);
deb_free(pkg);
if( tracks != NULL ) {
retvalue r2;
r2 = trackingdata_finish(tracks, &trackingdata, database);
RET_ENDUPDATE(r,r2);
}
if( RET_IS_OK(r) && delete >= D_MOVE ) {
deletefile(debfilename);
} else if( r == RET_NOTHING && delete >= D_DELETE )
deletefile(debfilename);
return r;
}
|