Commit 8108ef22 authored by Bernhard Link's avatar Bernhard Link

some starting code for import from incoming

parent d40729b9
2006-12-31 Bernhard R. Link <brlink@debian.org>
* first code for importing from an incoming dir, not
yet useable (supports no source, no overrides, no ... yet)
2006-12-17 Bernhard R. Link <brlink@debian.org>
* tell about the filename in the non-libarchive
case of failure to extract control or filelist
......
......@@ -16,12 +16,12 @@ AM_CPPFLAGS = -D_GNU_SOURCE=1 -Wall $(ARCHIVECPP) $(DBCPPFLAGS)
reprepro_LDADD = $(ARCHIVELIBS) $(DBLIBS)
changestool_LDADD = $(ARCHIVELIBS)
reprepro_SOURCES = changes.c uploaderslist.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 updates.c strlist.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c copyfile.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c ignore.c filterlist.c exports.c tracking.c optionsfile.c readrelease.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED)
reprepro_SOURCES = changes.c incoming.c uploaderslist.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 updates.c strlist.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c copyfile.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c ignore.c filterlist.c exports.c tracking.c optionsfile.c readrelease.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED)
EXTRA_reprepro_SOURCE = $(ARCHIVE_UNUSED)
changestool_SOURCES = tool.c chunkedit.c strlist.c md5sum.c md5.c mprintf.c chunks.c signature.c dirs.c ignore.c names.c copyfile.c $(ARCHIVE_USED)
noinst_HEADERS = changes.h 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 updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h copyfile.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h
noinst_HEADERS = changes.h incoming.h 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 updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h copyfile.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h
MAINTAINERCLEANFILES = Makefile.in configure install-sh stamp-h.in aclocal.m4 config.h.in mkinstalldirs config.guess config.sub missing
......
......@@ -304,7 +304,7 @@ retvalue deb_prepare(/*@out@*/struct debpackage **deb,filesdb filesdb,const char
const struct overrideinfo *oinfo;
const struct strlist *components;
assert( (givenmd5sum!=NULL && givenfilekey!=NULL ) ||
assert( givenmd5sum!=NULL ||
(givenmd5sum==NULL && givenfilekey==NULL ) );
/* First taking a closer look to the file: */
......@@ -435,16 +435,21 @@ retvalue deb_prepare(/*@out@*/struct debpackage **deb,filesdb filesdb,const char
return r;
}
/* then looking if we already have this, or copy it in */
if( givenfilekey != NULL ) {
assert(givenmd5sum != NULL);
if( givenmd5sum != NULL ) {
pkg->md5sum = strdup(givenmd5sum);
if( pkg->md5sum == NULL ) {
deb_free(pkg);
return RET_ERROR_OOM;
}
}
if( givenfilekey == NULL ) {
r = files_ready(filesdb, pkg->filekey,pkg->md5sum);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
return r;
}
}
} else {
assert(givenmd5sum == NULL);
assert(givenfilekey == NULL);
r = files_include(filesdb,debfilename,pkg->filekey,NULL,&pkg->md5sum,delete);
if( RET_WAS_ERROR(r) ) {
deb_free(pkg);
......@@ -463,6 +468,11 @@ retvalue deb_prepare(/*@out@*/struct debpackage **deb,filesdb filesdb,const char
return RET_OK;
}
retvalue deb_hardlinkfiles(struct debpackage *deb,filesdb filesdb,const char *debfilename) {
assert( deb != NULL );
assert( deb->filekey != NULL && deb-> md5sum != NULL );
return files_hardlink(filesdb, debfilename, deb->filekey, deb->md5sum);
}
retvalue deb_addprepared(const struct debpackage *pkg, const char *dbdir,references refs,const char *forcearchitecture,const char *packagetype,struct distribution *distribution,struct strlist *dereferencedfilekeys,struct trackingdata *trackingdata){
retvalue r,result;
......
......@@ -27,6 +27,7 @@ retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,/*@null@*/con
/* in two steps */
struct debpackage;
retvalue deb_addprepared(const struct debpackage *pkg, const char *dbdir,references refs,const char *forcearchitecture,const char *packagetype,struct distribution *distribution,struct strlist *dereferencedfilekeys,struct trackingdata *trackingdata);
retvalue deb_hardlinkfiles(struct debpackage *deb,filesdb filesdb,const char *debfilename);
retvalue deb_prepare(/*@out@*/struct debpackage **deb,filesdb filesdb,const char * const forcecomponent,const char * const forcearchitecture,const char *forcesection,const char *forcepriority,const char * const packagetype,struct distribution *distribution,const char *debfilename,const char * const givenfilekey,const char * const givenmd5sum,const struct overrideinfo *binoverride,int delete,bool_t needsourceversion,const struct strlist *allowed_binaries,const char *expectedsourcename,const char *expectedsourceversion);
void deb_free(/*@only@*/struct debpackage *pkg);
#endif
/* This file is part of "reprepro"
* Copyright (C) 2003,2004,2005,2006 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
* 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,
......@@ -175,7 +175,7 @@ static retvalue distribution_parse_and_filter(struct distribution **distribution
const char *missing;
char *option;
static const char * const allowedfields[] = {
"Codename", "Suite", "Version", "Origin", "Label", "Description",
"Codename", "Suite", "Version", "Origin", "Label", "Description",
"Architectures", "Components", "Update", "SignWith", "DebOverride",
"UDebOverride", "DscOverride", "Tracking", "NotAutomatic",
"UDebComponents", "DebIndices", "DscIndices", "UDebIndices",
......@@ -427,7 +427,7 @@ retvalue distribution_getmatched(const char *conf,int argc,const char *argv[],st
mydata.distributions = NULL;
fn = calc_dirconcat(conf,"distributions");
if( fn == NULL )
if( fn == NULL )
return RET_ERROR_OOM;
result = regularfileexists(fn);
......@@ -478,7 +478,7 @@ retvalue distribution_get(struct distribution **distribution,const char *confdir
/* This is a bit overkill, as it does not stop when it finds the
* definition of the distribution. But this way we can warn
* about emtpy lines in the definition (as this would split
* it in two definitions, the second one no valid one).
* it in two definitions, the second one no valid one).
*/
result = distribution_getmatched(confdir,1,&name,&d);
......@@ -573,7 +573,7 @@ retvalue distribution_exportandfreelist(enum exportwhen when,
}
for( d=distributions; d != NULL; d = d->next ) {
if( RET_IS_OK(d->status) ||
if( RET_IS_OK(d->status) ||
( d->status == RET_NOTHING && when != EXPORT_CHANGED) ||
when == EXPORT_FORCE) {
todo = TRUE;
......@@ -590,14 +590,14 @@ retvalue distribution_exportandfreelist(enum exportwhen when,
if( (RET_WAS_ERROR(d->status)||interrupted()) && when != EXPORT_FORCE ) {
if( verbose >= 10 )
fprintf(stderr,
fprintf(stderr,
" Not exporting %s because there have been errors and no --export=force.\n",
d->codename);
} else if( d->status==RET_NOTHING && when==EXPORT_CHANGED ) {
struct target *t;
if( verbose >= 10 )
fprintf(stderr,
fprintf(stderr,
" Not exporting %s because of no recorded changes and --export=changed.\n",
d->codename);
......@@ -617,8 +617,8 @@ retvalue distribution_exportandfreelist(enum exportwhen when,
}
}
} else {
assert( RET_IS_OK(d->status) ||
( d->status == RET_NOTHING &&
assert( RET_IS_OK(d->status) ||
( d->status == RET_NOTHING &&
when != EXPORT_CHANGED) ||
when == EXPORT_FORCE);
r = export(d,confdir,dbdir,distdir,files, TRUE);
......@@ -634,14 +634,14 @@ retvalue distribution_exportandfreelist(enum exportwhen when,
retvalue distribution_export(enum exportwhen when, struct distribution *distribution,const char *confdir,const char *dbdir,const char *distdir, filesdb files) {
if( when == EXPORT_NEVER ) {
if( verbose >= 10 )
fprintf(stderr,
fprintf(stderr,
"Not exporting %s because of --export=never.\n"
"Make sure to run a full export soon.\n", distribution->codename);
return RET_NOTHING;
}
if( when != EXPORT_FORCE && (RET_WAS_ERROR(distribution->status)||interrupted()) ) {
if( verbose >= 10 )
fprintf(stderr,
fprintf(stderr,
"Not exporting %s because there have been errors and no --export=force.\n"
"Make sure to run a full export soon.\n", distribution->codename);
return RET_NOTHING;
......@@ -650,7 +650,7 @@ retvalue distribution_export(enum exportwhen when, struct distribution *distribu
struct target *t;
if( verbose >= 10 )
fprintf(stderr,
fprintf(stderr,
"Not exporting %s because of no recorded changes and --export=changed.\n",
distribution->codename);
......@@ -677,3 +677,26 @@ retvalue distribution_export(enum exportwhen when, struct distribution *distribu
return export(distribution,confdir,dbdir,distdir,files, TRUE);
}
/* get a pointer to the apropiate part of the linked list */
struct distribution *distribution_find(struct distribution *distributions, const char *name) {
struct distribution *d = distributions, *r;
while( d != NULL && strcmp(d->codename, name) != 0 )
d = d->next;
if( d != NULL )
return d;
d = distributions;
while( d != NULL && ( d->suite == NULL || strcmp(d->suite, name) != 0 ))
d = d->next;
r = d;
if( r == NULL ) {
fprintf(stderr, "No distribution named '%s' found!\n", name);
return NULL;
}
while( d != NULL && ( d->suite == NULL || strcmp(d->suite, name) != 0 ))
d = d->next;
if( d == NULL )
return r;
fprintf(stderr, "No distribution has codename '%s' and multiple have it as suite-name!\n", name);
return NULL;
}
......@@ -86,6 +86,9 @@ retvalue distribution_export(enum exportwhen when, struct distribution *distribu
/* get all dists from <conf> fitting in the filter given in <argc,argv> */
retvalue distribution_getmatched(const char *conf,int argc,const char *argv[],/*@out@*/struct distribution **distributions);
/* get a pointer to the apropiate part of the linked list */
struct distribution *distribution_find(struct distribution *distributions, const char *name);
retvalue distribution_freelist(/*@only@*/struct distribution *distributions);
retvalue distribution_exportandfreelist(enum exportwhen when, /*@only@*/struct distribution *distributions,const char *confdir, const char *dbdir, const char *distdir, filesdb);
#endif
/* This file is part of "reprepro"
* Copyright (C) 2003,2004,2005,2006 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
* 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,
......@@ -267,8 +267,8 @@ retvalue files_deleteandremove(filesdb filesdb,const char *filekey,bool_t rmdirs
//to remove it anyway...
fprintf(stderr,"ignoring error trying to rmdir %s: %m(%d)\n",filename,en);
}
/* parent directories will contain this one
* thus not be empty, in other words:
/* parent directories will contain this one
* thus not be empty, in other words:
* everything's done */
break;
}
......@@ -311,6 +311,57 @@ static retvalue files_checkmd5sum(filesdb filesdb,const char *filekey,const char
return ret;
}
/* check if file is already there (RET_NOTHING) or could be added (RET_OK)
* or RET_ERROR_WRONG_MD5SUM if filekey is already there with different md5sum */
retvalue files_ready(filesdb db,const char *filekey,const char *md5sum) {
int dbret;
DBT key,data;
SETDBT(key,filekey);
CLEARDBT(data);
if( (dbret = db->database->get(db->database, NULL, &key, &data, 0)) == 0){
if( strcmp(md5sum,data.data) != 0 ) {
fprintf(stderr,"File \"%s\" is already registered with other md5sum!\n(expect: '%s', database:'%s')!\n",filekey,md5sum,(char*)data.data);
return RET_ERROR_WRONG_MD5;
}
return RET_NOTHING;
} else if( dbret != DB_NOTFOUND ){
db->database->err(db->database, dbret, "files.db:");
return RET_DBERR(dbret);
}
return RET_OK;;
}
/* hardlink file with known md5sum and add it to database */
retvalue files_hardlink(filesdb db,const char *tempfile, const char *filekey,const char *md5sum) {
retvalue ret;
int dbret;
DBT key,data;
SETDBT(key,filekey);
CLEARDBT(data);
/* an additional check to make sure nothing tricks us into
* overwriting it by another file */
if( (dbret = db->database->get(db->database, NULL, &key, &data, 0)) == 0){
if( strcmp(md5sum,data.data) != 0 ) {
fprintf(stderr,"File \"%s\" is already registered with other md5sum!\n(expect: '%s', database:'%s')!\n",filekey,md5sum,(char*)data.data);
return RET_ERROR_WRONG_MD5;
}
return RET_NOTHING;
} else if( dbret != DB_NOTFOUND ){
db->database->err(db->database, dbret, "files.db:");
return RET_DBERR(dbret);
}
ret = copyfile_hardlink(db->mirrordir, filekey, tempfile, md5sum);
if( RET_WAS_ERROR(ret) )
return ret;
return files_add(db,filekey,md5sum);
}
/* check for file in the database and if not found there, if it can be detected */
retvalue files_expect(filesdb db,const char *filekey,const char *md5sum) {
......@@ -482,7 +533,7 @@ static retvalue getfilesize(/*@out@*/off_t *s,const char *md5sum) {
*s = (off_t)atoll(p);
return RET_OK;
}
}
}
fprintf(stderr,"Strange md5sum as missing space: '%s'\n",md5sum);
return RET_ERROR;
}
......@@ -605,7 +656,7 @@ retvalue files_include(filesdb db,const char *sourcefilename,const char *filekey
char *md5indatabase,*md5offile;
r = files_get(db,filekey,&md5indatabase);
if( RET_WAS_ERROR(r) )
if( RET_WAS_ERROR(r) )
return r;
if( RET_IS_OK(r) ) {
if( delete == D_INPLACE ) {
......@@ -670,7 +721,7 @@ retvalue files_include(filesdb db,const char *sourcefilename,const char *filekey
}
if( calculatedmd5sum != NULL )
*calculatedmd5sum = md5sumfound;
else
else
free(md5sumfound);
return RET_OK;
}
......
......@@ -90,4 +90,10 @@ retvalue files_genfilelist(filesdb db,const char *filekey,const struct filelist_
retvalue files_regenerate_filelist(filesdb db, bool_t redo);
retvalue files_addfilelist(filesdb db,const char *filekey,const char *filelist);
/* hardlink file with known md5sum and add it to database */
retvalue files_hardlink(filesdb db,const char *tempfile, const char *filekey,const char *md5sum);
/* check if file is already there (RET_NOTHING) or could be added (RET_OK)
* or RET_ERROR_WRONG_MD5SUM if filekey is already there with different md5sum */
retvalue files_ready(filesdb db,const char *filekey,const char *md5sum);
#endif
This diff is collapsed.
#ifndef REPREPRO_INCOMING_H
#define REPREPRO_INCOMING_H
#ifndef REPREPRO_ERROR_H
#include "error.h"
#warning "What's hapening here?"
#endif
retvalue process_incoming(const char *confdir, filesdb files, const char *dbdir, references refs, struct strlist *dereferenced, struct distribution *distributions, const char *name);
#endif
......@@ -57,7 +57,7 @@
#include "optionsfile.h"
#include "dpkgversions.h"
#include "uploaderslist.h"
#include "incoming.h"
#ifndef STD_BASE_DIR
#define STD_BASE_DIR "."
......@@ -1985,6 +1985,30 @@ ACTION_N(versioncompare) {
}
return r;
}
/***********************import***********************************/
ACTION_D(import) {
retvalue result,r;
struct distribution *distributions;
if( argc != 2 ) {
fprintf(stderr,"reprepro import <import-name>\n");
return RET_ERROR;
}
r = distribution_getmatched(confdir,0,NULL,&distributions);
assert( r != RET_NOTHING );
if( RET_WAS_ERROR(r) ) {
return r;
}
result = process_incoming(confdir, filesdb, dbdir, references, dereferenced, distributions, argv[1]);
r = distribution_exportandfreelist(export,distributions,
confdir,dbdir,distdir, filesdb);
RET_ENDUPDATE(result,r);
return result;
}
/**********************/
/* lock file handling */
......@@ -2110,6 +2134,7 @@ static const struct action {
{"include", A_D(include)},
{"generatefilelists", A_F(generatefilelists)},
{"clearvanished", A_D(clearvanished)},
{"import", A_D(import)},
{NULL,NULL,0}
};
#undef A_N
......
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