Commit 2311ac4a authored by Bernhard Link's avatar Bernhard Link

stage 1 of referencing of sources rewriting

parent 4a9c25a0
......@@ -296,7 +296,8 @@ static int zexportpackages(int argc,char *argv[]) {
result = packages_dozprintout(dbdir,argv[1],argv[2]);
return EXIT_RET(result);
}
/*
// TODO: needs to be rewritten...
static int removepackage(int argc,char *argv[]) {
retvalue result,r;
DB *pkgs,*refs;
......@@ -347,6 +348,7 @@ static int removepackage(int argc,char *argv[]) {
RET_ENDUPDATE(result,r);
return EXIT_RET(result);
}
*/
/****** reference_{binary,source} *****/
struct referee {
DB *refs;
......@@ -388,7 +390,7 @@ static retvalue reference_source(void *data,const char *package,const char *chun
fprintf(stderr,"referencing source package: %s\n",package);
r = sources_reference(dist->refs,dist->identifier,package,version,dir,&files);
r = sources_reference(dist->refs,dist->identifier,dir,&files);
free(version); free(dir);strlist_done(&files);
return r;
}
......@@ -438,7 +440,7 @@ static retvalue add_source(void *data,const char *chunk,const char *package,cons
}
/* after all is there, reference it */
r = sources_reference(dist->refs,dist->referee,package,version,directory,files);
r = sources_reference(dist->refs,dist->referee,directory,files);
if( RET_WAS_ERROR(r) )
return r;
......@@ -1362,7 +1364,7 @@ static struct action {
{"addpackages", addpackages},
{"_genpackages", exportpackages},
{"_genzpackages", zexportpackages},
{"_removepackage", removepackage},
/* {"_removepackage", removepackage},*/
{"export", export},
{"check", check},
{"rereference", rereference},
......
......@@ -238,81 +238,60 @@ retvalue sources_add(DB *pkgs,const char *component,const char *sources_file, so
return chunk_foreach(sources_file,addsource,&mydata,force,0);
}
/* remove all references by the given chunk */
retvalue sources_dereference(DB *refs,const char *referee,const char *chunk) {
char *directory;
struct strlist files;
char *filename,*filekey;
char *package,*version,*identifier;
retvalue r,result;
retvalue sources_getfilekeys(const char *directory,const struct strlist *files,struct strlist *filekeys) {
int i;
retvalue r;
r = sources_parse_chunk(chunk,&package,&version,&directory,&files);
if( !RET_IS_OK(r) )
assert(directory != NULL && files != NULL);
r = strlist_init_n(files->count,filekeys);
if( RET_WAS_ERROR(r) )
return r;
identifier = mprintf("%s %s %s",referee,package,version);
free(version);free(package);
if( !identifier ) {
free(directory);strlist_done(&files);
return RET_ERROR_OOM;
}
for( i = 0 ; i < files->count ; i++ ) {
char *filekey;
result = RET_NOTHING;
for( i = 0 ; i < files.count ; i++ ) {
r = sources_getfile(files.values[i],&filename,NULL);
if( RET_WAS_ERROR(r) ) {
result = r;
break;
}
filekey = calc_srcfilekey(directory,filename);
if( verbose > 4 ) {
fprintf(stderr,"Decrementing reference for '%s' to '%s'...\n",referee,filekey);
filekey = calc_srcfilekey(directory,files->values[i]);
if( filekey == NULL ) {
strlist_done(filekeys);
return RET_ERROR_OOM;
}
strlist_add(filekeys,filekey);
}
assert( files->count == filekeys->count );
return RET_OK;
}
r = references_decrement(refs,filekey,identifier);
RET_UPDATE(result,r);
/* remove all references by the given chunk */
retvalue sources_dereference(DB *refs,const char *referee,const char *chunk) {
char *directory;
struct strlist files,filekeys;
retvalue r;
free(filename);free(filekey);
}
free(identifier);
free(directory);strlist_done(&files);
r = sources_parse_chunk(chunk,NULL,NULL,&directory,&files);
if( !RET_IS_OK(r) )
return r;
r = sources_getfilekeys(directory,&files,&filekeys);
free(directory);strlist_done(&filekeys);
if( !RET_IS_OK(r) )
return r;
return result;
r = references_delete(refs,referee,&filekeys,NULL);
strlist_done(&filekeys);
return r;
}
/* Add references for the given source */
retvalue sources_reference(DB *refs,const char *referee,const char *package,const char *version,const char *dir,const struct strlist *files) {
char *basefilename,*filekey;
char *identifier;
retvalue r,result;
int i;
retvalue sources_reference(DB *refs,const char *referee,const char *dir,const struct strlist *files) {
struct strlist filekeys;
retvalue r;
identifier = mprintf("%s %s %s",referee,package,version);
if( !identifier ) {
return RET_ERROR_OOM;
}
r = sources_getfilekeys(dir,files,&filekeys);
if( !RET_IS_OK(r) )
return r;
result = RET_NOTHING;
for( i = 0 ; i < files->count ; i++ ) {
r = sources_getfile(files->values[i],&basefilename,NULL);
if( RET_WAS_ERROR(r) ) {
RET_UPDATE(result,r);
break;
}
filekey = calc_srcfilekey(dir,basefilename);
free(basefilename);
if( !filekey) {
free(identifier);
return RET_ERROR_OOM;
}
r = references_increment(refs,filekey,identifier);
free(filekey);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) )
break;
}
free(identifier);
return result;
r = references_insert(refs,referee,&filekeys,NULL);
strlist_done(&filekeys);
return r;
}
......@@ -44,6 +44,6 @@ retvalue sources_add(DB *pkgs,const char *component,const char *sources_file,sou
/* remove all references by the given chunk */
retvalue sources_dereference(DB *refs,const char *referee,const char *chunk);
/* add all references by the given data */
retvalue sources_reference(DB *refs,const char *referee,const char *package,const char *version,const char *dir,const struct strlist *files);
retvalue sources_reference(DB *refs,const char *referee,const char *dir,const struct strlist *files);
#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