Commit 2f26ad54 authored by Bernhard Link's avatar Bernhard Link

move contents extraction filelist compression to filelist.c (and deactive in...

move contents extraction filelist compression to filelist.c (and deactive in extractcontrol.c, i.e. without libarchive)
parent 7ee18a00
......@@ -29,6 +29,7 @@
#include "ar.h"
#include "md5sum.h"
#include "chunks.h"
#include "filelist.h"
#include "debfile.h"
#ifndef HAVE_LIBARCHIVE
......@@ -220,14 +221,13 @@ retvalue extractcontrol(char **control,const char *debfile) {
static retvalue read_data_tar(/*@out@*/char **list, const char *debfile, struct ar_archive *ar, struct archive *tar) {
struct archive_entry *entry;
char *filelist;
size_t size,len;
struct filelistcompressor c;
retvalue r;
int a;
size = 2000; len = 0;
filelist = malloc(size);
if( filelist == NULL )
return RET_ERROR_OOM;
r = filelistcompressor_setup(&c);
if( RET_WAS_ERROR(r) )
return r;
archive_read_support_format_tar(tar);
a = archive_read_open(tar,ar,
......@@ -235,7 +235,7 @@ static retvalue read_data_tar(/*@out@*/char **list, const char *debfile, struct
ar_archivemember_read,
ar_archivemember_close);
if( a != ARCHIVE_OK ) {
free(filelist);
filelistcompressor_cancel(&c);
fprintf(stderr,"open data.tar.gz within '%s' failed: %d:%d:%s\n",
debfile,
a,archive_errno(tar),
......@@ -254,30 +254,14 @@ static retvalue read_data_tar(/*@out@*/char **list, const char *debfile, struct
continue;
mode = archive_entry_mode(entry);
if( !S_ISDIR(mode) ) {
size_t n_len = strlen(name);
if( len + n_len + 2 > size ) {
char *n;
if( size > 1024*1024*1024 ) {
fprintf(stderr, "Ridicilous long filelist for %s!\n",debfile);
free(filelist);
return RET_ERROR;
}
size = len + n_len + 2048;
n = realloc(filelist, size);
if( n == NULL ) {
free(filelist);
return RET_ERROR_OOM;
}
filelist = n;
r = filelistcompressor_add(&c, name, strlen(name));
if( RET_WAS_ERROR(r) ) {
filelistcompressor_cancel(&c);
return r;
}
memcpy(filelist + len, name, n_len+1);
len += n_len+1;
}
if( interrupted() ) {
free(filelist);
filelistcompressor_cancel(&c);
return RET_ERROR_INTERRUPTED;
}
a = archive_read_data_skip(tar);
......@@ -287,7 +271,7 @@ static retvalue read_data_tar(/*@out@*/char **list, const char *debfile, struct
archive_entry_pathname(entry),
debfile,
e, archive_error_string(tar));
free(filelist);
filelistcompressor_cancel(&c);
return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
}
}
......@@ -296,16 +280,10 @@ static retvalue read_data_tar(/*@out@*/char **list, const char *debfile, struct
printf("Error reading data.tar.gz from %s: %d=%s\n",
debfile,
e, archive_error_string(tar));
free(filelist);
filelistcompressor_cancel(&c);
return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
}
filelist[len] = '\0';
*list = realloc(filelist, len+1);
if( *list == NULL ) {
free(filelist);
return RET_ERROR_OOM;
}
return RET_OK;
return filelistcompressor_finish(&c, list);
}
......
......@@ -208,22 +208,30 @@ retvalue extractcontrol(char **control,const char *debfile) {
}
retvalue getfilelist(/*@out@*/char **filelist, const char *debfile) {
fprintf(stderr, "Extracing of filelist currently not implemented without libarchive.\n");
return RET_ERROR;
#if 0
int pipe1[2];
int pipe2[2];
int ret;
pid_t ar,tar,pid;
int status;
char *list = NULL;
size_t listsize = 0;
size_t len=0, last = 0;
struct filelistcompressor c;
size_t last = 0;
retvalue result;
#error this still needs to be reimplemented...
result = filelistcompressor_setup(&c);
if( RET_WAS_ERROR(result) )
return result;
result = RET_OK;
ret = pipe(pipe1);
if( ret < 0 ) {
int e = errno;
fprintf(stderr, "Error while creating pipe: %d=%s\n",e,strerror(e));
filelistcompressor_cancel(&c);
return RET_ERRNO(e);
}
......@@ -232,6 +240,7 @@ retvalue getfilelist(/*@out@*/char **filelist, const char *debfile) {
int e = errno;
fprintf(stderr, "Error while creating pipe: %d=%s\n",e,strerror(e));
close(pipe1[0]);close(pipe1[1]);
filelistcompressor_cancel(&c);
return RET_ERRNO(e);
}
......@@ -242,6 +251,7 @@ retvalue getfilelist(/*@out@*/char **filelist, const char *debfile) {
result = RET_ERRNO(e);
close(pipe1[0]);close(pipe1[1]);
close(pipe2[0]);close(pipe2[1]);
filelistcompressor_cancel(&c);
return result;
}
......@@ -395,11 +405,11 @@ retvalue getfilelist(/*@out@*/char **filelist, const char *debfile) {
fprintf(stderr,"Who is %d, and why does this bother me?\n",pid);
}
}
}
if( RET_IS_OK(result) )
*filelist = list;
return filelistcompressor_finish(&c, filelist);
else
free(list);
filelistcompressor_cancel(&c);
return result;
#endif
}
......@@ -297,3 +297,49 @@ retvalue filelist_write(struct filelist_list *list, struct filetorelease *file)
free(buffer);
return r;
}
retvalue filelistcompressor_setup(/*@out@*/struct filelistcompressor *c) {
c->size = 2000; c->len = 0;
c->filelist = malloc(c->size);
if( c->filelist == NULL )
return RET_ERROR_OOM;
return RET_OK;
}
retvalue filelistcompressor_add(struct filelistcompressor *c, const char *name, size_t name_len) {
if( c->len + name_len + 2 > c->size ) {
char *n;
if( c->size > 1024*1024*1024 ) {
fprintf(stderr, "Ridicilous long filelist!\n");
return RET_ERROR;
}
c->size = c->len + name_len + 2048;
n = realloc(c->filelist, c->size);
if( n == NULL )
return RET_ERROR_OOM;
c->filelist = n;
}
memcpy(c->filelist + c->len, name, name_len+1);
c->len += name_len+1;
return RET_OK;
}
retvalue filelistcompressor_finish(struct filelistcompressor *c, /*@out@*/char **list) {
char *l;
c->filelist[c->len] = '\0';
l = realloc(c->filelist, c->len+1);
if( l == NULL ) {
free(c->filelist);
return RET_ERROR_OOM;
}
*list = l;
return RET_OK;
}
void filelistcompressor_cancel(struct filelistcompressor *c) {
free(c->filelist);
}
......@@ -16,4 +16,15 @@ retvalue filelist_add(struct filelist_list *,const struct filelist_package *,con
retvalue filelist_write(struct filelist_list *list, struct filetorelease *file);
void filelist_free(/*@only@*/struct filelist_list *);
/* for use in routines reading the data: */
struct filelistcompressor {
unsigned int offsets[256];
size_t size, len, dirdept;
char *filelist;
};
retvalue filelistcompressor_setup(/*@out@*/struct filelistcompressor *);
retvalue filelistcompressor_add(struct filelistcompressor *, const char *, size_t);
retvalue filelistcompressor_finish(struct filelistcompressor *, /*@out@*/char **);
void filelistcompressor_cancel(struct filelistcompressor *);
#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