Commit 35fee174 authored by Bernhard Link's avatar Bernhard Link

add all missing Checksums-* when importing from remote repositories

parent 9cbbd9db
2010-02-16
2010-02-21
* support reading of Release files without MD5Sum
* add all missing Checksums-* when importing from
remote repositories
2010-02-16
* make 'sourcemissing', 'unusedsources' and 'reportcruft' work on
......
......@@ -587,6 +587,36 @@ retvalue binaries_complete(const struct deb_headers *pkg, const char *filekey, c
return RET_OK;
}
/* update Checksums */
retvalue binaries_complete_checksums(const char *chunk, const struct strlist *filekeys, struct checksums **c, char **out) {
struct fieldtoadd *replace;
char *newchunk;
enum checksumtype type;
const struct checksums *checksums;
assert (filekeys->count == 1);
checksums = c[0];
replace = NULL;
for( type = 0 ; type < cs_COUNT ; type++ ) {
const char *start;
size_t len;
if( checksums_getpart(checksums, type, &start, &len) ) {
replace = addfield_newn(deb_checksum_headers[type],
start, len, replace);
if( replace == NULL )
return RET_ERROR_OOM;
}
}
newchunk = chunk_replacefields(chunk, replace,
"Description", true);
addfield_free(replace);
if( newchunk == NULL )
return RET_ERROR_OOM;
*out = newchunk;
return RET_OK;
}
retvalue binaries_adddeb(const struct deb_headers *deb, struct database *database, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata, component_t component, const struct strlist *filekeys, const char *control) {
retvalue r,result;
int i;
......
......@@ -23,6 +23,7 @@ do_reoverride binaries_doreoverride;
do_reoverride ubinaries_doreoverride;
do_retrack binaries_retrack;
get_sourceandversion binaries_getsourceandversion;
complete_checksums binaries_complete_checksums;
/* Functions for checkindeb.c and incoming.c: */
......
......@@ -223,6 +223,40 @@ retvalue files_expectfiles(struct database *database, const struct strlist *file
return RET_OK;
}
/* check for several files in the database and update information */
retvalue files_checkorimprove(struct database *database, const struct strlist *filekeys, struct checksums *checksumsarray[]) {
int i;
retvalue r;
for( i = 0 ; i < filekeys->count ; i++ ) {
const char *filekey = filekeys->values[i];
const struct checksums *checksums = checksumsarray[i];
struct checksums *indatabase;
bool improves;
r = files_get_checksums(database, filekey, &indatabase);
if( r == RET_NOTHING ) {
fprintf(stderr, "Missing file %s\n", filekey);
return RET_ERROR_MISSING;
}
if( RET_WAS_ERROR(r) )
return r;
if( !checksums_check(checksums, indatabase, &improves) ) {
fprintf(stderr,
"File \"%s\" is already registered with different checksums!\n",
filekey);
checksums_printdifferences(stderr, indatabase, checksums);
r = RET_ERROR_WRONG_MD5;
} else if( improves ) {
r = checksums_combine(&checksumsarray[i], indatabase, NULL);
}
checksums_free(indatabase);
if( RET_WAS_ERROR(r) )
return r;
}
return RET_OK;
}
/* print missing files */
retvalue files_printmissing(struct database *database, const struct strlist *filekeys, const struct checksumsarray *origfiles) {
int i;
......
......@@ -28,6 +28,9 @@ retvalue files_expect(struct database *, const char *, const struct checksums *,
/* same for multiple files */
retvalue files_expectfiles(struct database *, const struct strlist *, struct checksums **);
/* check for several files in the database and update information */
retvalue files_checkorimprove(struct database *, const struct strlist *, struct checksums **);
/* print missing files */
retvalue files_printmissing(struct database *, const struct strlist *filekeys, const struct checksumsarray *);
......
......@@ -30,6 +30,7 @@
#include "chunks.h"
#include "sources.h"
#include "names.h"
#include "dirs.h"
#include "dpkgversions.h"
#include "override.h"
#include "tracking.h"
......@@ -611,6 +612,54 @@ retvalue sources_complete(const struct dsc_headers *dsc, const char *directory,
return RET_OK;
}
/* update Checksums */
retvalue sources_complete_checksums(const char *chunk, const struct strlist *filekeys, struct checksums **c, char **out) {
struct fieldtoadd *replace;
char *newchunk;
char *newfilelines, *newsha1lines, *newsha256lines;
struct checksumsarray checksums;
retvalue r;
int i;
/* fake a checksumarray... */
checksums.checksums = c;
checksums.names.count = filekeys->count;
checksums.names.values = calloc(filekeys->count, sizeof(char*));
if (checksums.names.values == NULL)
return RET_ERROR_OOM;
for( i = 0 ; i < filekeys->count ; i++ ) {
checksums.names.values[i] = (char*)
dirs_basename(filekeys->values[i]);
}
r = checksumsarray_genfilelist(&checksums,
&newfilelines, &newsha1lines, &newsha256lines);
if( RET_WAS_ERROR(r) )
return RET_ERROR_OOM;
assert( newfilelines != NULL );
replace = aodfield_new("Checksums-Sha256", newsha256lines, NULL);
if( replace != NULL )
replace = aodfield_new("Checksums-Sha1", newsha1lines, replace);
if( replace != NULL )
replace = addfield_new("Files", newfilelines, replace);
if( replace == NULL ) {
free(newsha256lines);
free(newsha1lines);
free(newfilelines);
return RET_ERROR_OOM;
}
newchunk = chunk_replacefields(chunk, replace, "Files", false);
free(newsha256lines);
free(newsha1lines);
free(newfilelines);
addfield_free(replace);
if( newchunk == NULL )
return RET_ERROR_OOM;
*out = newchunk;
return RET_OK;
}
char *calc_source_basename(const char *name, const char *version) {
const char *v = strchr(version, ':');
if( v != NULL )
......
......@@ -21,6 +21,7 @@ get_checksums sources_getchecksums;
do_reoverride sources_doreoverride;
do_retrack sources_retrack;
get_sourceandversion sources_getsourceandversion;
complete_checksums sources_complete_checksums;
/* Functions for checkindsc.c and incoming.c: */
struct dsc_headers {
......
......@@ -59,7 +59,7 @@ static char *calc_identifier(const char *codename, component_t component, archit
}
static retvalue target_initialize(/*@dependant@*/struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype, get_version getversion, get_installdata getinstalldata, get_architecture getarchitecture, get_filekeys getfilekeys, get_checksums getchecksums, get_sourceandversion getsourceandversion, do_reoverride doreoverride, do_retrack doretrack, /*@null@*//*@only@*/char *directory, /*@dependent@*/const struct exportmode *exportmode, bool readonly, /*@out@*/struct target **d) {
static retvalue target_initialize(/*@dependant@*/struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype, get_version getversion, get_installdata getinstalldata, get_architecture getarchitecture, get_filekeys getfilekeys, get_checksums getchecksums, get_sourceandversion getsourceandversion, do_reoverride doreoverride, do_retrack doretrack, complete_checksums docomplete, /*@null@*//*@only@*/char *directory, /*@dependent@*/const struct exportmode *exportmode, bool readonly, /*@out@*/struct target **d) {
struct target *t;
assert(exportmode != NULL);
......@@ -94,6 +94,7 @@ static retvalue target_initialize(/*@dependant@*/struct distribution *distributi
t->getsourceandversion = getsourceandversion;
t->doreoverride = doreoverride;
t->doretrack = doretrack;
t->completechecksums = docomplete;
t->readonly = readonly;
*d = t;
return RET_OK;
......@@ -121,6 +122,7 @@ retvalue target_initialize_ubinary(struct distribution *d, component_t component
binaries_getfilekeys, binaries_getchecksums,
binaries_getsourceandversion,
ubinaries_doreoverride, binaries_retrack,
binaries_complete_checksums,
mprintf("%s/debian-installer/binary-%s",
dist_component_name(component,
fakecomponentprefix),
......@@ -135,6 +137,7 @@ retvalue target_initialize_binary(struct distribution *d, component_t component,
binaries_getfilekeys, binaries_getchecksums,
binaries_getsourceandversion,
binaries_doreoverride, binaries_retrack,
binaries_complete_checksums,
mprintf("%s/binary-%s",
dist_component_name(component,
fakecomponentprefix),
......@@ -150,6 +153,7 @@ retvalue target_initialize_source(struct distribution *d, component_t component,
sources_getfilekeys, sources_getchecksums,
sources_getsourceandversion,
sources_doreoverride, sources_retrack,
sources_complete_checksums,
mprintf("%s/source", dist_component_name(component,
fakecomponentprefix)),
exportmode, readonly, target);
......
......@@ -35,6 +35,7 @@ typedef retvalue get_checksums(const char *, /*@out@*/struct checksumsarray *);
typedef retvalue do_reoverride(const struct target *, const char *packagename, const char *controlchunk, /*@out@*/char **newcontrolchunk);
typedef retvalue do_retrack(const char *packagename, const char *controlchunk, trackingdb, struct database *);
typedef retvalue get_sourceandversion(const char *chunk, const char *packagename, /*@out@*/char **source, /*@out@*/char **version);
typedef retvalue complete_checksums(const char *chunk, const struct strlist *, struct checksums **, /*@out@*/char **);
struct distribution;
struct target {
......@@ -57,6 +58,7 @@ struct target {
get_sourceandversion *getsourceandversion;
do_reoverride *doreoverride;
do_retrack *doretrack;
complete_checksums *completechecksums;
bool wasmodified, saved_wasmodified;
/* set when existed at startup time, only valid in --nofast mode */
bool existed;
......
......@@ -648,14 +648,26 @@ retvalue upgradelist_install(struct upgradelist *upgrade, struct logger *logger,
result = RET_NOTHING;
for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) {
if( pkg->version == pkg->new_version && !pkg->deleted ) {
r = files_expectfiles(database,
char *newcontrol;
r = files_checkorimprove(database,
&pkg->new_filekeys,
pkg->new_origfiles.checksums);
if( ! RET_WAS_ERROR(r) ) {
r = upgrade->target->completechecksums(
pkg->new_control,
&pkg->new_filekeys,
pkg->new_origfiles.checksums,
&newcontrol);
}
if( ! RET_WAS_ERROR(r) ) {
/* upgrade (or possibly downgrade) */
const char *causingrule = NULL,
*suitefrom = NULL;
free(pkg->new_control);
pkg->new_control = newcontrol;
callback(pkg->privdata, &causingrule, &suitefrom);
// TODO: trackingdata?
if( interrupted() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment