Commit ee4512c2 authored by Bernhard Link's avatar Bernhard Link

move compression_by_suffix to uncompression.c and use to remove some duplicate code

parent ccb07223
......@@ -186,8 +186,8 @@ retvalue changes_parsefileline(const char *fileline, /*@out@*/filetype *result_t
return RET_ERROR;
}
} else {
bool uncompressed = false;
enum compression c;
size_t l;
/* this looks like some source-package, we will have
* to look for the packagetype ourself... */
......@@ -195,28 +195,19 @@ retvalue changes_parsefileline(const char *fileline, /*@out@*/filetype *result_t
p++;
}
/* ignore compression suffix */
for( c = c_COUNT - 1 ; c > c_none ; c-- ) {
size_t l = strlen(uncompression_suffix[c]);
l = p - versionstart;
c = compression_by_suffix(versionstart, &l);
p = versionstart + l;
if( p - versionstart > l &&
strncmp(p - l, uncompression_suffix[c], l) == 0 ) {
p -= l;
break;
}
}
uncompressed = c == c_none;
if( p-versionstart > 9 && strncmp(p-9, ".orig.tar", 9) == 0 )
if( l > 9 && strncmp(p-9, ".orig.tar", 9) == 0 )
type = fe_ORIG;
else if( p-versionstart > 4 && strncmp(p-4, ".tar", 4) == 0 )
else if( l > 4 && strncmp(p-4, ".tar", 4) == 0 )
type = fe_TAR;
else if( p-versionstart > 5 && strncmp(p-5,".diff", 5) == 0 )
else if( l > 5 && strncmp(p-5,".diff", 5) == 0 )
type = fe_DIFF;
else if( p-versionstart > 4 && strncmp(p-4,".dsc",4) == 0 &&
uncompressed )
else if( l > 4 && strncmp(p-4,".dsc",4) == 0 && c == c_none )
type = fe_DSC;
else if( p-versionstart > 4 && strncmp(p-4, ".log", 4) == 0 &&
uncompressed )
else if( l > 4 && strncmp(p-4, ".log", 4) == 0 )
type = fe_LOG;
else {
type = fe_UNKNOWN;
......
......@@ -69,21 +69,8 @@ void sourceextraction_setpart(struct sourceextraction *e, int i, const char *bas
if( e->failed )
return;
if( endswith(basefilename, bl, ".gz" ) ) {
c = c_gzip;
bl -= 3;
} else if( endswith(basefilename, bl, ".bz2" ) ) {
c = c_bzip2;
bl -= 4;
} else if( endswith(basefilename, bl, ".lzma" ) ) {
c = c_lzma;
bl -= 5;
} else if( endswith(basefilename, bl, ".xz" ) ) {
c = c_xz;
bl -= 3;
} else {
c = c_none;
}
c = compression_by_suffix(basefilename, &bl);
if( endswith(basefilename, bl, ".dsc" ) )
return;
else if( endswith(basefilename, bl, ".diff" ) ) {
......
......@@ -232,23 +232,6 @@ static void changes_free(struct changes *c) {
free(c);
}
static enum compression compression_by_suffix(const char *name, size_t *len_p) {
enum compression c;
size_t len = *len_p;
for( c = c_COUNT - 1 ; c > c_none ; c-- ) {
size_t l = strlen(uncompression_suffix[c]);
if( len <= l )
continue;
if( strncmp(name + len - l, uncompression_suffix[c], l) == 0 ) {
*len_p -= l;
return c;
}
}
return c_none;
}
static struct fileentry *add_fileentry(struct changes *c, const char *basefilename, size_t len, bool source, size_t *ofs_p) {
struct fileentry **fp = &c->files;
struct fileentry *f;
......
......@@ -1135,3 +1135,21 @@ retvalue uncompress_close(struct compressedfile *file) {
free(file);
return r;
}
enum compression compression_by_suffix(const char *name, size_t *len_p) {
enum compression c;
size_t len = *len_p;
for( c = c_COUNT - 1 ; c > c_none ; c-- ) {
size_t l = strlen(uncompression_suffix[c]);
if( len <= l )
continue;
if( strncmp(name + len - l, uncompression_suffix[c], l) == 0 ) {
*len_p -= l;
return c;
}
}
return c_none;
}
......@@ -21,6 +21,8 @@ extern const char * const uncompression_config[c_COUNT];
uncompression_builtin(c) || \
extern_uncompressors[c] != NULL)
enum compression compression_by_suffix(const char *, size_t *);
/**** functions for aptmethod.c ****/
/* we got an pid, check if it is a uncompressor we care for */
......
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