Commit fb142e41 authored by Bernhard Link's avatar Bernhard Link

reenable rredtool and do some cleanups

parent 35504c1d
......@@ -2,7 +2,7 @@ SUBDIRS = docs tests
EXTRA_DIST = autogen.sh
bin_PROGRAMS = reprepro changestool # rredtool
bin_PROGRAMS = reprepro changestool rredtool
if HAVE_LIBARCHIVE
ARCHIVE_USED = ar.c debfile.c
......@@ -23,9 +23,9 @@ EXTRA_reprepro_SOURCE = $(ARCHIVE_UNUSED)
changestool_SOURCES = uncompression.c sourceextraction.c readtextfile.c filecntl.c tool.c chunkedit.c strlist.c checksums.c sha1.c sha256.c md5.c mprintf.c chunks.c signature.c dirs.c names.c $(ARCHIVE_USED)
# rredtool_SOURCES = rredtool.c rredpatch.c
rredtool_SOURCES = rredtool.c rredpatch.c
noinst_HEADERS = pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.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 indexfile.h # rredpatch.h
noinst_HEADERS = pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.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 indexfile.h rredpatch.h
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/configure $(srcdir)/stamp-h.in $(srcdir)/aclocal.m4 $(srcdir)/config.h.in
......
......@@ -509,19 +509,16 @@ retvalue combine_patches(struct modification **result_p, /*@only@*/struct modifi
return RET_OK;
}
static retvalue patch_file(const char *destination, const char *source, const struct modification *patch) {
FILE *i, *o;
retvalue patch_file(FILE *o, const char *source, const struct modification *patch) {
FILE *i;
int currentline, ignore, c;
i = fopen(source, "r");
if( i == NULL ) {
perror("error opening\n");
return RET_ERROR;
}
o = fopen(destination, "w");
if( o == NULL ) {
perror("error creating\n");
return RET_ERROR;
int e = errno;
fprintf(stderr, "Error %d opening %s: %s\n",
e, source, strerror(e));
return RET_ERRNO(e);
}
assert( patch == NULL || patch->oldlinestart > 0 );
currentline = 1;
......@@ -545,30 +542,33 @@ static retvalue patch_file(const char *destination, const char *source, const st
fprintf(stderr,
"Error patching '%s', file shorter than expected by patches!\n",
source);
(void)fclose(i);
return RET_ERROR;
}
return RET_OK;
break;
}
putc(c, o);
}
putc(c, o);
currentline++;
} while (1);
// TODO: check errors
fclose(i);
fclose(o);
return RET_OK;
}
static void modification_print(const struct modification *m) {
while( m != NULL ) {
printf("mod %d+%d to %d:\n", m->oldlinestart, m->oldlinecount, m->newlinecount);
fwrite(m->content, m->len, 1, stdout);
m = m->next;
if( ferror(i) != 0 ) {
int e = errno;
fprintf(stderr, "Error %d reading %s: %s\n",
e, source, strerror(e));
(void)fclose(i);
return RET_ERRNO(e);
}
if( fclose(i) != 0 ) {
int e = errno;
fprintf(stderr, "Error %d reading %s: %s\n",
e, source, strerror(e));
return RET_ERRNO(e);
}
return RET_OK;
}
void modification_printaspatch(const struct modification *m) {
void modification_printaspatch(FILE *f, const struct modification *m) {
const struct modification *p, *q, *r;
if( m == NULL )
......@@ -602,24 +602,24 @@ void modification_printaspatch(const struct modification *m) {
if( newcount == 0 ) {
assert( oldcount > 0 );
if( oldcount == 1 )
printf("%dd\n", start);
fprintf(f, "%dd\n", start);
else
printf("%d,%dd\n", start, start + oldcount - 1);
fprintf(f, "%d,%dd\n", start, start + oldcount - 1);
} else {
if( oldcount == 0 )
printf("%da\n", start-1);
fprintf(f, "%da\n", start-1);
else if( oldcount == 1 )
printf("%dc\n", start);
fprintf(f, "%dc\n", start);
else
printf("%d,%dc\n", start, start + oldcount - 1);
fprintf(f, "%d,%dc\n", start, start + oldcount - 1);
while( r != p->next ) {
if( r->len > 0 )
fwrite(r->content, r->len, 1, stdout);
fwrite(r->content, r->len, 1, f);
newcount -= r->newlinecount;
r = r->next;
}
assert( newcount == 0 );
puts(".");
fputs(".\n", f);
}
p = q;
}
......
#ifndef REPREPRO_RREDPATCH_H
#define REPREPRO_RREDPATCH_H
struct rred_patch;
struct modification;
retvalue patch_load(const char *, off_t, /*@out@*/struct rred_patch **);
void patch_free(/*@only@*/struct rred_patch *);
/*@only@*//*@null@*/struct modification *patch_getmodifications(struct rred_patch *);
void modification_freelist(/*@only@*/struct modification *);
retvalue combine_patches(/*@out@*/struct modification **, /*@only@*/struct modification *, /*@only@*/struct modification *);
void modification_printaspatch(const struct modification *);
void modification_printaspatch(FILE *, const struct modification *);
retvalue patch_file(FILE *, const char *, const struct modification *);
#endif
......@@ -22,7 +22,7 @@ int main(int argc, const char *argv[]) {
retvalue r;
bool mergemode = false;
int i, count;
const char *sourcename;
const char *sourcename IFSTUPIDCC(=NULL);
int debug = 0;
while( (i = getopt_long(argc, (char**)argv, "+hVDm", options, NULL)) != -1 ) {
......@@ -64,8 +64,11 @@ int main(int argc, const char *argv[]) {
if( RET_IS_OK(r) )
count++;
if( RET_WAS_ERROR(r) ) {
fprintf(stderr, "Aborting...\n");
return RET_ERRNO(r);
if( r == RET_ERROR_OOM )
fputs("Out of memory!\n", stderr);
else
fputs("Aborting...\n", stderr);
return EXIT_FAILURE;
}
i++;
}
......@@ -77,26 +80,41 @@ int main(int argc, const char *argv[]) {
for( i = 1; i < count ; i++ ) {
struct modification *a = patch_getmodifications(patches[i]);
if( debug ) {
puts("--------RESULT SO FAR----------------");
modification_printaspatch(m);
puts("--------TO BE MERGED WITH------------");
modification_printaspatch(a);
puts("-------------END---------------------");
fputs("--------RESULT SO FAR--------\n", stderr);
modification_printaspatch(stderr, m);
fputs("--------TO BE MERGED WITH-----\n", stderr);
modification_printaspatch(stderr, a);
fputs("-------------END--------------\n", stderr);
}
r = combine_patches(&m, m, a);
if( RET_WAS_ERROR(r) ) {
for( i = 0 ; i < count ; i++ ) {
patch_free(patches[i]);
}
fprintf(stderr, "Aborting...\n");
return RET_ERRNO(r);
if( r == RET_ERROR_OOM )
fputs("Out of memory!\n", stderr);
else
fputs("Aborting...\n", stderr);
return EXIT_FAILURE;
}
}
if( mergemode )
modification_printaspatch(m);
r = RET_OK;
if( mergemode ) {
modification_printaspatch(stdout, m);
} else {
r = patch_file(stdout, sourcename, m);
}
if( ferror(stdout) ) {
fputs("Error writing to stdout!\n", stderr);
r = RET_ERROR;
}
modification_freelist(m);
for( i = 0 ; i < count ; i++ )
patch_free(patches[i]);
if( r == RET_ERROR_OOM )
fputs("Out of memory!\n", stderr);
if( RET_WAS_ERROR(r) )
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
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