Commit 4343c268 authored by Bernhard Link's avatar Bernhard Link

Moved guess_component to its own file

parent d72cee1b
......@@ -3,8 +3,8 @@ bin_PROGRAMS = mirrorer
CPPFLAGS = @CPPFLAGS@ -D_GNU_SOURCE=1 -DPKGDATADIR=\"$(pkgdatadir)\" -Wall
mirrorer_SOURCES = main.c files.c md5.c md5sum.c dirs.c chunks.c reference.c packages.c binaries.c sources.c names.c dpkgversions.c release.c mprintf.c download.c updates.c strlist.c signature.c distribution.c extractcontrol.c checkindeb.c checkindsc.c checkin.c copyfile.c
mirrorer_SOURCES = main.c guesscomponent.c files.c md5.c md5sum.c dirs.c chunks.c reference.c packages.c binaries.c sources.c names.c dpkgversions.c release.c mprintf.c download.c updates.c strlist.c signature.c distribution.c extractcontrol.c checkindeb.c checkindsc.c checkin.c copyfile.c
mirrorer_LDFLAGS += -ldb3
noinst_HEADERS = md5.h md5sum.h dirs.h files.h chunks.h reference.h packages.h binaries.h sources.h names.h release.h error.h mprintf.h download.h updates.h strlist.h signature.h distribution.h extractcontrol.h checkindeb.h checkindsc.h copyfile.h
noinst_HEADERS = guesscomponent.h md5.h md5sum.h dirs.h files.h chunks.h reference.h packages.h binaries.h sources.h names.h release.h error.h mprintf.h download.h updates.h strlist.h signature.h distribution.h extractcontrol.h checkindeb.h checkindsc.h copyfile.h
MAINTAINERCLEANFILES = Makefile.in configure install-sh stamp-h.in aclocal.m4 config.h.in mkinstalldirs
TODO:
check if Source with other version number is
correctly handled by deb_read...
add adding uploads (via .changes, by .dsc and by .deb)
add automated updating of distributions
add searching for packages
......
......@@ -39,6 +39,7 @@
#include "binaries.h"
#include "files.h"
#include "extractcontrol.h"
#include "guesscomponent.h"
extern int verbose;
......@@ -105,6 +106,7 @@ void deb_free(struct debpackage *pkg) {
free(pkg->package);free(pkg->version);
free(pkg->source);free(pkg->architecture);
free(pkg->basename);free(pkg->control);
free(pkg->section);free(pkg->component);
}
free(pkg);
}
......@@ -212,85 +214,6 @@ retvalue deb_complete(struct debpackage *pkg, const char *filekey, const char *m
return RET_OK;
}
/* Guess which component to use:
* - if the user gave one, use that one.
* - if the section is a componentname, use this one
* - if the section starts with a componentname/, use this one
* - if the section ends with a /componentname, use this one
* - if the section/ is the start of a componentname, use this one
* - use the first component in the list
*/
retvalue guess_component(struct distribution *distribution,
struct debpackage *package,
const char *givencomponent) {
int i;
const char *section;
size_t section_len;
#define RETURNTHIS(comp) { \
char *c = strdup(comp); \
if( !c ) \
return RET_ERROR_OOM; \
free(package->component); \
package->component = c; \
return RET_OK; \
}
if( givencomponent ) {
if( givencomponent && !strlist_in(&distribution->components,givencomponent) ) {
fprintf(stderr,"Could not find '%s' in components of '%s': ",
givencomponent,distribution->codename);
strlist_fprint(stderr,&distribution->components);
fputs("'\n",stderr);
return RET_ERROR;
}
RETURNTHIS(givencomponent);
}
section = package->section;
if( section == NULL ) {
fprintf(stderr,"Found no section for '%s', so I cannot guess the component to put it in!\n",package->package);
return RET_ERROR;
}
if( distribution->components.count <= 0 ) {
fprintf(stderr,"I do not find any components in '%s', so there is no chance I cannot even take one by guessing!\n",distribution->codename);
return RET_ERROR;
}
section_len = strlen(section);
for( i = 0 ; i < distribution->components.count ; i++ ) {
const char *component = distribution->components.values[i];
if( strcmp(section,component) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < distribution->components.count ; i++ ) {
const char *component = distribution->components.values[i];
size_t len = strlen(component);
if( len<section_len && section[len] == '/' && strncmp(section,component,len) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < distribution->components.count ; i++ ) {
const char *component = distribution->components.values[i];
size_t len = strlen(component);
if( len<section_len && section[section_len-len-1] == '/' &&
strncmp(section+section_len-len,component,len) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < distribution->components.count ; i++ ) {
const char *component = distribution->components.values[i];
if( strncmp(section,component,section_len) == 0 && component[section_len] == '/' )
RETURNTHIS(component);
}
RETURNTHIS(distribution->components.values[0]);
#undef RETURNTHIS
}
/* 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)
......@@ -317,7 +240,8 @@ retvalue deb_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
/* decide where it has to go */
r = guess_component(distribution,pkg,forcecomponent);
r = guess_component(distribution->codename,&distribution->components,
pkg->package,pkg->section,forcecomponent,&pkg->component);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
......
/* This file is part of "mirrorer" (TODO: find better title)
* Copyright (C) 2003 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 as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <malloc.h>
#include "error.h"
#include "strlist.h"
#include "guesscomponent.h"
extern int verbose;
/* Guess which component to use:
* - if the user gave one, use that one.
* - if the section is a componentname, use this one
* - if the section starts with a componentname/, use this one
* - if the section ends with a /componentname, use this one
* - if the section/ is the start of a componentname, use this one
* - use the first component in the list
*/
retvalue guess_component(const char *codename,const struct strlist *components,
const char *package,const char *section,
const char *givencomponent,char **guess) {
int i;
size_t section_len;
#define RETURNTHIS(comp) { \
char *c = strdup(comp); \
if( !c ) \
return RET_ERROR_OOM; \
*guess = c; \
return RET_OK; \
}
if( givencomponent ) {
if( givencomponent && !strlist_in(components,givencomponent) ) {
fprintf(stderr,"Could not find '%s' in components of '%s': ",
givencomponent,codename);
strlist_fprint(stderr,components);
fputs("'\n",stderr);
return RET_ERROR;
}
RETURNTHIS(givencomponent);
}
if( section == NULL ) {
fprintf(stderr,"Found no section for '%s', so I cannot guess the component to put it in!\n",package);
return RET_ERROR;
}
if( components->count <= 0 ) {
fprintf(stderr,"I do not find any components in '%s', so there is no chance I cannot even take one by guessing!\n",codename);
return RET_ERROR;
}
section_len = strlen(section);
for( i = 0 ; i < components->count ; i++ ) {
const char *component = components->values[i];
if( strcmp(section,component) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < components->count ; i++ ) {
const char *component = components->values[i];
size_t len = strlen(component);
if( len<section_len && section[len] == '/' && strncmp(section,component,len) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < components->count ; i++ ) {
const char *component = components->values[i];
size_t len = strlen(component);
if( len<section_len && section[section_len-len-1] == '/' &&
strncmp(section+section_len-len,component,len) == 0 )
RETURNTHIS(component);
}
for( i = 0 ; i < components->count ; i++ ) {
const char *component = components->values[i];
if( strncmp(section,component,section_len) == 0 && component[section_len] == '/' )
RETURNTHIS(component);
}
RETURNTHIS(components->values[0]);
#undef RETURNTHIS
}
#ifndef __MIRRORER_GUESSCOMPONENT_H
#define __MIRRORER_GUESSCOMPONENT_H
#ifndef __MIRRORER_ERROR_H
#include "error.h"
#warning "What's hapening here?"
#endif
#ifndef __MIRRORER_STRLIST_H
#include "strlist.h"
#warning "What's hapening here?"
#endif
retvalue guess_component(const char *codename,const struct strlist *components,
const char *package,const char *section,
const char *givencomponent,char **component);
#endif
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