diff -Nru reprepro-4.5.0/aclocal.m4 reprepro-4.6.0/aclocal.m4 --- reprepro-4.5.0/aclocal.m4 2011-02-21 15:35:07.000000000 +0000 +++ reprepro-4.6.0/aclocal.m4 2011-05-05 14:52:26.000000000 +0000 @@ -13,8 +13,8 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],, -[m4_warning([this file was generated for autoconf 2.67. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, +[m4_warning([this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) diff -Nru reprepro-4.5.0/aptmethod.c reprepro-4.6.0/aptmethod.c --- reprepro-4.5.0/aptmethod.c 2009-10-30 13:28:21.000000000 +0000 +++ reprepro-4.6.0/aptmethod.c 2011-05-05 14:42:55.000000000 +0000 @@ -61,20 +61,25 @@ char *baseuri; /*@null@*/char *fallbackbaseuri; /*@null@*/char *config; - int mstdin,mstdout; + int mstdin, mstdout; pid_t child; - enum { ams_notstarted=0, ams_waitforcapabilities, ams_ok, ams_failed } status; + enum { + ams_notstarted=0, + ams_waitforcapabilities, + ams_ok, + ams_failed + } status; /*@null@*/struct tobedone *tobedone; /*@null@*//*@dependent@*/struct tobedone *lasttobedone; /*@null@*//*@dependent@*/const struct tobedone *nexttosend; /* what is currently read: */ /*@null@*/char *inputbuffer; - size_t input_size,alreadyread; + size_t input_size, alreadyread; /* What is currently written: */ /*@null@*/char *command; - size_t alreadywritten,output_length; + size_t alreadywritten, output_length; }; struct aptmethodrun { @@ -89,7 +94,7 @@ static void free_todolist(/*@only@*/ struct tobedone *todo) { - while( todo != NULL ) { + while (todo != NULL) { struct tobedone *h = todo->next; todo_free(todo); @@ -98,7 +103,7 @@ } static void aptmethod_free(/*@only@*/struct aptmethod *method) { - if( method == NULL ) + if (method == NULL) return; free(method->name); free(method->baseuri); @@ -114,15 +119,16 @@ retvalue aptmethod_shutdown(struct aptmethodrun *run) { retvalue result = RET_OK, r; - struct aptmethod *method,*lastmethod,**method_ptr; + struct aptmethod *method, *lastmethod, **method_ptr; /* first get rid of everything not running: */ method_ptr = &run->methods; - while( *method_ptr != NULL ) { + while (*method_ptr != NULL) { - if( (*method_ptr)->child > 0 ) { - if( verbose > 10 ) - fprintf(stderr,"Still waiting for %d\n",(int)(*method_ptr)->child); + if ((*method_ptr)->child > 0) { + if (verbose > 10) + fprintf(stderr, +"Still waiting for %d\n", (int)(*method_ptr)->child); method_ptr = &(*method_ptr)->next; continue; } else { @@ -135,32 +141,32 @@ } /* finally get rid of all the processes: */ - for( method = run->methods ; method != NULL ; method = method->next ) { - if( method->mstdin >= 0 ) { + for (method = run->methods ; method != NULL ; method = method->next) { + if (method->mstdin >= 0) { (void)close(method->mstdin); - if( verbose > 30 ) + if (verbose > 30) fprintf(stderr, "Closing stdin of %d\n", (int)method->child); } method->mstdin = -1; - if( method->mstdout >= 0 ) { + if (method->mstdout >= 0) { (void)close(method->mstdout); - if( verbose > 30 ) + if (verbose > 30) fprintf(stderr, "Closing stdout of %d\n", (int)method->child); } method->mstdout = -1; } - while( run->methods != NULL || uncompress_running() ) { + while (run->methods != NULL || uncompress_running()) { pid_t pid;int status; pid = wait(&status); lastmethod = NULL; method = run->methods; - while( method != NULL ) { - if( method->child == pid ) { + while (method != NULL) { + if (method->child == pid) { struct aptmethod *next = method->next; - if( lastmethod != NULL ) { + if (lastmethod != NULL) { lastmethod->next = next; } else run->methods = next; @@ -173,7 +179,7 @@ method = method->next; } } - if( pid > 0 ) { + if (pid > 0) { r = uncompress_checkpid(pid, status); RET_UPDATE(result, r); } @@ -187,64 +193,64 @@ retvalue aptmethod_initialize_run(struct aptmethodrun **run) { struct aptmethodrun *r; - r = calloc(1,sizeof(struct aptmethodrun)); - if( r == NULL ) + r = zNEW(struct aptmethodrun); + if (FAILEDTOALLOC(r)) return RET_ERROR_OOM; - else { - *run = r; - return RET_OK; - } + *run = r; + return RET_OK; } retvalue aptmethod_newmethod(struct aptmethodrun *run, const char *uri, const char *fallbackuri, const struct strlist *config, struct aptmethod **m) { struct aptmethod *method; const char *p; - method = calloc(1,sizeof(struct aptmethod)); - if( method == NULL ) + method = zNEW(struct aptmethod); + if (FAILEDTOALLOC(method)) return RET_ERROR_OOM; method->mstdin = -1; method->mstdout = -1; method->child = -1; method->status = ams_notstarted; p = uri; - while( *p != '\0' && ( *p == '_' || *p == '-' || + while (*p != '\0' && (*p == '_' || *p == '-' || (*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || - (*p>='0' && *p<='9') ) ) { + (*p>='0' && *p<='9'))) { p++; } - if( *p == '\0' ) { + if (*p == '\0') { fprintf(stderr, "No colon found in method-URI '%s'!\n", uri); free(method); return RET_ERROR; } - if( *p != ':' ) { - fprintf(stderr,"Unexpected character '%c' in method-URI '%s'!\n",*p,uri); + if (*p != ':') { + fprintf(stderr, +"Unexpected character '%c' in method-URI '%s'!\n", *p, uri); free(method); return RET_ERROR; } - if( p == uri ) { - fprintf(stderr,"Zero-length name in method-URI '%s'!\n",uri); + if (p == uri) { + fprintf(stderr, +"Zero-length name in method-URI '%s'!\n", uri); free(method); return RET_ERROR; } - method->name = strndup(uri,p-uri); - if( method->name == NULL ) { + method->name = strndup(uri, p-uri); + if (FAILEDTOALLOC(method->name)) { free(method); return RET_ERROR_OOM; } method->baseuri = strdup(uri); - if( method->baseuri == NULL ) { + if (FAILEDTOALLOC(method->baseuri)) { free(method->name); free(method); return RET_ERROR_OOM; } - if( fallbackuri == NULL ) + if (fallbackuri == NULL) method->fallbackbaseuri = NULL; else { method->fallbackbaseuri = strdup(fallbackuri); - if( method->fallbackbaseuri == NULL ) { + if (FAILEDTOALLOC(method->fallbackbaseuri)) { free(method->baseuri); free(method->name); free(method); @@ -253,12 +259,12 @@ } #define CONF601 "601 Configuration" #define CONFITEM "\nConfig-Item: " - if( config->count == 0 ) + if (config->count == 0) method->config = strdup(CONF601 CONFITEM "Dir=/" "\n\n"); else method->config = strlist_concat(config, CONF601 CONFITEM, CONFITEM, "\n\n"); - if( method->config == NULL ) { + if (FAILEDTOALLOC(method->config)) { free(method->fallbackbaseuri); free(method->baseuri); free(method->name); @@ -281,26 +287,26 @@ /* When there is nothing to get, there is no reason to startup * the method. */ - if( method->tobedone == NULL ) { + if (method->tobedone == NULL) { return RET_NOTHING; } /* when we are already running, we are already ready...*/ - if( method->child > 0 ) { + if (method->child > 0) { return RET_OK; } method->status = ams_waitforcapabilities; r = pipe(mstdin); - if( r < 0 ) { + if (r < 0) { int e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); return RET_ERRNO(e); } r = pipe(mstdout); - if( r < 0 ) { + if (r < 0) { int e = errno; (void)close(mstdin[0]); (void)close(mstdin[1]); fprintf(stderr, "Error %d in pipe syscall: %s\n", @@ -308,13 +314,13 @@ return RET_ERRNO(e); } - if( interrupted() ) { + if (interrupted()) { (void)close(mstdin[0]);(void)close(mstdin[1]); (void)close(mstdout[0]);(void)close(mstdout[1]); return RET_ERROR_INTERRUPTED; } f = fork(); - if( f < 0 ) { + if (f < 0) { int e = errno; (void)close(mstdin[0]); (void)close(mstdin[1]); (void)close(mstdout[0]); (void)close(mstdout[1]); @@ -322,19 +328,19 @@ e, strerror(e)); return RET_ERRNO(e); } - if( f == 0 ) { + if (f == 0) { char *methodname; int e; /* child: */ (void)close(mstdin[1]); (void)close(mstdout[0]); - if( dup2(mstdin[0],0) < 0 ) { + if (dup2(mstdin[0], 0) < 0) { e = errno; fprintf(stderr, "Error %d while setting stdin: %s\n", e, strerror(e)); exit(255); } - if( dup2(mstdout[1],1) < 0 ) { + if (dup2(mstdout[1], 1) < 0) { e = errno; fprintf(stderr, "Error %d while setting stdout: %s\n", e, strerror(e)); @@ -343,7 +349,7 @@ closefrom(3); methodname = calc_dirconcat(global.methoddir, method->name); - if( FAILEDTOALLOC(methodname) ) + if (FAILEDTOALLOC(methodname)) exit(255); /* not really useful here, unless someone write reprepro @@ -362,8 +368,9 @@ } /* the main program continues... */ method->child = f; - if( verbose > 10 ) - fprintf(stderr,"Method '%s' started as %d\n",method->baseuri,(int)f); + if (verbose > 10) + fprintf(stderr, +"Method '%s' started as %d\n", method->baseuri, (int)f); (void)close(mstdin[0]); (void)close(mstdout[1]); markcloseonexec(mstdin[1]); @@ -383,12 +390,12 @@ static inline void enqueue(struct aptmethod *method, /*@only@*/struct tobedone *todo) { todo->next = NULL; - if( method->lasttobedone == NULL ) + if (method->lasttobedone == NULL) method->nexttosend = method->lasttobedone = method->tobedone = todo; else { method->lasttobedone->next = todo; method->lasttobedone = todo; - if( method->nexttosend == NULL ) + if (method->nexttosend == NULL) method->nexttosend = todo; } } @@ -396,17 +403,17 @@ static retvalue enqueuenew(struct aptmethod *method, /*@only@*/char *uri, /*@only@*/char *destfile, queue_callback *callback, void *privdata1, void *privdata2) { struct tobedone *todo; - if( FAILEDTOALLOC(destfile) ) { + if (FAILEDTOALLOC(destfile)) { free(uri); return RET_ERROR_OOM; } - if( FAILEDTOALLOC(uri) ) { + if (FAILEDTOALLOC(uri)) { free(destfile); return RET_ERROR_OOM; } - todo = malloc(sizeof(struct tobedone)); - if( FAILEDTOALLOC(todo) ) { + todo = NEW(struct tobedone); + if (FAILEDTOALLOC(todo)) { free(uri); free(destfile); return RET_ERROR_OOM; } @@ -441,8 +448,8 @@ static retvalue requeue_or_fail(struct aptmethod *method, /*@only@*/struct tobedone *todo) { retvalue r; - if( todo->lasttry ) { - if( todo->callback == NULL ) + if (todo->lasttry) { + if (todo->callback == NULL) r = RET_ERROR; else r = todo->callback(qa_error, @@ -455,13 +462,13 @@ size_t l, old_len, new_len; char *s; - assert( method->fallbackbaseuri != NULL ); + assert (method->fallbackbaseuri != NULL); old_len = strlen(method->baseuri); new_len = strlen(method->fallbackbaseuri); l = strlen(todo->uri); s = malloc(l+new_len+1-old_len); - if( FAILEDTOALLOC(s) ) { + if (FAILEDTOALLOC(s)) { todo_free(todo); return RET_ERROR_OOM; } @@ -476,27 +483,28 @@ } /* look which file could not be received and remove it: */ -static retvalue urierror(struct aptmethod *method,const char *uri,/*@only@*/char *message) { - struct tobedone *todo,*lasttodo; +static retvalue urierror(struct aptmethod *method, const char *uri, /*@only@*/char *message) { + struct tobedone *todo, *lasttodo; lasttodo = NULL; todo = method->tobedone; - while( todo != NULL ) { - if( strcmp(todo->uri,uri) == 0) { + while (todo != NULL) { + if (strcmp(todo->uri, uri) == 0) { /* remove item: */ - if( lasttodo == NULL ) + if (lasttodo == NULL) method->tobedone = todo->next; else lasttodo->next = todo->next; - if( method->nexttosend == todo ) { + if (method->nexttosend == todo) { /* just in case some method received * files before we request them ;-) */ method->nexttosend = todo->next; } - if( method->lasttobedone == todo ) { + if (method->lasttobedone == todo) { method->lasttobedone = todo->next; } - fprintf(stderr,"aptmethod error receiving '%s':\n'%s'\n", + fprintf(stderr, +"aptmethod error receiving '%s':\n'%s'\n", uri, (message != NULL)?message:""); /* put message in failed items to show it later? */ free(message); @@ -506,7 +514,8 @@ todo = todo->next; } /* huh? If if have not asked for it, how can there be errors? */ - fprintf(stderr, "Method '%s' reported error with unrequested file '%s':\n'%s'!\n", + fprintf(stderr, +"Method '%s' reported error with unrequested file '%s':\n'%s'!\n", method->name, uri, message); free(message); return RET_ERROR; @@ -514,12 +523,12 @@ /* look where a received file has to go to: */ static retvalue uridone(struct aptmethod *method, const char *uri, const char *filename, /*@only@*//*@null@*/struct checksums *checksumsfromapt) { - struct tobedone *todo,*lasttodo; + struct tobedone *todo, *lasttodo; retvalue r; lasttodo = NULL; todo = method->tobedone; - while( todo != NULL ) { - if( strcmp(todo->uri,uri) != 0) { + while (todo != NULL) { + if (strcmp(todo->uri, uri) != 0) { lasttodo = todo; todo = todo->next; continue; @@ -532,73 +541,76 @@ checksums_free(checksumsfromapt); /* remove item: */ - if( lasttodo == NULL ) + if (lasttodo == NULL) method->tobedone = todo->next; else lasttodo->next = todo->next; - if( method->nexttosend == todo ) { + if (method->nexttosend == todo) { /* just in case some method received * files before we request them ;-) */ method->nexttosend = todo->next; } - if( method->lasttobedone == todo ) { + if (method->lasttobedone == todo) { method->lasttobedone = todo->next; } todo_free(todo); return r; } /* huh? */ - fprintf(stderr, "Method '%s' retrieved unexpected file '%s' at '%s'!\n", + fprintf(stderr, +"Method '%s' retrieved unexpected file '%s' at '%s'!\n", method->name, uri, filename); checksums_free(checksumsfromapt); return RET_ERROR; } /***************************Input and Output****************************/ -static retvalue logmessage(const struct aptmethod *method,const char *chunk,const char *type) { +static retvalue logmessage(const struct aptmethod *method, const char *chunk, const char *type) { retvalue r; char *message; - r = chunk_getvalue(chunk,"Message",&message); - if( RET_WAS_ERROR(r) ) + r = chunk_getvalue(chunk, "Message", &message); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { - fprintf(stderr,"aptmethod '%s': '%s'\n",method->baseuri,message); + if (RET_IS_OK(r)) { + fprintf(stderr, "aptmethod '%s': '%s'\n", + method->baseuri, message); free(message); return RET_OK; } - r = chunk_getvalue(chunk,"URI",&message); - if( RET_WAS_ERROR(r) ) + r = chunk_getvalue(chunk, "URI", &message); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { - fprintf(stderr,"aptmethod %s '%s'\n",type,message); + if (RET_IS_OK(r)) { + fprintf(stderr, "aptmethod %s '%s'\n", type, message); free(message); return RET_OK; } - fprintf(stderr,"aptmethod '%s': '%s'\n",method->baseuri,type); + fprintf(stderr, "aptmethod '%s': '%s'\n", method->baseuri, type); return RET_OK; } -static inline retvalue gotcapabilities(struct aptmethod *method,const char *chunk) { +static inline retvalue gotcapabilities(struct aptmethod *method, const char *chunk) { retvalue r; - r = chunk_gettruth(chunk,"Single-Instance"); - if( RET_WAS_ERROR(r) ) + r = chunk_gettruth(chunk, "Single-Instance"); + if (RET_WAS_ERROR(r)) return r; // TODO: what to do with this? -// if( r != RET_NOTHING ) { -// fprintf(stderr,"WARNING: Single-instance not yet supported!\n"); +// if (r != RET_NOTHING) { +// fprintf(stderr, "WARNING: Single-instance not yet supported!\n"); // } - r = chunk_gettruth(chunk,"Send-Config"); - if( RET_WAS_ERROR(r) ) + r = chunk_gettruth(chunk, "Send-Config"); + if (RET_WAS_ERROR(r)) return r; - if( r != RET_NOTHING ) { + if (r != RET_NOTHING) { assert(method->command == NULL); method->alreadywritten = 0; method->command = method->config; method->config = NULL; method->output_length = strlen(method->command); - if( verbose > 11 ) { - fprintf(stderr,"Sending config: '%s'\n",method->command); + if (verbose > 11) { + fprintf(stderr, "Sending config: '%s'\n", + method->command); } } else { free(method->config); @@ -620,27 +632,28 @@ //TODO: is it worth the mess to make this in-situ? - r = chunk_getvalue(chunk,"URI",&uri); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "URI", &uri); + if (r == RET_NOTHING) { fprintf(stderr, "Missing URI header in uridone received from '%s' method!\n", method->name); r = RET_ERROR; method->status = ams_failed; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - r = chunk_getvalue(chunk,"Filename",&filename); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "Filename", &filename); + if (r == RET_NOTHING) { char *altfilename; r = chunk_getvalue(chunk, "Alt-Filename", &altfilename); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Missing Filename header in uridone received from '%s' method!\n", method->name); - r = urierror(method, uri, strdup("")); + r = urierror(method, uri, strdup( +"")); } else { r = urierror(method, uri, mprintf( "", altfilename)); @@ -649,65 +662,65 @@ free(uri); return r; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(uri); return r; } - if( verbose >= 1 ) + if (verbose >= 1) fprintf(stderr, "aptmethod got '%s'\n", uri); result = RET_NOTHING; - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) { + for (type = cs_md5sum ; type < cs_COUNT ; type++) { hashes[type] = NULL; r = chunk_getvalue(chunk, method_hash_names[type], &hashes[type]); RET_UPDATE(result, r); } - if( RET_IS_OK(result) && hashes[cs_md5sum] == NULL ) { + if (RET_IS_OK(result) && hashes[cs_md5sum] == NULL) { /* the lenny version also has this, better ask for * in case the old MD5-Hash vanishes in the future */ r = chunk_getvalue(chunk, "MD5Sum-Hash", &hashes[cs_md5sum]); RET_UPDATE(result, r); } - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { free(uri); free(filename); - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); return result; } - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { /* ignore errors, we can recompute them from the file */ (void)checksums_init(&checksums, hashes); } - r = uridone(method, uri, filename, checksums); + r = uridone(method, uri, filename, checksums); free(uri); free(filename); return r; } -static inline retvalue goturierror(struct aptmethod *method,const char *chunk) { +static inline retvalue goturierror(struct aptmethod *method, const char *chunk) { retvalue r; - char *uri,*message; + char *uri, *message; - r = chunk_getvalue(chunk,"URI",&uri); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "URI", &uri); + if (r == RET_NOTHING) { fprintf(stderr, "Missing URI header in urierror received from '%s' method!\n", method->name); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - r = chunk_getvalue(chunk,"Message",&message); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "Message", &message); + if (r == RET_NOTHING) { message = NULL; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(uri); return r; } - r = urierror(method,uri,message); + r = urierror(method, uri, message); free(uri); return r; } @@ -715,52 +728,54 @@ static inline retvalue parsereceivedblock(struct aptmethod *method, const char *input) { const char *p; retvalue r; -#define OVERLINE {while( *p != '\0' && *p != '\n') p++; if(*p == '\n') p++; } +#define OVERLINE {while (*p != '\0' && *p != '\n') p++; if (*p == '\n') p++; } - while( *input == '\n' || *input == '\r' ) + while (*input == '\n' || *input == '\r') input++; - if( *input == '\0' ) { + if (*input == '\0') { fprintf(stderr, "Unexpected number of newlines from '%s' method!\n", method->name); return RET_NOTHING; } p = input; - switch( (*(input+1)=='0')?*input:'\0' ) { + switch ((*(input+1)=='0')?*input:'\0') { case '1': - switch( *(input+2) ) { + switch (*(input+2)) { /* 100 Capabilities */ case '0': OVERLINE; - if( verbose > 14 ) { - fprintf(stderr,"Got '%s'\n",input); + if (verbose > 14) { + fprintf(stderr, "Got '%s'\n", + input); } - return gotcapabilities(method,input); + return gotcapabilities(method, input); /* 101 Log */ case '1': - if( verbose > 10 ) { + if (verbose > 10) { OVERLINE; - return logmessage(method,p,"101"); + return logmessage(method, p, "101"); } return RET_OK; /* 102 Status */ case '2': - if( verbose > 5 ) { + if (verbose > 5) { OVERLINE; - return logmessage(method,p,"102"); + return logmessage(method, p, "102"); } return RET_OK; default: fprintf(stderr, -"Error or unsupported message received: '%s'\n", input); +"Error or unsupported message received: '%s'\n", + input); return RET_ERROR; } case '2': - switch( *(input+2) ) { + switch (*(input+2)) { /* 200 URI Start */ case '0': - if( verbose > 5 ) { + if (verbose > 5) { OVERLINE; - return logmessage(method,p,"start"); + return logmessage(method, p, "start"); } return RET_OK; /* 201 URI Done */ @@ -769,32 +784,35 @@ return goturidone(method, p); default: fprintf(stderr, -"Error or unsupported message received: '%s'\n", input); +"Error or unsupported message received: '%s'\n", + input); return RET_ERROR; } case '4': - switch( *(input+2) ) { + switch (*(input+2)) { case '0': OVERLINE; - r = goturierror(method,p); + r = goturierror(method, p); break; case '1': OVERLINE; - (void)logmessage(method,p,"general error"); + (void)logmessage(method, p, "general error"); method->status = ams_failed; r = RET_ERROR; break; default: fprintf(stderr, -"Error or unsupported message received: '%s'\n", input); +"Error or unsupported message received: '%s'\n", + input); r = RET_ERROR; } /* a failed download is not a error yet, as it might * be redone from another source later */ return r; default: - fprintf(stderr, "Unexpected data from '%s' method: '%s'\n", + fprintf(stderr, +"Unexpected data from '%s' method: '%s'\n", method->name, input); return RET_ERROR; } @@ -806,33 +824,36 @@ char *p; int consecutivenewlines; - assert( method->status != ams_ok || method->tobedone != NULL ); - if( method->status != ams_waitforcapabilities && method->status != ams_ok ) + assert (method->status != ams_ok || method->tobedone != NULL); + if (method->status != ams_waitforcapabilities + && method->status != ams_ok) return RET_NOTHING; /* First look if we have enough room to read.. */ - if( method->alreadyread + 1024 >= method->input_size ) { + if (method->alreadyread + 1024 >= method->input_size) { char *newptr; - if( method->input_size >= (size_t)128000 ) { - fprintf(stderr, "Ridiculously long answer from method!\n"); + if (method->input_size >= (size_t)128000) { + fprintf(stderr, +"Ridiculously long answer from method!\n"); method->status = ams_failed; return RET_ERROR; } - newptr = realloc(method->inputbuffer,method->alreadyread+1024); - if( newptr == NULL ) { + newptr = realloc(method->inputbuffer, method->alreadyread+1024); + if (FAILEDTOALLOC(newptr)) { return RET_ERROR_OOM; } method->inputbuffer = newptr; method->input_size = method->alreadyread + 1024; } - assert( method->inputbuffer != NULL ); + assert (method->inputbuffer != NULL); /* then read as much as the pipe is able to fill of our buffer */ - r = read(method->mstdout,method->inputbuffer+method->alreadyread,method->input_size-method->alreadyread-1); + r = read(method->mstdout, method->inputbuffer + method->alreadyread, + method->input_size - method->alreadyread - 1); - if( r < 0 ) { + if (r < 0) { int e = errno; fprintf(stderr, "Error %d reading pipe from aptmethod: %s\n", e, strerror(e)); @@ -849,29 +870,30 @@ p = method->inputbuffer; consecutivenewlines = 0; - while( r > 0 ) { - if( *p == '\0' ) { - fprintf(stderr, "Unexpected Zeroes in method output!\n"); + while (r > 0) { + if (*p == '\0') { + fprintf(stderr, +"Unexpected Zeroes in method output!\n"); method->status = ams_failed; return RET_ERROR; - } else if( *p == '\n' ) { + } else if (*p == '\n') { consecutivenewlines++; - if( consecutivenewlines >= 2 ) + if (consecutivenewlines >= 2) break; - } else if( *p != '\r' ) { + } else if (*p != '\r') { consecutivenewlines = 0; } p++; r--; } - if( r <= 0 ) { + if (r <= 0) { return result; } *p ='\0'; p++; r--; res = parsereceivedblock(method, method->inputbuffer); - if( r > 0 ) - memmove(method->inputbuffer,p,r); + if (r > 0) + memmove(method->inputbuffer, p, r); method->alreadyread = r; - RET_UPDATE(result,res); + RET_UPDATE(result, res); } } @@ -879,33 +901,34 @@ size_t l; ssize_t r; - if( method->status != ams_ok ) + if (method->status != ams_ok) return RET_NOTHING; - if( method->command == NULL ) { + if (method->command == NULL) { const struct tobedone *todo; /* nothing queued to send, nothing to be queued...*/ todo = method->nexttosend; - if( todo == NULL ) + if (todo == NULL) return RET_OK; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; method->alreadywritten = 0; // TODO: make sure this is already checked for earlier... - assert( strchr(todo->uri, '\n') == NULL && - strchr(todo->filename,'\n') == NULL ); - /* http-aptmethod seems to loose the last byte if the file is already - * in place, so we better unlink the target first... + assert (strchr(todo->uri, '\n') == NULL && + strchr(todo->filename, '\n') == NULL); + /* http-aptmethod seems to loose the last byte, + * if the file is already in place, + * so we better unlink the target first... * but this is done elsewhere already unlink(todo->filename); */ method->command = mprintf( "600 URI Acquire\nURI: %s\nFilename: %s\n\n", todo->uri, todo->filename); - if( method->command == NULL ) { + if (FAILEDTOALLOC(method->command)) { return RET_ERROR_OOM; } method->output_length = strlen(method->command); @@ -915,8 +938,8 @@ l = method->output_length - method->alreadywritten; - r = write(method->mstdin,method->command+method->alreadywritten,l); - if( r < 0 ) { + r = write(method->mstdin, method->command + method->alreadywritten, l); + if (r < 0) { int e = errno; fprintf(stderr, "Error %d writing to pipe: %s\n", @@ -924,7 +947,7 @@ //TODO: disable the whole method?? method->status = ams_failed; return RET_ERRNO(e); - } else if( (size_t)r < l ) { + } else if ((size_t)r < l) { method->alreadywritten += r; return RET_OK; } @@ -938,48 +961,49 @@ pid_t child;int status; retvalue result = RET_OK, r; - while( (child = waitpid(-1,&status,WNOHANG)) > 0 ) { + while ((child = waitpid(-1, &status, WNOHANG)) > 0) { struct aptmethod *method; - for( method = run->methods; method != NULL ; method = method->next) { - if( method->child == child ) + for (method = run->methods ; method != NULL ; + method = method->next) { + if (method->child == child) break; } - if( method == NULL ) { + if (method == NULL) { /* perhaps an uncompressor terminated */ r = uncompress_checkpid(child, status); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) continue; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; continue; } else { fprintf(stderr, - "Unexpected child died (maybe gpg died if signing/verifing was done): %d\n", +"Unexpected child died (maybe gpg died if signing/verifing was done): %d\n", (int)child); continue; } } /* Make sure we do not cope with this child any more */ - if( method->mstdin != -1 ) { + if (method->mstdin != -1) { (void)close(method->mstdin); method->mstdin = -1; } - if( method->mstdout != -1 ) { + if (method->mstdout != -1) { (void)close(method->mstdout); method->mstdout = -1; } method->child = -1; - if( method->status != ams_failed ) + if (method->status != ams_failed) method->status = ams_notstarted; /* say something if it exited unnormal: */ - if( WIFEXITED(status) ) { + if (WIFEXITED(status)) { int exitcode; exitcode = WEXITSTATUS(status); - if( exitcode != 0 ) { + if (exitcode != 0) { fprintf(stderr, "Method %s://%s exited with non-zero exit code %d!\n", method->name, method->baseuri, @@ -988,7 +1012,8 @@ result = RET_ERROR; } } else { - fprintf(stderr,"Method %s://%s exited unnormally!\n",method->name,method->baseuri); + fprintf(stderr, "Method %s://%s exited unnormally!\n", + method->name, method->baseuri); method->status = ams_notstarted; result = RET_ERROR; } @@ -996,46 +1021,49 @@ return result; } -/* *workleft is always set, even when return indicated error. (workleft < 0 when critical)*/ +/* *workleft is always set, even when return indicated error. + * (workleft < 0 when critical)*/ static retvalue readwrite(struct aptmethodrun *run, /*@out@*/int *workleft) { - int maxfd,v; - fd_set readfds,writefds; + int maxfd, v; + fd_set readfds, writefds; struct aptmethod *method; - retvalue result,r; + retvalue result, r; /* First calculate what to look at: */ FD_ZERO(&readfds); FD_ZERO(&writefds); maxfd = 0; *workleft = 0; - for( method = run->methods ; method != NULL ; method = method->next ) { - if( method->status == ams_ok && - ( method->command != NULL || method->nexttosend != NULL )) { - FD_SET(method->mstdin,&writefds); - if( method->mstdin > maxfd ) + for (method = run->methods ; method != NULL ; method = method->next) { + if (method->status == ams_ok && + (method->command != NULL || method->nexttosend != NULL)) { + FD_SET(method->mstdin, &writefds); + if (method->mstdin > maxfd) maxfd = method->mstdin; (*workleft)++; - if( verbose > 19 ) - fprintf(stderr,"want to write to '%s'\n",method->baseuri); + if (verbose > 19) + fprintf(stderr, "want to write to '%s'\n", + method->baseuri); } - if( method->status == ams_waitforcapabilities || + if (method->status == ams_waitforcapabilities || (method->status == ams_ok && - method->tobedone != NULL ) ) { - FD_SET(method->mstdout,&readfds); - if( method->mstdout > maxfd ) + method->tobedone != NULL)) { + FD_SET(method->mstdout, &readfds); + if (method->mstdout > maxfd) maxfd = method->mstdout; (*workleft)++; - if( verbose > 19 ) - fprintf(stderr,"want to read from '%s'\n",method->baseuri); + if (verbose > 19) + fprintf(stderr, "want to read from '%s'\n", + method->baseuri); } } - if( *workleft == 0 ) + if (*workleft == 0) return RET_NOTHING; // TODO: think about a timeout... - v = select(maxfd+1,&readfds,&writefds,NULL,NULL); - if( v < 0 ) { + v = select(maxfd + 1, &readfds, &writefds, NULL, NULL); + if (v < 0) { int e = errno; //TODO: handle (e == EINTR) && interrupted() specially fprintf(stderr, "Select returned error %d: %s\n", @@ -1048,14 +1076,16 @@ result = RET_NOTHING; maxfd = 0; - for( method = run->methods ; method != NULL ; method = method->next ) { - if( method->mstdout != -1 && FD_ISSET(method->mstdout,&readfds) ) { + for (method = run->methods ; method != NULL ; method = method->next) { + if (method->mstdout != -1 && + FD_ISSET(method->mstdout, &readfds)) { r = receivedata(method); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - if( method->mstdin != -1 && FD_ISSET(method->mstdin,&writefds) ) { + if (method->mstdin != -1 && + FD_ISSET(method->mstdin, &writefds)) { r = senddata(method); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } } return result; @@ -1063,28 +1093,28 @@ retvalue aptmethod_download(struct aptmethodrun *run) { struct aptmethod *method; - retvalue result,r; + retvalue result, r; int workleft; result = RET_NOTHING; /* fire up all methods, removing those that do not work: */ - for( method = run->methods; method != NULL ; method = method->next ) { + for (method = run->methods; method != NULL ; method = method->next) { r = aptmethod_startup(method); /* do not remove failed methods here any longer, * and not remove methods having nothing to do, * as this breaks when no index files are downloaded * due to all already being in place... */ - RET_UPDATE(result,r); + RET_UPDATE(result, r); } /* waiting for them to finish: */ do { r = checkchilds(run); - RET_UPDATE(result,r); + RET_UPDATE(result, r); r = readwrite(run, &workleft); - RET_UPDATE(result,r); + RET_UPDATE(result, r); // TODO: check interrupted here... - } while( workleft > 0 || uncompress_running() ); + } while (workleft > 0 || uncompress_running()); return result; } diff -Nru reprepro-4.5.0/aptmethod.h reprepro-4.6.0/aptmethod.h --- reprepro-4.5.0/aptmethod.h 2009-06-02 17:47:10.000000000 +0000 +++ reprepro-4.6.0/aptmethod.h 2011-05-05 14:42:55.000000000 +0000 @@ -13,13 +13,13 @@ enum queue_action { qa_abort, qa_got, qa_error }; -typedef retvalue queue_callback(enum queue_action, void *privdata, void *privdata2, const char *uri, const char *gotfilename, const char *wantedfilename, /*@null@*/const struct checksums *, const char *methodname); +typedef retvalue queue_callback(enum queue_action, void *, void *, const char * /*uri*/, const char * /*gotfilename*/, const char * /*wantedfilename*/, /*@null@*/const struct checksums *, const char * /*methodname*/); -retvalue aptmethod_initialize_run(/*@out@*/struct aptmethodrun **run); -retvalue aptmethod_newmethod(struct aptmethodrun *, const char *uri, const char *fallbackuri, const struct strlist *config, /*@out@*/struct aptmethod **); +retvalue aptmethod_initialize_run(/*@out@*/struct aptmethodrun **); +retvalue aptmethod_newmethod(struct aptmethodrun *, const char * /*uri*/, const char * /*fallbackuri*/, const struct strlist * /*config*/, /*@out@*/struct aptmethod **); -retvalue aptmethod_enqueue(struct aptmethod *, const char *origfile, /*@only@*/char *destfile, queue_callback *, void *, void *); -retvalue aptmethod_enqueueindex(struct aptmethod *, const char *suite, const char *origfile, const char *, const char *destfile, const char *, queue_callback *, void *, void *); +retvalue aptmethod_enqueue(struct aptmethod *, const char * /*origfile*/, /*@only@*/char */*destfile*/, queue_callback *, void *, void *); +retvalue aptmethod_enqueueindex(struct aptmethod *, const char * /*suite*/, const char * /*origfile*/, const char *, const char * /*destfile*/, const char *, queue_callback *, void *, void *); retvalue aptmethod_download(struct aptmethodrun *); retvalue aptmethod_shutdown(/*@only@*/struct aptmethodrun *); diff -Nru reprepro-4.5.0/ar.c reprepro-4.6.0/ar.c --- reprepro-4.5.0/ar.c 2008-11-04 10:12:20.000000000 +0000 +++ reprepro-4.6.0/ar.c 2011-05-05 14:42:55.000000000 +0000 @@ -61,21 +61,21 @@ totalread = 0; - while( count > 0 ) { + while (count > 0) { ssize_t s; - s = read(fd,buf,count); - if( s < 0 ) + s = read(fd, buf, count); + if (s < 0) return s; - if( interrupted() ) { + if (interrupted()) { errno = EINTR; return -1; } - if( (size_t)s > count ) { + if ((size_t)s > count) { errno = EINVAL; return -1; } - if( s == 0 ) + if (s == 0) break; totalread += s; buf += s; @@ -89,13 +89,13 @@ char buffer[sizeof(AR_MAGIC)]; ssize_t bytesread; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - ar = calloc(1,sizeof(struct ar_archive)); - if( ar == NULL ) + ar = zNEW(struct ar_archive); + if (FAILEDTOALLOC(ar)) return RET_ERROR_OOM; - ar->fd = open(filename,O_NOCTTY|O_RDONLY); - if( ar->fd < 0 ) { + ar->fd = open(filename, O_NOCTTY|O_RDONLY); + if (ar->fd < 0) { int e = errno; fprintf(stderr, "Error %d opening %s: %s\n", e, filename, strerror(e)); @@ -103,28 +103,31 @@ return RET_ERRNO(e); } - bytesread = readwait(ar->fd,buffer,sizeof(AR_MAGIC)-1); - if( bytesread != sizeof(AR_MAGIC)-1 ) { + bytesread = readwait(ar->fd, buffer, sizeof(AR_MAGIC) - 1); + if (bytesread != sizeof(AR_MAGIC)-1) { int e = errno; (void)close(ar->fd); free(ar); - if( bytesread < 0 ) { + if (bytesread < 0) { fprintf(stderr, "Error %d reading from %s: %s\n", e, filename, strerror(e)); return RET_ERRNO(e); } else { - fprintf(stderr,"Premature end of reading from %s\n",filename); + fprintf(stderr, "Premature end of reading from %s\n", + filename); return RET_ERROR; } } - if( memcmp(buffer,AR_MAGIC,sizeof(AR_MAGIC)-1) != 0 ) { + if (memcmp(buffer, AR_MAGIC, sizeof(AR_MAGIC)-1) != 0) { (void)close(ar->fd); free(ar); - fprintf(stderr, "Missing ar header '!' at the beginning of %s\n", filename); + fprintf(stderr, +"Missing ar header '!' at the beginning of %s\n", + filename); return RET_ERROR; } ar->filename = strdup(filename); - if( ar->filename == NULL ) { + if (FAILEDTOALLOC(ar->filename)) { close(ar->fd); free(ar); return RET_ERROR_OOM; @@ -136,8 +139,8 @@ } void ar_close(/*@only@*/struct ar_archive *ar) { - if( ar != NULL ) { - if( ar->fd >= 0 ) + if (ar != NULL) { + if (ar->fd >= 0) (void)close(ar->fd); free(ar->filename); free(ar); @@ -145,7 +148,7 @@ } /* RET_OK = next is there, RET_NOTHING = eof, < 0 = error */ -retvalue ar_nextmember(struct ar_archive *ar,/*@out@*/char **filename) { +retvalue ar_nextmember(struct ar_archive *ar, /*@out@*/char **filename) { ssize_t bytesread; char *p; off_t s; @@ -155,25 +158,26 @@ /* seek over what is left from the last part: */ s = lseek(ar->fd, ar->next_position, SEEK_SET); - if( s == (off_t)-1 ) { + if (s == (off_t)-1) { int e = errno; fprintf(stderr, - "Error %d seeking to next member in ar file %s: %s\n", +"Error %d seeking to next member in ar file %s: %s\n", e, ar->filename, strerror(e)); return RET_ERRNO(e); } /* read the next header from the file */ - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - bytesread = readwait(ar->fd,&ar->currentheader,sizeof(ar->currentheader)); + bytesread = readwait(ar->fd, &ar->currentheader, + sizeof(ar->currentheader)); ar->next_position += sizeof(ar->currentheader); - if( bytesread == 0 ) + if (bytesread == 0) return RET_NOTHING; - if( bytesread != sizeof(ar->currentheader) ){ + if (bytesread != sizeof(ar->currentheader)){ int e = errno; - if( bytesread < 0 ) { + if (bytesread < 0) { fprintf(stderr, "Error %d reading from ar file %s: %s\n", e, ar->filename, strerror(e)); @@ -184,7 +188,7 @@ return RET_ERROR; } } - if( memcmp(ar->currentheader.ah_magictrailer,AR_HEADERMAGIC,2) != 0 ) { + if (memcmp(ar->currentheader.ah_magictrailer, AR_HEADERMAGIC, 2) != 0) { fprintf(stderr, "Corrupt ar file %s\n", ar->filename); return RET_ERROR; } @@ -192,33 +196,35 @@ /* calculate the length and mark possible fillers being needed */ /* make ah_size null-terminated by overwriting the following field */ - assert( &ar->currentheader.ah_magictrailer[0] == ar->currentheader.ah_size + 10 ); + assert (&ar->currentheader.ah_magictrailer[0] + == ar->currentheader.ah_size + 10); ar->currentheader.ah_magictrailer[0] = '\0'; - ar->member_size = strtoul(ar->currentheader.ah_size,&p,10); - if( *p != '\0' && *p != ' ' ) { - fprintf(stderr, "Error calculating length field in ar file %s\n", + ar->member_size = strtoul(ar->currentheader.ah_size, &p, 10); + if (*p != '\0' && *p != ' ') { + fprintf(stderr, +"Error calculating length field in ar file %s\n", ar->filename); return RET_ERROR; } ar->next_position += ar->member_size; - if( (ar->member_size & 1) != 0 ) + if ((ar->member_size & 1) != 0) ar->next_position ++; /* get the name of the file */ - if( false ) { + if (false) { /* handle long filenames */ // TODO! } else { /* normal filenames */ int i = sizeof(ar->currentheader.ah_filename); - while( i > 0 && ar->currentheader.ah_filename[i-1] == ' ') + while (i > 0 && ar->currentheader.ah_filename[i-1] == ' ') i--; /* hop over GNU style filenames, though they should not * be in a .deb file... */ - if( i > 0 && ar->currentheader.ah_filename[i-1] == '/' ) + if (i > 0 && ar->currentheader.ah_filename[i-1] == '/') i--; - *filename = strndup(ar->currentheader.ah_filename,i); + *filename = strndup(ar->currentheader.ah_filename, i); } ar->compression = c_none; return RET_OK; @@ -232,18 +238,17 @@ struct ar_archive *ar = d; ssize_t bytesread; - assert( ar->readbuffer != NULL ); - if( ar->member == NULL ) + assert (ar->readbuffer != NULL); + if (ar->member == NULL) return 0; *p = ar->readbuffer; bytesread = uncompress_read(ar->member, ar->readbuffer, BLOCKSIZE); - if( bytesread < 0 ) { - retvalue r; + if (bytesread < 0) { const char *msg; int e; - r = uncompress_fdclose(ar->member, &e, &msg); + (void)uncompress_fdclose(ar->member, &e, &msg); ar->member = NULL; archive_set_error(a, e, msg); return -1; @@ -257,17 +262,17 @@ const char *msg; int e; - assert( uncompression_supported(ar->compression) ); + assert (uncompression_supported(ar->compression)); - assert(ar->readbuffer == NULL ); + assert (ar->readbuffer == NULL); ar->readbuffer = malloc(BLOCKSIZE); - if( ar->readbuffer == NULL ) { + if (FAILEDTOALLOC(ar->readbuffer)) { archive_set_error(a, ENOMEM, "Out of memory"); return ARCHIVE_FATAL; } r = uncompress_fdopen(&ar->member, ar->fd, ar->member_size, ar->compression, &e, &msg); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) return ARCHIVE_OK; archive_set_error(a, e, msg); return ARCHIVE_FATAL; @@ -282,12 +287,12 @@ free(ar->readbuffer); ar->readbuffer = NULL; - if( ar->member == NULL ) + if (ar->member == NULL) return ARCHIVE_OK; r = uncompress_fdclose(ar->member, &e, &msg); ar->member = NULL; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) return ARCHIVE_OK; archive_set_error(a, e, msg); return ARCHIVE_FATAL; diff -Nru reprepro-4.5.0/archallflood.c reprepro-4.6.0/archallflood.c --- reprepro-4.5.0/archallflood.c 2009-08-18 09:06:14.000000000 +0000 +++ reprepro-4.6.0/archallflood.c 2011-05-05 14:42:55.000000000 +0000 @@ -80,7 +80,7 @@ }; static void aa_package_data_free(/*@only@*/struct aa_package_data *data){ - if( data == NULL ) + if (data == NULL) return; free(data->name); free(data->old_version); @@ -95,21 +95,21 @@ struct aa_source_package *s; struct aa_package_data *l; - if( list == NULL ) + if (list == NULL) return; l = list->list; - while( l != NULL ) { + while (l != NULL) { struct aa_package_data *n = l->next; aa_package_data_free(l); l = n; } s = list->sources; - while( s != NULL ) { + while (s != NULL) { struct aa_source_package *n; - while( s->left_child != NULL || s->right_child != NULL ) { - if( s->left_child != NULL ) { + while (s->left_child != NULL || s->right_child != NULL) { + if (s->left_child != NULL) { n = s->left_child; s->left_child = NULL; s = n; @@ -120,7 +120,7 @@ } } - while( s->nextversion != NULL ) { + while (s->nextversion != NULL) { n = s->nextversion->nextversion; /* do not free name, it is not malloced */ free(s->nextversion->version); @@ -147,20 +147,20 @@ /* if this gets too slow, make it a balanced tree, * but it seems fast enough even as simple tree */ - while( *p != NULL ) { + while (*p != NULL) { c = strcmp(source, (*p)->name); - if( c == 0 ) + if (c == 0) break; parent = *p; - if( c > 0 ) + if (c > 0) p = &parent->right_child; else p = &parent->left_child; } - if( *p == NULL ) { + if (*p == NULL) { /* there is not even something with this name */ - n = calloc(1, sizeof(struct aa_source_package)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct aa_source_package); + if (FAILEDTOALLOC(n)) { free(source); free(sourceversion); return RET_ERROR_OOM; } @@ -175,16 +175,16 @@ source = (*p)->name; /* source name found, now look for version: */ c = strcmp(sourceversion, (*p)->version); - if( c == 0 ) { + if (c == 0) { free(sourceversion); *src_p = *p; return RET_OK; } - if( c < 0 ) { + if (c < 0) { /* before first item, do some swapping as this is * part of the name linked list */ - n = calloc(1, sizeof(struct aa_source_package)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct aa_source_package); + if (FAILEDTOALLOC(n)) { free(sourceversion); return RET_ERROR_OOM; } @@ -204,19 +204,19 @@ } do { p = &(*p)->nextversion; - if( *p == NULL ) + if (*p == NULL) break; c = strcmp(sourceversion, (*p)->version); - } while( c > 0 ); + } while (c > 0); - if( c == 0 ) { - assert( *p != NULL ); + if (c == 0) { + assert (*p != NULL); free(sourceversion); *src_p = *p; return RET_OK; } - n = calloc(1, sizeof(struct aa_source_package)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct aa_source_package); + if (FAILEDTOALLOC(n)) { free(sourceversion); return RET_ERROR_OOM; } @@ -234,20 +234,20 @@ p = list->sources; - while( p != NULL ) { + while (p != NULL) { c = strcmp(source, p->name); - if( c == 0 ) + if (c == 0) break; - if( c > 0 ) + if (c > 0) p = p->right_child; else p = p->left_child; } - if( p == NULL ) + if (p == NULL) return NULL; - while( p != NULL && (c = strcmp(sourceversion, p->version)) > 0 ) + while (p != NULL && (c = strcmp(sourceversion, p->version)) > 0) p = p->nextversion; - if( c < 0 ) + if (c < 0) return NULL; else return p; @@ -264,38 +264,38 @@ struct aa_package_data *package; r = list->target->getarchitecture(chunk, &architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = list->target->getsourceandversion(chunk, packagename, &source, &sourceversion); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = find_or_add_source(list, source, sourceversion, &src); source = NULL; sourceversion = NULL; // just to be sure - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = list->target->getversion(chunk, &version); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( architecture != architecture_all ) { + if (architecture != architecture_all) { free(version); src->has_sibling = true; return RET_NOTHING; } - package = calloc(1,sizeof(struct aa_package_data)); - if( package == NULL ) { + package = zNEW(struct aa_package_data); + if (FAILEDTOALLOC(package)) { free(version); return RET_ERROR_OOM; } package->name = strdup(packagename); - if( package->name == NULL ) { + if (FAILEDTOALLOC(package->name)) { free(package); free(version); return RET_ERROR_OOM; @@ -304,19 +304,20 @@ version = NULL; // just to be sure... package->old_source = src; - if( list->list == NULL ) { + if (list->list == NULL) { /* first chunk to add: */ list->list = package; list->last = package; } else { - if( strcmp(packagename, list->last->name) > 0 ) { + if (strcmp(packagename, list->last->name) > 0) { list->last->next = package; list->last = package; } else { /* this should only happen if the underlying * database-method get changed, so just throwing * out here */ - fprintf(stderr, "INTERNAL ERROR: Package database is not sorted!!!\n"); + fprintf(stderr, +"INTERNAL ERROR: Package database is not sorted!!!\n"); assert(false); exit(EXIT_FAILURE); } @@ -324,35 +325,35 @@ return RET_OK; } -static retvalue floodlist_initialize(struct floodlist **fl, struct target *t, struct database *database) { +static retvalue floodlist_initialize(struct floodlist **fl, struct target *t) { struct floodlist *list; - retvalue r,r2; + retvalue r, r2; const char *packagename, *controlchunk; struct target_cursor iterator; - list = calloc(1,sizeof(struct floodlist)); - if( list == NULL ) + list = zNEW(struct floodlist); + if (FAILEDTOALLOC(list)) return RET_ERROR_OOM; list->target = t; /* Begin with the packages currently in the archive */ - r = target_openiterator(t, database, READONLY, &iterator); - if( RET_WAS_ERROR(r) ) { + r = target_openiterator(t, READONLY, &iterator); + if (RET_WAS_ERROR(r)) { floodlist_free(list); return r; } - while( target_nextpackage(&iterator, &packagename, &controlchunk) ) { + while (target_nextpackage(&iterator, &packagename, &controlchunk)) { r2 = save_package_version(list, packagename, controlchunk); RET_UPDATE(r, r2); - if( RET_WAS_ERROR(r2) ) + if (RET_WAS_ERROR(r2)) break; } r2 = target_closeiterator(&iterator); RET_UPDATE(r, r2); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { floodlist_free(list); return r; } @@ -368,7 +369,7 @@ /* insertafter = NULL will mean insert before list */ insertafter = list->last; /* the next one to test, current = NULL will mean not found */ - if( insertafter != NULL ) + if (insertafter != NULL) current = insertafter->next; else current = list->list; @@ -376,34 +377,34 @@ /* the algorithm assumes almost all packages are feed in * alphabetically. */ - while( true ) { + while (true) { int cmp; - assert( insertafter == NULL || insertafter->next == current ); - assert( insertafter != NULL || current == list->list ); + assert (insertafter == NULL || insertafter->next == current); + assert (insertafter != NULL || current == list->list); - if( current == NULL ) + if (current == NULL) cmp = -1; /* every package is before the end of list */ else cmp = strcmp(packagename_const, current->name); - if( cmp == 0 ) + if (cmp == 0) break; - if( cmp < 0 ) { + if (cmp < 0) { int precmp; - if( insertafter == NULL ) { + if (insertafter == NULL) { /* if we are before the first * package, add us there...*/ current = NULL; break; } precmp = strcmp(packagename_const, insertafter->name); - if( precmp == 0 ) { + if (precmp == 0) { current = insertafter; break; - } else if( precmp < 0 ) { + } else if (precmp < 0) { /* restart at the beginning: */ current = list->list; insertafter = NULL; @@ -413,19 +414,19 @@ current = NULL; break; } - assert( "This is not reached" == NULL ); + assert ("This is not reached" == NULL); } /* cmp > 0 : may come later... */ - assert( current != NULL ); + assert (current != NULL); insertafter = current; current = current->next; - if( current == NULL ) { + if (current == NULL) { /* add behind insertafter at end of list */ break; } /* otherwise repeat until place found */ } - if( current == NULL ) { + if (current == NULL) { /* adding a package not yet known */ struct aa_package_data *new; char *source, *sourceversion; @@ -433,14 +434,14 @@ r = list->target->getsourceandversion(chunk, packagename_const, &source, &sourceversion); - if( ! RET_IS_OK(r) ) { + if (! RET_IS_OK(r)) { free(version); return r; } src = find_source(list, source, sourceversion); free(source); free(sourceversion); - new = calloc(1,sizeof(struct aa_package_data)); - if( new == NULL ) { + new = zNEW(struct aa_package_data); + if (FAILEDTOALLOC(new)) { free(version); return RET_ERROR_OOM; } @@ -448,7 +449,7 @@ new->new_version = version; version = NULL; new->name = strdup(packagename_const); - if( FAILEDTOALLOC(new->name) ) { + if (FAILEDTOALLOC(new->name)) { aa_package_data_free(new); return RET_ERROR_OOM; } @@ -457,11 +458,11 @@ architecture_all, chunk, &new->new_control, &new->new_filekeys, &new->new_origfiles); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { aa_package_data_free(new); return r; } - if( insertafter != NULL ) { + if (insertafter != NULL) { new->next = insertafter->next; insertafter->next = new; } else { @@ -480,30 +481,30 @@ list->last = current; - if( current->new_has_sibling ) { + if (current->new_has_sibling) { /* it has a new and that has a binary sibling, * which means this becomes the new version * exactly when it is newer than the old newest */ r = dpkgversions_cmp(version, current->new_version, &versioncmp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); return r; } - if( versioncmp <= 0 ) { + if (versioncmp <= 0) { free(version); return RET_NOTHING; } - } else if( current->old_version != NULL ) { + } else if (current->old_version != NULL) { /* if it is older than the old one, we will * always discard it */ r = dpkgversions_cmp(version, current->old_version, &versioncmp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); return r; } - if( versioncmp <= 0 ) { + if (versioncmp <= 0) { free(version); return RET_NOTHING; } @@ -512,33 +513,34 @@ r = list->target->getsourceandversion(chunk, packagename_const, &source, &sourceversion); - if( ! RET_IS_OK(r) ) { + if (! RET_IS_OK(r)) { free(version); return r; } src = find_source(list, source, sourceversion); free(source); free(sourceversion); - if( src == NULL || !src->has_sibling ) { + if (src == NULL || !src->has_sibling) { /* the new one has no sibling, only allowed * to override those that have: */ - if( current->new_version == NULL ) { - if( current->old_source->has_sibling ) { + if (current->new_version == NULL) { + if (current->old_source->has_sibling) { free(version); return RET_NOTHING; } - } else if( current->new_has_sibling ) { + } else if (current->new_has_sibling) { free(version); return RET_NOTHING; } else { /* the new one has no sibling and the old one * has not too, take the newer one: */ - r = dpkgversions_cmp(version, current->new_version, + r = dpkgversions_cmp(version, + current->new_version, &versioncmp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); return r; } - if( versioncmp <= 0 ) { + if (versioncmp <= 0) { free(version); return RET_NOTHING; } @@ -549,7 +551,7 @@ packagename_const, version, architecture_all, chunk, &control, &files, &origfiles); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); return r; } @@ -567,76 +569,76 @@ return RET_OK; } -static retvalue floodlist_pull(struct floodlist *list, struct target *source, struct database *database) { +static retvalue floodlist_pull(struct floodlist *list, struct target *source) { retvalue result, r; const char *package, *control; struct target_cursor iterator; list->last = NULL; - r = target_openiterator(source, database, READONLY, &iterator); - if( RET_WAS_ERROR(r) ) + r = target_openiterator(source, READONLY, &iterator); + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &package, &control) ) { + while (target_nextpackage(&iterator, &package, &control)) { char *version; architecture_t package_architecture; - r = list->target->getarchitecture(control, &package_architecture); - if( r == RET_NOTHING ) + r = list->target->getarchitecture(control, + &package_architecture); + if (r == RET_NOTHING) continue; - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { RET_UPDATE(result, r); break; } - if( package_architecture != architecture_all ) + if (package_architecture != architecture_all) continue; r = list->target->getversion(control, &version); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { RET_UPDATE(result, r); break; } r = floodlist_trypackage(list, package, version, control); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - if( interrupted() ) { + if (interrupted()) { result = RET_ERROR_INTERRUPTED; break; } } r = target_closeiterator(&iterator); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } -static retvalue floodlist_install(struct floodlist *list, struct logger *logger, struct database *database, /*@NULL@*/struct trackingdata *td) { +static retvalue floodlist_install(struct floodlist *list, struct logger *logger, /*@NULL@*/struct trackingdata *td) { struct aa_package_data *pkg; - retvalue result,r; + retvalue result, r; - if( list->list == NULL ) + if (list->list == NULL) return RET_NOTHING; - result = target_initpackagesdb(list->target, database, READWRITE); - if( RET_WAS_ERROR(result) ) + result = target_initpackagesdb(list->target, READWRITE); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( pkg = list->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->new_version != NULL ) { - r = files_expectfiles(database, - &pkg->new_filekeys, + for (pkg = list->list ; pkg != NULL ; pkg = pkg->next) { + if (pkg->new_version != NULL) { + r = files_expectfiles(&pkg->new_filekeys, pkg->new_origfiles.checksums); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) continue; - if( interrupted() ) { + if (interrupted()) { r = RET_ERROR_INTERRUPTED; break; } - if( td != NULL ) { - if( pkg->new_source != NULL ) { + if (td != NULL) { + if (pkg->new_source != NULL) { r = trackingdata_switch(td, pkg->new_source->name, pkg->new_source->version); @@ -648,8 +650,8 @@ pkg->name, &source, &sourceversion); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { RET_UPDATE(result, r); break; } @@ -658,19 +660,18 @@ free(source); free(sourceversion); } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { RET_UPDATE(result, r); break; } } r = target_addpackage(list->target, - logger, database, - pkg->name, pkg->new_version, + logger, pkg->name, pkg->new_version, pkg->new_control, &pkg->new_filekeys, - false, td, architecture_all, + false, td, architecture_all, NULL, NULL); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } } @@ -679,73 +680,72 @@ return result; } -retvalue flood(struct distribution *d, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, architecture_t architecture, struct database *database, trackingdb tracks) { +retvalue flood(struct distribution *d, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, architecture_t architecture, trackingdb tracks) { struct target *t, *s; retvalue result = RET_NOTHING, r; struct trackingdata trackingdata; - if( tracks != NULL ) { + if (tracks != NULL) { r = trackingdata_new(tracks, &trackingdata); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - for( t = d->targets ; t != NULL ; t = t->next ) { + for (t = d->targets ; t != NULL ; t = t->next) { struct floodlist *fl = NULL; - if( atom_defined(architecture) ) { - if( architecture != t->architecture_atom ) + if (atom_defined(architecture)) { + if (architecture != t->architecture) continue; - } else if( limitations_missed(architectures, - t->architecture_atom) ) + } else if (limitations_missed(architectures, + t->architecture)) continue; - if( limitations_missed(components, t->component_atom) ) + if (limitations_missed(components, t->component)) continue; - if( limitations_missed(packagetypes, t->packagetype_atom) ) + if (limitations_missed(packagetypes, t->packagetype)) continue; - if( t->packagetype_atom != pt_deb - && t->packagetype_atom != pt_udeb ) + if (t->packagetype != pt_deb && t->packagetype != pt_udeb) continue; - r = floodlist_initialize(&fl, t, database); - if( RET_WAS_ERROR(r) ) { - if( tracks != NULL ) + r = floodlist_initialize(&fl, t); + if (RET_WAS_ERROR(r)) { + if (tracks != NULL) trackingdata_done(&trackingdata); return r; } - for( s = d->targets ; s != NULL ; s = s->next ) { - if( s->component_atom != t->component_atom ) + for (s = d->targets ; s != NULL ; s = s->next) { + if (s->component != t->component) continue; - if( s->packagetype_atom != t->packagetype_atom ) + if (s->packagetype != t->packagetype) continue; /* no need to copy things from myself: */ - if( s->architecture_atom == t->architecture_atom ) + if (s->architecture == t->architecture) continue; - if( limitations_missed(architectures, - s->architecture_atom) ) + if (limitations_missed(architectures, + s->architecture)) continue; - r = floodlist_pull(fl, s, database); + r = floodlist_pull(fl, s); RET_UPDATE(d->status, r); - if( RET_WAS_ERROR(r) ) { - if( tracks != NULL ) + if (RET_WAS_ERROR(r)) { + if (tracks != NULL) trackingdata_done(&trackingdata); floodlist_free(fl); return r; } } - r = floodlist_install(fl, d->logger, database, + r = floodlist_install(fl, d->logger, (tracks != NULL)?&trackingdata:NULL); RET_UPDATE(result, r); floodlist_free(fl); - if( RET_WAS_ERROR(r) ) { - if( tracks != NULL ) + if (RET_WAS_ERROR(r)) { + if (tracks != NULL) trackingdata_done(&trackingdata); return r; } } - if( tracks != NULL ) { - r = trackingdata_finish(tracks, &trackingdata, database); + if (tracks != NULL) { + r = trackingdata_finish(tracks, &trackingdata); RET_ENDUPDATE(result, r); } return result; diff -Nru reprepro-4.5.0/archallflood.h reprepro-4.6.0/archallflood.h --- reprepro-4.5.0/archallflood.h 2009-08-17 18:47:31.000000000 +0000 +++ reprepro-4.6.0/archallflood.h 2011-05-05 14:42:55.000000000 +0000 @@ -1,6 +1,6 @@ #ifndef REPREPRO_ARCHALLFLOOD_H #define REPREPRO_ARCHALLFLOOD_H -retvalue flood(struct distribution *d, /*@null@*/const struct atomlist */*components*/, /*@NULL@*/const struct atomlist */*architectures*/, /*@NULL@*/const struct atomlist */*packagetypes*/, architecture_t, struct database *, trackingdb); +retvalue flood(struct distribution *, /*@null@*/const struct atomlist * /*components*/, /*@NULL@*/const struct atomlist * /*architectures*/, /*@NULL@*/const struct atomlist * /*packagetypes*/, architecture_t, trackingdb); #endif diff -Nru reprepro-4.5.0/ar.h reprepro-4.6.0/ar.h --- reprepro-4.5.0/ar.h 2008-09-07 12:28:17.000000000 +0000 +++ reprepro-4.6.0/ar.h 2011-05-05 14:42:55.000000000 +0000 @@ -3,11 +3,11 @@ struct ar_archive; -retvalue ar_open(/*@out@*/struct ar_archive **, const char *filename); +retvalue ar_open(/*@out@*/struct ar_archive **, const char *); void ar_close(/*@only@*/struct ar_archive *); /* RET_OK = next is there, RET_NOTHING = eof, < 0 = error */ -retvalue ar_nextmember(struct ar_archive *,/*@out@*/char **filename); +retvalue ar_nextmember(struct ar_archive *, /*@out@*/char ** /*filename*/); /* set compression for the next member */ void ar_archivemember_setcompression(struct ar_archive *, enum compression); diff -Nru reprepro-4.5.0/atoms.c reprepro-4.6.0/atoms.c --- reprepro-4.5.0/atoms.c 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/atoms.c 2011-05-05 14:42:55.000000000 +0000 @@ -30,7 +30,9 @@ const char **atoms_packagetypes = (const char **)&packagetypes; const char **atoms_commands; static int command_count; -static const char * const types[4] = {"architecture", "component", "packagetype", "command"}; +static const char * const types[4] = { + "architecture", "component", "packagetype", "command" +}; const char **atomtypes = (const char **)types; /* trivial implementation for now, perhaps make it more complicated later */ @@ -44,27 +46,27 @@ /* add a 0th entry to all, so 0 means uninitialized */ r = strlist_add_dup(&architectures, "!!NONE!!"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = strlist_add_dup(&architectures, "source"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = strlist_add_dup(&architectures, "all"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = strlist_add_dup(&components, "!!NONE!!"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* a fallback component to put things without a component in */ r = strlist_add_dup(&components, "strange"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; atoms_components = (const char**)components.values; atoms_architectures = (const char**)architectures.values; command_count = count; - if( command_count > 0 ) { - atoms_commands = calloc(command_count + 1, sizeof(const char*)); - if( FAILEDTOALLOC(atoms_commands) ) + if (command_count > 0) { + atoms_commands = nzNEW(command_count + 1, const char*); + if (FAILEDTOALLOC(atoms_commands)) return RET_ERROR_OOM; } return RET_OK; @@ -75,14 +77,14 @@ int i; i = strlist_ofs(&architectures, value); - if( i >= 0 ) { + if (i >= 0) { *atom_p = (architecture_t)i; return RET_OK; } i = architectures.count; r = strlist_add_dup(&architectures, value); atoms_architectures = (const char**)architectures.values; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { *atom_p = (architecture_t)i; return RET_OK; } else @@ -93,14 +95,14 @@ int i; i = strlist_ofs(&components, value); - if( i >= 0 ) { + if (i >= 0) { *atom_p = (component_t)i; return RET_OK; } i = components.count; r = strlist_add_dup(&components, value); atoms_components = (const char**)components.values; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { *atom_p = (component_t)i; return RET_OK; } else @@ -109,7 +111,7 @@ architecture_t architecture_find(const char *value) { int i = strlist_ofs(&architectures, value); - if( i < 0 ) + if (i < 0) return atom_unknown; else return (architecture_t)i; @@ -118,11 +120,11 @@ architecture_t architecture_find_l(const char *value, size_t l) { architecture_t a; - for( a = architectures.count - 1 ; a > 0 ; a-- ) { + for (a = architectures.count - 1 ; a > 0 ; a--) { const char *name = atoms_architectures[a]; size_t len = strlen(name); - if( len == l && memcmp(name, value, len) == 0 ) + if (len == l && memcmp(name, value, len) == 0) return a; } return atom_unknown; @@ -132,11 +134,11 @@ component_t component_find_l(const char *value, size_t l) { component_t a; - for( a = components.count - 1 ; a > 0 ; a-- ) { + for (a = components.count - 1 ; a > 0 ; a--) { const char *name = atoms_components[a]; size_t len = strlen(name); - if( len == l && memcmp(name, value, len) == 0 ) + if (len == l && memcmp(name, value, len) == 0) return a; } return atom_unknown; @@ -144,30 +146,30 @@ component_t component_find(const char *value) { int i = strlist_ofs(&components, value); - if( i < 0 ) + if (i < 0) return atom_unknown; else return (architecture_t)i; } packagetype_t packagetype_find(const char *value) { - if( strcmp(value, "dsc") == 0 ) + if (strcmp(value, "dsc") == 0) return pt_dsc; - else if( strcmp(value, "deb") == 0 ) + else if (strcmp(value, "deb") == 0) return pt_deb; - else if( strcmp(value, "udeb") == 0 ) + else if (strcmp(value, "udeb") == 0) return pt_udeb; else return atom_unknown; } packagetype_t packagetype_find_l(const char *value, size_t len) { - if( len == 3 ) { - if( strncmp(value, "dsc", 3) == 0 ) + if (len == 3) { + if (strncmp(value, "dsc", 3) == 0) return pt_dsc; - else if( strncmp(value, "deb",3) == 0 ) + else if (strncmp(value, "deb", 3) == 0) return pt_deb; - } else if( len == 4 && strncmp(value, "udeb",4) == 0 ) + } else if (len == 4 && strncmp(value, "udeb", 4) == 0) return pt_udeb; return atom_unknown; } @@ -175,15 +177,15 @@ static inline command_t command_find(const char *value) { command_t c; - for( c = command_count ; c > 0 ; c-- ) { - if( strcmp(atoms_commands[c], value) == 0 ) + for (c = command_count ; c > 0 ; c--) { + if (strcmp(atoms_commands[c], value) == 0) return c; } return atom_unknown; } atom_t atom_find(enum atom_type type, const char *value) { - switch( type ) { + switch (type) { case at_packagetype: return packagetype_find(value); case at_architecture: @@ -198,8 +200,8 @@ } retvalue atom_intern(enum atom_type type, const char *value, atom_t *atom_p) { - assert( type == at_architecture || type == at_component ); - switch( type ) { + assert (type == at_architecture || type == at_component); + switch (type) { case at_architecture: return architecture_intern(value, atom_p); case at_component: @@ -215,8 +217,8 @@ } void atomlist_done(struct atomlist *list) { - if( list->size > 0 ) { - assert( list->atoms != 0 ); + if (list->size > 0) { + assert (list->atoms != 0); free(list->atoms); } /* reset atoms but not size, so reuse can be catched */ @@ -228,15 +230,15 @@ int i; atom_t *n; - assert( atom_defined(atom) ); + assert (atom_defined(atom)); - for( i = 0 ; i < list->count ; i++ ) { - if( list->atoms[i] == atom ) + for (i = 0 ; i < list->count ; i++) { + if (list->atoms[i] == atom) return RET_NOTHING; } - if( list->size <= list->count ) { - n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8) ); - if( FAILEDTOALLOC(n) ) + if (list->size <= list->count) { + n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8)); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; list->size = list->count + 8; list->atoms = n; @@ -248,11 +250,11 @@ retvalue atomlist_add(struct atomlist *list, atom_t atom) { atom_t *n; - assert( atom_defined(atom) ); + assert (atom_defined(atom)); - if( list->size <= list->count ) { - n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8) ); - if( FAILEDTOALLOC(n) ) + if (list->size <= list->count) { + n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8)); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; list->size = list->count + 8; list->atoms = n; @@ -273,8 +275,8 @@ bool atomlist_hasexcept(const struct atomlist *list, atom_t atom) { int i; - for( i = 0 ; i < list->count ; i++ ) { - if( list->atoms[i] != atom ) + for (i = 0 ; i < list->count ; i++) { + if (list->atoms[i] != atom) return true; } return false; @@ -283,8 +285,8 @@ bool atomlist_in(const struct atomlist *list, atom_t atom) { int i; - for( i = 0 ; i < list->count ; i++ ) { - if( list->atoms[i] == atom ) + for (i = 0 ; i < list->count ; i++) { + if (list->atoms[i] == atom) return true; } return false; @@ -292,8 +294,8 @@ int atomlist_ofs(const struct atomlist *list, atom_t atom) { int i; - for( i = 0 ; i < list->count ; i++ ) { - if( list->atoms[i] == atom ) + for (i = 0 ; i < list->count ; i++) { + if (list->atoms[i] == atom) return i; } return -1; @@ -302,15 +304,15 @@ bool atomlist_subset(const struct atomlist *list, const struct atomlist *subset, atom_t *missing) { int i, j; - for( j = 0 ; j < subset->count ; j++ ) { + for (j = 0 ; j < subset->count ; j++) { atom_t atom = subset->atoms[j]; - for( i = 0 ; i < list->count ; i++ ) { - if( list->atoms[i] == atom ) + for (i = 0 ; i < list->count ; i++) { + if (list->atoms[i] == atom) break; } - if( i >= list->count ) { - if( missing != NULL ) + if (i >= list->count) { + if (missing != NULL) *missing = atom; return false; } @@ -327,7 +329,7 @@ assert(list != NULL); assert(file != NULL); - switch( type ) { + switch (type) { case at_architecture: atoms = atoms_architectures; break; @@ -346,10 +348,10 @@ c = list->count; p = list->atoms; result = RET_OK; - while( c > 0 ) { - if( fputs(atoms[*(p++)], file) == EOF ) + while (c > 0) { + if (fputs(atoms[*(p++)], file) == EOF) result = RET_ERROR; - if( --c > 0 && fputc(' ', file) == EOF ) + if (--c > 0 && fputc(' ', file) == EOF) result = RET_ERROR; } return result; @@ -366,20 +368,20 @@ atom_t a; atomlist_init(&l); - while( *string != '\0' ) { + while (*string != '\0') { e = strchr(string, '|'); - if( e == NULL ) + if (e == NULL) e = strchr(string, '\0'); else *(e++) = '\0'; a = atom_find(type, string); - if( !atom_defined(a) ) { + if (!atom_defined(a)) { atomlist_done(&l); *missing = string; return RET_NOTHING; } r = atomlist_add(&l, a); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&l); return r; } diff -Nru reprepro-4.5.0/atoms.h reprepro-4.6.0/atoms.h --- reprepro-4.5.0/atoms.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/atoms.h 2011-05-05 14:42:55.000000000 +0000 @@ -39,7 +39,7 @@ atom_t atom_find(enum atom_type, const char *); retvalue atom_intern(enum atom_type, const char *, /*@out@*/atom_t *); -#define limitation_missed(a, b) ((atom_defined(a) && (a) != (b) )) +#define limitation_missed(a, b) ((atom_defined(a) && (a) != (b))) #define limitations_missed(a, b) ((a) != NULL && !atomlist_in(a, b)) @@ -65,10 +65,10 @@ int atomlist_ofs(const struct atomlist *, atom_t); /* if missing != NULL And subset no subset of atomlist, set *missing to the first missing one */ -bool atomlist_subset(const struct atomlist *, const struct atomlist *subset, /*@null@*/atom_t *missing); +bool atomlist_subset(const struct atomlist *, const struct atomlist * /*subset*/, /*@null@*/atom_t * /*missing*/ ); /* print a space separated list of elements */ retvalue atomlist_fprint(FILE *, enum atom_type, const struct atomlist *); -retvalue atomlist_filllist(enum atom_type, /*@out@*/struct atomlist *, char *string, /*@out@*/const char **missing); +retvalue atomlist_filllist(enum atom_type, /*@out@*/struct atomlist *, char * /*string*/, /*@out@*/const char ** /*missing*/); #endif diff -Nru reprepro-4.5.0/binaries.c reprepro-4.6.0/binaries.c --- reprepro-4.5.0/binaries.c 2011-02-21 15:34:27.000000000 +0000 +++ reprepro-4.6.0/binaries.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,9 +43,12 @@ static char *calc_binary_basename(const char *name, const char *version, architecture_t arch, packagetype_t packagetype) { const char *v; - assert( name != NULL && version != NULL && atom_defined(arch) && atom_defined(packagetype) ); + assert (name != NULL); + assert (version != NULL); + assert (atom_defined(arch)); + assert (atom_defined(packagetype)); v = strchr(version, ':'); - if( v != NULL ) + if (v != NULL) v++; else v = version; @@ -62,24 +65,26 @@ result = RET_NOTHING; - for( type = 0 ; type < cs_COUNT ; type++ ) { + for (type = 0 ; type < cs_COUNT ; type++) { checksums[type] = NULL; r = chunk_getvalue(chunk, deb_checksum_headers[type], &checksums[type]); RET_UPDATE(result, r); } - if( checksums[cs_md5sum] == NULL ) { - fprintf(stderr, "Missing 'MD5sum' line in binary control chunk:\n '%s'\n", + if (checksums[cs_md5sum] == NULL) { + fprintf(stderr, +"Missing 'MD5sum' line in binary control chunk:\n '%s'\n", chunk); RET_UPDATE(result, RET_ERROR_MISSING); } - if( checksums[cs_length] == NULL ) { - fprintf(stderr, "Missing 'Size' line in binary control chunk:\n '%s'\n", + if (checksums[cs_length] == NULL) { + fprintf(stderr, +"Missing 'Size' line in binary control chunk:\n '%s'\n", chunk); RET_UPDATE(result, RET_ERROR_MISSING); } - if( RET_WAS_ERROR(result) ) { - for( type = 0 ; type < cs_COUNT ; type++ ) + if (RET_WAS_ERROR(result)) { + for (type = 0 ; type < cs_COUNT ; type++) free(checksums[type]); return result; } @@ -91,52 +96,55 @@ retvalue r; r = chunk_getvalue(chunk, "Architecture", &parch); - if( r == RET_NOTHING ) { - fprintf(stderr, "Internal Error: Missing Architecture: header in '%s'!\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"Internal Error: Missing Architecture: header in '%s'!\n", chunk); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; *architecture_p = architecture_find(parch); free(parch); - if( !atom_defined(*architecture_p) ) { - fprintf(stderr, "Internal Error: Unexpected Architecture: header in '%s'!\n", + if (!atom_defined(*architecture_p)) { + fprintf(stderr, +"Internal Error: Unexpected Architecture: header in '%s'!\n", chunk); return RET_ERROR; } return RET_OK; } -/* get somefields out of a "Packages.gz"-chunk. returns RET_OK on success, RET_NOTHING if incomplete, error otherwise */ -static retvalue binaries_parse_chunk(const char *chunk, const char *packagename, packagetype_t packagetype_atom, architecture_t package_architecture, const char *version, /*@out@*/char **sourcename_p, /*@out@*/char **basename_p) { +/* get somefields out of a "Packages.gz"-chunk. + * returns RET_OK on success, RET_NOTHING if incomplete, error otherwise */ +static retvalue binaries_parse_chunk(const char *chunk, const char *packagename, packagetype_t packagetype, architecture_t package_architecture, const char *version, /*@out@*/char **sourcename_p, /*@out@*/char **basename_p) { retvalue r; - char *mysourcename,*mybasename; + char *mysourcename, *mybasename; assert(packagename!=NULL); /* get the sourcename */ r = chunk_getname(chunk, "Source", &mysourcename, true); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { mysourcename = strdup(packagename); - if( mysourcename == NULL ) + if (FAILEDTOALLOC(mysourcename)) r = RET_ERROR_OOM; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } r = properpackagename(packagename); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = properversion(version); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(mysourcename); return r; } mybasename = calc_binary_basename(packagename, version, - package_architecture, packagetype_atom); - if( mybasename == NULL ) { + package_architecture, packagetype); + if (FAILEDTOALLOC(mybasename)) { free(mysourcename); return RET_ERROR_OOM; } @@ -152,45 +160,46 @@ char *filename; /* Read the filename given there */ - r = chunk_getvalue(chunk,"Filename",&filename); - if( !RET_IS_OK(r) ) { - if( r == RET_NOTHING ) { - fprintf(stderr, "Data does not look like binary control: '%s'\n", + r = chunk_getvalue(chunk, "Filename", &filename); + if (!RET_IS_OK(r)) { + if (r == RET_NOTHING) { + fprintf(stderr, +"Data does not look like binary control: '%s'\n", chunk); r = RET_ERROR; } return r; } - r = strlist_init_singleton(filename,files); + r = strlist_init_singleton(filename, files); return r; } -static retvalue calcfilekeys(component_t component_atom, const char *sourcename, const char *basefilename, struct strlist *filekeys) { +static retvalue calcfilekeys(component_t component, const char *sourcename, const char *basefilename, struct strlist *filekeys) { char *filekey; retvalue r; r = propersourcename(sourcename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } - filekey = calc_filekey(component_atom, sourcename, basefilename); - if( filekey == NULL ) + filekey = calc_filekey(component, sourcename, basefilename); + if (FAILEDTOALLOC(filekey)) return RET_ERROR_OOM; - r = strlist_init_singleton(filekey,filekeys); + r = strlist_init_singleton(filekey, filekeys); return r; } -static inline retvalue calcnewcontrol(const char *chunk, const char *sourcename, const char *basefilename, component_t component_atom, struct strlist *filekeys, char **newchunk) { +static inline retvalue calcnewcontrol(const char *chunk, const char *sourcename, const char *basefilename, component_t component, struct strlist *filekeys, char **newchunk) { retvalue r; - r = calcfilekeys(component_atom, sourcename, basefilename, filekeys); - if( RET_WAS_ERROR(r) ) + r = calcfilekeys(component, sourcename, basefilename, filekeys); + if (RET_WAS_ERROR(r)) return r; - assert( filekeys->count == 1 ); + assert (filekeys->count == 1); *newchunk = chunk_replacefield(chunk, "Filename", filekeys->values[0], false); - if( *newchunk == NULL ) { + if (FAILEDTOALLOC(*newchunk)) { strlist_done(filekeys); return RET_ERROR_OOM; } @@ -200,11 +209,13 @@ retvalue binaries_getversion(const char *control, char **version) { retvalue r; - r = chunk_getvalue(control,"Version",version); - if( RET_WAS_ERROR(r) ) + r = chunk_getvalue(control, "Version", version); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", control); + if (r == RET_NOTHING) { + fprintf(stderr, +"Missing 'Version' field in chunk:'%s'\n", + control); return RET_ERROR; } return r; @@ -216,26 +227,27 @@ retvalue r; r = binaries_parse_chunk(chunk, packagename, - t->packagetype_atom, package_architecture, + t->packagetype, package_architecture, version, &sourcename, &basefilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; - } else if( r == RET_NOTHING ) { - fprintf(stderr, "Does not look like a binary package: '%s'!\n", chunk); + } else if (r == RET_NOTHING) { + fprintf(stderr, "Does not look like a binary package: '%s'!\n", + chunk); return RET_ERROR; } r = binaries_getchecksums(chunk, &origfilekeys); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(sourcename); free(basefilename); return r; } r = calcnewcontrol(chunk, sourcename, basefilename, - t->component_atom, filekeys, control); - if( RET_WAS_ERROR(r) ) { + t->component, filekeys, control); + if (RET_WAS_ERROR(r)) { checksumsarray_done(&origfilekeys); } else { - assert( r != RET_NOTHING ); + assert (r != RET_NOTHING); checksumsarray_move(origfiles, &origfilekeys); } free(sourcename); free(basefilename); @@ -247,17 +259,17 @@ struct checksumsarray a; r = binaries_getfilekeys(chunk, &a.names); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( a.names.count == 1 ); - a.checksums = malloc(sizeof(struct checksums *)); - if( a.checksums == NULL ) { + assert (a.names.count == 1); + a.checksums = NEW(struct checksums *); + if (FAILEDTOALLOC(a.checksums)) { strlist_done(&a.names); return RET_ERROR_OOM; } r = binaries_parse_checksums(chunk, a.checksums); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(a.checksums); strlist_done(&a.names); return r; @@ -272,19 +284,19 @@ char *newchunk; retvalue r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; o = override_search(target->distribution->overrides.deb, packagename); - if( o == NULL ) + if (o == NULL) return RET_NOTHING; r = override_allreplacefields(o, &fields); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; newchunk = chunk_replacefields(controlchunk, fields, "Filename", false); addfield_free(fields); - if( newchunk == NULL ) + if (FAILEDTOALLOC(newchunk)) return RET_ERROR_OOM; *newcontrolchunk = newchunk; return RET_OK; @@ -295,85 +307,87 @@ struct fieldtoadd *fields; char *newchunk; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; o = override_search(target->distribution->overrides.udeb, packagename); - if( o == NULL ) + if (o == NULL) return RET_NOTHING; - fields = override_addreplacefields(o,NULL); - if( fields == NULL ) + fields = override_addreplacefields(o, NULL); + if (FAILEDTOALLOC(fields)) return RET_ERROR_OOM; newchunk = chunk_replacefields(controlchunk, fields, "Description", true); addfield_free(fields); - if( newchunk == NULL ) + if (FAILEDTOALLOC(newchunk)) return RET_ERROR_OOM; *newcontrolchunk = newchunk; return RET_OK; } -retvalue binaries_retrack(const char *packagename, const char *chunk, trackingdb tracks, struct database *database) { +retvalue binaries_retrack(const char *packagename, const char *chunk, trackingdb tracks) { retvalue r; const char *sourcename; - char *fsourcename,*sourceversion,*arch,*filekey; + char *fsourcename, *sourceversion, *arch, *filekey; enum filetype filetype; struct trackedpackage *pkg; //TODO: elliminate duplicate code! assert(packagename!=NULL); - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; /* is there a sourcename */ - r = chunk_getnameandversion(chunk,"Source",&fsourcename,&sourceversion); - if( RET_WAS_ERROR(r) ) + r = chunk_getnameandversion(chunk, "Source", + &fsourcename, &sourceversion); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { sourceversion = NULL; sourcename = packagename; fsourcename = NULL; } else { sourcename = fsourcename; } - if( sourceversion == NULL ) { + if (sourceversion == NULL) { // Think about binNMUs, can something be done here? - r = chunk_getvalue(chunk,"Version",&sourceversion); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(chunk, "Version", &sourceversion); + if (RET_WAS_ERROR(r)) { free(fsourcename); return r; } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { free(fsourcename); - fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", + fprintf(stderr, +"Missing 'Version' field in chunk:'%s'\n", chunk); return RET_ERROR; } } - r = chunk_getvalue(chunk,"Architecture",&arch); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "Architecture", &arch); + if (r == RET_NOTHING) { fprintf(stderr, "No Architecture field in chunk:'%s'\n", chunk); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(sourceversion); free(fsourcename); return r; } - if( strcmp(arch,"all") == 0 ) { + if (strcmp(arch, "all") == 0) { filetype = ft_ALL_BINARY; } else { filetype = ft_ARCH_BINARY; } free(arch); - r = chunk_getvalue(chunk,"Filename",&filekey); - if( !RET_IS_OK(r) ) { - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, "Filename", &filekey); + if (!RET_IS_OK(r)) { + if (r == RET_NOTHING) { fprintf(stderr, "No Filename field in chunk: '%s'\n", chunk); r = RET_ERROR; @@ -382,17 +396,16 @@ free(fsourcename); return r; } - r = tracking_getornew(tracks,sourcename,sourceversion,&pkg); + r = tracking_getornew(tracks, sourcename, sourceversion, &pkg); free(fsourcename); free(sourceversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(filekey); return r; } - assert( r != RET_NOTHING ); - r = trackedpackage_addfilekey(tracks, pkg, filetype, filekey, true, - database); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + r = trackedpackage_addfilekey(tracks, pkg, filetype, filekey, true); + if (RET_WAS_ERROR(r)) { trackedpackage_free(pkg); return r; } @@ -401,30 +414,32 @@ retvalue binaries_getsourceandversion(const char *chunk, const char *packagename, char **source, char **version) { retvalue r; - char *sourcename,*sourceversion; + char *sourcename, *sourceversion; //TODO: elliminate duplicate code! assert(packagename!=NULL); /* is there a sourcename */ - r = chunk_getnameandversion(chunk,"Source",&sourcename,&sourceversion); - if( RET_WAS_ERROR(r) ) + r = chunk_getnameandversion(chunk, "Source", + &sourcename, &sourceversion); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { sourceversion = NULL; sourcename = strdup(packagename); - if( sourcename == NULL ) + if (FAILEDTOALLOC(sourcename)) return RET_ERROR_OOM; } - if( sourceversion == NULL ) { - r = chunk_getvalue(chunk,"Version",&sourceversion); - if( RET_WAS_ERROR(r) ) { + if (sourceversion == NULL) { + r = chunk_getvalue(chunk, "Version", &sourceversion); + if (RET_WAS_ERROR(r)) { free(sourcename); return r; } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { free(sourcename); - fprintf(stderr, "No Version field in chunk:'%s'\n", chunk); + fprintf(stderr, "No Version field in chunk:'%s'\n", + chunk); return RET_ERROR; } } @@ -433,11 +448,11 @@ return RET_OK; } -static inline retvalue getvalue(const char *filename,const char *chunk,const char *field,char **value) { +static inline retvalue getvalue(const char *filename, const char *chunk, const char *field, char **value) { retvalue r; - r = chunk_getvalue(chunk,field,value); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, field, value); + if (r == RET_NOTHING) { fprintf(stderr, "No %s field in %s's control file!\n", field, filename); r = RET_ERROR; @@ -445,11 +460,11 @@ return r; } -static inline retvalue checkvalue(const char *filename,const char *chunk,const char *field) { +static inline retvalue checkvalue(const char *filename, const char *chunk, const char *field) { retvalue r; - r = chunk_checkfield(chunk,field); - if( r == RET_NOTHING ) { + r = chunk_checkfield(chunk, field); + if (r == RET_NOTHING) { fprintf(stderr, "No %s field in %s's control file!\n", field, filename); r = RET_ERROR; @@ -457,11 +472,11 @@ return r; } -static inline retvalue getvalue_n(const char *chunk,const char *field,char **value) { +static inline retvalue getvalue_n(const char *chunk, const char *field, char **value) { retvalue r; - r = chunk_getvalue(chunk,field,value); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, field, value); + if (r == RET_NOTHING) { *value = NULL; } return r; @@ -479,64 +494,65 @@ retvalue r; char *architecture; - r = extractcontrol(&deb->control,filename); - if( RET_WAS_ERROR(r) ) + r = extractcontrol(&deb->control, filename); + if (RET_WAS_ERROR(r)) return r; /* first look for fields that should be there */ r = chunk_getname(deb->control, "Package", &deb->name, false); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Missing 'Package' field in %s!\n", filename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - r = checkvalue(filename,deb->control,"Maintainer"); - if( RET_WAS_ERROR(r) ) + r = checkvalue(filename, deb->control, "Maintainer"); + if (RET_WAS_ERROR(r)) return r; - r = checkvalue(filename,deb->control,"Description"); - if( RET_WAS_ERROR(r) ) + r = checkvalue(filename, deb->control, "Description"); + if (RET_WAS_ERROR(r)) return r; - r = getvalue(filename,deb->control,"Version",&deb->version); - if( RET_WAS_ERROR(r) ) + r = getvalue(filename, deb->control, "Version", &deb->version); + if (RET_WAS_ERROR(r)) return r; r = getvalue(filename, deb->control, "Architecture", &architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = properfilenamepart(architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(architecture); return r; } - r = architecture_intern(architecture, &deb->architecture_atom); + r = architecture_intern(architecture, &deb->architecture); free(architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* can be there, otherwise we also know what it is */ - if( needssourceversion ) - r = chunk_getnameandversion(deb->control,"Source",&deb->source,&deb->sourceversion); + if (needssourceversion) + r = chunk_getnameandversion(deb->control, "Source", + &deb->source, &deb->sourceversion); else r = chunk_getname(deb->control, "Source", &deb->source, true); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { deb->source = strdup(deb->name); - if( deb->source == NULL ) + if (FAILEDTOALLOC(deb->source)) r = RET_ERROR_OOM; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( needssourceversion && deb->sourceversion == NULL ) { + if (needssourceversion && deb->sourceversion == NULL) { deb->sourceversion = strdup(deb->version); - if( deb->sourceversion == NULL ) + if (FAILEDTOALLOC(deb->sourceversion)) return RET_ERROR_OOM; } /* normaly there, but optional: */ - r = getvalue_n(deb->control,PRIORITY_FIELDNAME,&deb->priority); - if( RET_WAS_ERROR(r) ) + r = getvalue_n(deb->control, PRIORITY_FIELDNAME, &deb->priority); + if (RET_WAS_ERROR(r)) return r; - r = getvalue_n(deb->control,SECTION_FIELDNAME,&deb->section); - if( RET_WAS_ERROR(r) ) + r = getvalue_n(deb->control, SECTION_FIELDNAME, &deb->section); + if (RET_WAS_ERROR(r)) return r; return RET_OK; } @@ -547,38 +563,38 @@ char *newchunk; enum checksumtype type; - assert( section != NULL && priority != NULL); - assert( filekey != NULL && checksums != NULL); + assert (section != NULL && priority != NULL); + assert (filekey != NULL && checksums != NULL); replace = NULL; - for( type = 0 ; type < cs_COUNT ; type++ ) { + for (type = 0 ; type < cs_COUNT ; type++) { const char *start; size_t len; - if( checksums_getpart(checksums, type, &start, &len) ) { + if (checksums_getpart(checksums, type, &start, &len)) { replace = addfield_newn(deb_checksum_headers[type], start, len, replace); - if( replace == NULL ) + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; } } replace = addfield_new("Filename", filekey, replace); - if( replace == NULL ) + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; replace = addfield_new(SECTION_FIELDNAME, section, replace); - if( replace == NULL ) + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; replace = addfield_new(PRIORITY_FIELDNAME, priority, replace); - if( replace == NULL ) + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; - replace = override_addreplacefields(override,replace); - if( replace == NULL ) + replace = override_addreplacefields(override, replace); + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; - newchunk = chunk_replacefields(pkg->control, replace, + newchunk = chunk_replacefields(pkg->control, replace, "Description", true); addfield_free(replace); - if( newchunk == NULL ) { + if (FAILEDTOALLOC(newchunk)) { return RET_ERROR_OOM; } @@ -598,58 +614,57 @@ checksums = c[0]; replace = NULL; - for( type = 0 ; type < cs_COUNT ; type++ ) { + for (type = 0 ; type < cs_COUNT ; type++) { const char *start; size_t len; - if( checksums_getpart(checksums, type, &start, &len) ) { + if (checksums_getpart(checksums, type, &start, &len)) { replace = addfield_newn(deb_checksum_headers[type], start, len, replace); - if( replace == NULL ) + if (FAILEDTOALLOC(replace)) return RET_ERROR_OOM; } } newchunk = chunk_replacefields(chunk, replace, "Description", true); addfield_free(replace); - if( newchunk == NULL ) + if (FAILEDTOALLOC(newchunk)) return RET_ERROR_OOM; *out = newchunk; return RET_OK; } -retvalue binaries_adddeb(const struct deb_headers *deb, struct database *database, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata, component_t component, const struct strlist *filekeys, const char *control) { - retvalue r,result; +retvalue binaries_adddeb(const struct deb_headers *deb, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata, component_t component, const struct strlist *filekeys, const char *control) { + retvalue r, result; int i; - assert( logger_isprepared(distribution->logger) ); + assert (logger_isprepared(distribution->logger)); /* finally put it into one or more architectures of the distribution */ result = RET_NOTHING; - if( deb->architecture_atom != architecture_all ) { + if (deb->architecture != architecture_all) { struct target *t = distribution_getpart(distribution, - component, deb->architecture_atom, + component, deb->architecture, packagetype); - r = target_initpackagesdb(t, database, READWRITE); - if( !RET_WAS_ERROR(r) ) { + r = target_initpackagesdb(t, READWRITE); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_addpackage(t, distribution->logger, - database, deb->name, deb->version, control, filekeys, false, trackingdata, - deb->architecture_atom, + deb->architecture, NULL, NULL); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } - RET_UPDATE(result,r); + RET_UPDATE(result, r); RET_UPDATE(distribution->status, result); return result; } @@ -659,56 +674,55 @@ * given. (as it behaved this way when there was only one -A possible, * and to allow incoming to force it into architecture 'all' ) * */ - if( forcearchitectures != NULL && - atomlist_in(forcearchitectures, architecture_all) ) + if (forcearchitectures != NULL && + atomlist_in(forcearchitectures, architecture_all)) forcearchitectures = NULL; - for( i = 0 ; i < distribution->architectures.count ; i++ ) { + for (i = 0 ; i < distribution->architectures.count ; i++) { /*@dependent@*/struct target *t; architecture_t a = distribution->architectures.atoms[i]; - if( a == architecture_source ) + if (a == architecture_source) continue; - if( forcearchitectures != NULL && - !atomlist_in(forcearchitectures, a) ) + if (forcearchitectures != NULL && + !atomlist_in(forcearchitectures, a)) continue; t = distribution_getpart(distribution, component, a, packagetype); - r = target_initpackagesdb(t, database, READWRITE); - if( !RET_WAS_ERROR(r) ) { + r = target_initpackagesdb(t, READWRITE); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_addpackage(t, distribution->logger, - database, deb->name, deb->version, control, filekeys, false, trackingdata, - deb->architecture_atom, + deb->architecture, NULL, NULL); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } RET_UPDATE(distribution->status, result); return result; } -static inline retvalue checkadddeb(struct database *database, struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype, bool tracking, const struct deb_headers *deb, bool permitnewerold) { +static inline retvalue checkadddeb(struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype, bool tracking, const struct deb_headers *deb, bool permitnewerold) { retvalue r; struct target *t; t = distribution_getpart(distribution, component, architecture, packagetype); - assert( t != NULL ); - r = target_initpackagesdb(t, database, READONLY); - if( !RET_WAS_ERROR(r) ) { + assert (t != NULL); + r = target_initpackagesdb(t, READONLY); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_checkaddpackage(t, @@ -716,39 +730,37 @@ tracking, permitnewerold); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } return r; } -retvalue binaries_checkadddeb(const struct deb_headers *deb, struct database *database, architecture_t forcearchitecture, packagetype_t packagetype, struct distribution *distribution, bool tracking, component_t component, bool permitnewerold) { - retvalue r,result; +retvalue binaries_checkadddeb(const struct deb_headers *deb, architecture_t forcearchitecture, packagetype_t packagetype, struct distribution *distribution, bool tracking, component_t component, bool permitnewerold) { + retvalue r, result; int i; /* finally put it into one or more architectures of the distribution */ result = RET_NOTHING; - if( deb->architecture_atom != architecture_all ) { - r = checkadddeb(database, distribution, - component, deb->architecture_atom, packagetype, - tracking, deb, - permitnewerold); - RET_UPDATE(result,r); - } else if( atom_defined(forcearchitecture) && forcearchitecture != architecture_all ) { - r = checkadddeb(database, distribution, + if (deb->architecture != architecture_all) { + r = checkadddeb(distribution, + component, deb->architecture, packagetype, + tracking, deb, permitnewerold); + RET_UPDATE(result, r); + } else if (atom_defined(forcearchitecture) + && forcearchitecture != architecture_all) { + r = checkadddeb(distribution, component, forcearchitecture, packagetype, - tracking, deb, - permitnewerold); - RET_UPDATE(result,r); - } else for( i = 0 ; i < distribution->architectures.count ; i++ ) { + tracking, deb, permitnewerold); + RET_UPDATE(result, r); + } else for (i = 0 ; i < distribution->architectures.count ; i++) { architecture_t a = distribution->architectures.atoms[i]; - if( a == architecture_source ) + if (a == architecture_source) continue; - r = checkadddeb(database, distribution, + r = checkadddeb(distribution, component, a, packagetype, - tracking, deb, - permitnewerold); - RET_UPDATE(result,r); + tracking, deb, permitnewerold); + RET_UPDATE(result, r); } return result; } @@ -758,8 +770,8 @@ char *basefilename; basefilename = calc_binary_basename(deb->name, deb->version, - deb->architecture_atom, packagetype); - if( FAILEDTOALLOC(basefilename) ) + deb->architecture, packagetype); + if (FAILEDTOALLOC(basefilename)) return RET_ERROR_OOM; r = calcfilekeys(component, deb->source, basefilename, filekeys); diff -Nru reprepro-4.5.0/binaries.h reprepro-4.6.0/binaries.h --- reprepro-4.5.0/binaries.h 2011-02-21 15:34:27.000000000 +0000 +++ reprepro-4.6.0/binaries.h 2011-05-05 14:42:55.000000000 +0000 @@ -28,9 +28,9 @@ /* Functions for checkindeb.c and incoming.c: */ struct deb_headers { - char *name,*version; + char *name, *version; char *source; - architecture_t architecture_atom; + architecture_t architecture; char *control; /* only extracted when requested: */ /*@null@*/char *sourceversion; @@ -44,14 +44,14 @@ * error returned * - no checks for sanity of values, left to the caller */ -retvalue binaries_readdeb(struct deb_headers *, const char *filename, bool needssourceversion); +retvalue binaries_readdeb(struct deb_headers *, const char *filename, bool /*needssourceversion*/); void binaries_debdone(struct deb_headers *); retvalue binaries_calcfilekeys(component_t, const struct deb_headers *, packagetype_t, /*@out@*/struct strlist *); struct overridedata; -retvalue binaries_complete(const struct deb_headers *, const char *filekey, const struct checksums *, const struct overridedata *, const char *section, const char *priority, char **newcontrol); +retvalue binaries_complete(const struct deb_headers *, const char * /*filekey*/, const struct checksums *, const struct overridedata *, const char * /*section*/, const char * /*priority*/, char **/*newcontrol_p*/); -retvalue binaries_adddeb(const struct deb_headers *, struct database *, const struct atomlist *forcedarchitectures, packagetype_t, struct distribution *, /*@null@*/struct trackingdata *, component_t, const struct strlist *filekeys, const char *control); -retvalue binaries_checkadddeb(const struct deb_headers *, struct database *, architecture_t forcearchitecture, packagetype_t, struct distribution *, bool tracking, component_t, bool permitnewerold); +retvalue binaries_adddeb(const struct deb_headers *, const struct atomlist */*forcedarchitectures*/, packagetype_t, struct distribution *, /*@null@*/struct trackingdata *, component_t, const struct strlist */*filekeys*/, const char */*control*/); +retvalue binaries_checkadddeb(const struct deb_headers *, architecture_t /*forcearchitecture*/, packagetype_t, struct distribution *, bool tracking, component_t, bool /*permitnewerold*/); #endif diff -Nru reprepro-4.5.0/byhandhook.c reprepro-4.6.0/byhandhook.c --- reprepro-4.5.0/byhandhook.c 2011-02-09 14:20:21.000000000 +0000 +++ reprepro-4.6.0/byhandhook.c 2011-05-05 14:42:55.000000000 +0000 @@ -42,7 +42,7 @@ }; void byhandhooks_free(struct byhandhook *l) { - while( l != NULL ) { + while (l != NULL) { /*@null@*/struct byhandhook *n = l->next; free(l->sectionglob); @@ -60,8 +60,10 @@ struct byhandhook *h, *hooks = NULL, **nexthook_p = &hooks; r = config_getwordinline(iter, &v); - if( RET_IS_OK(r) ) { - fprintf(stderr, "Error parsing %s, line %u, column %u: unexpected input '%s' (each hook must be in its own line)!\n", + if (RET_IS_OK(r)) { + fprintf(stderr, +"Error parsing %s, line %u, column %u: unexpected input '%s'" +" (each hook must be in its own line)!\n", config_filename(iter), config_markerline(iter), config_markercolumn(iter), @@ -69,16 +71,16 @@ free(v); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( config_nextline(iter) ) { + while (config_nextline(iter)) { r = config_getwordinline(iter, &v); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - h = calloc(1, sizeof(struct byhandhook)); - if( FAILEDTOALLOC(h) ) { + h = zNEW(struct byhandhook); + if (FAILEDTOALLOC(h)) { r = RET_ERROR_OOM; break; } @@ -86,60 +88,64 @@ nexthook_p = &h->next; h->sectionglob = v; r = config_getwordinline(iter, &v); - if( r == RET_NOTHING ) { - fprintf(stderr, "Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 1!\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 1!\n", config_filename(iter), config_markerline(iter), config_markercolumn(iter)); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; h->priorityglob = v; r = config_getwordinline(iter, &v); - if( r == RET_NOTHING ) { - fprintf(stderr, "Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 2!\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 2!\n", config_filename(iter), config_markerline(iter), config_markercolumn(iter)); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; h->filenameglob = v; r = config_getwordinline(iter, &v); - if( r == RET_NOTHING ) { - fprintf(stderr, "Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 2!\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"Error parsing %s, line %u, column %u: each byhand hooks needs 4 arguments, found only 2!\n", config_filename(iter), config_markerline(iter), config_markercolumn(iter)); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - assert( v != NULL && v[0] != '\0' ); \ - if( v[0] != '/' ) { + assert (v != NULL && v[0] != '\0'); \ + if (v[0] != '/') { h->script = calc_dirconcat(global.confdir, v); free(v); - if( h->script == NULL ) { + if (FAILEDTOALLOC(h->script)) { r = RET_ERROR_OOM; break; } } else h->script = v; r = config_getwordinline(iter, &v); - if( RET_IS_OK(r) ) { - fprintf(stderr, "Error parsing %s, line %u, column %u: each byhand hooks needs exactly 4 arguments, but there are more (first unexpected: '%s'!\n", + if (RET_IS_OK(r)) { + fprintf(stderr, +"Error parsing %s, line %u, column %u: each byhand hooks needs exactly 4 arguments, but there are more (first unexpected: '%s'!\n", config_filename(iter), config_markerline(iter), config_markercolumn(iter), v); free(v); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { byhandhooks_free(hooks); return r; } @@ -152,15 +158,15 @@ /* for each file the first matching hook is called * it might later be extended to allow multiple with some keywords */ - if( *touse != NULL ) - /* if( (*touse)->nonexclusive ) list = (*touse)->next ; else */ + if (*touse != NULL) + /* if ((*touse)->nonexclusive) list = (*touse)->next ; else */ return false; - for( h = list ; h != NULL ; h = h->next ) { - if( !globmatch(section, h->sectionglob) ) + for (h = list ; h != NULL ; h = h->next) { + if (!globmatch(section, h->sectionglob)) continue; - if( !globmatch(priority, h->priorityglob) ) + if (!globmatch(priority, h->priorityglob)) continue; - if( !globmatch(filename, h->filenameglob) ) + if (!globmatch(filename, h->filenameglob)) continue; *touse = h; return true; @@ -172,16 +178,16 @@ pid_t child; child = fork(); - if( child == 0 ) { + if (child == 0) { /* Try to close all open fd but 0,1,2 */ closefrom(3); - if( causingfile != NULL ) + if (causingfile != NULL) setenv("REPREPRO_CAUSING_FILE", causingfile, true); else unsetenv("REPREPRO_CAUSING_FILE"); - if( atom_defined(causingcommand_atom) ) + if (atom_defined(causingcommand)) setenv("REPREPRO_CAUSING_COMMAND", - atoms_commands[causingcommand_atom], + atoms_commands[causingcommand], true); else unsetenv("REPREPRO_CAUSING_COMMAND"); @@ -201,19 +207,19 @@ } _exit(255); } - if( child < 0 ) { + if (child < 0) { int e = errno; fprintf(stderr, "Error %d forking: %s!\n", e, strerror(e)); return RET_ERRNO(e); } - while( true ) { + while (true) { int status; pid_t pid; pid = waitpid(child, &status, 0); - if( pid == child ) { - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0) { + if (pid == child) { + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) { return RET_OK; } fprintf(stderr, @@ -222,7 +228,7 @@ section, priority, name, fullfilename, (int)(WEXITSTATUS(status))); - } else if( WIFSIGNALED(status) ) { + } else if (WIFSIGNALED(status)) { fprintf(stderr, "Byhandhook '%s' '%s' '%s' '%s' '%s' '%s' killed by signal %d!\n", h->script, codename, @@ -237,10 +243,10 @@ fullfilename); } return RET_ERROR; - } else if( pid == (pid_t)-1 ) { + } else if (pid == (pid_t)-1) { int e = errno; - if( e == EINTR ) + if (e == EINTR) continue; fprintf(stderr, "Error %d calling waitpid on byhandhook child: %s\n", diff -Nru reprepro-4.5.0/byhandhook.h reprepro-4.6.0/byhandhook.h --- reprepro-4.5.0/byhandhook.h 2010-01-24 18:21:22.000000000 +0000 +++ reprepro-4.6.0/byhandhook.h 2011-05-05 14:42:55.000000000 +0000 @@ -16,9 +16,9 @@ retvalue byhandhooks_parse(struct configiterator *, /*@out@*/struct byhandhook **); /* 2nd argument starts as NULL, returns true as long as there are hooks */ -bool byhandhooks_matched(const struct byhandhook *, const struct byhandhook **, const char *section, const char *priority, const char *name); +bool byhandhooks_matched(const struct byhandhook *, const struct byhandhook **, const char * /*section*/, const char * /*priority*/, const char * /*name*/); -retvalue byhandhook_call(const struct byhandhook *, const char *codename, const char *section, const char *priority, const char *basename, const char *fullfilename); +retvalue byhandhook_call(const struct byhandhook *, const char * /*codename*/, const char * /*section*/, const char * /*priority*/, const char * /*basename*/, const char * /*fullfilename*/); void byhandhooks_free(/*@null@*//*@only@*/struct byhandhook *); diff -Nru reprepro-4.5.0/ChangeLog reprepro-4.6.0/ChangeLog --- reprepro-4.5.0/ChangeLog 2011-02-21 15:34:27.000000000 +0000 +++ reprepro-4.6.0/ChangeLog 2011-05-05 14:42:55.000000000 +0000 @@ -1,3 +1,38 @@ +2010-05-05 + * ignore leading comments in control files + +2010-04-18 + * add --restrict and --restrict-bin to restrict update + and pull operations to specific packages. + * add --restrict-file and --restrict-file-bin. + +2010-04-17 + * add --export=silent-never like never but silenting + all warnings (mostly useful for testsuite). + * avoid 'Data seems not to be signed trying to use directly' + message if data start like unsigned file should start. + +2010-04-16 + * add 'FilterSrcList'. + +2010-04-15 + * Many clean-ups and coding style fixes. + +2010-03-30 + * Support specifying a version in FilterList + +2010-02-29 + * support compiling with libdb5 + * fix memory bug in filelist generation + (as realloc usually not moves stuff when reducing the size that + is no real issue, but newer valgrind detects it and warns). + +2010-02-28 + * 'check' also checks if architectures match + * fix 'sourcemissing', 'unusedsources' and 'reportcruft' + on distributions without tracking. + * fix 'pull' copying packages with wrong architecture + 2010-02-21 * support reading of Release files without MD5Sum * add all missing Checksums-* when importing from diff -Nru reprepro-4.5.0/changes.c reprepro-4.6.0/changes.c --- reprepro-4.5.0/changes.c 2010-05-08 12:01:37.000000000 +0000 +++ reprepro-4.6.0/changes.c 2011-05-05 14:42:55.000000000 +0000 @@ -31,12 +31,12 @@ retvalue changes_parsefileline(const char *fileline, /*@out@*/filetype *result_type, /*@out@*/char **result_basename, /*@out@*/struct hash_data *hash_p, /*@out@*/struct hash_data *size_p, /*@out@*/char **result_section, /*@out@*/char **result_priority, /*@out@*/architecture_t *result_architecture, /*@out@*/char **result_name) { - const char *p,*md5start,*md5end; - const char *sizestart,*sizeend; - const char *sectionstart,*sectionend; - const char *priostart,*prioend; - const char *filestart,*nameend,*fileend; - const char *archstart,*archend; + const char *p, *md5start, *md5end; + const char *sizestart, *sizeend; + const char *sectionstart, *sectionend; + const char *priostart, *prioend; + const char *filestart, *nameend, *fileend; + const char *archstart, *archend; const char *versionstart; filetype type; char *section, *priority, *basefilename, *name; @@ -45,75 +45,79 @@ bool checkfilename = false; p = fileline; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; md5start = p; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') ) + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) p++; - if( *p == '\0' ) { - fprintf(stderr,"Missing md5sum in '%s'!\n", fileline); + if (*p == '\0') { + fprintf(stderr, "Missing md5sum in '%s'!\n", fileline); return RET_ERROR; } - if( !xisspace(*p) ) { - fprintf(stderr,"Malformed md5 hash in '%s'!\n", fileline); + if (!xisspace(*p)) { + fprintf(stderr, "Malformed md5 hash in '%s'!\n", fileline); return RET_ERROR; } md5end = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - while( *p == '0' && p[1] >= '0' && p[1] <= '9' ) + while (*p == '0' && p[1] >= '0' && p[1] <= '9') p++; sizestart = p; - while( *p >= '0' && *p <= '9' ) + while (*p >= '0' && *p <= '9') p++; - if( *p == '\0' ) { - fprintf(stderr,"Missing size (second argument) in '%s'!\n", fileline); + if (*p == '\0') { + fprintf(stderr, +"Missing size (second argument) in '%s'!\n", fileline); return RET_ERROR; } - if( !xisspace(*p) ) { - fprintf(stderr,"Malformed size (second argument) in '%s'!\n", fileline); + if (!xisspace(*p)) { + fprintf(stderr, +"Malformed size (second argument) in '%s'!\n", fileline); return RET_ERROR; } sizeend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; sectionstart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; sectionend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; priostart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; prioend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; filestart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; fileend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - if( *p != '\0' ) { - fprintf(stderr,"Unexpected sixth argument in '%s'!\n",fileline); + if (*p != '\0') { + fprintf(stderr, +"Unexpected sixth argument in '%s'!\n", fileline); return RET_ERROR; } - if( *md5start == '\0' || *sizestart == '\0' || *sectionstart == '\0' - || *priostart == '\0' || *filestart == '\0' ) { - fprintf(stderr, "Wrong number of arguments in '%s' (5 expected)!\n", + if (*md5start == '\0' || *sizestart == '\0' || *sectionstart == '\0' + || *priostart == '\0' || *filestart == '\0') { + fprintf(stderr, +"Wrong number of arguments in '%s' (5 expected)!\n", fileline); return RET_ERROR; } - if( (sectionend - sectionstart == 6 && + if ((sectionend - sectionstart == 6 && strncmp(sectionstart, "byhand", 6) == 0) || (sectionend - sectionstart > 4 && strncmp(sectionstart, "raw-", 4) == 0)) { section = strndup(sectionstart, sectionend - sectionstart); priority = strndup(priostart, prioend - priostart); basefilename = strndup(filestart, fileend - filestart); - if( FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) || - FAILEDTOALLOC(basefilename) ) { + if (FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) || + FAILEDTOALLOC(basefilename)) { free(section); free(priority); free(basefilename); return RET_ERROR_OOM; @@ -132,14 +136,16 @@ } p = filestart; - while( *p != '\0' && *p != '_' && !xisspace(*p) ) + while (*p != '\0' && *p != '_' && !xisspace(*p)) p++; - if( *p != '_' ) { - if( *p == '\0' ) - fprintf(stderr, "No underscore found in file name in '%s'!\n", + if (*p != '_') { + if (*p == '\0') + fprintf(stderr, +"No underscore found in file name in '%s'!\n", fileline); else - fprintf(stderr, "Unexpected character '%c' in file name in '%s'!\n", + fprintf(stderr, +"Unexpected character '%c' in file name in '%s'!\n", *p, fileline); return RET_ERROR; } @@ -150,43 +156,45 @@ /* changing 3.0 format to now also allow _ in source files * makes this parsing quite more ugly... */ - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; l = p - versionstart; /* identify the binary types (they have no compression * and will need a _ */ - if( l >= 4 && memcmp(p-4, ".deb", 4) == 0 ) + if (l >= 4 && memcmp(p-4, ".deb", 4) == 0) type = fe_DEB; - else if( l >= 5 && memcmp(p-5, ".udeb", 5) == 0 ) + else if (l >= 5 && memcmp(p-5, ".udeb", 5) == 0) type = fe_UDEB; else type = fe_UNKNOWN; - if( type != fe_UNKNOWN ) { + if (type != fe_UNKNOWN) { /* a _ should separate the version from the rest */ p = versionstart; names_overversion(&p, true); - if( *p != '\0' && *p != '_' ) { - fprintf(stderr, "Unexpected character '%c' in file name within '%s'!\n", - *p, fileline); + if (*p != '\0' && *p != '_') { + fprintf(stderr, +"Unexpected character '%c' in file name within '%s'!\n", *p, fileline); return RET_ERROR; } - if( *p != '_' ) { - fprintf(stderr, "Cannot cope with .[u]deb filename not containing an underscore (in '%s')!", fileline); + if (*p != '_') { + fprintf(stderr, +"Cannot cope with .[u]deb filename not containing an underscore (in '%s')!", + fileline); return RET_ERROR; } p++; archstart = p; - if( type == fe_DEB ) + if (type == fe_DEB) archend = versionstart + l - 4; else { - assert( type == fe_UDEB ); + assert (type == fe_UDEB); archend = versionstart + l - 5; } - if( archend - archstart == 6 && - strncmp(archstart,"source",6) == 0 ) { + if (archend - archstart == 6 && + strncmp(archstart, "source", 6) == 0) { fprintf(stderr, "Architecture 'source' not allowed for .[u]debs ('%s')!\n", filestart); return RET_ERROR; @@ -207,32 +215,33 @@ archstart = "source"; archend = archstart + 6; - if( l > 9 && strncmp(p-9, ".orig.tar", 9) == 0 ) { + if (l > 9 && strncmp(p-9, ".orig.tar", 9) == 0) { type = fe_ORIG; eoi = p - 9; - } else if( l > 4 && strncmp(p-4, ".tar", 4) == 0 ) { + } else if (l > 4 && strncmp(p-4, ".tar", 4) == 0) { type = fe_TAR; eoi = p - 4; - } else if( l > 5 && strncmp(p-5,".diff", 5) == 0 ) { + } else if (l > 5 && strncmp(p-5, ".diff", 5) == 0) { type = fe_DIFF; eoi = p - 5; - } else if( l > 4 && strncmp(p-4,".dsc",4) == 0 && c == c_none ) { + } else if (l > 4 && strncmp(p-4, ".dsc", 4) == 0 + && c == c_none) { type = fe_DSC; eoi = p - 4; - } else if( l > 4 && strncmp(p-4, ".log", 4) == 0 ) { + } else if (l > 4 && strncmp(p-4, ".log", 4) == 0) { type = fe_LOG; eoi = p - 4; - } else if( l > 6 && strncmp(p-6, ".build", 6) == 0 ) { + } else if (l > 6 && strncmp(p-6, ".build", 6) == 0) { type = fe_LOG; eoi = p - 6; } - if( type != fe_UNKNOWN ) { + if (type != fe_UNKNOWN) { /* check for a proper version */ p = versionstart; names_overversion(&p, true); - if( p >= eoi ) { + if (p >= eoi) { /* all well */ - } else if( type == fe_TAR ) { + } else if (type == fe_TAR) { /* a tar might be a component with ugly * data between .orig- and the .tar.c */ const char *o = strstr(versionstart, ".orig-"); @@ -243,8 +252,8 @@ return RET_ERROR; } checkfilename = true; - } else if( type == fe_LOG ) { - if( *p == '_' ) { + } else if (type == fe_LOG) { + if (*p == '_') { archstart = p + 1; archend = eoi; checkfilename = true; @@ -274,21 +283,21 @@ // list multiple.. architecture = architecture_find_l(archstart, archend - archstart); name = strndup(filestart, nameend - filestart); - if( FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) || - FAILEDTOALLOC(basefilename) || FAILEDTOALLOC(name) ) { + if (FAILEDTOALLOC(section) || FAILEDTOALLOC(priority) || + FAILEDTOALLOC(basefilename) || FAILEDTOALLOC(name)) { free(section); free(priority); free(basefilename); free(name); return RET_ERROR_OOM; } - if( checkfilename || !atom_defined(architecture)) { + if (checkfilename || !atom_defined(architecture)) { retvalue r; /* as we no longer run properversion over the whole * rest of the string, at least make sure nothing evil * is in this name */ r = properfilename(basefilename); - if( !RET_IS_OK(r) ) { - assert( r != RET_NOTHING ); + if (!RET_IS_OK(r)) { + assert (r != RET_NOTHING); free(section); free(priority); free(basefilename); free(name); return r; diff -Nru reprepro-4.5.0/changes.h reprepro-4.6.0/changes.h --- reprepro-4.5.0/changes.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/changes.h 2011-05-05 14:42:55.000000000 +0000 @@ -5,17 +5,17 @@ #include "atoms.h" #endif -typedef enum { +typedef enum { fe_UNKNOWN=0, fe_DEB, fe_UDEB, fe_DSC, fe_DIFF, fe_ORIG, fe_TAR, fe_BYHAND, fe_LOG, fe_CHANGES } filetype; -#define FE_PACKAGE(ft) ( (ft) == fe_DEB || (ft) == fe_UDEB || (ft) == fe_DSC ) -#define FE_BINARY(ft) ( (ft) == fe_DEB || (ft) == fe_UDEB ) -#define FE_SOURCE(ft) ( (ft) == fe_DIFF || (ft) == fe_ORIG || (ft) == fe_TAR || (ft) == fe_DSC || (ft) == fe_UNKNOWN) +#define FE_PACKAGE(ft) ((ft) == fe_DEB || (ft) == fe_UDEB || (ft) == fe_DSC) +#define FE_BINARY(ft) ((ft) == fe_DEB || (ft) == fe_UDEB) +#define FE_SOURCE(ft) ((ft) == fe_DIFF || (ft) == fe_ORIG || (ft) == fe_TAR || (ft) == fe_DSC || (ft) == fe_UNKNOWN) struct hash_data; -retvalue changes_parsefileline(const char *fileline, /*@out@*/filetype *result_type, /*@out@*/char **result_basename, /*@out@*/struct hash_data *, /*@out@*/struct hash_data *, /*@out@*/char **result_section, /*@out@*/char **result_priority, /*@out@*/architecture_t *, /*@out@*/char **result_name); +retvalue changes_parsefileline(const char * /*fileline*/, /*@out@*/filetype *, /*@out@*/char ** /*result_basename*/, /*@out@*/struct hash_data *, /*@out@*/struct hash_data *, /*@out@*/char ** /*result_section*/, /*@out@*/char ** /*result_priority*/, /*@out@*/architecture_t *, /*@out@*/char ** /*result_name*/); #endif diff -Nru reprepro-4.5.0/checkin.c reprepro-4.6.0/checkin.c --- reprepro-4.5.0/checkin.c 2011-02-09 14:20:21.000000000 +0000 +++ reprepro-4.6.0/checkin.c 2011-05-05 14:42:55.000000000 +0000 @@ -55,7 +55,7 @@ * - Read in the chunk of the possible signed file. * (In later versions possibly checking the signature) * - Parse it, extracting: - * + Distribution + * + Distribution * + Source * + Architecture * + Binary @@ -83,7 +83,7 @@ /* this might be different for different files, * (though this is only allowed in rare cases), * will be set by _fixfields */ - component_t component_atom; + component_t component; /* only set after changes_includefiles */ char *filekey; /* was already found in the pool before */ @@ -123,7 +123,7 @@ static void freeentries(/*@only@*/struct fileentry *entry) { struct fileentry *h; - while( entry != NULL ) { + while (entry != NULL) { h = entry->next; free(entry->filekey); free(entry->basename); @@ -131,9 +131,9 @@ free(entry->section); free(entry->priority); free(entry->name); - if( entry->type == fe_DEB || entry->type == fe_UDEB) + if (entry->type == fe_DEB || entry->type == fe_UDEB) deb_free(entry->pkg.deb); - else if( entry->type == fe_DSC ) { + else if (entry->type == fe_DSC) { strlist_done(&entry->needed_filekeys); sources_done(&entry->pkg.dsc); } @@ -143,7 +143,7 @@ } static void changes_free(/*@only@*/struct changes *changes) { - if( changes != NULL ) { + if (changes != NULL) { free(changes->source); free(changes->sourceversion); free(changes->changesversion); @@ -166,21 +166,22 @@ struct fileentry *e; retvalue r; - e = calloc(1,sizeof(struct fileentry)); - if( e == NULL ) + e = zNEW(struct fileentry); + if (FAILEDTOALLOC(e)) return RET_ERROR_OOM; r = changes_parsefileline(fileline, &e->type, &e->basename, &e->hashes.hashes[cs_md5sum], &e->hashes.hashes[cs_length], - &e->section, &e->priority, &e->architecture_into, &e->name); - if( RET_WAS_ERROR(r) ) { + &e->section, &e->priority, &e->architecture_into, + &e->name); + if (RET_WAS_ERROR(r)) { free(e); return r; } - assert( RET_IS_OK(r) ); - if( e->type == fe_BYHAND ) { - if( !includebyhand ) { + assert (RET_IS_OK(r)); + if (e->type == fe_BYHAND) { + if (!includebyhand) { // TODO: at least check them and fail if wrong? fprintf(stderr, "Ignoring byhand file: '%s'!\n", e->basename); @@ -192,35 +193,35 @@ *entry = e; return RET_OK; } - if( FE_SOURCE(e->type) && limitations_missed(packagetypes, pt_dsc) ) { + if (FE_SOURCE(e->type) && limitations_missed(packagetypes, pt_dsc)) { freeentries(e); *ignoredlines_p = true; return RET_NOTHING; } - if( e->type == fe_DEB && limitations_missed(packagetypes, pt_deb) ) { + if (e->type == fe_DEB && limitations_missed(packagetypes, pt_deb)) { freeentries(e); *ignoredlines_p = true; return RET_NOTHING; } - if( e->type == fe_UDEB && limitations_missed(packagetypes, pt_udeb) ) { + if (e->type == fe_UDEB && limitations_missed(packagetypes, pt_udeb)) { freeentries(e); *ignoredlines_p = true; return RET_NOTHING; } - if( e->type != fe_LOG && + if (e->type != fe_LOG && e->architecture_into == architecture_source && - strcmp(e->name, sourcename) != 0 ) { + strcmp(e->name, sourcename) != 0) { fprintf(stderr, "Warning: File '%s' looks like source but does not start with '%s_'!\n", e->basename, sourcename); } - if( e->type == fe_LOG ) { - if( strcmp(e->name, sourcename) != 0 ) { + if (e->type == fe_LOG) { + if (strcmp(e->name, sourcename) != 0) { fprintf(stderr, "Warning: File '%s' looks like log but does not start with '%s_'!\n", e->basename, sourcename); } - if( !includelogs ) { + if (!includelogs) { // TODO: at least check them and fail if wrong? fprintf(stderr, "Ignoring log file: '%s'!\n", e->basename); @@ -228,10 +229,10 @@ *ignoredlines_p = true; return RET_NOTHING; } - if( atom_defined(e->architecture_into) && + if (atom_defined(e->architecture_into) && limitations_missed(forcearchitectures, - e->architecture_into ) ) { - if( verbose > 1 ) + e->architecture_into)) { + if (verbose > 1) fprintf(stderr, "Skipping '%s' as not for architecture ", e->basename); @@ -242,10 +243,10 @@ *ignoredlines_p = true; return RET_NOTHING; } - } else if( forcearchitectures != NULL ) { - if( e->architecture_into == architecture_all && + } else if (forcearchitectures != NULL) { + if (e->architecture_into == architecture_all && !skip_binaries) { - if( verbose > 2 ) { + if (verbose > 2) { fprintf(stderr, "Limiting '%s' to architectures ", e->basename); @@ -255,13 +256,14 @@ } /* keep e->architecture_into to all, this wil * be restricted to forcearchitectures when added */ - } else if( !atomlist_in(forcearchitectures, - e->architecture_into) ) { - if( verbose > 1 ) + } else if (!atomlist_in(forcearchitectures, + e->architecture_into)) { + if (verbose > 1) fprintf(stderr, "Skipping '%s' as architecture '%s' is not in the requested set.\n", e->basename, - atoms_architectures[e->architecture_into]); + atoms_architectures[ + e->architecture_into]); freeentries(e); *ignoredlines_p = true; return RET_NOTHING; @@ -275,25 +277,26 @@ /* Parse the Files-header to see what kind of files we carry around */ static retvalue changes_parsefilelines(const char *filename, struct changes *changes, const struct strlist *filelines, const struct atomlist *packagetypes, const struct atomlist *forcearchitectures, bool includebyhand, bool includelogs, bool *ignoredlines_p, bool skip_binaries) { - retvalue result,r; + retvalue result, r; int i; - assert( changes->files == NULL); + assert (changes->files == NULL); result = RET_NOTHING; - for( i = 0 ; i < filelines->count ; i++ ) { + for (i = 0 ; i < filelines->count ; i++) { const char *fileline = filelines->values[i]; r = newentry(&changes->files, fileline, packagetypes, forcearchitectures, changes->source, includebyhand, includelogs, ignoredlines_p, skip_binaries); - RET_UPDATE(result,r); - if( r == RET_ERROR ) + RET_UPDATE(result, r); + if (r == RET_ERROR) return r; } - if( result == RET_NOTHING ) { - fprintf(stderr,"%s: Not enough files in .changes!\n",filename); + if (result == RET_NOTHING) { + fprintf(stderr, +"%s: Not enough files in .changes!\n", filename); return RET_ERROR; } return result; @@ -303,37 +306,40 @@ int i; retvalue r; - for( i = 0 ; i < filelines->count ; i++ ) { + for (i = 0 ; i < filelines->count ; i++) { struct hash_data data, size; const char *fileline = filelines->values[i]; struct fileentry *e; const char *basefilename; - r = hashline_parse(filename, fileline, cs, &basefilename, &data, &size); - if( r == RET_NOTHING ) + r = hashline_parse(filename, fileline, cs, &basefilename, + &data, &size); + if (r == RET_NOTHING) continue; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; e = changes->files; - while( e != NULL && strcmp(e->basename, basefilename) != 0 ) + while (e != NULL && strcmp(e->basename, basefilename) != 0) e = e->next; - if( e == NULL ) { - if( ignoresomefiles ) + if (e == NULL) { + if (ignoresomefiles) /* we might already have ignored files when * creating changes->files, so we cannot say * if this is an error. */ continue; fprintf(stderr, "In '%s': file '%s' listed in '%s' but not in 'Files'\n", - filename, basefilename, changes_checksum_names[cs]); + filename, basefilename, + changes_checksum_names[cs]); return RET_ERROR; } - if( e->hashes.hashes[cs_length].len != size.len || + if (e->hashes.hashes[cs_length].len != size.len || memcmp(e->hashes.hashes[cs_length].start, - size.start, size.len) != 0 ) { + size.start, size.len) != 0) { fprintf(stderr, "In '%s': file '%s' listed in '%s' with different size than in 'Files'\n", - filename, basefilename, changes_checksum_names[cs]); + filename, basefilename, + changes_checksum_names[cs]); return RET_ERROR; } e->hashes.hashes[cs] = data; @@ -345,22 +351,22 @@ struct fileentry *e; retvalue r; - for( e = changes->files ; e != NULL ; e = e->next ) { + for (e = changes->files ; e != NULL ; e = e->next) { r = checksums_initialize(&e->checksums, e->hashes.hashes); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; } -static retvalue check(const char *filename,struct changes *changes,const char *field) { +static retvalue check(const char *filename, struct changes *changes, const char *field) { retvalue r; - r = chunk_checkfield(changes->control,field); - if( r == RET_NOTHING ) { - if( IGNORING("Ignoring","To Ignore",missingfield, - "In '%s': Missing '%s' field!\n",filename,field) ) { + r = chunk_checkfield(changes->control, field); + if (r == RET_NOTHING) { + if (IGNORING(missingfield, +"In '%s': Missing '%s' field!\n", filename, field)) { return RET_OK; } else { return RET_ERROR; @@ -379,59 +385,60 @@ bool skip_binaries; #define E(err) { \ - if( r == RET_NOTHING ) { \ - fprintf(stderr,"In '%s': " err "\n",filename); \ + if (r == RET_NOTHING) { \ + fprintf(stderr, "In '%s': " err "\n", filename); \ r = RET_ERROR; \ - } \ - if( RET_WAS_ERROR(r) ) { \ + } \ + if (RET_WAS_ERROR(r)) { \ changes_free(c); \ return r; \ } \ } #define R { \ - if( RET_WAS_ERROR(r) ) { \ + if (RET_WAS_ERROR(r)) { \ changes_free(c); \ return r; \ } \ } - c = calloc(1,sizeof(struct changes)); - if( c == NULL ) + c = zNEW(struct changes); + if (FAILEDTOALLOC(c)) return RET_ERROR_OOM; r = signature_readsignedchunk(filename, filename, &c->control, &c->signatures, &broken); R; - if( broken && !IGNORING_(brokensignatures, + if (broken && !IGNORING(brokensignatures, "'%s' contains only broken signatures.\n" "This most likely means the file was damaged or edited improperly.\n", - filename) ) { + filename)) { r = RET_ERROR; R; } - r = check(filename,c,"Format"); + r = check(filename, c, "Format"); R; - r = check(filename,c,"Date"); + r = check(filename, c, "Date"); R; - r = chunk_getnameandversion(c->control,"Source",&c->source,&c->sourceversion); + r = chunk_getnameandversion(c->control, "Source", + &c->source, &c->sourceversion); E("Missing 'Source' field"); r = propersourcename(c->source); R; - if( c->sourceversion != NULL ) { + if (c->sourceversion != NULL) { r = properversion(c->sourceversion); R; } - r = chunk_getwordlist(c->control,"Binary",&c->binaries); + r = chunk_getwordlist(c->control, "Binary", &c->binaries); E("Missing 'Binary' field"); - r = chunk_getwordlist(c->control,"Architecture",&c->architectures); + r = chunk_getwordlist(c->control, "Architecture", &c->architectures); E("Missing 'Architecture' field"); - r = chunk_getvalue(c->control,"Version",&c->changesversion); + r = chunk_getvalue(c->control, "Version", &c->changesversion); E("Missing 'Version' field"); r = properversion(c->changesversion); E("Malforce Version number"); - if( c->sourceversion == NULL ) { + if (c->sourceversion == NULL) { c->sourceversion = strdup(c->changesversion); - if( c->sourceversion == NULL ) { + if (FAILEDTOALLOC(c->sourceversion)) { changes_free(c); return RET_ERROR_OOM; } @@ -442,9 +449,9 @@ E("Error comparing versions. (That should have been caught earlier, why now?)"); c->isbinnmu = versioncmp != 0; } - r = chunk_getwordlist(c->control,"Distribution",&c->distributions); + r = chunk_getwordlist(c->control, "Distribution", &c->distributions); E("Missing 'Distribution' field"); - r = check(filename,c,"Maintainer"); + r = check(filename, c, "Maintainer"); R; r = chunk_getextralinelist(c->control, changes_checksum_names[cs_md5sum], @@ -453,7 +460,7 @@ ignoredlines = false; /* check if forcearchitectures allows non-source binaries, * (used to check if Architecture all are skipped) */ - if( forcearchitectures == NULL ) { + if (forcearchitectures == NULL) { skip_binaries = false; } else { skip_binaries = !atomlist_hasexcept(forcearchitectures, @@ -463,31 +470,31 @@ packagetypes, forcearchitectures, includebyhand, includelogs, &ignoredlines, skip_binaries); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filelines[cs_md5sum]); changes_free(c); return r; } - for( cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++) { r = chunk_getextralinelist(c->control, changes_checksum_names[cs], &filelines[cs]); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = changes_addhashes(filename, c, cs, &filelines[cs], ignoredlines); else strlist_init(&filelines[cs]); - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) strlist_done(&filelines[cs]); changes_free(c); return r; } } r = changes_finishhashes(c); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) strlist_done(&filelines[cs]); R; - r = dirs_getdirectory(filename,&c->incomingdirectory); + r = dirs_getdirectory(filename, &c->incomingdirectory); R; *changes = c; @@ -504,77 +511,82 @@ bool has_source_package = false; r = propersourcename(changes->source); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; e = changes->files; - if( e == NULL ) { - fprintf(stderr,"No files given in '%s'!\n",filename); + if (e == NULL) { + fprintf(stderr, "No files given in '%s'!\n", filename); return RET_ERROR; } - for( ; e != NULL ; e = e->next ) { + for (; e != NULL ; e = e->next) { const struct overridedata *oinfo = NULL; const char *force = NULL; - if( e->type == fe_BYHAND || e->type == fe_LOG ) { + if (e->type == fe_BYHAND || e->type == fe_LOG) { needsourcedir = true; continue; } /* section and priority are only needed for the dsc, * not for the other source files */ - if( FE_SOURCE(e->type) && !FE_PACKAGE(e->type) ) { + if (FE_SOURCE(e->type) && !FE_PACKAGE(e->type)) { needs_source_package = e; continue; } - if( forcesection == NULL || forcepriority == NULL ) { + if (forcesection == NULL || forcepriority == NULL) { oinfo = override_search( - FE_BINARY(e->type)?(e->type==fe_UDEB?distribution->overrides.udeb:distribution->overrides.deb):distribution->overrides.dsc, + FE_BINARY(e->type)?(e->type==fe_UDEB? + distribution->overrides.udeb + :distribution->overrides.deb) + :distribution->overrides.dsc, e->name); } - if( forcesection != NULL ) + if (forcesection != NULL) force = forcesection; else - force = override_get(oinfo,SECTION_FIELDNAME); - if( force != NULL ) { + force = override_get(oinfo, SECTION_FIELDNAME); + if (force != NULL) { free(e->section); e->section = strdup(force); - if( e->section == NULL ) + if (FAILEDTOALLOC(e->section)) return RET_ERROR_OOM; } - if( strcmp(e->section,"unknown") == 0 ) { + if (strcmp(e->section, "unknown") == 0) { fprintf(stderr, "Invalid section '%s' of '%s'!\n", e->section, filename); return RET_ERROR; } - if( strcmp(e->section,"-") == 0 ) { - fprintf(stderr,"No section specified for '%s' in '%s'!\n", e->basename, filename); + if (strcmp(e->section, "-") == 0) { + fprintf(stderr, +"No section specified for '%s' in '%s'!\n", e->basename, filename); return RET_ERROR; } - if( forcepriority != NULL ) + if (forcepriority != NULL) force = forcepriority; else - force = override_get(oinfo,PRIORITY_FIELDNAME); - if( force != NULL ) { + force = override_get(oinfo, PRIORITY_FIELDNAME); + if (force != NULL) { free(e->priority); e->priority = strdup(force); - if( e->priority == NULL ) + if (FAILEDTOALLOC(e->priority)) return RET_ERROR_OOM; } - if( strcmp(e->priority,"-") == 0 ) { - fprintf(stderr,"No priority specified for '%s'!\n",filename); + if (strcmp(e->priority, "-") == 0) { + fprintf(stderr, +"No priority specified for '%s'!\n", filename); return RET_ERROR; } - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { const char *fc; fc = override_get(oinfo, "$Component"); - if( fc != NULL ) { + if (fc != NULL) { forcecomponent = component_find(fc); - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { fprintf(stderr, "Unparseable component '%s' in $Component override of '%s'\n", fc, e->name); @@ -589,100 +601,104 @@ r = guess_component(distribution->codename, &distribution->components, changes->source, e->section, forcecomponent, - &e->component_atom); - if( RET_WAS_ERROR(r) ) + &e->component); + if (RET_WAS_ERROR(r)) return r; - assert(atom_defined(e->component_atom)); + assert(atom_defined(e->component)); - if( !atom_defined(changes->firstcomponent) ) { - changes->firstcomponent = e->component_atom; - } else if( changes->firstcomponent != e->component_atom ) { + if (!atom_defined(changes->firstcomponent)) { + changes->firstcomponent = e->component; + } else if (changes->firstcomponent != e->component) { fprintf(stderr, "Warning: %s contains files guessed to be in different components ('%s' vs '%s)!\n", filename, - atoms_components[e->component_atom], + atoms_components[e->component], atoms_components[changes->firstcomponent]); } - if( FE_SOURCE(e->type) ) { - assert( FE_PACKAGE(e->type) ); + if (FE_SOURCE(e->type)) { + assert (FE_PACKAGE(e->type)); has_source_package = true; - if( strcmp(changes->source,e->name) != 0 ) { + if (strcmp(changes->source, e->name) != 0) { r = propersourcename(e->name); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( !atom_defined(changes->srccomponent) ) { - changes->srccomponent = e->component_atom; - } else if( changes->srccomponent != e->component_atom ) { + if (!atom_defined(changes->srccomponent)) { + changes->srccomponent = e->component; + } else if (changes->srccomponent != e->component) { fprintf(stderr, "%s contains source files guessed to be in different components ('%s' vs '%s)!\n", filename, - atoms_components[e->component_atom], + atoms_components[e->component], atoms_components[changes->srccomponent]); return RET_ERROR; } - } else if( FE_BINARY(e->type) ) { + } else if (FE_BINARY(e->type)) { r = properpackagename(e->name); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // Let's just check here, perhaps - if( e->type == fe_UDEB && - !atomlist_in(&distribution->udebcomponents, - e->component_atom)) { + if (e->type == fe_UDEB && + !atomlist_in( + &distribution->udebcomponents, + e->component)) { fprintf(stderr, "Cannot put file '%s' into component '%s', as it is not listed in UDebComponents!\n", - e->basename, atoms_components[e->component_atom]); + e->basename, + atoms_components[e->component]); return RET_ERROR; } } else { - assert( FE_SOURCE(e->type) || FE_BINARY(e->type) ); - fprintf(stderr,"Internal Error!\n"); + assert (FE_SOURCE(e->type) || FE_BINARY(e->type)); + fprintf(stderr, "Internal Error!\n"); return RET_ERROR; } } - if( needs_source_package != NULL && !has_source_package ) { + if (needs_source_package != NULL && !has_source_package) { fprintf(stderr, "'%s' looks like part of an source package, but no dsc file listed in the .changes file!\n", needs_source_package->basename); return RET_ERROR; } - if( atom_defined(changes->srccomponent) ) { + if (atom_defined(changes->srccomponent)) { changes->srcdirectory = calc_sourcedir(changes->srccomponent, changes->source); - if( changes->srcdirectory == NULL ) + if (FAILEDTOALLOC(changes->srcdirectory)) return RET_ERROR_OOM; - } else if( distribution->trackingoptions.includechanges || - needsourcedir ) { + } else if (distribution->trackingoptions.includechanges || + needsourcedir) { component_t component = forcecomponent; - if( !atom_defined(forcecomponent) ) { - for( e = changes->files ; e != NULL ; e = e->next ) { - if( FE_PACKAGE(e->type) ){ - component = e->component_atom; + if (!atom_defined(forcecomponent)) { + for (e = changes->files ; e != NULL ; e = e->next) { + if (FE_PACKAGE(e->type)){ + component = e->component; break; } } } - if( !atom_defined(component) ) { - fprintf(stderr,"No component found to place .changes or byhand files in. Aborting.\n"); + if (!atom_defined(component)) { + fprintf(stderr, +"No component found to place .changes or byhand files in. Aborting.\n"); return RET_ERROR; } - changes->srcdirectory = calc_sourcedir(component,changes->source); - if( changes->srcdirectory == NULL ) + changes->srcdirectory = calc_sourcedir(component, + changes->source); + if (FAILEDTOALLOC(changes->srcdirectory)) return RET_ERROR_OOM; } return RET_OK; } -static inline retvalue checkforarchitecture(const struct fileentry *e, architecture_t architecture ) { - if( !atom_defined(architecture) ) +static inline retvalue checkforarchitecture(const struct fileentry *e, architecture_t architecture) { + if (!atom_defined(architecture)) return RET_NOTHING; - while( e != NULL && e->architecture_into != architecture ) + while (e != NULL && e->architecture_into != architecture) e = e->next; - if( e == NULL ) { - if( !IGNORING_(unusedarch, + if (e == NULL) { + if (!IGNORING(unusedarch, "Architecture header lists architecture '%s', but no files for it!\n", atoms_architectures[architecture])) return RET_ERROR; @@ -694,17 +710,17 @@ const struct atomlist *da = &d->architectures; int i; - if( forcearchitectures == NULL ) { + if (forcearchitectures == NULL) { return atomlist_hasexcept(da, architecture_source); } - for( i = 0 ; i < forcearchitectures->count ; i++ ) { + for (i = 0 ; i < forcearchitectures->count ; i++) { architecture_t a = forcearchitectures->atoms[i]; - if( a == architecture_source ) + if (a == architecture_source) continue; - if( a == architecture_all ) + if (a == architecture_all) return atomlist_hasexcept(da, architecture_source); - if( atomlist_in(da, a) ) + if (atomlist_in(da, a)) return true; } return false; @@ -714,100 +730,104 @@ int i; struct fileentry *e; retvalue r = RET_OK; - bool havedsc = false, haveorig = false, havetar = false, havediff = false; + bool havedsc = false, + haveorig = false, + havetar = false, + havediff = false; /* First check for each given architecture, if it has files: */ - if( forcearchitectures != NULL ) { - for( i = 0 ; i < forcearchitectures->count ; i++ ) { + if (forcearchitectures != NULL) { + for (i = 0 ; i < forcearchitectures->count ; i++) { architecture_t a = forcearchitectures->atoms[i]; - if( !strlist_in(&changes->architectures, - atoms_architectures[a]) ){ + if (!strlist_in(&changes->architectures, + atoms_architectures[a])) { // TODO: check if this is sensible - if( !IGNORING_(surprisingarch, + if (!IGNORING(surprisingarch, "Architecture header does not list the" " architecture '%s' to be forced in!\n", atoms_architectures[a])) return RET_ERROR_MISSING; } r = checkforarchitecture(changes->files, a); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } else { bool limitedtosource = false; bool limitedtononsource = false; - if( packagetypes != NULL ) { + if (packagetypes != NULL) { limitedtosource = true; limitedtononsource = true; - for( i = 0 ; i < packagetypes->count ; i++ ) { - if( packagetypes->atoms[i] == pt_dsc ) + for (i = 0 ; i < packagetypes->count ; i++) { + if (packagetypes->atoms[i] == pt_dsc) limitedtononsource = false; else limitedtosource = false; } } - for( i = 0 ; i < changes->architectures.count ; i++ ) { + for (i = 0 ; i < changes->architectures.count ; i++) { const char *architecture = changes->architectures.values[i]; - if( strcmp(architecture, "source") == 0 ) { - if( limitedtononsource ) + if (strcmp(architecture, "source") == 0) { + if (limitedtononsource) continue; } else { - if( limitedtosource ) + if (limitedtosource) continue; } r = checkforarchitecture(changes->files, architecture_find(architecture)); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } /* Then check for each file, if its architecture is sensible * and listed. */ - for( e = changes->files ; e != NULL ; e = e->next ) { - if( e->type == fe_BYHAND || e->type == fe_LOG ) + for (e = changes->files ; e != NULL ; e = e->next) { + if (e->type == fe_BYHAND || e->type == fe_LOG) continue; - if( atom_defined(e->architecture_into) ) { - if( e->architecture_into == architecture_all ) { + if (atom_defined(e->architecture_into)) { + if (e->architecture_into == architecture_all) { /* "all" can be added if at least one binary * architecture */ - if( !can_add_all(forcearchitectures, - distribution) ) + if (!can_add_all(forcearchitectures, + distribution)) e->architecture_into = atom_unknown; - } else if( !atomlist_in(&distribution->architectures, - e->architecture_into) ) + } else if (!atomlist_in(&distribution->architectures, + e->architecture_into)) e->architecture_into = atom_unknown; } - if( !atom_defined(e->architecture_into) ) { + if (!atom_defined(e->architecture_into)) { fprintf(stderr, "Error: '%s' has the wrong architecture to add it to %s!\n", e->basename, distribution->codename); return RET_ERROR; } - if( !strlist_in(&changes->architectures, - atoms_architectures[e->architecture_into]) ) { - if( !IGNORING_(surprisingarch, + if (!strlist_in(&changes->architectures, + atoms_architectures[e->architecture_into])) { + if (!IGNORING(surprisingarch, "'%s' looks like architecture '%s', but this is not listed in the Architecture-Header!\n", e->basename, atoms_architectures[e->architecture_into])) return RET_ERROR; } - if( e->type == fe_DSC ) { + if (e->type == fe_DSC) { char *calculatedname; - if( havedsc ) { + if (havedsc) { fprintf(stderr, "I don't know what to do with multiple .dsc files in '%s'!\n", filename); return RET_ERROR; } havedsc = true; - calculatedname = calc_source_basename(changes->source,changes->sourceversion); - if( calculatedname == NULL ) + calculatedname = calc_source_basename(changes->source, + changes->sourceversion); + if (FAILEDTOALLOC(calculatedname)) return RET_ERROR_OOM; - if( strcmp(calculatedname,e->basename) != 0 ) { + if (strcmp(calculatedname, e->basename) != 0) { fprintf(stderr, "dsc file name is '%s' instead of the expected '%s'!\n", e->basename, calculatedname); @@ -815,52 +835,58 @@ return RET_ERROR; } free(calculatedname); - } else if( e->type == fe_DIFF ) { - if( havediff ) { + } else if (e->type == fe_DIFF) { + if (havediff) { fprintf(stderr, "I don't know what to do with multiple .diff files in '%s'!\n", filename); return RET_ERROR; } havediff = true; - } else if( e->type == fe_ORIG ) { - if( haveorig ) { + } else if (e->type == fe_ORIG) { + if (haveorig) { fprintf(stderr, "I don't know what to do with multiple .orig.tar.gz files in '%s'!\n", filename); return RET_ERROR; } haveorig = true; - } else if( e->type == fe_TAR ) { + } else if (e->type == fe_TAR) { havetar = true; } } - if( havetar && !haveorig && havediff ) { - fprintf(stderr,"I don't know what to do having a .tar.gz not being a .orig.tar.gz and a .diff.gz in '%s'!\n",filename); + if (havetar && !haveorig && havediff) { + fprintf(stderr, +"I don't know what to do having a .tar.gz not being a .orig.tar.gz and a .diff.gz in '%s'!\n", + filename); return RET_ERROR; } - if( strlist_in(&changes->architectures,"source") && !havedsc && + if (strlist_in(&changes->architectures, "source") && !havedsc && !limitations_missed(forcearchitectures, architecture_source) && !limitations_missed(packagetypes, pt_dsc)) { - fprintf(stderr,"I don't know what to do with a source-upload not containing a .dsc in '%s'!\n",filename); + fprintf(stderr, +"I don't know what to do with a source-upload not containing a .dsc in '%s'!\n", + filename); return RET_ERROR; } - if( havedsc && !havediff && !haveorig && !havetar ) { - fprintf(stderr,"I don't know what to do having a .dsc without a .diff.gz or .tar.gz in '%s'!\n",filename); + if (havedsc && !havediff && !haveorig && !havetar) { + fprintf(stderr, +"I don't know what to do having a .dsc without a .diff.gz or .tar.gz in '%s'!\n", + filename); return RET_ERROR; } return r; } -static retvalue changes_checkfiles(struct database *database,const char *filename,struct changes *changes) { +static retvalue changes_checkfiles(const char *filename, struct changes *changes) { struct fileentry *e; retvalue r; r = RET_NOTHING; - for( e = changes->files; e != NULL ; e = e->next ) { + for (e = changes->files; e != NULL ; e = e->next) { //TODO: decide earlier which files to include - if( e->type == fe_BYHAND ) { + if (e->type == fe_BYHAND) { /* byhand files might have the same name and not * contain the version, so store separately */ assert(changes->srcdirectory!=NULL); @@ -869,30 +895,32 @@ changes->source, changes->changesversion, e->basename); - } else if( FE_SOURCE(e->type) || e->type == fe_LOG) { + } else if (FE_SOURCE(e->type) || e->type == fe_LOG) { assert(changes->srcdirectory!=NULL); - e->filekey = calc_dirconcat(changes->srcdirectory,e->basename); + e->filekey = calc_dirconcat(changes->srcdirectory, + e->basename); } else { char *directory; // TODO: make this in-situ? /* as the directory depends on the sourcename, it can be * different for every file... */ - directory = calc_sourcedir(e->component_atom, changes->source); - if( FAILEDTOALLOC(directory) ) + directory = calc_sourcedir(e->component, + changes->source); + if (FAILEDTOALLOC(directory)) return RET_ERROR_OOM; - e->filekey = calc_dirconcat(directory,e->basename); + e->filekey = calc_dirconcat(directory, e->basename); free(directory); } - if( e->filekey == NULL ) + if (FAILEDTOALLOC(e->filekey)) return RET_ERROR_OOM; /* do not copy yet, but only check if it could be included */ - r = files_canadd(database, e->filekey, e->checksums); - if( RET_WAS_ERROR(r) ) + r = files_canadd(e->filekey, e->checksums); + if (RET_WAS_ERROR(r)) return r; /* If is was already there, remember that */ - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { e->wasalreadythere = true; } else { /* and if it needs inclusion check if there is a file */ @@ -901,11 +929,14 @@ assert(RET_IS_OK(r)); // TODO: add a --paranoid to also check md5sums before copying? - fullfilename = calc_dirconcat(changes->incomingdirectory,e->basename); - if( fullfilename == NULL ) + fullfilename = calc_dirconcat( + changes->incomingdirectory, + e->basename); + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; - if( !isregularfile(fullfilename) ) { - fprintf(stderr, "Cannot find file '%s' needed by '%s'!\n", fullfilename,filename); + if (!isregularfile(fullfilename)) { + fprintf(stderr, +"Cannot find file '%s' needed by '%s'!\n", fullfilename, filename); free(fullfilename); return RET_ERROR_MISSING; } @@ -916,22 +947,21 @@ return RET_OK; } -static retvalue changes_includefiles(struct database *database,struct changes *changes) { +static retvalue changes_includefiles(struct changes *changes) { struct fileentry *e; retvalue r; r = RET_NOTHING; - for( e = changes->files; e != NULL ; e = e->next ) { - assert( e->filekey != NULL ); + for (e = changes->files; e != NULL ; e = e->next) { + assert (e->filekey != NULL); - if( e->wasalreadythere && checksums_iscomplete(e->checksums) ) + if (e->wasalreadythere && checksums_iscomplete(e->checksums)) continue; - r = files_checkincludefile(database, - changes->incomingdirectory, e->basename, - e->filekey, &e->checksums); - if( RET_WAS_ERROR(r) ) + r = files_checkincludefile(changes->incomingdirectory, + e->basename, e->filekey, &e->checksums); + if (RET_WAS_ERROR(r)) return r; } @@ -939,27 +969,27 @@ } /* delete the files included */ -static retvalue changes_deleteleftoverfiles(struct changes *changes,int delete) { +static retvalue changes_deleteleftoverfiles(struct changes *changes, int delete) { struct fileentry *e; - retvalue result,r; + retvalue result, r; - if( delete < D_MOVE ) + if (delete < D_MOVE) return RET_OK; result = RET_OK; // TODO: we currently only see files included here, so D_DELETE // only affacts the .changes file. - for( e = changes->files; e != NULL ; e = e->next ) { + for (e = changes->files; e != NULL ; e = e->next) { char *fullorigfilename; - if( delete < D_DELETE && e->filekey == NULL ) + if (delete < D_DELETE && e->filekey == NULL) continue; fullorigfilename = calc_dirconcat(changes->incomingdirectory, e->basename); - if( unlink(fullorigfilename) != 0 ) { + if (unlink(fullorigfilename) != 0) { int err = errno; fprintf(stderr, "Error deleting '%s': %d=%s\n", fullorigfilename, err, strerror(err)); @@ -972,17 +1002,17 @@ return result; } -static retvalue changes_check_sourcefile(struct changes *changes, struct fileentry *dsc, struct database *database, const char *basefilename, const char *filekey, struct checksums **checksums_p) { +static retvalue changes_check_sourcefile(struct changes *changes, struct fileentry *dsc, const char *basefilename, const char *filekey, struct checksums **checksums_p) { retvalue r; - r = files_expect(database, filekey, *checksums_p, false); - if( RET_WAS_ERROR(r) ) + r = files_expect(filekey, *checksums_p, false); + if (RET_WAS_ERROR(r)) return r; // TODO: get additionals checksum out of database, as future // source file completion code might need them... - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) return RET_OK; - if( !IGNORABLE(missingfile) ) { + if (!IGNORABLE(missingfile)) { fprintf(stderr, "Unable to find %s needed by %s!\n" "Perhaps you forgot to give dpkg-buildpackage the -sa option,\n" @@ -995,11 +1025,11 @@ "Perhaps you forgot to give dpkg-buildpackage the -sa option.\n" "--ignore=missingfile was given, searching for file...\n", filekey); - return files_checkincludefile(database, changes->incomingdirectory, + return files_checkincludefile(changes->incomingdirectory, basefilename, filekey, checksums_p); } -static retvalue dsc_prepare(struct changes *changes, struct fileentry *dsc, struct database *database, struct distribution *distribution, const char *dscfilename){ +static retvalue dsc_prepare(struct changes *changes, struct fileentry *dsc, struct distribution *distribution, const char *dscfilename){ retvalue r; const struct overridedata *oinfo; char *dscbasename; @@ -1007,17 +1037,17 @@ int i; bool broken; - assert( dsc->section != NULL ); - assert( dsc->priority != NULL ); - assert( atom_defined(changes->srccomponent) ); - assert( dsc->basename != NULL ); - assert( dsc->checksums != NULL ); - assert( changes->source != NULL ); - assert( changes->sourceversion != NULL ); + assert (dsc->section != NULL); + assert (dsc->priority != NULL); + assert (atom_defined(changes->srccomponent)); + assert (dsc->basename != NULL); + assert (dsc->checksums != NULL); + assert (changes->source != NULL); + assert (changes->sourceversion != NULL); /* First make sure this distribution has a source section at all, * for which it has to be listed in the "Architectures:"-field ;-) */ - if( !atomlist_in(&distribution->architectures, architecture_source) ) { + if (!atomlist_in(&distribution->architectures, architecture_source)) { fprintf(stderr, "Cannot put a source package into Distribution '%s' not having 'source' in its 'Architectures:'-field!\n", distribution->codename); @@ -1028,29 +1058,30 @@ /* Then take a closer look in the file: */ r = sources_readdsc(&dsc->pkg.dsc, dscfilename, dscfilename, &broken); - if( RET_IS_OK(r) && broken && !IGNORING_(brokensignatures, + if (RET_IS_OK(r) && broken && !IGNORING(brokensignatures, "'%s' contains only broken signatures.\n" "This most likely means the file was damaged or edited improperly\n", - dscfilename) ) + dscfilename)) r = RET_ERROR; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = propersourcename(dsc->pkg.dsc.name); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properversion(dsc->pkg.dsc.version); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properfilenames(&dsc->pkg.dsc.files.names); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( strcmp(changes->source, dsc->pkg.dsc.name) != 0 ) { + if (strcmp(changes->source, dsc->pkg.dsc.name) != 0) { /* This cannot be ignored, as too much depends on it yet */ fprintf(stderr, "'%s' says it is '%s', while .changes file said it is '%s'\n", - dsc->basename, dsc->pkg.dsc.name, changes->source); + dsc->basename, dsc->pkg.dsc.name, + changes->source); return RET_ERROR; } - if( strcmp(changes->sourceversion, dsc->pkg.dsc.version) != 0 && - !IGNORING_(wrongversion, + if (strcmp(changes->sourceversion, dsc->pkg.dsc.version) != 0 && + !IGNORING(wrongversion, "'%s' says it is version '%s', while .changes file said it is '%s'\n", dsc->basename, dsc->pkg.dsc.version, changes->sourceversion)) { @@ -1061,50 +1092,50 @@ free(dsc->pkg.dsc.section); dsc->pkg.dsc.section = strdup(dsc->section); - if( dsc->pkg.dsc.section == NULL ) + if (FAILEDTOALLOC(dsc->pkg.dsc.section)) return RET_ERROR_OOM; free(dsc->pkg.dsc.priority); dsc->pkg.dsc.priority = strdup(dsc->priority); - if( dsc->pkg.dsc.priority == NULL ) + if (FAILEDTOALLOC(dsc->pkg.dsc.priority)) return RET_ERROR_OOM; - assert( dsc->pkg.dsc.name != NULL && dsc->pkg.dsc.version != NULL ); + assert (dsc->pkg.dsc.name != NULL && dsc->pkg.dsc.version != NULL); /* Add the dsc file to the list of files in this source package: */ dscbasename = strdup(dsc->basename); - if( dscbasename == NULL ) + if (FAILEDTOALLOC(dscbasename)) r = RET_ERROR_OOM; else r = checksumsarray_include(&dsc->pkg.dsc.files, dscbasename, dsc->checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* Calculate the filekeys: */ r = calc_dirconcats(changes->srcdirectory, &dsc->pkg.dsc.files.names, &dsc->needed_filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* noone else might have looked yet, if we have them: */ - assert( dsc->pkg.dsc.files.names.count == dsc->needed_filekeys.count ); - for( i = 1 ; i < dsc->pkg.dsc.files.names.count ; i ++ ) { - if( !RET_WAS_ERROR(r) ) { + assert (dsc->pkg.dsc.files.names.count == dsc->needed_filekeys.count); + for (i = 1 ; i < dsc->pkg.dsc.files.names.count ; i ++) { + if (!RET_WAS_ERROR(r)) { r = changes_check_sourcefile( - changes, dsc, database, + changes, dsc, dsc->pkg.dsc.files.names.values[i], dsc->needed_filekeys.values[i], &dsc->pkg.dsc.files.checksums[i]); } } - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = sources_complete(&dsc->pkg.dsc, changes->srcdirectory, oinfo, dsc->pkg.dsc.section, dsc->pkg.dsc.priority, &control); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(dsc->pkg.dsc.control); dsc->pkg.dsc.control = control; } @@ -1112,57 +1143,58 @@ } -static retvalue changes_checkpkgs(struct database *database, struct distribution *distribution, struct changes *changes) { +static retvalue changes_checkpkgs(struct distribution *distribution, struct changes *changes) { struct fileentry *e; retvalue r; r = RET_NOTHING; e = changes->files; - while( e != NULL ) { + while (e != NULL) { char *fullfilename; - if( e->type != fe_DEB && e->type != fe_DSC && e->type != fe_UDEB) { + if (e->type != fe_DEB && e->type != fe_DSC + && e->type != fe_UDEB) { e = e->next; continue; } fullfilename = files_calcfullfilename(e->filekey); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; - if( e->type == fe_DEB ) { + if (e->type == fe_DEB) { r = deb_prepare(&e->pkg.deb, - e->component_atom, e->architecture_into, + e->component, e->architecture_into, e->section, e->priority, pt_deb, distribution, fullfilename, e->filekey, e->checksums, &changes->binaries, changes->source, changes->sourceversion); - } else if( e->type == fe_UDEB ) { + } else if (e->type == fe_UDEB) { r = deb_prepare(&e->pkg.deb, - e->component_atom, e->architecture_into, + e->component, e->architecture_into, e->section, e->priority, pt_udeb, distribution, fullfilename, e->filekey, e->checksums, &changes->binaries, changes->source, changes->sourceversion); - } else if( e->type == fe_DSC ) { - if( !changes->isbinnmu || IGNORING_(dscinbinnmu, + } else if (e->type == fe_DSC) { + if (!changes->isbinnmu || IGNORING(dscinbinnmu, "File '%s' looks like a source package, but this .changes looks like a binNMU\n" "(as '%s' (from Source:) and '%s' (From Version:) differ.)\n", e->filekey, changes->sourceversion, - changes->changesversion) ) { + changes->changesversion)) { - assert( atom_defined(changes->srccomponent)); - assert(changes->srcdirectory!=NULL); - r = dsc_prepare(changes, e, database, + assert (atom_defined(changes->srccomponent)); + assert (changes->srcdirectory!=NULL); + r = dsc_prepare(changes, e, distribution, fullfilename); } else r = RET_ERROR; } free(fullfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; e = e->next; } @@ -1170,67 +1202,66 @@ return r; } -static retvalue changes_includepkgs(struct database *database, struct distribution *distribution, struct changes *changes, /*@null@*/struct trackingdata *trackingdata, const struct atomlist *forcearchitectures, bool *missed_p) { +static retvalue changes_includepkgs(struct distribution *distribution, struct changes *changes, /*@null@*/struct trackingdata *trackingdata, const struct atomlist *forcearchitectures, bool *missed_p) { struct fileentry *e; - retvalue result,r; + retvalue result, r; *missed_p = false; r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; e = changes->files; - while( e != NULL ) { - if( e->type != fe_DEB && e->type != fe_DSC && e->type != fe_UDEB - && e->type != fe_LOG && e->type != fe_BYHAND ) { + while (e != NULL) { + if (e->type != fe_DEB && e->type != fe_DSC + && e->type != fe_UDEB && e->type != fe_LOG + && e->type != fe_BYHAND) { e = e->next; continue; } - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - if( e->type == fe_DEB ) { - r = deb_addprepared(e->pkg.deb, database, + if (e->type == fe_DEB) { + r = deb_addprepared(e->pkg.deb, /* architecture all needs this, the rest is * already filtered out */ (e->architecture_into == architecture_all)? forcearchitectures:NULL, pt_deb, distribution, trackingdata); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) *missed_p = true; - } else if( e->type == fe_UDEB ) { - r = deb_addprepared(e->pkg.deb, database, + } else if (e->type == fe_UDEB) { + r = deb_addprepared(e->pkg.deb, /* architecture all needs this, the rest is * already filtered out */ (e->architecture_into == architecture_all)? forcearchitectures:NULL, pt_udeb, distribution, trackingdata); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) *missed_p = true; - } else if( e->type == fe_DSC ) { - r = dsc_addprepared(database, &e->pkg.dsc, + } else if (e->type == fe_DSC) { + r = dsc_addprepared(&e->pkg.dsc, changes->srccomponent, &e->needed_filekeys, distribution, trackingdata); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) *missed_p = true; - } else if( e->type == fe_LOG && trackingdata != NULL ) { + } else if (e->type == fe_LOG && trackingdata != NULL) { r = trackedpackage_addfilekey(trackingdata->tracks, trackingdata->pkg, - ft_LOG, e->filekey, false, - database); + ft_LOG, e->filekey, false); e->filekey = NULL; - } else if( e->type == fe_BYHAND && trackingdata != NULL ) { + } else if (e->type == fe_BYHAND && trackingdata != NULL) { r = trackedpackage_addfilekey(trackingdata->tracks, trackingdata->pkg, - ft_XTRA_DATA, e->filekey, false, - database); + ft_XTRA_DATA, e->filekey, false); e->filekey = NULL; } RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; e = e->next; } @@ -1243,14 +1274,14 @@ static void verifyarchitectures(const struct changes *changes, struct upload_conditions *conditions) { const struct fileentry *e; - for( e = changes->files ; e != NULL ; e = e->next ) { - if( FE_SOURCE(e->type) ) { - if( !uploaders_verifyatom(conditions, - architecture_source) ) + for (e = changes->files ; e != NULL ; e = e->next) { + if (FE_SOURCE(e->type)) { + if (!uploaders_verifyatom(conditions, + architecture_source)) break; - } else if( FE_BINARY(e->type) ) { - if( !uploaders_verifyatom(conditions, - e->architecture_into) ) + } else if (FE_BINARY(e->type)) { + if (!uploaders_verifyatom(conditions, + e->architecture_into)) break; } } @@ -1258,12 +1289,12 @@ static void verifysection(const struct changes *changes, struct upload_conditions *conditions) { const struct fileentry *e; - for( e = changes->files ; e != NULL ; e = e->next ) { - if( FE_SOURCE(e->type) ) { - if( !uploaders_verifystring(conditions, e->section) ) + for (e = changes->files ; e != NULL ; e = e->next) { + if (FE_SOURCE(e->type)) { + if (!uploaders_verifystring(conditions, e->section)) break; - } else if( FE_BINARY(e->type) ) { - if( !uploaders_verifystring(conditions, e->section) ) + } else if (FE_BINARY(e->type)) { + if (!uploaders_verifystring(conditions, e->section)) break; } } @@ -1271,9 +1302,9 @@ static void verifybinary(const struct changes *changes, struct upload_conditions *conditions) { const struct fileentry *e; - for( e = changes->files ; e != NULL ; e = e->next ) { - if( FE_BINARY(e->type) ) { - if( !uploaders_verifystring(conditions, e->name) ) + for (e = changes->files ; e != NULL ; e = e->next) { + if (FE_BINARY(e->type)) { + if (!uploaders_verifystring(conditions, e->name)) break; } } @@ -1281,16 +1312,16 @@ static void verifybyhands(const struct changes *changes, struct upload_conditions *conditions) { const struct fileentry *e; - for( e = changes->files ; e != NULL ; e = e->next ) { - if( e->type == fe_BYHAND ) { - if( !uploaders_verifystring(conditions, e->name) ) + for (e = changes->files ; e != NULL ; e = e->next) { + if (e->type == fe_BYHAND) { + if (!uploaders_verifystring(conditions, e->name)) break; } } } static bool permissionssuffice(struct changes *changes, const struct distribution *into, struct upload_conditions *conditions) { - do switch( uploaders_nextcondition(conditions) ) { + do switch (uploaders_nextcondition(conditions)) { case uc_ACCEPTED: return true; case uc_REJECTED: @@ -1300,7 +1331,7 @@ into->codename); break; case uc_SOURCENAME: - assert( changes->source != NULL); + assert (changes->source != NULL); (void)uploaders_verifystring(conditions, changes->source); break; @@ -1316,14 +1347,14 @@ case uc_ARCHITECTURES: verifyarchitectures(changes, conditions); break; - } while( true ); + } while (true); } /* insert the given .changes into the mirror in the * if forcecomponent, forcesection or forcepriority is NULL * get it from the files or try to guess it. */ -retvalue changes_add(struct database *database, trackingdb const tracks, const struct atomlist *packagetypes, component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *changesfilename, int delete) { - retvalue result,r; +retvalue changes_add(trackingdb const tracks, const struct atomlist *packagetypes, component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *changesfilename, int delete) { + retvalue result, r; struct changes *changes; struct trackingdata trackingdata; bool somethingwasmissed; @@ -1334,35 +1365,38 @@ packagetypes, forcearchitectures, distribution->trackingoptions.includebyhand, distribution->trackingoptions.includelogs); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( (distribution->suite == NULL || - !strlist_in(&changes->distributions,distribution->suite)) && - !strlist_in(&changes->distributions,distribution->codename) && + if ((distribution->suite == NULL || + !strlist_in(&changes->distributions, distribution->suite)) && + !strlist_in(&changes->distributions, distribution->codename) && !strlist_intersects(&changes->distributions, - &distribution->alsoaccept) ) { - if( !IGNORING("Ignoring","To ignore",wrongdistribution,".changes put in a distribution not listed within it!\n") ) { + &distribution->alsoaccept)) { + if (!IGNORING(wrongdistribution, +".changes put in a distribution not listed within it!\n")) { changes_free(changes); return RET_ERROR; } } /* make sure caller has called distribution_loaduploaders */ - assert( distribution->uploaders == NULL || distribution->uploaderslist != NULL ); - if( distribution->uploaderslist != NULL ) { + assert (distribution->uploaders == NULL + || distribution->uploaderslist != NULL); + if (distribution->uploaderslist != NULL) { struct upload_conditions *conditions; r = uploaders_permissions(distribution->uploaderslist, changes->signatures, &conditions); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { changes_free(changes); return r; } - if( !permissionssuffice(changes, distribution, conditions) && - !IGNORING_(uploaders,"No rule allowing this package in found in %s!\n", - distribution->uploaders) ) { + if (!permissionssuffice(changes, distribution, conditions) && + !IGNORING(uploaders, +"No rule allowing this package in found in %s!\n", + distribution->uploaders)) { free(conditions); changes_free(changes); return RET_ERROR; @@ -1370,44 +1404,46 @@ free(conditions); } - /* look for component, section and priority to be correct or guess them*/ - r = changes_fixfields(distribution, changesfilename, changes, forcecomponent, forcesection, forcepriority); + /*look for component, section and priority to be correct or guess them*/ + r = changes_fixfields(distribution, changesfilename, changes, + forcecomponent, forcesection, forcepriority); /* do some tests if values are sensible */ - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = changes_check(distribution, changesfilename, changes, forcearchitectures, packagetypes); - if( interrupted() ) + if (interrupted()) RET_UPDATE(r, RET_ERROR_INTERRUPTED); - if( !RET_WAS_ERROR(r) ) - r = changes_checkfiles(database, changesfilename, changes); + if (!RET_WAS_ERROR(r)) + r = changes_checkfiles(changesfilename, changes); - if( interrupted() ) + if (interrupted()) RET_UPDATE(r, RET_ERROR_INTERRUPTED); /* add files in the pool */ - if( !RET_WAS_ERROR(r) ) - r = changes_includefiles(database, changes); + if (!RET_WAS_ERROR(r)) + r = changes_includefiles(changes); - if( !RET_WAS_ERROR(r) ) - r = changes_checkpkgs(database, distribution, changes); + if (!RET_WAS_ERROR(r)) + r = changes_checkpkgs(distribution, changes); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { changes_free(changes); return r; } - if( tracks != NULL ) { - r = trackingdata_summon(tracks,changes->source,changes->sourceversion,&trackingdata); - if( RET_WAS_ERROR(r) ) { + if (tracks != NULL) { + r = trackingdata_summon(tracks, changes->source, + changes->sourceversion, &trackingdata); + if (RET_WAS_ERROR(r)) { changes_free(changes); return r; } - if( distribution->trackingoptions.includechanges ) { + if (distribution->trackingoptions.includechanges) { char *basefilename; - assert( changes->srcdirectory != NULL ); + assert (changes->srcdirectory != NULL); basefilename = calc_changes_basename(changes->source, changes->changesversion, @@ -1416,93 +1452,96 @@ calc_dirconcat(changes->srcdirectory, basefilename); free(basefilename); - if( changes->changesfilekey == NULL ) { + if (FAILEDTOALLOC(changes->changesfilekey)) { changes_free(changes); trackingdata_done(&trackingdata); return RET_ERROR_OOM; } - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else - r = files_preinclude(database, - changesfilename, + r = files_preinclude(changesfilename, changes->changesfilekey, NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { changes_free(changes); trackingdata_done(&trackingdata); return r; } } } - if( interrupted() ) { - if( tracks != NULL ) + if (interrupted()) { + if (tracks != NULL) trackingdata_done(&trackingdata); changes_free(changes); return RET_ERROR_INTERRUPTED; } /* add the source and binary packages in the given distribution */ - result = changes_includepkgs(database, distribution, changes, + result = changes_includepkgs(distribution, changes, (tracks!=NULL)?&trackingdata:NULL, forcearchitectures, &somethingwasmissed); - if( RET_WAS_ERROR(result) ) { - if( tracks != NULL ) { + if (RET_WAS_ERROR(result)) { + if (tracks != NULL) { trackingdata_done(&trackingdata); } changes_free(changes); return result; } - if( tracks != NULL ) { - if( changes->changesfilekey != NULL ) { + if (tracks != NULL) { + if (changes->changesfilekey != NULL) { char *changesfilekey = strdup(changes->changesfilekey); - assert( changes->srcdirectory != NULL ); - if( changesfilekey == NULL ) { + assert (changes->srcdirectory != NULL); + if (FAILEDTOALLOC(changesfilekey)) { trackingdata_done(&trackingdata); changes_free(changes); return RET_ERROR_OOM; } r = trackedpackage_addfilekey(tracks, trackingdata.pkg, - ft_CHANGES, changesfilekey, false, - database); - RET_ENDUPDATE(result,r); - } - r = trackingdata_finish(tracks, &trackingdata, database); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + ft_CHANGES, changesfilekey, false); + RET_ENDUPDATE(result, r); + } + r = trackingdata_finish(tracks, &trackingdata); + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(result)) { changes_free(changes); return result; } } /* if something was included, call --changes notify scripts */ - if( RET_IS_OK(result) ) { - assert( logger_isprepared(distribution->logger) ); + if (RET_IS_OK(result)) { + assert (logger_isprepared(distribution->logger)); logger_logchanges(distribution->logger, distribution->codename, - changes->source, changes->changesversion, changes->control, + changes->source, changes->changesversion, + changes->control, changesfilename, changes->changesfilekey); } /* wait for notify scripts (including those for the packages) * before deleting the .changes */ logger_wait(); - if( (delete >= D_MOVE && changes->changesfilekey != NULL) || - delete >= D_DELETE ) { - if( somethingwasmissed && delete < D_DELETE ) { - if( verbose >= 0 ) { - fprintf(stderr,"Not deleting '%s' as no package was added or some package was missed.\n(Use --delete --delete to delete anyway in such cases)\n",changesfilename); + if ((delete >= D_MOVE && changes->changesfilekey != NULL) || + delete >= D_DELETE) { + if (somethingwasmissed && delete < D_DELETE) { + if (verbose >= 0) { + fprintf(stderr, +"Not deleting '%s' as no package was added or some package was missed.\n" +"(Use --delete --delete to delete anyway in such cases)\n", + changesfilename); } } else { - if( verbose >= 5 ) { - printf("Deleting '%s'.\n",changesfilename); + if (verbose >= 5) { + printf("Deleting '%s'.\n", changesfilename); } - if( unlink(changesfilename) != 0 ) { + if (unlink(changesfilename) != 0) { int e = errno; fprintf(stderr, "Error %d deleting '%s': %s\n", - e, changesfilename, strerror(e)); + e, changesfilename, + strerror(e)); } } } diff -Nru reprepro-4.5.0/checkindeb.c reprepro-4.6.0/checkindeb.c --- reprepro-4.5.0/checkindeb.c 2010-07-11 10:15:58.000000000 +0000 +++ reprepro-4.6.0/checkindeb.c 2011-05-05 14:42:55.000000000 +0000 @@ -48,7 +48,7 @@ Things to do with .deb's checkin by hand: (by comparison with apt-ftparchive) - extract the control file (that's the hard part -> extractcontrol.c ) - check for Package, Version, Architecture, Maintainer, Description -- apply overwrite if neccesary (section,priority and perhaps maintainer). +- apply overwrite if neccesary (section, priority and perhaps maintainer). - add Size, MD5sum, Filename, Priority, Section - remove Status (warning if existant?) - check for Optional-field and reject then.. @@ -58,16 +58,16 @@ /* things to be set by deb_read: */ struct deb_headers deb; /* things that will still be NULL then: */ - component_t component_atom; + component_t component; /* with deb_calclocations: */ const char *filekey; struct strlist filekeys; }; void deb_free(/*@only@*/struct debpackage *pkg) { - if( pkg != NULL ) { + if (pkg != NULL) { binaries_debdone(&pkg->deb); - if( pkg->filekey != NULL ) + if (pkg->filekey != NULL) strlist_done(&pkg->filekeys); } free(pkg); @@ -78,18 +78,20 @@ retvalue r; struct debpackage *deb; - deb = calloc(1,sizeof(struct debpackage)); + deb = zNEW(struct debpackage); + if (FAILEDTOALLOC(deb)) + return RET_ERROR_OOM; r = binaries_readdeb(&deb->deb, filename, needssourceversion); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properpackagename(deb->deb.name); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = propersourcename(deb->deb.source); - if( RET_IS_OK(r) && needssourceversion ) + if (RET_IS_OK(r) && needssourceversion) r = properversion(deb->deb.sourceversion); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properversion(deb->deb.version); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { deb_free(deb); return r; } @@ -104,7 +106,7 @@ const struct overridedata *oinfo; retvalue r; - if( packagetype == pt_udeb ) { + if (packagetype == pt_udeb) { binoverride = distribution->overrides.udeb; components = &distribution->udebcomponents; } else { @@ -112,21 +114,21 @@ components = &distribution->components; } - oinfo = override_search(binoverride,pkg->deb.name); + oinfo = override_search(binoverride, pkg->deb.name); *oinfo_ptr = oinfo; - if( forcesection == NULL ) { - forcesection = override_get(oinfo,SECTION_FIELDNAME); + if (forcesection == NULL) { + forcesection = override_get(oinfo, SECTION_FIELDNAME); } - if( forcepriority == NULL ) { - forcepriority = override_get(oinfo,PRIORITY_FIELDNAME); + if (forcepriority == NULL) { + forcepriority = override_get(oinfo, PRIORITY_FIELDNAME); } - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { const char *fc; fc = override_get(oinfo, "$Component"); - if( fc != NULL ) { + if (fc != NULL) { forcecomponent = component_find(fc); - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { fprintf(stderr, "Unparseable component '%s' in $Component override of '%s'\n", fc, pkg->deb.name); @@ -135,27 +137,27 @@ } } - if( forcesection != NULL ) { + if (forcesection != NULL) { free(pkg->deb.section); pkg->deb.section = strdup(forcesection); - if( pkg->deb.section == NULL ) { + if (FAILEDTOALLOC(pkg->deb.section)) { return RET_ERROR_OOM; } } - if( forcepriority != NULL ) { + if (forcepriority != NULL) { free(pkg->deb.priority); pkg->deb.priority = strdup(forcepriority); - if( pkg->deb.priority == NULL ) { + if (FAILEDTOALLOC(pkg->deb.priority)) { return RET_ERROR_OOM; } } - if( pkg->deb.section == NULL ) { + if (pkg->deb.section == NULL) { fprintf(stderr, "No section given for '%s', skipping.\n", pkg->deb.name); return RET_ERROR; } - if( pkg->deb.priority == NULL ) { + if (pkg->deb.priority == NULL) { fprintf(stderr, "No priority given for '%s', skipping.\n", pkg->deb.name); return RET_ERROR; @@ -165,50 +167,52 @@ r = guess_component(distribution->codename, components, pkg->deb.name, pkg->deb.section, - forcecomponent, &pkg->component_atom); - if( RET_WAS_ERROR(r) ) + forcecomponent, &pkg->component); + if (RET_WAS_ERROR(r)) return r; - if( verbose > 0 && !atom_defined(forcecomponent) ) { + if (verbose > 0 && !atom_defined(forcecomponent)) { fprintf(stderr, "%s: component guessed as '%s'\n", debfilename, - atoms_components[pkg->component_atom]); + atoms_components[pkg->component]); } /* some sanity checks: */ - if( forcearchitectures != NULL && - pkg->deb.architecture_atom != architecture_all && + if (forcearchitectures != NULL && + pkg->deb.architecture != architecture_all && !atomlist_in(forcearchitectures, - pkg->deb.architecture_atom) ) { - fprintf(stderr, "Cannot add '%s', as it is architecture '%s' and you specified to only include ", + pkg->deb.architecture)) { + fprintf(stderr, +"Cannot add '%s', as it is architecture '%s' and you specified to only include ", debfilename, - atoms_architectures[pkg->deb.architecture_atom]); + atoms_architectures[pkg->deb.architecture]); atomlist_fprint(stderr, at_architecture, forcearchitectures); fputs(".\n", stderr); return RET_ERROR; - } else if( pkg->deb.architecture_atom != architecture_all && + } else if (pkg->deb.architecture != architecture_all && !atomlist_in(&distribution->architectures, - pkg->deb.architecture_atom)) { + pkg->deb.architecture)) { (void)fprintf(stderr, "Error looking at '%s': '%s' is not one of the valid architectures: '", debfilename, - atoms_architectures[pkg->deb.architecture_atom]); + atoms_architectures[pkg->deb.architecture]); (void)atomlist_fprint(stderr, at_architecture, &distribution->architectures); - (void)fputs("'\n",stderr); + (void)fputs("'\n", stderr); return RET_ERROR; } - if( !atomlist_in(components, pkg->component_atom) ) { + if (!atomlist_in(components, pkg->component)) { fprintf(stderr, "Error looking at %s': Would be placed in unavailable component '%s'!\n", debfilename, - atoms_components[pkg->component_atom]); - /* this cannot be ignored as there is not data structure available*/ + atoms_components[pkg->component]); + /* this cannot be ignored + * as there is not data structure available */ return RET_ERROR; } - r = binaries_calcfilekeys(pkg->component_atom, &pkg->deb, + r = binaries_calcfilekeys(pkg->component, &pkg->deb, packagetype, &pkg->filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; pkg->filekey = pkg->filekeys.values[0]; return RET_OK; @@ -222,26 +226,26 @@ char *control; struct atomlist forcearchitectures; - assert( givenfilekey != NULL ); - assert( checksums != NULL ); - assert( allowed_binaries != NULL ); - assert( expectedsourcepackage != NULL ); - assert( expectedsourceversion != NULL ); + assert (givenfilekey != NULL); + assert (checksums != NULL); + assert (allowed_binaries != NULL); + assert (expectedsourcepackage != NULL); + assert (expectedsourceversion != NULL); /* First taking a closer look in the file: */ - r = deb_read(&pkg,debfilename, true); - if( RET_WAS_ERROR(r) ) { + r = deb_read(&pkg, debfilename, true); + if (RET_WAS_ERROR(r)) { return r; } - if( !strlist_in(allowed_binaries, pkg->deb.name) && - !IGNORING_(surprisingbinary, + if (!strlist_in(allowed_binaries, pkg->deb.name) && + !IGNORING(surprisingbinary, "'%s' has packagename '%s' not listed in the .changes file!\n", debfilename, pkg->deb.name)) { deb_free(pkg); return RET_ERROR; } - if( strcmp(pkg->deb.source, expectedsourcepackage) != 0 ) { + if (strcmp(pkg->deb.source, expectedsourcepackage) != 0) { /* this cannot be ignored easily, as it determines * the directory this file is stored into */ fprintf(stderr, @@ -251,8 +255,8 @@ deb_free(pkg); return RET_ERROR; } - if( strcmp(pkg->deb.sourceversion, expectedsourceversion) != 0 && - !IGNORING_(wrongsourceversion, + if (strcmp(pkg->deb.sourceversion, expectedsourceversion) != 0 && + !IGNORING(wrongsourceversion, "'%s' lists source version '%s', but .changes says it is '%s'!\n", debfilename, pkg->deb.sourceversion, expectedsourceversion)) { @@ -264,13 +268,15 @@ forcearchitectures.size = 1; forcearchitectures.atoms = &forcearchitecture; - r = deb_preparelocation(pkg, forcecomponent, &forcearchitectures, forcesection, forcepriority, packagetype, distribution, &oinfo, debfilename); - if( RET_WAS_ERROR(r) ) { + r = deb_preparelocation(pkg, forcecomponent, &forcearchitectures, + forcesection, forcepriority, packagetype, distribution, + &oinfo, debfilename); + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } - if( strcmp(givenfilekey,pkg->filekey) != 0 ) { + if (strcmp(givenfilekey, pkg->filekey) != 0) { fprintf(stderr, "Name mismatch: .changes indicates '%s', but the file itself says '%s'!\n", givenfilekey, pkg->filekey); @@ -280,7 +286,7 @@ /* Prepare everything that can be prepared beforehand */ r = binaries_complete(&pkg->deb, pkg->filekey, checksums, oinfo, pkg->deb.section, pkg->deb.priority, &control); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } @@ -289,10 +295,10 @@ return RET_OK; } -retvalue deb_addprepared(const struct debpackage *pkg, struct database *database, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata) { - return binaries_adddeb(&pkg->deb, database, forcearchitectures, +retvalue deb_addprepared(const struct debpackage *pkg, const struct atomlist *forcearchitectures, packagetype_t packagetype, struct distribution *distribution, struct trackingdata *trackingdata) { + return binaries_adddeb(&pkg->deb, forcearchitectures, packagetype, distribution, trackingdata, - pkg->component_atom, &pkg->filekeys, + pkg->component, &pkg->filekeys, pkg->deb.control); } @@ -300,7 +306,7 @@ * putting things with architecture of "all" into architectures> (and also * causing error, if it is not one of them otherwise) * if component is NULL, guessing it from the section. */ -retvalue deb_add(struct database *database, component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, packagetype_t packagetype, struct distribution *distribution, const char *debfilename, int delete, /*@null@*/trackingdb tracks) { +retvalue deb_add(component_t forcecomponent, const struct atomlist *forcearchitectures, const char *forcesection, const char *forcepriority, packagetype_t packagetype, struct distribution *distribution, const char *debfilename, int delete, /*@null@*/trackingdb tracks) { struct debpackage *pkg; retvalue r; struct trackingdata trackingdata; @@ -310,17 +316,19 @@ causingfile = debfilename; - r = deb_read(&pkg, debfilename, tracks != NULL ); - if( RET_WAS_ERROR(r) ) { + r = deb_read(&pkg, debfilename, tracks != NULL); + if (RET_WAS_ERROR(r)) { return r; } - r = deb_preparelocation(pkg, forcecomponent, forcearchitectures, forcesection, forcepriority, packagetype, distribution, &oinfo, debfilename); - if( RET_WAS_ERROR(r) ) { + r = deb_preparelocation(pkg, forcecomponent, forcearchitectures, + forcesection, forcepriority, packagetype, distribution, + &oinfo, debfilename); + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } - r = files_preinclude(database, debfilename, pkg->filekey, &checksums); - if( RET_WAS_ERROR(r) ) { + r = files_preinclude(debfilename, pkg->filekey, &checksums); + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } @@ -328,40 +336,40 @@ r = binaries_complete(&pkg->deb, pkg->filekey, checksums, oinfo, pkg->deb.section, pkg->deb.priority, &control); checksums_free(checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } free(pkg->deb.control); pkg->deb.control = control; - if( tracks != NULL ) { + if (tracks != NULL) { assert(pkg->deb.sourceversion != NULL); r = trackingdata_summon(tracks, pkg->deb.source, pkg->deb.sourceversion, &trackingdata); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { deb_free(pkg); return r; } } - r = binaries_adddeb(&pkg->deb, database, forcearchitectures, + r = binaries_adddeb(&pkg->deb, forcearchitectures, packagetype, distribution, (tracks!=NULL)?&trackingdata:NULL, - pkg->component_atom, &pkg->filekeys, + pkg->component, &pkg->filekeys, pkg->deb.control); RET_UPDATE(distribution->status, r); deb_free(pkg); - if( tracks != NULL ) { + if (tracks != NULL) { retvalue r2; - r2 = trackingdata_finish(tracks, &trackingdata, database); - RET_ENDUPDATE(r,r2); + r2 = trackingdata_finish(tracks, &trackingdata); + RET_ENDUPDATE(r, r2); } - if( RET_IS_OK(r) && delete >= D_MOVE ) { + if (RET_IS_OK(r) && delete >= D_MOVE) { deletefile(debfilename); - } else if( r == RET_NOTHING && delete >= D_DELETE ) + } else if (r == RET_NOTHING && delete >= D_DELETE) deletefile(debfilename); return r; diff -Nru reprepro-4.5.0/checkindeb.h reprepro-4.6.0/checkindeb.h --- reprepro-4.5.0/checkindeb.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/checkindeb.h 2011-05-05 14:42:55.000000000 +0000 @@ -18,11 +18,11 @@ * if overwrite is not NULL, it will be search for fields to reset for this * package. (forcesection and forcepriority have higher priority than the * information there), */ -retvalue deb_add(struct database *, component_t forcecomponent, const struct atomlist *forcearchitectures, /*@null@*/const char *forcesection, /*@null@*/const char *forcepriority, packagetype_t, struct distribution *, const char *debfilename, int delete, /*@null@*/trackingdb); +retvalue deb_add(component_t, const struct atomlist * /*forcearchitectures*/, /*@null@*/const char * /*forcesection*/, /*@null@*/const char * /*forcepriority*/, packagetype_t, struct distribution *, const char * /*debfilename*/, int /*delete*/, /*@null@*/trackingdb); /* in two steps */ struct debpackage; -retvalue deb_addprepared(const struct debpackage *, struct database *, const struct atomlist *forcearchitecture, packagetype_t, struct distribution *, struct trackingdata *); -retvalue deb_prepare(/*@out@*/struct debpackage **deb, component_t forcecomponent, architecture_t forcearchitecture, const char *forcesection, const char *forcepriority, packagetype_t, struct distribution *distribution, const char *debfilename, const char * const filekey, const struct checksums *checksums, const struct strlist *allowed_binaries, const char *expectedsourcename, const char *expectedsourceversion); -void deb_free(/*@only@*/struct debpackage *pkg); +retvalue deb_addprepared(const struct debpackage *, const struct atomlist * /*forcearchitectures*/, packagetype_t, struct distribution *, struct trackingdata *); +retvalue deb_prepare(/*@out@*/struct debpackage **, component_t, architecture_t /*forcearchitectures*/, const char * /*forcesection*/, const char * /*forcepriority*/, packagetype_t, struct distribution *, const char * /*debfilename*/, const char * const /*filekey*/, const struct checksums *, const struct strlist * /*allowed_binaries*/, const char * /*expectedsourcename*/, const char * /*expectedsourceversion*/); +void deb_free(/*@only@*/struct debpackage *); #endif diff -Nru reprepro-4.5.0/checkindsc.c reprepro-4.6.0/checkindsc.c --- reprepro-4.5.0/checkindsc.c 2010-07-11 10:15:58.000000000 +0000 +++ reprepro-4.6.0/checkindsc.c 2011-05-05 14:42:55.000000000 +0000 @@ -55,9 +55,9 @@ before the pgp-end-block.(in case someone missed the newline there)) -* check to have source,version,maintainer, +* check to have source, version, maintainer, standards-version, files. And also look - at binary,architecture and build*, as + at binary, architecture and build*, as described in policy 5.4 * Get overwrite information, ecspecially @@ -84,13 +84,13 @@ /* things to be set by dsc_read: */ struct dsc_headers dsc; /* things that will still be NULL then: */ - component_t component_atom; + component_t component; /* Things that may be calculated by dsc_calclocations: */ struct strlist filekeys; }; static void dsc_free(/*@only@*/struct dscpackage *pkg) { - if( pkg != NULL ) { + if (pkg != NULL) { sources_done(&pkg->dsc); strlist_done(&pkg->filekeys); free(pkg); @@ -103,52 +103,54 @@ bool broken; - dsc = calloc(1,sizeof(struct dscpackage)); + dsc = zNEW(struct dscpackage); + if (FAILEDTOALLOC(dsc)) + return RET_ERROR_OOM; r = sources_readdsc(&dsc->dsc, filename, filename, &broken); - if( RET_IS_OK(r) && broken && !IGNORING_(brokensignatures, + if (RET_IS_OK(r) && broken && !IGNORING(brokensignatures, "'%s' contains only broken signatures.\n" "This most likely means the file was damaged or edited improperly\n", - filename) ) + filename)) r = RET_ERROR; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = propersourcename(dsc->dsc.name); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properversion(dsc->dsc.version); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properfilenames(&dsc->dsc.files.names); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dsc_free(dsc); return r; } - dsc->component_atom = atom_unknown; + dsc->component = atom_unknown; *pkg = dsc; return RET_OK; } -retvalue dsc_addprepared(struct database *database, const struct dsc_headers *dsc, component_t component, const struct strlist *filekeys, struct distribution *distribution, struct trackingdata *trackingdata){ +retvalue dsc_addprepared(const struct dsc_headers *dsc, component_t component, const struct strlist *filekeys, struct distribution *distribution, struct trackingdata *trackingdata){ retvalue r; struct target *t = distribution_getpart(distribution, component, architecture_source, pt_dsc); - assert( logger_isprepared(distribution->logger) ); + assert (logger_isprepared(distribution->logger)); /* finally put it into the source distribution */ - r = target_initpackagesdb(t, database, READWRITE); - if( !RET_WAS_ERROR(r) ) { + r = target_initpackagesdb(t, READWRITE); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else - r = target_addpackage(t, distribution->logger, database, + r = target_addpackage(t, distribution->logger, dsc->name, dsc->version, dsc->control, filekeys, false, trackingdata, architecture_source, NULL, NULL); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } RET_UPDATE(distribution->status, r); return r; @@ -159,7 +161,7 @@ * If basename, filekey and directory are != NULL, then they are used instead * of being newly calculated. * (And all files are expected to already be in the pool). */ -retvalue dsc_add(struct database *database, component_t forcecomponent, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *dscfilename, int delete, trackingdb tracks){ +retvalue dsc_add(component_t forcecomponent, const char *forcesection, const char *forcepriority, struct distribution *distribution, const char *dscfilename, int delete, trackingdb tracks){ retvalue r; struct dscpackage *pkg; struct trackingdata trackingdata; @@ -172,7 +174,7 @@ /* First make sure this distribution has a source section at all, * for which it has to be listed in the "Architectures:"-field ;-) */ - if( !atomlist_in(&distribution->architectures, architecture_source) ) { + if (!atomlist_in(&distribution->architectures, architecture_source)) { fprintf(stderr, "Cannot put a source package into Distribution '%s' not having 'source' in its 'Architectures:'-field!\n", distribution->codename); @@ -182,59 +184,59 @@ } r = dsc_read(&pkg, dscfilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } - oinfo = override_search(distribution->overrides.dsc,pkg->dsc.name); - if( forcesection == NULL ) { - forcesection = override_get(oinfo,SECTION_FIELDNAME); + oinfo = override_search(distribution->overrides.dsc, pkg->dsc.name); + if (forcesection == NULL) { + forcesection = override_get(oinfo, SECTION_FIELDNAME); } - if( forcepriority == NULL ) { - forcepriority = override_get(oinfo,PRIORITY_FIELDNAME); + if (forcepriority == NULL) { + forcepriority = override_get(oinfo, PRIORITY_FIELDNAME); } - if( forcesection != NULL ) { + if (forcesection != NULL) { free(pkg->dsc.section); pkg->dsc.section = strdup(forcesection); - if( pkg->dsc.section == NULL ) { + if (FAILEDTOALLOC(pkg->dsc.section)) { dsc_free(pkg); return RET_ERROR_OOM; } } - if( forcepriority != NULL ) { + if (forcepriority != NULL) { free(pkg->dsc.priority); pkg->dsc.priority = strdup(forcepriority); - if( pkg->dsc.priority == NULL ) { + if (FAILEDTOALLOC(pkg->dsc.priority)) { dsc_free(pkg); return RET_ERROR_OOM; } } r = dirs_getdirectory(dscfilename, &origdirectory); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dsc_free(pkg); return r; } - if( pkg->dsc.section == NULL || pkg->dsc.priority == NULL ) { + if (pkg->dsc.section == NULL || pkg->dsc.priority == NULL) { struct sourceextraction *extraction; extraction = sourceextraction_init( (pkg->dsc.section == NULL)?&pkg->dsc.section:NULL, (pkg->dsc.priority == NULL)?&pkg->dsc.priority:NULL); - if( FAILEDTOALLOC(extraction) ) { + if (FAILEDTOALLOC(extraction)) { free(origdirectory); dsc_free(pkg); return RET_ERROR_OOM; } - for( i = 0 ; i < pkg->dsc.files.names.count ; i ++ ) + for (i = 0 ; i < pkg->dsc.files.names.count ; i ++) sourceextraction_setpart(extraction, i, pkg->dsc.files.names.values[i]); - while( sourceextraction_needs(extraction, &i) ) { + while (sourceextraction_needs(extraction, &i)) { char *fullfilename = calc_dirconcat(origdirectory, pkg->dsc.files.names.values[i]); - if( FAILEDTOALLOC(fullfilename) ) { + if (FAILEDTOALLOC(fullfilename)) { free(origdirectory); dsc_free(pkg); return RET_ERROR_OOM; @@ -246,7 +248,7 @@ // TODO: but if forcecomponent is set it might be possible. r = sourceextraction_analyse(extraction, fullfilename); free(fullfilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); dsc_free(pkg); sourceextraction_abort(extraction); @@ -254,39 +256,42 @@ } } r = sourceextraction_finish(extraction); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); dsc_free(pkg); return r; } } - if( pkg->dsc.section == NULL && pkg->dsc.priority == NULL ) { - fprintf(stderr, "No section and no priority for '%s', skipping.\n", + if (pkg->dsc.section == NULL && pkg->dsc.priority == NULL) { + fprintf(stderr, +"No section and no priority for '%s', skipping.\n", pkg->dsc.name); free(origdirectory); dsc_free(pkg); return RET_ERROR; } - if( pkg->dsc.section == NULL ) { - fprintf(stderr, "No section for '%s', skipping.\n", pkg->dsc.name); + if (pkg->dsc.section == NULL) { + fprintf(stderr, "No section for '%s', skipping.\n", + pkg->dsc.name); free(origdirectory); dsc_free(pkg); return RET_ERROR; } - if( pkg->dsc.priority == NULL ) { - fprintf(stderr, "No priority for '%s', skipping.\n", pkg->dsc.name); + if (pkg->dsc.priority == NULL) { + fprintf(stderr, "No priority for '%s', skipping.\n", + pkg->dsc.name); free(origdirectory); dsc_free(pkg); return RET_ERROR; } - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { const char *fc; fc = override_get(oinfo, "$Component"); - if( fc != NULL ) { + if (fc != NULL) { forcecomponent = component_find(fc); - if( !atom_defined(forcecomponent) ) { + if (!atom_defined(forcecomponent)) { fprintf(stderr, "Unparseable component '%s' in $Component override of '%s'\n", fc, pkg->dsc.name); @@ -299,28 +304,28 @@ r = guess_component(distribution->codename, &distribution->components, pkg->dsc.name, pkg->dsc.section, forcecomponent, - &pkg->component_atom); - if( RET_WAS_ERROR(r) ) { + &pkg->component); + if (RET_WAS_ERROR(r)) { free(origdirectory); dsc_free(pkg); return r; } - if( verbose > 0 && !atom_defined(forcecomponent) ) { + if (verbose > 0 && !atom_defined(forcecomponent)) { fprintf(stderr, "%s: component guessed as '%s'\n", dscfilename, - atoms_components[pkg->component_atom]); + atoms_components[pkg->component]); } { char *dscbasename, *dscfilekey; struct checksums *dscchecksums; dscbasename = calc_source_basename(pkg->dsc.name, pkg->dsc.version); - destdirectory = calc_sourcedir(pkg->component_atom, pkg->dsc.name); + destdirectory = calc_sourcedir(pkg->component, pkg->dsc.name); /* Calculate the filekeys: */ - if( destdirectory != NULL ) + if (destdirectory != NULL) r = calc_dirconcats(destdirectory, &pkg->dsc.files.names, &pkg->filekeys); - if( dscbasename == NULL || destdirectory == NULL || RET_WAS_ERROR(r) ) { + if (dscbasename == NULL || destdirectory == NULL || RET_WAS_ERROR(r)) { free(dscbasename); free(destdirectory); free(origdirectory); dsc_free(pkg); @@ -328,21 +333,21 @@ } dscfilekey = calc_dirconcat(destdirectory, dscbasename); dscchecksums = NULL; - if( dscfilename == NULL ) + if (FAILEDTOALLOC(dscfilename)) r = RET_ERROR_OOM; else /* then look if we already have this, or copy it in */ - r = files_preinclude(database, + r = files_preinclude( dscfilename, dscfilekey, &dscchecksums); - if( !RET_WAS_ERROR(r) ) { - /* Add the dsc-file to basenames,filekeys and md5sums, + if (!RET_WAS_ERROR(r)) { + /* Add the dsc-file to basenames, filekeys and md5sums, * so that it will be listed in the Sources.gz */ r = checksumsarray_include(&pkg->dsc.files, dscbasename, dscchecksums); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = strlist_include(&pkg->filekeys, dscfilekey); else free(dscfilekey); @@ -353,10 +358,10 @@ checksums_free(dscchecksums); } - assert( pkg->dsc.files.names.count == pkg->filekeys.count ); - for( i = 1 ; i < pkg->dsc.files.names.count ; i ++ ) { - if( !RET_WAS_ERROR(r) ) { - r = files_checkincludefile(database, origdirectory, + assert (pkg->dsc.files.names.count == pkg->filekeys.count); + for (i = 1 ; i < pkg->dsc.files.names.count ; i ++) { + if (!RET_WAS_ERROR(r)) { + r = files_checkincludefile(origdirectory, pkg->dsc.files.names.values[i], pkg->filekeys.values[i], &pkg->dsc.files.checksums[i]); @@ -365,11 +370,11 @@ /* Calculate the chunk to include: */ - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = sources_complete(&pkg->dsc, destdirectory, oinfo, pkg->dsc.section, pkg->dsc.priority, &control); free(destdirectory); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(pkg->dsc.control); pkg->dsc.control = control; } else { @@ -378,38 +383,39 @@ return r; } - if( interrupted() ) { + if (interrupted()) { dsc_free(pkg); free(origdirectory); return RET_ERROR_INTERRUPTED; } - if( tracks != NULL ) { - r = trackingdata_summon(tracks,pkg->dsc.name,pkg->dsc.version,&trackingdata); - if( RET_WAS_ERROR(r) ) { + if (tracks != NULL) { + r = trackingdata_summon(tracks, pkg->dsc.name, + pkg->dsc.version, &trackingdata); + if (RET_WAS_ERROR(r)) { free(origdirectory); dsc_free(pkg); return r; } } - r = dsc_addprepared(database, &pkg->dsc, pkg->component_atom, + r = dsc_addprepared(&pkg->dsc, pkg->component, &pkg->filekeys, distribution, (tracks!=NULL)?&trackingdata:NULL); /* delete source files, if they are to be */ - if( ( RET_IS_OK(r) && delete >= D_MOVE ) || - ( r == RET_NOTHING && delete >= D_DELETE ) ) { + if ((RET_IS_OK(r) && delete >= D_MOVE) || + (r == RET_NOTHING && delete >= D_DELETE)) { char *fullfilename; - for( i = 0 ; i < pkg->dsc.files.names.count ; i++ ) { + for (i = 0 ; i < pkg->dsc.files.names.count ; i++) { fullfilename = calc_dirconcat(origdirectory, pkg->dsc.files.names.values[i]); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { r = RET_ERROR_OOM; break; } - if( isregularfile(fullfilename) ) + if (isregularfile(fullfilename)) deletefile(fullfilename); free(fullfilename); } @@ -417,10 +423,10 @@ free(origdirectory); dsc_free(pkg); - if( tracks != NULL ) { + if (tracks != NULL) { retvalue r2; - r2 = trackingdata_finish(tracks, &trackingdata, database); - RET_ENDUPDATE(r,r2); + r2 = trackingdata_finish(tracks, &trackingdata); + RET_ENDUPDATE(r, r2); } return r; } diff -Nru reprepro-4.5.0/checkindsc.h reprepro-4.6.0/checkindsc.h --- reprepro-4.5.0/checkindsc.h 2008-11-04 10:10:05.000000000 +0000 +++ reprepro-4.6.0/checkindsc.h 2011-05-05 14:42:55.000000000 +0000 @@ -17,7 +17,7 @@ /* insert the given .dsc into the mirror in in the * if component is NULL, guess it from the section. */ -retvalue dsc_add(struct database *, component_t, /*@null@*/const char *forcesection, /*@null@*/const char *forcepriority, struct distribution *, const char *dscfilename, int delete, /*@null@*/trackingdb tracks); +retvalue dsc_add(component_t, /*@null@*/const char * /*forcesection*/, /*@null@*/const char * /*forcepriority*/, struct distribution *, const char * /*dscfilename*/, int /*delete*/, /*@null@*/trackingdb); /* in two steps: * If basename, filekey and directory are != NULL, then they are used instead @@ -26,6 +26,6 @@ * delete should be D_INPLACE then */ -retvalue dsc_addprepared(struct database *, const struct dsc_headers *, component_t , const struct strlist *filekeys, struct distribution *distribution, /*@null@*/struct trackingdata *trackingdata); +retvalue dsc_addprepared(const struct dsc_headers *, component_t, const struct strlist * /*filekeys*/, struct distribution *, /*@null@*/struct trackingdata *); #endif diff -Nru reprepro-4.5.0/checkin.h reprepro-4.6.0/checkin.h --- reprepro-4.5.0/checkin.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/checkin.h 2011-05-05 14:42:55.000000000 +0000 @@ -20,7 +20,7 @@ * get it from the files or try to guess it. * if dereferencedfilekeys is != NULL, add filekeys that lost reference, * if tracks != NULL, update/add tracking information there... */ -retvalue changes_add(struct database *, /*@null@*/trackingdb tracks, const struct atomlist *packagetypes, component_t, const struct atomlist *forcearchitecture, /*@null@*/const char *forcesection, /*@null@*/const char *forcepriority, struct distribution *, const char *changesfilename, int delete); +retvalue changes_add(/*@null@*/trackingdb, const struct atomlist * /*packagetypes*/, component_t, const struct atomlist * /*forcearchitecture*/, /*@null@*/const char * /*forcesection*/, /*@null@*/const char * /*forcepriority*/, struct distribution *, const char * /*changesfilename*/, int /*delete*/); #endif diff -Nru reprepro-4.5.0/checks.c reprepro-4.6.0/checks.c --- reprepro-4.5.0/checks.c 2008-10-12 17:28:23.000000000 +0000 +++ reprepro-4.6.0/checks.c 2011-05-05 14:42:55.000000000 +0000 @@ -45,43 +45,44 @@ * anyway). */ uchar c = *character; - if( (c & (uchar)0xC2 /*11000010*/) == (uchar)0xC0 /*11000000*/ ) { + if ((c & (uchar)0xC2 /*11000010*/) == (uchar)0xC0 /*11000000*/) { uchar nextc = *(character+1); - if( (nextc & (uchar)0xC0 /*11000000*/ ) != (uchar)0x80 /*10000000*/ ) + if ((nextc & (uchar)0xC0 /*11000000*/) + != (uchar)0x80 /*10000000*/) return false; - if( (c & (uchar)0x3E /* 00111110 */ ) == (uchar)0 ) + if ((c & (uchar)0x3E /* 00111110 */) == (uchar)0) return true; - if( c == (uchar)0xE0 /*11100000*/ && - (nextc & (uchar)0x20 /*00100000*/ ) == (uchar)0) + if (c == (uchar)0xE0 /*11100000*/ && + (nextc & (uchar)0x20 /*00100000*/) == (uchar)0) return true; - if( c == (uchar)0xF0 /*11110000*/ && - (nextc & (uchar)0x30 /*00110000*/ ) == (uchar)0) + if (c == (uchar)0xF0 /*11110000*/ && + (nextc & (uchar)0x30 /*00110000*/) == (uchar)0) return true; - if( c == (uchar)0xF8 /*11111000*/ && - (nextc & (uchar)0x38 /*00111000*/ ) == (uchar)0) + if (c == (uchar)0xF8 /*11111000*/ && + (nextc & (uchar)0x38 /*00111000*/) == (uchar)0) return true; - if( c == (uchar)0xFC /*11111100*/ && - (nextc & (uchar)0x3C /*00111100*/ ) == (uchar)0) + if (c == (uchar)0xFC /*11111100*/ && + (nextc & (uchar)0x3C /*00111100*/) == (uchar)0) return true; } return false; } -#define REJECTLOWCHARS(s,str,descr) \ - if( (uchar)*s < (uchar)' ' ) { \ +#define REJECTLOWCHARS(s, str, descr) \ + if ((uchar)*s < (uchar)' ') { \ fprintf(stderr, \ "Character 0x%02hhx not allowed within %s '%s'!\n", \ - *s,descr,str); \ + *s, descr, str); \ return RET_ERROR; \ } -#define REJECTCHARIF(c,s,str,descr) \ - if( c ) { \ +#define REJECTCHARIF(c, s, str, descr) \ + if (c) { \ fprintf(stderr, \ "Character '%c' not allowed within %s '%s'!\n", \ - *s,descr,string); \ + *s, descr, string); \ return RET_ERROR; \ } @@ -91,41 +92,40 @@ const char *s; bool firstcharacter = true; - if( string[0] == '\0' ) { + if (string[0] == '\0') { /* This is not really ignoreable, as this will lead * to paths not normalized, so all checks go wrong */ - fprintf(stderr,"Source name is not allowed to be emtpy!\n"); + fprintf(stderr, "Source name is not allowed to be emtpy!\n"); return RET_ERROR; } - if( string[0] == '.' ) { + if (string[0] == '.') { /* A dot is not only hard to see, it would cause the directory * to become /./.bla, which is quite dangerous. */ - fprintf(stderr,"Source names are not allowed to start with a dot!\n"); + fprintf(stderr, +"Source names are not allowed to start with a dot!\n"); return RET_ERROR; } s = string; - while( *s != '\0' ) { - if( (*s > 'z' || *s < 'a' ) && - (*s > '9' || *s < '0' ) && + while (*s != '\0') { + if ((*s > 'z' || *s < 'a') && + (*s > '9' || *s < '0') && (firstcharacter || - ( *s != '+' && *s != '-' && *s != '.'))) { - REJECTLOWCHARS(s,string,"sourcename"); - REJECTCHARIF( *s == '/', s,string, "sourcename"); - if( overlongUTF8(s) ) { + (*s != '+' && *s != '-' && *s != '.'))) { + REJECTLOWCHARS(s, string, "sourcename"); + REJECTCHARIF (*s == '/', s, string, "sourcename"); + if (overlongUTF8(s)) { fprintf(stderr, "This could contain an overlong UTF8 sequence, rejecting source name '%s'!\n", string); return RET_ERROR; } - if( !IGNORING( -"Not rejecting", "To ignore this", forbiddenchar, -"Character 0x%02hhx not allowed in sourcename: '%s'!\n", *s, string) ) { + if (!IGNORING_(forbiddenchar, +"Character 0x%02hhx not allowed in sourcename: '%s'!\n", *s, string)) { return RET_ERROR; } - if( ISSET(*s,0x80) ) { - if( !IGNORING( -"Not rejecting", "To ignore this", 8bit, -"8bit character in source name: '%s'!\n", string) ) { + if (ISSET(*s, 0x80)) { + if (!IGNORING_(8bit, +"8bit character in source name: '%s'!\n", string)) { return RET_ERROR; } } @@ -140,28 +140,27 @@ retvalue properfilename(const char *string) { const char *s; - if( string[0] == '\0' ) { - fprintf(stderr,"Error: empty filename!\n"); + if (string[0] == '\0') { + fprintf(stderr, "Error: empty filename!\n"); return RET_ERROR; } - if( (string[0] == '.' && string[1] == '\0') || - (string[0] == '.' && string[1] == '.' && string[2] == '\0') ) { + if ((string[0] == '.' && string[1] == '\0') || + (string[0] == '.' && string[1] == '.' && string[2] == '\0')) { fprintf(stderr, "File name not allowed: '%s'!\n", string); return RET_ERROR; } - for( s = string ; *s != '\0' ; s++ ) { - REJECTLOWCHARS(s,string,"filename"); - REJECTCHARIF( *s == '/' ,s,string,"filename"); - if( ISSET(*s,0x80) ) { - if( overlongUTF8(s) ) { + for (s = string ; *s != '\0' ; s++) { + REJECTLOWCHARS(s, string, "filename"); + REJECTCHARIF (*s == '/' , s, string, "filename"); + if (ISSET(*s, 0x80)) { + if (overlongUTF8(s)) { fprintf(stderr, "This could contain an overlong UTF8 sequence, rejecting file name '%s'!\n", string); return RET_ERROR; } - if( !IGNORING( -"Not rejecting", "To ignore this", 8bit, -"8bit character in file name: '%s'!\n", string)) { + if (!IGNORING_(8bit, +"8bit character in file name: '%s'!\n", string)) { return RET_ERROR; } } @@ -173,12 +172,12 @@ va_list ap; static char *data = NULL; - if( data != NULL ) + if (data != NULL) free(data); va_start(ap, format); data = vmprintf(format, ap); va_end(ap); - if( data == NULL ) + if (data == NULL) return "Out of memory"; return data; } @@ -187,30 +186,32 @@ const char *checkfordirectoryandidentifier(const char *string) { const char *s; - assert( string != NULL && string[0] != '\0' ); + assert (string != NULL && string[0] != '\0'); - if( (string[0] == '.' && (string[1] == '\0'||string[1]=='/')) ) + if ((string[0] == '.' && (string[1] == '\0'||string[1]=='/'))) return "'.' is not allowed as directory part"; - if( (string[0] == '.' && string[1] == '.' && - (string[2] == '\0'||string[2] =='/')) ) + if ((string[0] == '.' && string[1] == '.' + && (string[2] == '\0'||string[2] =='/'))) return "'..' is not allowed as directory part"; - for( s = string; *s != '\0'; s++ ) { - if( *s == '|' ) + for (s = string; *s != '\0'; s++) { + if (*s == '|') return "'|' is not allowed"; - if( (uchar)*s < (uchar)' ' ) + if ((uchar)*s < (uchar)' ') return formaterror("Character 0x%02hhx not allowed", *s); - if( *s == '/' && s[1] == '.' && (s[2] == '\0' || s[2] == '/') ) + if (*s == '/' && s[1] == '.' && (s[2] == '\0' || s[2] == '/')) return "'.' is not allowed as directory part"; - if( *s == '/' && s[1] == '.' && s[2] == '.' && - (s[3] == '\0' || s[3] =='/')) + if (*s == '/' && s[1] == '.' && s[2] == '.' + && (s[3] == '\0' || s[3] =='/')) return "'..' is not allowed as directory part"; - if( *s == '/' && s[1] == '/' ) + if (*s == '/' && s[1] == '/') return "\"//\" is not allowed"; - if( ISSET(*s,0x80) ) { - if( overlongUTF8(s) ) - return "Contains overlong UTF-8 sequence if treated as UTF-8"; - if( !IGNORABLE(8bit) ) - return "Contains 8bit character (use --ignore=8bit to ignore)"; + if (ISSET(*s, 0x80)) { + if (overlongUTF8(s)) + return +"Contains overlong UTF-8 sequence if treated as UTF-8"; + if (!IGNORABLE(8bit)) + return +"Contains 8bit character (use --ignore=8bit to ignore)"; } } return NULL; @@ -220,20 +221,22 @@ const char *checkforidentifierpart(const char *string) { const char *s; - assert( string != NULL && string[0] != '\0' ); + assert (string != NULL && string[0] != '\0'); - for( s = string; *s != '\0' ; s++ ) { - if( *s == '|' ) + for (s = string; *s != '\0' ; s++) { + if (*s == '|') return "'|' is not allowed"; - if( *s == '/' ) + if (*s == '/') return "'/' is not allowed"; - if( (uchar)*s < (uchar)' ' ) + if ((uchar)*s < (uchar)' ') return formaterror("Character 0x%02hhx not allowed", *s); - if( ISSET(*s,0x80) ) { - if( overlongUTF8(s) ) - return "Contains overlong UTF-8 sequence if treated as UTF-8"; - if( !IGNORABLE(8bit) ) - return "Contains 8bit character (use --ignore=8bit to ignore)"; + if (ISSET(*s, 0x80)) { + if (overlongUTF8(s)) + return +"Contains overlong UTF-8 sequence if treated as UTF-8"; + if (!IGNORABLE(8bit)) + return +"Contains 8bit character (use --ignore=8bit to ignore)"; } } return NULL; @@ -242,18 +245,18 @@ retvalue properfilenamepart(const char *string) { const char *s; - for( s = string ; *s != '\0' ; s++ ) { - REJECTLOWCHARS(s,string,"filenamepart"); - REJECTCHARIF( *s == '/' ,s,string,"filenamepart"); - if( ISSET(*s,0x80) ) { - if( overlongUTF8(s) ) { + for (s = string ; *s != '\0' ; s++) { + REJECTLOWCHARS(s, string, "filenamepart"); + REJECTCHARIF (*s == '/' , s, string, "filenamepart"); + if (ISSET(*s, 0x80)) { + if (overlongUTF8(s)) { fprintf(stderr, "This could contain an overlong UTF8 sequence, rejecting part of file name '%s'!\n", string); return RET_ERROR; } - if( !IGNORING( -"Not rejecting", "To ignore this", 8bit, "8bit character in part of file name: '%s'!\n", + if (!IGNORING_(8bit, +"8bit character in part of file name: '%s'!\n", string)) return RET_ERROR; } @@ -267,51 +270,51 @@ bool first = true; bool yetonlydigits = true; - if( string[0] == '\0' && !IGNORING( -"Ignoring","To ignore this",emptyfilenamepart,"A version string is empty!\n") ) { + if (string[0] == '\0' && !IGNORING(emptyfilenamepart, +"A version string is empty!\n")) { return RET_ERROR; } - if( ( *s < '0' || *s > '9' ) && - (( *s >= 'a' && *s <= 'z') || (*s >='A' && *s <= 'Z'))) { + if ((*s < '0' || *s > '9') && + ((*s >= 'a' && *s <= 'z') || (*s >='A' && *s <= 'Z'))) { /* As there are official packages violating the rule * of policy 5.6.11 to start with a digit, disabling * this test, and only omitting a warning. */ - if( verbose >= 0 ) - fprintf(stderr,"Warning: Package version '%s' does not start with a digit, violating 'should'-directive in policy 5.6.11\n",string); + if (verbose >= 0) + fprintf(stderr, +"Warning: Package version '%s' does not start with a digit, violating 'should'-directive in policy 5.6.11\n", + string); } - for( ; *s != '\0' ; s++,first=false ) { - if( (*s <= '9' || *s >= '0' ) ) { + for (; *s != '\0' ; s++, first=false) { + if ((*s <= '9' || *s >= '0')) { continue; } - if( !first && yetonlydigits && *s == ':' ) { + if (!first && yetonlydigits && *s == ':') { hadepoch = true; continue; } yetonlydigits = false; - if( (*s >= 'A' && *s <= 'Z' ) || - (*s >= 'a' || *s <= 'z' )) { + if ((*s >= 'A' && *s <= 'Z') || + (*s >= 'a' || *s <= 'z')) { yetonlydigits = false; continue; } - if( first || (*s != '+' && *s != '-' && - *s != '.' && *s != '~' && - (!hadepoch || *s != ':' ))) { - REJECTLOWCHARS(s,string,"version"); - REJECTCHARIF( *s == '/' ,s,string,"version"); - if( overlongUTF8(s) ) { + if (first || (*s != '+' && *s != '-' + && *s != '.' && *s != '~' + && (!hadepoch || *s != ':'))) { + REJECTLOWCHARS(s, string, "version"); + REJECTCHARIF (*s == '/' , s, string, "version"); + if (overlongUTF8(s)) { fprintf(stderr, "This could contain an overlong UTF8 sequence, rejecting version '%s'!\n", string); return RET_ERROR; } - if( !IGNORING( -"Not rejecting", "To ignore this", forbiddenchar, -"Character '%c' not allowed in version: '%s'!\n", *s, string) ) + if (!IGNORING_(forbiddenchar, +"Character '%c' not allowed in version: '%s'!\n", *s, string)) return RET_ERROR; - if( ISSET(*s,0x80) ) { - if( !IGNORING( -"Not rejecting", "To ignore this", 8bit, -"8bit character in version: '%s'!\n", string) ) + if (ISSET(*s, 0x80)) { + if (!IGNORING_(8bit, +"8bit character in version: '%s'!\n", string)) return RET_ERROR; } } @@ -322,10 +325,10 @@ retvalue properfilenames(const struct strlist *names) { int i; - for( i = 0 ; i < names->count ; i ++ ) { + for (i = 0 ; i < names->count ; i ++) { retvalue r = properfilename(names->values[i]); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -338,37 +341,36 @@ /* To be able to avoid multiple warnings, * this should always be a subset of propersourcename */ - if( string[0] == '\0' ) { + if (string[0] == '\0') { /* This is not really ignoreable, as this is a primary * key for our database */ - fprintf(stderr,"Package name is not allowed to be emtpy!\n"); + fprintf(stderr, "Package name is not allowed to be emtpy!\n"); return RET_ERROR; } s = string; - while( *s != '\0' ) { + while (*s != '\0') { /* DAK also allowed upper case letters last I looked, policy * does not, so they are not allowed without --ignore=forbiddenchar */ // perhaps some extra ignore-rule for upper case? - if( (*s > 'z' || *s < 'a' ) && - (*s > '9' || *s < '0' ) && - ( firstcharacter || - (*s != '+' && *s != '-' && *s != '.'))) { - REJECTLOWCHARS(s,string,"package name"); - REJECTCHARIF( *s == '/' ,s,string,"package name"); - if( overlongUTF8(s) ) { + if ((*s > 'z' || *s < 'a') && + (*s > '9' || *s < '0') && + (firstcharacter + || (*s != '+' && *s != '-' && *s != '.'))) { + REJECTLOWCHARS(s, string, "package name"); + REJECTCHARIF (*s == '/' , s, string, "package name"); + if (overlongUTF8(s)) { fprintf(stderr, "This could contain an overlong UTF8 sequence, rejecting package name '%s'!\n", string); return RET_ERROR; } - if( !IGNORING( -"Not rejecting", "To ignore this", forbiddenchar, -"Character 0x%02hhx not allowed in package name: '%s'!\n", *s, string) ) { + if (!IGNORING(forbiddenchar, +"Character 0x%02hhx not allowed in package name: '%s'!\n", *s, string)) { return RET_ERROR; } - if( ISSET(*s,0x80) ) { - if( !IGNORING( -"Not rejecting","To ignore this",8bit,"8bit character in package name: '%s'!\n",string) ) { + if (ISSET(*s, 0x80)) { + if (!IGNORING_(8bit, +"8bit character in package name: '%s'!\n", string)) { return RET_ERROR; } } diff -Nru reprepro-4.5.0/checksums.c reprepro-4.6.0/checksums.c --- reprepro-4.5.0/checksums.c 2011-02-21 15:34:27.000000000 +0000 +++ reprepro-4.6.0/checksums.c 2011-05-05 14:42:55.000000000 +0000 @@ -70,7 +70,7 @@ } parts[cs_COUNT]; char representation[]; }; -#define checksums_hashpart(c,t) ((c)->representation + (c)->parts[t].ofs) +#define checksums_hashpart(c, t) ((c)->representation + (c)->parts[t].ofs) #define checksums_totallength(c) ((c)->parts[cs_length].ofs + (c)->parts[cs_length].len) @@ -89,18 +89,18 @@ size_t len, hashlens[cs_COUNT]; /* everything assumes yet that this is available */ - if( hashes[cs_length] == NULL ) { - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + if (hashes[cs_length] == NULL) { + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); *checksums_p = NULL; return RET_OK; } size = hashes[cs_length]; - while( *size == '0' && size[1] >= '0' && size[1] <= '9' ) + while (*size == '0' && size[1] >= '0' && size[1] <= '9') size++; - if( hashes[cs_md5sum] == NULL ) + if (hashes[cs_md5sum] == NULL) hashlens[cs_md5sum] = 1; else hashlens[cs_md5sum] = strlen(hashes[cs_md5sum]); @@ -108,41 +108,41 @@ len = hashlens[cs_md5sum] + 1 + hashlens[cs_length]; p = hashes[cs_md5sum]; - if( p != NULL ) { - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F') ) + if (p != NULL) { + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) p++; - if( *p != '\0' ) { + if (*p != '\0') { // TODO: find way to give more meaningfull error message fprintf(stderr, "Invalid md5 hash: '%s'\n", hashes[cs_md5sum]); - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); return RET_ERROR; } } p = size; - while( (*p >= '0' && *p <= '9') ) + while ((*p >= '0' && *p <= '9')) p++; - if( *p != '\0' ) { + if (*p != '\0') { // TODO: find way to give more meaningfull error message fprintf(stderr, "Invalid size: '%s'\n", size); - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); return RET_ERROR; } - for( type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++ ) { - if( hashes[type] == NULL ) + for (type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++) { + if (hashes[type] == NULL) continue; p = hashes[type]; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F') ) + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) p++; - if( *p != '\0' ) { + if (*p != '\0') { // TODO: find way to give more meaningfull error message fprintf(stderr, "Invalid hash: '%s'\n", hashes[type]); - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); return RET_ERROR; } @@ -151,16 +151,16 @@ } n = malloc(sizeof(struct checksums) + len + 1); - if( n == NULL ) { - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + if (FAILEDTOALLOC(n)) { + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); return RET_ERROR_OOM; } memset(n, 0, sizeof(struct checksums)); d = n->representation; - for( type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++ ) { - if( hashes[type] == NULL ) + for (type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++) { + if (hashes[type] == NULL) continue; *(d++) = ':'; *(d++) = '1' + (char)(type - cs_sha1sum); @@ -171,7 +171,7 @@ d += hashlens[type]; *(d++) = ' '; } - if( hashes[cs_md5sum] == NULL ) { + if (hashes[cs_md5sum] == NULL) { n->parts[cs_md5sum].ofs = d - n->representation; n->parts[cs_md5sum].len = 0; *(d++) = '-'; @@ -186,9 +186,9 @@ n->parts[cs_length].len = (hashlen_t)hashlens[cs_length]; memcpy(d, size, hashlens[cs_length] + 1); d += hashlens[cs_length] + 1; - assert( (size_t)(d-n->representation) == len + 1 ); + assert ((size_t)(d-n->representation) == len + 1); - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) free(hashes[type]); *checksums_p = n; return RET_OK; @@ -201,33 +201,33 @@ size_t len; /* everything assumes that this is available */ - if( hashes[cs_length].start == NULL ) { - assert( 0 == 1 ); + if (hashes[cs_length].start == NULL) { + assert (0 == 1); *checksums_p = NULL; return RET_ERROR; } len = hashes[cs_md5sum].len + 1 + hashes[cs_length].len; - if( hashes[cs_md5sum].start == NULL ) { + if (hashes[cs_md5sum].start == NULL) { assert(hashes[cs_md5sum].len == 0); len++; } - for( type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++ ) { - if( hashes[type].start == NULL ) + for (type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++) { + if (hashes[type].start == NULL) continue; len += strlen(" :x:") + hashes[type].len; } n = malloc(sizeof(struct checksums) + len + 1); - if( FAILEDTOALLOC(n) ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; memset(n, 0, sizeof(struct checksums)); d = n->representation; - for( type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++ ) { - if( hashes[type].start == NULL ) + for (type = cs_firstEXTENDED ; type < cs_hashCOUNT ; type++) { + if (hashes[type].start == NULL) continue; *(d++) = ':'; *(d++) = '1' + (char)(type - cs_firstEXTENDED); @@ -238,7 +238,7 @@ d += hashes[type].len; *(d++) = ' '; } - if( hashes[cs_md5sum].start == NULL ) { + if (hashes[cs_md5sum].start == NULL) { n->parts[cs_md5sum].ofs = d - n->representation; n->parts[cs_md5sum].len = 0; *(d++) = '-'; @@ -254,12 +254,12 @@ memcpy(d, hashes[cs_length].start, hashes[cs_length].len); d += hashes[cs_length].len; *(d++) = '\0'; - assert( (size_t)(d-n->representation) == len + 1 ); + assert ((size_t)(d-n->representation) == len + 1); *checksums_p = n; return RET_OK; } -retvalue checksums_setall(/*@out@*/struct checksums **checksums_p, const char *combinedchecksum, size_t len) { +retvalue checksums_setall(/*@out@*/struct checksums **checksums_p, const char *combinedchecksum, UNUSED(size_t len)) { // This comes from our database, so it surely well formed // (as alreadyassumed above), so this should be possible to // do faster than that... @@ -275,14 +275,14 @@ /*@dependent@*/const char *start; n = malloc(sizeof(struct checksums) + len + 1); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; memset(n, 0, sizeof(struct checksums)); d = n->representation; - while( *p == ':' ) { + while (*p == ':') { p++; - if( p[0] == '\0' || p[1] != ':' ) { + if (p[0] == '\0' || p[1] != ':') { // TODO: how to get some context in this? fprintf(stderr, "Malformed checksums representation: '%s'!\n", @@ -295,37 +295,37 @@ *(d++) = ':'; *(d++) = type; *(d++) = ':'; - if( type == '1' ) { + if (type == '1') { start = d; n->parts[cs_sha1sum].ofs = d - n->representation; - while( *p != ' ' && *p != '\0' ) + while (*p != ' ' && *p != '\0') *(d++) = *(p++); n->parts[cs_sha1sum].len = (hashlen_t)(d - start); - } else if( type == '2' ) { + } else if (type == '2') { start = d; n->parts[cs_sha256sum].ofs = d - n->representation; - while( *p != ' ' && *p != '\0' ) + while (*p != ' ' && *p != '\0') *(d++) = *(p++); n->parts[cs_sha256sum].len = (hashlen_t)(d - start); } else { - while( *p != ' ' && *p != '\0' ) + while (*p != ' ' && *p != '\0') *(d++) = *(p++); } *(d++) = ' '; - while( *p == ' ' ) + while (*p == ' ') p++; } n->parts[cs_md5sum].ofs = d - n->representation; start = d; - if( *p == '-' && p[1] == ' ' ) { + if (*p == '-' && p[1] == ' ') { p++; *(d++) = '-'; start = d; - } else while( *p != ' ' && *p != '\0' ) { - if( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') ) { + } else while (*p != ' ' && *p != '\0') { + if ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) { *(d++) = *(p++); - } else if( *p >= 'A' && *p <= 'F' ) { + } else if (*p >= 'A' && *p <= 'F') { *(d++) = *(p++) + ('a' - 'A'); } else { // TODO: how to get some context in this? @@ -338,14 +338,14 @@ } n->parts[cs_md5sum].len = (hashlen_t)(d - start); *(d++) = ' '; - while( *p == ' ' ) + while (*p == ' ') p++; n->parts[cs_length].ofs = d - n->representation; - while( *p == '0' && ( p[1] >= '0' && p[1] <= '9' ) ) + while (*p == '0' && (p[1] >= '0' && p[1] <= '9')) p++; start = d; - while( *p != '\0' ) { - if( *p >= '0' && *p <= '9' ) { + while (*p != '\0') { + if (*p >= '0' && *p <= '9') { *(d++) = *(p++); } else { // TODO: how to get some context in this? @@ -357,7 +357,7 @@ } } n->parts[cs_length].len = (hashlen_t)(d - start); - if( d == start ) { + if (d == start) { // TODO: how to get some context in this? fprintf(stderr, "Malformed checksums representation (no size): '%s'!\n", @@ -366,7 +366,7 @@ return RET_ERROR; } *d = '\0'; - assert( (size_t)(d - n->representation) <= len ); + assert ((size_t)(d - n->representation) <= len); *checksums_p = n; return RET_OK; } @@ -375,23 +375,23 @@ struct checksums *n; size_t len; - assert( checksums != NULL ); + assert (checksums != NULL); len = checksums_totallength(checksums); - assert( checksums->representation[len] == '\0' ); + assert (checksums->representation[len] == '\0'); n = malloc(sizeof(struct checksums) + len + 1); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return NULL; memcpy(n, checksums, sizeof(struct checksums) + len + 1); - assert( n->representation[len] == '\0' ); + assert (n->representation[len] == '\0'); return n; } bool checksums_getpart(const struct checksums *checksums, enum checksumtype type, const char **sum_p, size_t *size_p) { - assert( type < cs_COUNT ); + assert (type < cs_COUNT); - if( checksums->parts[type].len == 0 ) + if (checksums->parts[type].len == 0) return false; *size_p = checksums->parts[type].len; *sum_p = checksums_hashpart(checksums, type); @@ -399,8 +399,8 @@ } bool checksums_gethashpart(const struct checksums *checksums, enum checksumtype type, const char **hash_p, size_t *hashlen_p, const char **size_p, size_t *sizelen_p) { - assert( type < cs_hashCOUNT ); - if( checksums->parts[type].len == 0 ) + assert (type < cs_hashCOUNT); + if (checksums->parts[type].len == 0) return false; *hashlen_p = checksums->parts[type].len; *hash_p = checksums_hashpart(checksums, type); @@ -412,9 +412,9 @@ retvalue checksums_getcombined(const struct checksums *checksums, /*@out@*/const char **data_p, /*@out@*/size_t *datalen_p) { size_t len; - assert( checksums != NULL ); + assert (checksums != NULL); len = checksums->parts[cs_length].ofs + checksums->parts[cs_length].len; - assert( checksums->representation[len] == '\0' ); + assert (checksums->representation[len] == '\0'); *data_p = checksums->representation; *datalen_p = len; @@ -426,37 +426,37 @@ off_t filesize; filesize = 0; - while( *p <= '9' && *p >= '0' ) { + while (*p <= '9' && *p >= '0') { filesize = filesize*10 + (size_t)(*p-'0'); p++; } - assert( *p == '\0' ); + assert (*p == '\0'); return filesize; } -bool checksums_matches(const struct checksums *checksums,enum checksumtype type, const char *sum) { +bool checksums_matches(const struct checksums *checksums, enum checksumtype type, const char *sum) { size_t len = (size_t)checksums->parts[type].len; - assert( type < cs_hashCOUNT ); + assert (type < cs_hashCOUNT); - if( len == 0 ) + if (len == 0) return true; - if( strncmp(sum, checksums_hashpart(checksums, type), len) != 0 ) + if (strncmp(sum, checksums_hashpart(checksums, type), len) != 0) return false; - if( sum[len] != ' ' ) + if (sum[len] != ' ') return false; /* assuming count is the last part: */ - if( strncmp(sum + len + 1, checksums_hashpart(checksums, cs_length), - checksums->parts[cs_length].len + 1) != 0 ) + if (strncmp(sum + len + 1, checksums_hashpart(checksums, cs_length), + checksums->parts[cs_length].len + 1) != 0) return false; return true; } static inline bool differ(const struct checksums *a, const struct checksums *b, enum checksumtype type) { - if( a->parts[type].len == 0 || b->parts[type].len == 0 ) + if (a->parts[type].len == 0 || b->parts[type].len == 0) return false; - if( a->parts[type].len != b->parts[type].len ) + if (a->parts[type].len != b->parts[type].len) return true; return memcmp(checksums_hashpart(a, type), checksums_hashpart(b, type), @@ -467,14 +467,14 @@ enum checksumtype type; bool additional = false; - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) { - if( differ(checksums, realchecksums, type) ) + for (type = cs_md5sum ; type < cs_COUNT ; type++) { + if (differ(checksums, realchecksums, type)) return false; - if( checksums->parts[type].len == 0 && - realchecksums->parts[type].len != 0 ) + if (checksums->parts[type].len == 0 && + realchecksums->parts[type].len != 0) additional = true; } - if( improves != NULL ) + if (improves != NULL) *improves = additional; return true; } @@ -482,8 +482,8 @@ void checksums_printdifferences(FILE *f, const struct checksums *expected, const struct checksums *got) { enum checksumtype type; - for( type = cs_md5sum ; type < cs_COUNT ; type++ ) { - if( differ(expected, got, type) ) { + for (type = cs_md5sum ; type < cs_COUNT ; type++) { + if (differ(expected, got, type)) { fprintf(f, "%s expected: %.*s, got: %.*s\n", hash_name[type], (int)expected->parts[type].len, @@ -502,42 +502,42 @@ char typeid; n = malloc(sizeof(struct checksums)+ len + 1); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; memset(n, 0, sizeof(struct checksums)); o = old->representation; b = by->representation; d = n->representation; - while( *o == ':' || *b == ':' ) { - if( b[0] != ':' || (o[0] == ':' && o[1] <= b[1]) ) { + while (*o == ':' || *b == ':') { + if (b[0] != ':' || (o[0] == ':' && o[1] <= b[1])) { *(d++) = *(o++); typeid = *o; *(d++) = *(o++); *(d++) = *(o++); - if( typeid == '1' ) { + if (typeid == '1') { start = d; n->parts[cs_sha1sum].ofs = d - n->representation; - while( *o != ' ' && *o != '\0' ) + while (*o != ' ' && *o != '\0') *(d++) = *(o++); n->parts[cs_sha1sum].len = (hashlen_t)(d - start); - } else if( typeid == '2' ) { + } else if (typeid == '2') { start = d; n->parts[cs_sha256sum].ofs = d - n->representation; - while( *o != ' ' && *o != '\0' ) + while (*o != ' ' && *o != '\0') *(d++) = *(o++); n->parts[cs_sha256sum].len = (hashlen_t)(d - start); } else - while( *o != ' ' && *o != '\0' ) + while (*o != ' ' && *o != '\0') *(d++) = *(o++); - assert( *o == ' ' ); - if( *o == ' ' ) + assert (*o == ' '); + if (*o == ' ') *(d++) = *(o++); - if( b[0] == ':' && typeid == b[1] ) { - while( *b != ' ' && *b != '\0' ) + if (b[0] == ':' && typeid == b[1]) { + while (*b != ' ' && *b != '\0') b++; - assert( *b == ' ' ); - if( *b == ' ' ) + assert (*b == ' '); + if (*b == ' ') b++; } } else { @@ -545,66 +545,66 @@ typeid = *b; *(d++) = *(b++); *(d++) = *(b++); - if( typeid == '1' ) { - if( improvedhashes != NULL) + if (typeid == '1') { + if (improvedhashes != NULL) improvedhashes[cs_sha1sum] = true; start = d; n->parts[cs_sha1sum].ofs = d - n->representation; - while( *b != ' ' && *b != '\0' ) + while (*b != ' ' && *b != '\0') *(d++) = *(b++); n->parts[cs_sha1sum].len = (hashlen_t)(d - start); - } else if( typeid == '2' ) { - if( improvedhashes != NULL) + } else if (typeid == '2') { + if (improvedhashes != NULL) improvedhashes[cs_sha256sum] = true; start = d; n->parts[cs_sha256sum].ofs = d - n->representation; - while( *b != ' ' && *b != '\0' ) + while (*b != ' ' && *b != '\0') *(d++) = *(b++); n->parts[cs_sha256sum].len = (hashlen_t)(d - start); } else - while( *b != ' ' && *b != '\0' ) + while (*b != ' ' && *b != '\0') *(d++) = *(b++); - assert( *b == ' ' ); - if( *b == ' ' ) + assert (*b == ' '); + if (*b == ' ') *(d++) = *(b++); } } /* now take md5sum from original code, unless only the new one has it */ n->parts[cs_md5sum].ofs = d - n->representation; start = d; - if( *o == '-' && *b != '-' ) + if (*o == '-' && *b != '-') o = b; - while( *o != ' ' && *o != '\0' ) + while (*o != ' ' && *o != '\0') *(d++) = *(o++); n->parts[cs_md5sum].len = (hashlen_t)(d - start); - assert( *o == ' ' ); - if( *o == ' ' ) + assert (*o == ' '); + if (*o == ' ') *(d++) = *(o++); /* and now the size */ n->parts[cs_length].ofs = d - n->representation; start = d; - while( *o != '\0' ) + while (*o != '\0') *(d++) = *(o++); n->parts[cs_length].len = (hashlen_t)(d - start); - assert( (size_t)(d - n->representation) <= len ); + assert ((size_t)(d - n->representation) <= len); *(d++) = '\0'; *checksums_p = realloc(n, sizeof(struct checksums) + (d-n->representation)); - if( *checksums_p == NULL ) + if (*checksums_p == NULL) *checksums_p = n; checksums_free(old); return RET_OK; } void checksumsarray_done(struct checksumsarray *array) { - if( array->names.count > 0 ) { + if (array->names.count > 0) { int i; - assert( array->checksums != NULL ); - for( i = 0 ; i < array->names.count ; i++ ) { + assert (array->checksums != NULL); + for (i = 0 ; i < array->names.count ; i++) { checksums_free(array->checksums[i]); } } else - assert( array->checksums == NULL ); + assert (array->checksums == NULL); strlist_done(&array->names); free(array->checksums); } @@ -614,31 +614,31 @@ const char *hash_start, *size_start, *filename; size_t hash_len, size_len; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; hash_start = p; - while( (*p >= '0' && *p <= '9') || - (*p >= 'a' && *p <= 'f' ) ) + while ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f')) p++; hash_len = p - hash_start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; - while( *p == '0' && p[1] >= '0' && p[1] <= '9' ) + while (*p == '0' && p[1] >= '0' && p[1] <= '9') p++; size_start = p; - while( (*p >= '0' && *p <= '9') ) + while ((*p >= '0' && *p <= '9')) p++; size_len = p - size_start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; filename = p; - while( *p != '\0' && *p != ' ' && *p != '\t' - && *p != '\r' && *p != '\n' ) + while (*p != '\0' && *p != ' ' && *p != '\t' + && *p != '\r' && *p != '\n') p++; - if( unlikely( size_len == 0 || hash_len == 0 - || filename == p || *p != '\0' ) ) { + if (unlikely(size_len == 0 || hash_len == 0 + || filename == p || *p != '\0')) { fprintf(stderr, - "Error parsing %s checksum line ' %s' within '%s'\n", +"Error parsing %s checksum line ' %s' within '%s'\n", hash_name[cs], line, filenametoshow); return RET_ERROR; @@ -666,46 +666,45 @@ /* avoid realloc by allocing the absolute maximum only * if every checksum field contains different files */ count = 0; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { count += l[cs].count; } - parsed = calloc(count, sizeof(struct hashes)); - if( FAILEDTOALLOC(parsed) ) { + parsed = nzNEW(count, struct hashes); + if (FAILEDTOALLOC(parsed)) return RET_ERROR_OOM; - } strlist_init_n(count + 1, &filenames); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - for( i = 0 ; i < l[cs].count ; i++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + for (i = 0 ; i < l[cs].count ; i++) { const char *line = l[cs].values[i]; const char *p = line, *hash_start, *size_start, *filename; size_t hash_len, size_len; int fileofs; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; hash_start = p; - while( (*p >= '0' && *p <= '9') || - (*p >= 'a' && *p <= 'f' ) ) + while ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f')) p++; hash_len = p - hash_start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; - while( *p == '0' && p[1] >= '0' && p[1] <= '9' ) + while (*p == '0' && p[1] >= '0' && p[1] <= '9') p++; size_start = p; - while( (*p >= '0' && *p <= '9') ) + while ((*p >= '0' && *p <= '9')) p++; size_len = p - size_start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; filename = p; - while( *p != '\0' && *p != ' ' && *p != '\t' - && *p != '\r' && *p != '\n' ) + while (*p != '\0' && *p != ' ' && *p != '\t' + && *p != '\r' && *p != '\n') p++; - if( unlikely( size_len == 0 || hash_len == 0 - || filename == p || *p != '\0' ) ) { + if (unlikely(size_len == 0 || hash_len == 0 + || filename == p || *p != '\0')) { fprintf(stderr, "Error parsing %s checksum line ' %s' within '%s'\n", hash_name[cs], line, @@ -713,10 +712,10 @@ strlist_done(&filenames); free(parsed); return RET_ERROR; - } else if( cs == cs_md5sum ) { + } else if (cs == cs_md5sum) { fileofs = filenames.count; r = strlist_add_dup(&filenames, filename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filenames); free(parsed); return r; @@ -730,10 +729,10 @@ struct hash_data *hashes; fileofs = strlist_ofs(&filenames, filename); - if( fileofs == -1 ) { + if (fileofs == -1) { fileofs = filenames.count; r = strlist_add_dup(&filenames, filename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filenames); free(parsed); return r; @@ -743,10 +742,10 @@ hashes[cs_length].len = size_len; } else hashes = parsed[fileofs].hashes; - if( unlikely( hashes[cs_length].len + if (unlikely(hashes[cs_length].len != size_len || memcmp(hashes[cs_length].start, - size_start, size_len) != 0) ) { + size_start, size_len) != 0)) { fprintf(stderr, "WARNING: %s checksum line ' %s' in '%s' contradicts previous filesize!\n", hash_name[cs], line, @@ -759,9 +758,9 @@ } } } - assert( count >= (size_t)filenames.count ); + assert (count >= (size_t)filenames.count); - if( filenames.count == 0 ) { + if (filenames.count == 0) { strlist_done(&filenames); strlist_init(&out->names); out->checksums = NULL; @@ -770,12 +769,13 @@ } #if 0 // TODO: reenable this once apt-utils is fixed for a long enough time... - for( i = 0 ; i < filenames.count ; i++ ) { - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( !foundhashtype[cs] ) + for (i = 0 ; i < filenames.count ; i++) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if (!foundhashtype[cs]) continue; - if( parsed[i].hashes[cs].start == NULL ) { - fprintf(stderr, "WARNING: Inconsistent hashes in %s: '%s' missing %s!\n", + if (parsed[i].hashes[cs].start == NULL) { + fprintf(stderr, +"WARNING: Inconsistent hashes in %s: '%s' missing %s!\n", filenametoshow, filenames.values[i], hash_name[cs]); @@ -786,17 +786,17 @@ } } #endif - a.checksums = calloc(filenames.count+1, sizeof(struct checksums *)); - if( FAILEDTOALLOC(a.checksums) ) { + a.checksums = nzNEW(filenames.count+1, struct checksums *); + if (FAILEDTOALLOC(a.checksums)) { strlist_done(&filenames); free(parsed); return RET_ERROR_OOM; } strlist_move(&a.names, &filenames); - for( i = 0 ; i < a.names.count ; i++ ) { + for (i = 0 ; i < a.names.count ; i++) { r = checksums_initialize(a.checksums + i, parsed[i].hashes); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(parsed); checksumsarray_done(&a); return r; @@ -818,49 +818,49 @@ memset(missing, 0, sizeof(missing)); memset(lens, 0, sizeof(lens)); - for( i=0 ; i < a->names.count ; i++ ) { + for (i=0 ; i < a->names.count ; i++) { const struct checksums *checksums = a->checksums[i]; size_t len; filenamelen[i] = strlen(a->names.values[i]); len = 4 + filenamelen[i] + checksums->parts[cs_length].len; - assert( checksums != NULL ); - if( checksums->parts[cs_md5sum].len == 0 ) + assert (checksums != NULL); + if (checksums->parts[cs_md5sum].len == 0) lens[cs_md5sum] += len + 1; else lens[cs_md5sum] += len + checksums->parts[cs_md5sum].len; - for( cs = cs_md5sum+1 ; cs < cs_hashCOUNT ; cs++ ) { - if( checksums->parts[cs].len == 0 ) + for (cs = cs_md5sum+1 ; cs < cs_hashCOUNT ; cs++) { + if (checksums->parts[cs].len == 0) missing[cs] = true; lens[cs] += len + checksums->parts[cs].len; } } - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( missing[cs] ) + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if (missing[cs]) filelines[cs] = NULL; else { filelines[cs] = malloc(lens[cs] + 1); - if( FAILEDTOALLOC(filelines[cs]) ) { - while( cs-- > cs_md5sum ) + if (FAILEDTOALLOC(filelines[cs])) { + while (cs-- > cs_md5sum) free(filelines[cs]); return RET_ERROR_OOM; } } } - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { char *p; - if( missing[cs] ) + if (missing[cs]) continue; p = filelines[cs]; *(p++) = '\n'; - for( i=0 ; i < a->names.count ; i++ ) { + for (i=0 ; i < a->names.count ; i++) { const struct checksums *c = a->checksums[i]; *(p++) = ' '; - if( c->parts[cs].len == 0 ) { + if (c->parts[cs].len == 0) { *(p++) = '-'; } else { memcpy(p, checksums_hashpart(c, cs), @@ -877,7 +877,7 @@ *(p++) = '\n'; } *(--p) = '\0'; - assert( (size_t)(p - filelines[cs]) == lens[cs]); + assert ((size_t)(p - filelines[cs]) == lens[cs]); } *md5_p = filelines[cs_md5sum]; *sha1_p = filelines[cs_sha1sum]; @@ -895,10 +895,10 @@ int i; enum checksumtype cs; - for( i = 0 ; i < a->names.count ; i++ ) { + for (i = 0 ; i < a->names.count ; i++) { struct checksums *c = a->checksums[i]; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( c->parts[cs].len == 0 ) + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if (c->parts[cs].len == 0) types[cs] = false; } } @@ -909,26 +909,26 @@ struct checksums **n; int count = a->names.count; - n = malloc((count+1) * sizeof(struct checksums*)); - if( n == NULL ) { + n = nNEW(count + 1, struct checksums *); + if (FAILEDTOALLOC(n)) { free(name); return RET_ERROR_OOM; } n[0] = checksums_dup(checksums); - if( n[0] == NULL ) { + if (FAILEDTOALLOC(n[0])) { free(name); free(n); return RET_ERROR_OOM; } r = strlist_include(&a->names, name); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { checksums_free(n[0]); free(n); return r; } - assert( a->names.count == count + 1 ); - if( count > 0 ) { - assert( a->checksums != NULL ); + assert (a->names.count == count + 1); + if (count > 0) { + assert (a->checksums != NULL); memcpy(&n[1], a->checksums, count*sizeof(struct checksums*)); } free(a->checksums); @@ -944,12 +944,12 @@ struct stat s; i = stat(fullfilename, &s); - if( i < 0 ) { + if (i < 0) { i = errno; - if( i == EACCES || i == ENOENT ) + if (i == EACCES || i == ENOENT) return RET_NOTHING; else { - fprintf(stderr,"Error %d stating '%s': %s!\n", + fprintf(stderr, "Error %d stating '%s': %s!\n", i, fullfilename, strerror(i)); return RET_ERRNO(i); } @@ -957,9 +957,9 @@ expectedsize = checksums_getfilesize(checksums); - if( s.st_size == expectedsize ) + if (s.st_size == expectedsize) return RET_OK; - if( complain ) + if (complain) fprintf(stderr, "WRONG SIZE of '%s': expected %lld found %lld\n", fullfilename, @@ -976,24 +976,24 @@ /* check if it is there and has the correct size */ r = checksums_cheaptest(filename, checksums, false); /* if it is, read its checksums */ - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = checksums_read(filename, &filechecksums); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - if( !checksums_check(checksums, filechecksums, &improves) ) { + if (!checksums_check(checksums, filechecksums, &improves)) { checksums_free(filechecksums); return RET_ERROR_WRONG_MD5; } - if( improves && checksums_p != NULL ) { - if( *checksums_p == NULL ) { + if (improves && checksums_p != NULL) { + if (*checksums_p == NULL) { *checksums_p = checksums_dup(checksums); - if( FAILEDTOALLOC(*checksums_p) ) { + if (FAILEDTOALLOC(*checksums_p)) { checksums_free(filechecksums); return RET_ERROR_OOM; } } r = checksums_combine(checksums_p, filechecksums, NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(filechecksums); return r; } @@ -1012,20 +1012,19 @@ int e, i; int infd, outfd; - if( buffer == NULL ) { + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; - } infd = open(source, O_RDONLY); - if( infd < 0 ) { + if (infd < 0) { e = errno; - fprintf(stderr,"Error %d opening '%s': %s\n", + fprintf(stderr, "Error %d opening '%s': %s\n", e, source, strerror(e)); free(buffer); return RET_ERRNO(e); } outfd = open(destination, O_NOCTTY|O_WRONLY|O_CREAT|O_EXCL, 0666); - if( outfd < 0 ) { + if (outfd < 0) { e = errno; fprintf(stderr, "Error %d creating '%s': %s\n", e, destination, strerror(e)); @@ -1036,9 +1035,9 @@ filesize = 0; do { sizeread = read(infd, buffer, bufsize); - if( sizeread < 0 ) { + if (sizeread < 0) { e = errno; - fprintf(stderr,"Error %d while reading %s: %s\n", + fprintf(stderr, "Error %d while reading %s: %s\n", e, source, strerror(e)); free(buffer); (void)close(infd); (void)close(outfd); @@ -1048,11 +1047,12 @@ filesize += sizeread; towrite = sizeread; start = buffer; - while( towrite > 0 ) { + while (towrite > 0) { written = write(outfd, start, (size_t)towrite); - if( written < 0 ) { + if (written < 0) { e = errno; - fprintf(stderr,"Error %d while writing to %s: %s\n", + fprintf(stderr, +"Error %d while writing to %s: %s\n", e, destination, strerror(e)); free(buffer); (void)close(infd); (void)close(outfd); @@ -1062,27 +1062,27 @@ towrite -= written; start += written; } - } while( sizeread > 0 ); + } while (sizeread > 0); free(buffer); i = close(infd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d reading %s: %s\n", + fprintf(stderr, "Error %d reading %s: %s\n", e, source, strerror(e)); (void)close(outfd); deletefile(destination); return RET_ERRNO(e);; } i = close(outfd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d writing to %s: %s\n", + fprintf(stderr, "Error %d writing to %s: %s\n", e, destination, strerror(e)); deletefile(destination); return RET_ERRNO(e);; } expected = checksums_getfilesize(checksums); - if( filesize != expected ) { + if (filesize != expected) { fprintf(stderr, "Error copying %s to %s:\n" " File seems to be of size %llu, while %llu was expected!\n", @@ -1097,29 +1097,29 @@ retvalue checksums_hardlink(const char *directory, const char *filekey, const char *sourcefilename, const struct checksums *checksums) { retvalue r; - int i,e; + int i, e; char *fullfilename = calc_dirconcat(directory, filekey); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; i = link(sourcefilename, fullfilename); e = errno; - if( i != 0 && e == EEXIST ) { + if (i != 0 && e == EEXIST) { (void)unlink(fullfilename); errno = 0; i = link(sourcefilename, fullfilename); e = errno; } - if( i != 0 && ( e == EACCES || e == ENOENT || e == ENOTDIR ) ) { + if (i != 0 && (e == EACCES || e == ENOENT || e == ENOTDIR)) { errno = 0; (void)dirs_make_parent(fullfilename); i = link(sourcefilename, fullfilename); e = errno; } - if( i != 0 ) { - if( e == EXDEV || e == EPERM || e == EMLINK ) { + if (i != 0) { + if (e == EXDEV || e == EPERM || e == EMLINK) { r = copy(fullfilename, sourcefilename, checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } @@ -1149,7 +1149,8 @@ SHA256Update(&context->sha256, data, len); } -static const char tab[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; +static const char tab[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; retvalue checksums_from_context(struct checksums **out, struct checksumscontext *context) { #define MD5_DIGEST_SIZE 16 @@ -1161,7 +1162,7 @@ n = malloc(sizeof(struct checksums) + 2*MD5_DIGEST_SIZE + 2*SHA1_DIGEST_SIZE + 2*SHA256_DIGEST_SIZE + 30); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; memset(n, 0, sizeof(struct checksums)); d = n->representation; @@ -1171,7 +1172,7 @@ n->parts[cs_sha1sum].ofs = 3; n->parts[cs_sha1sum].len = 2*SHA1_DIGEST_SIZE; SHA1Final(&context->sha1, sha1buffer); - for( i = 0 ; i < SHA1_DIGEST_SIZE ; i++ ) { + for (i = 0 ; i < SHA1_DIGEST_SIZE ; i++) { *(d++) = tab[sha1buffer[i] >> 4]; *(d++) = tab[sha1buffer[i] & 0xF]; } @@ -1183,29 +1184,29 @@ n->parts[cs_sha256sum].ofs = d - n->representation; n->parts[cs_sha256sum].len = 2*SHA256_DIGEST_SIZE; SHA256Final(&context->sha256, sha256buffer); - for( i = 0 ; i < SHA256_DIGEST_SIZE ; i++ ) { + for (i = 0 ; i < SHA256_DIGEST_SIZE ; i++) { *(d++) = tab[sha256buffer[i] >> 4]; *(d++) = tab[sha256buffer[i] & 0xF]; } *(d++) = ' '; n->parts[cs_md5sum].ofs = d - n->representation; - assert( d - n->representation == n->parts[cs_md5sum].ofs); + assert (d - n->representation == n->parts[cs_md5sum].ofs); n->parts[cs_md5sum].len = 2*MD5_DIGEST_SIZE; MD5Final(md5buffer, &context->md5); - for( i=0 ; i < MD5_DIGEST_SIZE ; i++ ) { + for (i=0 ; i < MD5_DIGEST_SIZE ; i++) { *(d++) = tab[md5buffer[i] >> 4]; *(d++) = tab[md5buffer[i] & 0xF]; } *(d++) = ' '; n->parts[cs_length].ofs = d - n->representation; - assert( d - n->representation == n->parts[cs_length].ofs); + assert (d - n->representation == n->parts[cs_length].ofs); n->parts[cs_length].len = (hashlen_t)snprintf(d, 2*MD5_DIGEST_SIZE + 2*SHA1_DIGEST_SIZE + 2*SHA256_DIGEST_SIZE + 30 - (d - n->representation), "%lld", (long long)context->sha1.count); - assert( strlen(d) == n->parts[cs_length].len ); + assert (strlen(d) == n->parts[cs_length].len); *out = n; return RET_OK; } @@ -1220,7 +1221,7 @@ * if the file is not there, return RET_NOTHING. * return RET_ERROR_WRONG_MD5 if already existing do not match */ retvalue checksums_complete(struct checksums **checksums_p, const char *fullfilename) { - if( checksums_iscomplete(*checksums_p) ) + if (checksums_iscomplete(*checksums_p)) return RET_OK; return checksums_test(fullfilename, *checksums_p, checksums_p); } @@ -1233,42 +1234,41 @@ int e, i; int infd; - if( buffer == NULL ) { + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; - } checksumscontext_init(&context); infd = open(fullfilename, O_RDONLY); - if( infd < 0 ) { + if (infd < 0) { e = errno; - if( (e == EACCES || e == ENOENT) && - !isregularfile(fullfilename) ) { + if ((e == EACCES || e == ENOENT) && + !isregularfile(fullfilename)) { free(buffer); return RET_NOTHING; } - fprintf(stderr,"Error %d opening '%s': %s\n", + fprintf(stderr, "Error %d opening '%s': %s\n", e, fullfilename, strerror(e)); free(buffer); return RET_ERRNO(e); } do { sizeread = read(infd, buffer, bufsize); - if( sizeread < 0 ) { + if (sizeread < 0) { e = errno; - fprintf(stderr,"Error %d while reading %s: %s\n", + fprintf(stderr, "Error %d while reading %s: %s\n", e, fullfilename, strerror(e)); free(buffer); (void)close(infd); return RET_ERRNO(e);; } checksumscontext_update(&context, buffer, (size_t)sizeread); - } while( sizeread > 0 ); + } while (sizeread > 0); free(buffer); i = close(infd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d reading %s: %s\n", + fprintf(stderr, "Error %d reading %s: %s\n", e, fullfilename, strerror(e)); return RET_ERRNO(e);; } @@ -1284,25 +1284,24 @@ int e, i; int infd, outfd; - if( FAILEDTOALLOC(buffer) ) { + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; - } infd = open(source, O_RDONLY); - if( infd < 0 ) { + if (infd < 0) { e = errno; - fprintf(stderr,"Error %d opening '%s': %s\n", + fprintf(stderr, "Error %d opening '%s': %s\n", e, source, strerror(e)); free(buffer); return RET_ERRNO(e); } outfd = open(destination, O_NOCTTY|O_WRONLY|O_CREAT|O_EXCL, 0666); - if( outfd < 0 ) { + if (outfd < 0) { e = errno; - if( e == EEXIST ) { - if( deletetarget ) { + if (e == EEXIST) { + if (deletetarget) { i = unlink(destination); - if( i != 0 ) { + if (i != 0) { e = errno; fprintf(stderr, "Error %d deleting '%s': %s\n", @@ -1321,7 +1320,7 @@ return RET_ERROR_EXIST; } } - if( outfd < 0 ) { + if (outfd < 0) { fprintf(stderr, "Error %d creating '%s': %s\n", e, destination, strerror(e)); @@ -1333,9 +1332,9 @@ checksumscontext_init(&context); do { sizeread = read(infd, buffer, bufsize); - if( sizeread < 0 ) { + if (sizeread < 0) { e = errno; - fprintf(stderr,"Error %d while reading %s: %s\n", + fprintf(stderr, "Error %d while reading %s: %s\n", e, source, strerror(e)); free(buffer); (void)close(infd); (void)close(outfd); @@ -1345,11 +1344,12 @@ checksumscontext_update(&context, buffer, (size_t)sizeread); towrite = sizeread; start = buffer; - while( towrite > 0 ) { + while (towrite > 0) { written = write(outfd, start, (size_t)towrite); - if( written < 0 ) { + if (written < 0) { e = errno; - fprintf(stderr,"Error %d while writing to %s: %s\n", + fprintf(stderr, +"Error %d while writing to %s: %s\n", e, destination, strerror(e)); free(buffer); (void)close(infd); (void)close(outfd); @@ -1359,21 +1359,21 @@ towrite -= written; start += written; } - } while( sizeread > 0 ); + } while (sizeread > 0); free(buffer); i = close(infd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d reading %s: %s\n", + fprintf(stderr, "Error %d reading %s: %s\n", e, source, strerror(e)); (void)close(outfd); deletefile(destination); return RET_ERRNO(e);; } i = close(outfd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d writing to %s: %s\n", + fprintf(stderr, "Error %d writing to %s: %s\n", e, destination, strerror(e)); deletefile(destination); return RET_ERRNO(e);; @@ -1387,12 +1387,12 @@ // TODO: is this needed? perhaps move this duty to the caller... r = dirs_make_parent(destination); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; errno = 0; i = link(source, destination); - if( i != 0 ) + if (i != 0) return checksums_copyfile(destination, source, true, checksums_p); *checksums_p = NULL; return RET_OK; @@ -1407,11 +1407,11 @@ retvalue r; tempfilename = calc_addsuffix(filename, "new"); - if( tempfilename == NULL ) + if (FAILEDTOALLOC(tempfilename)) return RET_ERROR_OOM; fd = open(tempfilename, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "ERROR creating '%s': %s\n", tempfilename, strerror(e)); @@ -1420,9 +1420,9 @@ } todo = len; towrite = data; - while( todo > 0 ) { + while (todo > 0) { ssize_t written = write(fd, towrite, todo); - if( written >= 0 ) { + if (written >= 0) { todo -= written; towrite += written; } else { @@ -1436,7 +1436,7 @@ } } ret = close(fd); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error writing to '%s': %s\n", tempfilename, strerror(e)); @@ -1445,12 +1445,12 @@ return RET_ERRNO(e); } - if( checksums_p != NULL ) { + if (checksums_p != NULL) { checksumscontext_init(&context); checksumscontext_update(&context, (const unsigned char *)data, len); r = checksums_from_context(&checksums, &context); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { unlink(tempfilename); free(tempfilename); return r; @@ -1458,7 +1458,7 @@ } else checksums = NULL; ret = rename(tempfilename, filename); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error moving '%s' to '%s': %s\n", tempfilename, filename, strerror(e)); @@ -1468,7 +1468,7 @@ return RET_ERRNO(e); } free(tempfilename); - if( checksums_p != NULL ) + if (checksums_p != NULL) *checksums_p = checksums; return RET_OK; } diff -Nru reprepro-4.5.0/checksums.h reprepro-4.6.0/checksums.h --- reprepro-4.5.0/checksums.h 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/checksums.h 2011-05-05 14:42:55.000000000 +0000 @@ -60,31 +60,32 @@ bool checksums_gethashpart(const struct checksums *, enum checksumtype, /*@out@*/const char **hash_p, /*@out@*/size_t *hashlen_p, /*@out@*/const char **size_p, /*@out@*/size_t *sizelen_p); /* check if a single checksum fits */ -bool checksums_matches(const struct checksums *,enum checksumtype, const char *); +bool checksums_matches(const struct checksums *, enum checksumtype, const char *); /* Copy file to file , calculating checksums */ -retvalue checksums_copyfile(const char *destination, const char *origin, bool deletetarget, /*@out@*/struct checksums **); -retvalue checksums_hardlink(const char *directory, const char *filekey, const char *sourcefilename, const struct checksums *); +retvalue checksums_copyfile(const char * /*destination*/, const char * /*origin*/, bool /*deletetarget*/, /*@out@*/struct checksums **); +retvalue checksums_hardlink(const char * /*directory*/, const char * /*filekey*/, const char * /*sourcefilename*/, const struct checksums *); -retvalue checksums_linkorcopyfile(const char *destination, const char *origin, /*@out@*/struct checksums **); +retvalue checksums_linkorcopyfile(const char * /*destination*/, const char * /*origin*/, /*@out@*/struct checksums **); /* calculare checksums of a file: */ -retvalue checksums_read(const char *fullfilename, /*@out@*/struct checksums **); +retvalue checksums_read(const char * /*fullfilename*/, /*@out@*/struct checksums **); /* replace the contents of a file with data and calculate the new checksums */ -retvalue checksums_replace(const char *filename, const char *, size_t len, /*@out@*//*@null@*/struct checksums **); +retvalue checksums_replace(const char * /*filename*/, const char *, size_t, /*@out@*//*@null@*/struct checksums **); /* check if the file has the given md5sum (only cheap tests like size), - * RET_NOTHING means file does not exist, RET_ERROR_WRONG_MD5 means wrong size */ -retvalue checksums_cheaptest(const char *fullfilename, const struct checksums *, bool); + * RET_NOTHING means file does not exist, + * RET_ERROR_WRONG_MD5 means wrong size */ +retvalue checksums_cheaptest(const char * /*fullfilename*/, const struct checksums *, bool); /* check if filename has specified checksums, if not return RET_ERROR_WRONG_MD5, - * if it has, and checksums_p put the improved checksum there (*checksums_p should - * either be NULL or checksums */ + * if it has, and checksums_p put the improved checksum there + * (*checksums_p should either be NULL or checksums) */ retvalue checksums_test(const char *, const struct checksums *, /*@null@*/struct checksums **); /* check if checksum of filekey in database and checksum of actual file, set improve if some new has is in the last */ -bool checksums_check(const struct checksums *, const struct checksums *, /*@out@*/bool *improves); +bool checksums_check(const struct checksums *, const struct checksums *, /*@out@*/bool * /*improves_p*/); /* return true, iff all supported checksums are available */ bool checksums_iscomplete(const struct checksums *); @@ -92,11 +93,11 @@ /* Collect missing checksums (if all are there always RET_OK without checking). * if the file is not there, return RET_NOTHING, * if it is but not matches, return RET_ERROR_WRONG_MD5 */ -retvalue checksums_complete(struct checksums **, const char *fullfilename); +retvalue checksums_complete(struct checksums **, const char * /*fullfilename*/); -void checksums_printdifferences(FILE *,const struct checksums *expected, const struct checksums *got); +void checksums_printdifferences(FILE *, const struct checksums * /*expected*/, const struct checksums * /*got*/); -retvalue checksums_combine(struct checksums **checksums, const struct checksums *by, /*@null@*/bool improvedhashes[cs_hashCOUNT]); +retvalue checksums_combine(struct checksums **, const struct checksums *, /*@null@*/bool[cs_hashCOUNT]); typedef /*@only@*/ struct checksums *ownedchecksums; struct checksumsarray { @@ -105,15 +106,14 @@ }; void checksumsarray_move(/*@out@*/struct checksumsarray *, /*@special@*/struct checksumsarray *array)/*@requires maxSet(array->names.values) >= array->names.count /\ maxSet(array->checksums) >= array->names.count @*/ /*@releases array->checksums, array->names.values @*/; void checksumsarray_done(/*@special@*/struct checksumsarray *array) /*@requires maxSet(array->names.values) >= array->names.count /\ maxSet(array->checksums) >= array->names.count @*/ /*@releases array->checksums, array->names.values @*/; -retvalue checksumsarray_parse(/*@out@*/struct checksumsarray *, const struct strlist [cs_hashCOUNT], const char *filenametoshow); +retvalue checksumsarray_parse(/*@out@*/struct checksumsarray *, const struct strlist [cs_hashCOUNT], const char * /*filenametoshow*/); retvalue checksumsarray_genfilelist(const struct checksumsarray *, /*@out@*/char **, /*@out@*/char **, /*@out@*/char **); retvalue checksumsarray_include(struct checksumsarray *, /*@only@*/char *, const struct checksums *); void checksumsarray_resetunsupported(const struct checksumsarray *, bool[cs_hashCOUNT]); -retvalue hashline_parse(const char *filenametoshow, const char *line, enum checksumtype cs, /*@out@*/const char **basename_p, /*@out@*/struct hash_data *data_p, /*@out@*/struct hash_data *size_p); +retvalue hashline_parse(const char * /*filenametoshow*/, const char * /*line*/, enum checksumtype, /*@out@*/const char ** /*basename_p*/, /*@out@*/struct hash_data *, /*@out@*/struct hash_data *); struct configiterator; -retvalue checksums_parseignorelist(bool ignorelist[cs_hashCOUNT], const char *, struct configiterator *); #ifdef CHECKSUMS_CONTEXT #ifndef MD5_H diff -Nru reprepro-4.5.0/chunkedit.c reprepro-4.6.0/chunkedit.c --- reprepro-4.5.0/chunkedit.c 2008-07-25 08:38:51.000000000 +0000 +++ reprepro-4.6.0/chunkedit.c 2011-05-05 14:42:55.000000000 +0000 @@ -28,36 +28,13 @@ #include "chunkedit.h" #include "names.h" -/* modifications of a chunk: +/ -struct chunkeditfield { - /+@null@+/struct chunkeditfield +next; - /+ The name of the field: +/ - const char +field; size_ len_field; - enum cefaction { CEF_DELETE, /+ delete if there +/ - CEF_ADDMISSED, /+ add if not there +/ - CEF_REPLACE, /+ replace if there +/ - CEF_ADD /+ add if not there or replace if there +/ - } action; - bool early; /+ add as early as possible or as late as possible +/ - /+ the following must be 0 or NULL for CEF_DELETE +/ - size_t len_all_data; - /+@null@+/const char +data; size_t len_data; - const struct strlist +words; - unsigned int linecount; - struct cef_line { - int wordcount; - char + const +words; - size_t +wordlen; - } lines[]; -}; */ - void cef_free(struct chunkeditfield *f) { - while( f != NULL ) { + while (f != NULL) { int i; struct chunkeditfield *p = f; f = f->next; - for( i = 0 ; i < p->linecount ; i++ ) { + for (i = 0 ; i < p->linecount ; i++) { free(p->lines[i].words); free(p->lines[i].wordlen); } @@ -68,8 +45,9 @@ struct chunkeditfield *cef_newfield(const char *field, enum cefaction action, enum cefwhen when, unsigned int linecount, struct chunkeditfield *next) { struct chunkeditfield *n; - n = calloc(1, sizeof(struct chunkeditfield)+linecount*sizeof(struct cef_line)); - if( n == NULL ) { + n = calloc(1, sizeof(struct chunkeditfield) + + linecount * sizeof(struct cef_line)); + if (FAILEDTOALLOC(n)) { cef_free(next); return NULL; } @@ -85,9 +63,9 @@ void cef_setdatalen(struct chunkeditfield *cef, const char *data, size_t len) { - assert( data != NULL || len == 0); + assert (data != NULL || len == 0); - assert( cef->len_all_data >= cef->len_data ); + assert (cef->len_all_data >= cef->len_data); cef->len_all_data -= cef->len_data; cef->len_all_data += len; cef->data = data; @@ -96,18 +74,18 @@ } void cef_setdata(struct chunkeditfield *cef, const char *data) { - cef_setdatalen(cef,data,strlen(data)); + cef_setdatalen(cef, data, strlen(data)); } void cef_setwordlist(struct chunkeditfield *cef, const struct strlist *words) { int i; size_t len = 0; - for( i = 0 ; i < words->count ; i++ ) { + for (i = 0 ; i < words->count ; i++) { len += 1+strlen(words->values[i]); } - if( len > 0 ) + if (len > 0) len--; - assert( cef->len_all_data >= cef->len_data ); + assert (cef->len_all_data >= cef->len_data); cef->len_all_data -= cef->len_data; cef->len_all_data += len; cef->data = NULL; @@ -121,33 +99,33 @@ const char *word; size_t len; - assert( line < cef->linecount ); - assert( wordcount > 0 ); + assert (line < cef->linecount); + assert (wordcount > 0); l = &cef->lines[line]; - assert( l->wordcount == 0 && l->words == NULL && l->wordlen == NULL ); + assert (l->wordcount == 0 && l->words == NULL && l->wordlen == NULL); l->wordcount = wordcount; - l->words = calloc(wordcount, sizeof(const char*)); - if( l->words == NULL ) + l->words = nzNEW(wordcount, const char*); + if (FAILEDTOALLOC(l->words)) return RET_ERROR_OOM; - l->wordlen = calloc(wordcount, sizeof(size_t)); - if( l->wordlen == NULL ) { + l->wordlen = nzNEW(wordcount, size_t); + if (FAILEDTOALLOC(l->wordlen)) { free(l->words);l->words = NULL; return RET_ERROR_OOM; } - va_start(ap,wordcount); + va_start(ap, wordcount); len = 1; /* newline */ - for( i = 0 ; i < wordcount; i++ ) { - word = va_arg(ap,const char*); + for (i = 0 ; i < wordcount; i++) { + word = va_arg(ap, const char*); assert(word != NULL); l->words[i] = word; l->wordlen[i] = strlen(word); len += 1 + l->wordlen[i]; } - word = va_arg(ap,const char*); - assert( word == NULL ); + word = va_arg(ap, const char*); + assert (word == NULL); va_end(ap); cef->len_all_data += len; @@ -160,22 +138,22 @@ const char *word; size_t len; - assert( line < cef->linecount ); - assert( wordcount >= 0 ); + assert (line < cef->linecount); + assert (wordcount >= 0); l = &cef->lines[line]; - assert( l->wordcount == 0 && l->words == NULL && l->wordlen == NULL ); + assert (l->wordcount == 0 && l->words == NULL && l->wordlen == NULL); l->wordcount = wordcount + 2; - l->words = calloc(wordcount + 2, sizeof(const char*)); - if( l->words == NULL ) + l->words = nzNEW(wordcount + 2, const char *); + if (FAILEDTOALLOC(l->words)) return RET_ERROR_OOM; - l->wordlen = calloc(wordcount + 2, sizeof(size_t)); - if( l->wordlen == NULL ) { - free(l->words);l->words = NULL; + l->wordlen = nzNEW(wordcount + 2, size_t); + if (FAILEDTOALLOC(l->wordlen)) { + free(l->words); l->words = NULL; return RET_ERROR_OOM; } - va_start(ap,wordcount); + va_start(ap, wordcount); len = 1; /* newline */ l->words[0] = hash; l->wordlen[0] = hashlen; @@ -183,16 +161,16 @@ l->words[1] = size; l->wordlen[1] = sizelen; len += 1 + sizelen; - for( i = 0 ; i < wordcount; i++ ) { - word = va_arg(ap,const char*); + for (i = 0 ; i < wordcount; i++) { + word = va_arg(ap, const char*); assert(word != NULL); l->words[i + 2] = word; l->wordlen[i + 2] = strlen(word); len += 1 + l->wordlen[i + 2]; } - word = va_arg(ap,const char*); - assert( word == NULL ); + word = va_arg(ap, const char*); + assert (word == NULL); va_end(ap); cef->len_all_data += len; @@ -201,9 +179,9 @@ static inline int findcef(const struct chunkeditfield *cef, const char *p, size_t len) { int result = 0; - while( cef != NULL ) { - if( cef->len_field == len && - strncasecmp(p, cef->field, len) == 0 ) { + while (cef != NULL) { + if (cef->len_field == len && + strncasecmp(p, cef->field, len) == 0) { return result; } cef = cef->next; @@ -227,46 +205,46 @@ oldlen = strlen(chunk); maxlen = 1; /* a newline might get missed */ - for( cef = cefs ; cef != NULL ; cef=cef->next ) { + for (cef = cefs ; cef != NULL ; cef=cef->next) { maxlen += cef->len_field + cef->len_all_data + 3; /* ': \n' */ count ++; } - fields = calloc(count, sizeof(struct field)); - if( fields == NULL ) + fields = nzNEW(count, struct field); + if (FAILEDTOALLOC(fields)) return RET_ERROR_OOM; i = 0; - for( cef = cefs ; cef != NULL ; cef=cef->next ) { - assert( i < count ); + for (cef = cefs ; cef != NULL ; cef=cef->next) { + assert (i < count); fields[i++].cef = cef; } - assert( i == count ); + assert (i == count); /* get rid of empty or strange lines at the beginning: */ - while( *chunk == ' ' || *chunk == '\t' ) { - while( *chunk != '\0' && *chunk != '\n' ) + while (*chunk == ' ' || *chunk == '\t') { + while (*chunk != '\0' && *chunk != '\n') chunk++; - if( *chunk == '\n' ) + if (*chunk == '\n') chunk++; } p = chunk; - while( true ) { + while (true) { q = p; - while( *q != '\0' && *q != '\n' && *q != ':' ) + while (*q != '\0' && *q != '\n' && *q != ':') q++; - if( *q == '\0' ) + if (*q == '\0') break; - if( *q == '\n' ) { + if (*q == '\n') { /* header without colon? what kind of junk is this? */ q++; - while( *q == ' ' || *q == '\t' ) { - while( *q != '\0' && *q != '\n' ) + while (*q == ' ' || *q == '\t') { + while (*q != '\0' && *q != '\n') q++; - if( *q == '\n' ) + if (*q == '\n') q++; } - if( p == chunk ) + if (p == chunk) chunk = q; p = q; continue; @@ -274,89 +252,88 @@ i = findcef(cefs, p, q-p); /* find begin and end of data */ q++; - while( *q == ' ' ) + while (*q == ' ') q++; e = q; - while( *e != '\0' && *e != '\n' ) + while (*e != '\0' && *e != '\n') e++; - while( e[0] == '\n' && ( e[1] == ' ' || e[1] == '\t') ) { + while (e[0] == '\n' && (e[1] == ' ' || e[1] == '\t')) { e++; - while( *e != '\0' && *e != '\n' ) + while (*e != '\0' && *e != '\n') e++; } - if( i < 0 ) { + if (i < 0) { /* not known, we'll have to copy it */ maxlen += 1+e-p; - if( *e == '\0' ) + if (*e == '\0') break; p = e+1; continue; } - if( fields[i].endofs == 0 ) { + if (fields[i].endofs == 0) { fields[i].startofs = p-chunk; fields[i].endofs = e-chunk; - if( fields[i].cef->action == CEF_KEEP || - fields[i].cef->action == CEF_ADDMISSED ) + if (fields[i].cef->action == CEF_KEEP || + fields[i].cef->action == CEF_ADDMISSED) maxlen += 1+e-q; } - if( *e == '\0' ) + if (*e == '\0') break; p = e+1; } - n = malloc(maxlen+1); - if( n == NULL ) { + n = malloc(maxlen + 1); + if (FAILEDTOALLOC(n)) { free(fields); return RET_ERROR_OOM; } len = 0; - for( processed = 0; + for (processed = 0; processed < count && fields[processed].cef->when == CEF_EARLY; processed++) { struct field *f = &fields[processed]; const struct chunkeditfield *ef = f->cef; - if( ef->action == CEF_DELETE ) + if (ef->action == CEF_DELETE) continue; - if( ef->action == CEF_REPLACE && - f->endofs == 0 ) + if (ef->action == CEF_REPLACE && f->endofs == 0) continue; - if( f->endofs != 0 && - ( ef->action == CEF_KEEP || - ef->action == CEF_ADDMISSED ) ) { + if (f->endofs != 0 && + (ef->action == CEF_KEEP || + ef->action == CEF_ADDMISSED)) { size_t l = f->endofs - f->startofs; - assert( maxlen >= len + l ); - memcpy( n+len, chunk + f->startofs, l); + assert (maxlen >= len + l); + memcpy(n+len, chunk + f->startofs, l); len +=l; n[len++] = '\n'; continue; } - if( ef->action == CEF_KEEP ) + if (ef->action == CEF_KEEP) continue; - assert( maxlen >= len+ 3+ ef->len_field ); - memcpy( n+len, ef->field, ef->len_field); + assert (maxlen >= len+ 3+ ef->len_field); + memcpy(n+len, ef->field, ef->len_field); len += ef->len_field; n[len++] = ':'; n[len++] = ' '; - if( ef->data != NULL ) { - assert( maxlen >= len+1+ef->len_data ); + if (ef->data != NULL) { + assert (maxlen >= len+1+ef->len_data); memcpy(n+len, ef->data, ef->len_data); len += ef->len_data; - } else if( ef->words != NULL ) { + } else if (ef->words != NULL) { int j; - for( j = 0 ; j < ef->words->count ; j++ ) { + for (j = 0 ; j < ef->words->count ; j++) { const char *v = ef->words->values[j]; size_t l = strlen(v); - if( j > 0 ) + if (j > 0) n[len++] = ' '; - memcpy( n+len, v, l); + memcpy(n+len, v, l); len += l; } } - for( i = 0 ; i < ef->linecount ; i++ ) { + for (i = 0 ; i < ef->linecount ; i++) { int j; n[len++] = '\n'; - for( j = 0 ; j < ef->lines[i].wordcount ; j++ ) { + for (j = 0 ; j < ef->lines[i].wordcount ; j++) { n[len++] = ' '; - memcpy( n+len, ef->lines[i].words[j], + memcpy(n+len, ef->lines[i].words[j], ef->lines[i].wordlen[j]); len += ef->lines[i].wordlen[j]; } @@ -366,19 +343,19 @@ } p = chunk; /* now add all headers in between */ - while( true ) { + while (true) { q = p; - while( *q != '\0' && *q != '\n' && *q != ':' ) + while (*q != '\0' && *q != '\n' && *q != ':') q++; - if( *q == '\0' ) + if (*q == '\0') break; - if( *q == '\n' ) { + if (*q == '\n') { /* header without colon? what kind of junk is this? */ q++; - while( *q == ' ' || *q == '\t' ) { - while( *q != '\0' && *q != '\n' ) + while (*q == ' ' || *q == '\t') { + while (*q != '\0' && *q != '\n') q++; - if( *q == '\n' ) + if (*q == '\n') q++; } @@ -388,78 +365,77 @@ i = findcef(cefs, p, q-p); /* find begin and end of data */ q++; - while( *q == ' ' ) + while (*q == ' ') q++; e = q; - while( *e != '\0' && *e != '\n' ) + while (*e != '\0' && *e != '\n') e++; - while( e[0] == '\n' && ( e[1] == ' ' || e[1] == '\t') ) { + while (e[0] == '\n' && (e[1] == ' ' || e[1] == '\t')) { e++; - while( *e != '\0' && *e != '\n' ) + while (*e != '\0' && *e != '\n') e++; } - if( i < 0 ) { + if (i < 0) { /* not known, copy it */ size_t l = e - p; - assert( maxlen >= len + l ); - memcpy( n+len, p, l); + assert (maxlen >= len + l); + memcpy(n+len, p, l); len += l; n[len++] = '\n'; - if( *e == '\0' ) + if (*e == '\0') break; p = e+1; continue; } - if( *e == '\0' ) + if (*e == '\0') break; p = e+1; } - for( ; processed < count ; processed++) { + for (; processed < count ; processed++) { struct field *f = &fields[processed]; const struct chunkeditfield *ef = f->cef; - if( ef->action == CEF_DELETE ) + if (ef->action == CEF_DELETE) continue; - if( ef->action == CEF_REPLACE && - f->endofs == 0 ) + if (ef->action == CEF_REPLACE && f->endofs == 0) continue; - if( f->endofs != 0 && - ( ef->action == CEF_KEEP || - ef->action == CEF_ADDMISSED ) ) { + if (f->endofs != 0 && + (ef->action == CEF_KEEP || + ef->action == CEF_ADDMISSED)) { size_t l = f->endofs - f->startofs; - assert( maxlen >= len + l ); - memcpy( n+len, chunk + f->startofs, l); + assert (maxlen >= len + l); + memcpy(n+len, chunk + f->startofs, l); len +=l; n[len++] = '\n'; continue; } - if( ef->action == CEF_KEEP ) + if (ef->action == CEF_KEEP) continue; - assert( maxlen >= len+ 3+ ef->len_field ); - memcpy( n+len, ef->field, ef->len_field); + assert (maxlen >= len+ 3+ ef->len_field); + memcpy(n+len, ef->field, ef->len_field); len += ef->len_field; n[len++] = ':'; n[len++] = ' '; - if( ef->data != NULL ) { - assert( maxlen >= len+1+ef->len_data ); + if (ef->data != NULL) { + assert (maxlen >= len+1+ef->len_data); memcpy(n+len, ef->data, ef->len_data); len += ef->len_data; - } else if( ef->words != NULL ) { + } else if (ef->words != NULL) { int j; - for( j = 0 ; j < ef->words->count ; j++ ) { + for (j = 0 ; j < ef->words->count ; j++) { const char *v = ef->words->values[j]; size_t l = strlen(v); - if( j > 0 ) + if (j > 0) n[len++] = ' '; - memcpy( n+len, v, l); + memcpy(n+len, v, l); len += l; } } - for( i = 0 ; i < ef->linecount ; i++ ) { + for (i = 0 ; i < ef->linecount ; i++) { int j; n[len++] = '\n'; - for( j = 0 ; j < ef->lines[i].wordcount ; j++ ) { + for (j = 0 ; j < ef->lines[i].wordcount ; j++) { n[len++] = ' '; - memcpy( n+len, ef->lines[i].words[j], + memcpy(n+len, ef->lines[i].words[j], ef->lines[i].wordlen[j]); len += ef->lines[i].wordlen[j]; } @@ -471,7 +447,7 @@ n[len] = '\0'; free(fields); *result = realloc(n, len+1); - if( *result == NULL ) + if (*result == NULL) *result = n; *rlen = len; return RET_OK; diff -Nru reprepro-4.5.0/chunkedit.h reprepro-4.6.0/chunkedit.h --- reprepro-4.5.0/chunkedit.h 2008-03-13 14:31:59.000000000 +0000 +++ reprepro-4.6.0/chunkedit.h 2011-05-05 14:42:55.000000000 +0000 @@ -15,11 +15,11 @@ /*@null@*/struct chunkeditfield *next; /* The name of the field: */ const char *field; size_t len_field; - enum cefaction { CEF_DELETE, /* delete if there */ + enum cefaction { CEF_DELETE, /* delete if there */ CEF_ADDMISSED, /* add if not there */ CEF_REPLACE, /* replace if there */ - CEF_ADD, /* add if not there or replace if there */ - CEF_KEEP /* keep it */ + CEF_ADD, /* add if not there or replace if there */ + CEF_KEEP /* keep it */ } action; enum cefwhen { CEF_EARLY, CEF_LATE } when; /* the following must be 0 or NULL for CEF_DELETE */ @@ -35,18 +35,18 @@ }; /* those return NULL on out of memory and free next in that case */ -/*@null@*/struct chunkeditfield *cef_newfield(const char *field, enum cefaction action, enum cefwhen when, unsigned int linecount, /*@only@*//*@null@*/struct chunkeditfield *next); +/*@null@*/struct chunkeditfield *cef_newfield(const char *, enum cefaction, enum cefwhen, unsigned int /*linecount*/, /*@only@*//*@null@*/struct chunkeditfield *); -void cef_setdata(struct chunkeditfield *cef, const char *data); -void cef_setdatalen(struct chunkeditfield *cef, const char *data, size_t len); +void cef_setdata(struct chunkeditfield *, const char *); +void cef_setdatalen(struct chunkeditfield *, const char *, size_t); /* calculate the length, do not change the strlist after that before free */ -void cef_setwordlist(struct chunkeditfield *cef, const struct strlist *words); -retvalue cef_setline(struct chunkeditfield *cef, int line, int wordcount, ...); +void cef_setwordlist(struct chunkeditfield *, const struct strlist *); +retvalue cef_setline(struct chunkeditfield *, int /*line*/, int /*wordcount*/, ...); retvalue cef_setline2(struct chunkeditfield *, int, const char *, size_t, const char *, size_t, int, ...); -retvalue chunk_edit(const char *chunk, char **result, size_t *len, const struct chunkeditfield *cef); +retvalue chunk_edit(const char *, char **, size_t *, const struct chunkeditfield *); -void cef_free(/*@only@*//*@null@*/struct chunkeditfield *f); +void cef_free(/*@only@*//*@null@*/struct chunkeditfield *); static inline struct chunkeditfield *cef_pop(/*@only@*/struct chunkeditfield *cef) { struct chunkeditfield *next = cef->next; diff -Nru reprepro-4.5.0/chunks.c reprepro-4.6.0/chunks.c --- reprepro-4.5.0/chunks.c 2009-01-24 15:57:04.000000000 +0000 +++ reprepro-4.6.0/chunks.c 2011-05-05 14:42:55.000000000 +0000 @@ -27,20 +27,20 @@ #include "names.h" /* point to a specified field in a chunk */ -static const char *chunk_getfield(const char *name,const char *chunk) { +static const char *chunk_getfield(const char *name, const char *chunk) { size_t l; - if( chunk == NULL ) + if (chunk == NULL) return NULL; l = strlen(name); - while( *chunk != '\0' ) { - if(strncasecmp(name,chunk,l) == 0 && chunk[l] == ':' ) { + while (*chunk != '\0') { + if (strncasecmp(name, chunk, l) == 0 && chunk[l] == ':') { chunk += l+1; return chunk; } - while( *chunk != '\n' && *chunk != '\0' ) + while (*chunk != '\n' && *chunk != '\0') chunk++; - if( *chunk == '\0' ) + if (*chunk == '\0') return NULL; chunk++; } @@ -49,40 +49,40 @@ /* get the content of the given field, including all following lines, in a format * that may be put into chunk_replacefields -static retvalue chunk_getcontent(const char *chunk,const char *name,char **value) { +static retvalue chunk_getcontent(const char *chunk, const char *name, char **value) { const char *field; char *val; - const char *b,*e; + const char *b, *e; assert(value != NULL); - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; b = field; * jump over spaces at the beginning * - if( xisspace(*b) ) + if (xisspace(*b)) b++; * search for the end * e = b; do { - while( *e != '\n' && *e != '\0' ) + while (*e != '\n' && *e != '\0') e++; - if( *e != '\0' ) + if (*e != '\0') e++; - } while( *e != ' ' && *e != '\t' && *e != '\0' ); + } while (*e != ' ' && *e != '\t' && *e != '\0'); - if( e > b && *e == '\0' ) + if (e > b && *e == '\0') e--; * remove trailing newline * - if( e > b && *e == '\n' ) + if (e > b && *e == '\n') e--; - if( e > b ) - val = strndup(b,e-b+1); + if (e > b) + val = strndup(b, e - b + 1); else val = strdup(""); - if( val == NULL ) + if (FAILEDTOALLOC(val)) return RET_ERROR_OOM; *value = val; return RET_OK; @@ -90,168 +90,145 @@ */ /* look for name in chunk. returns RET_NOTHING if not found */ -retvalue chunk_getvalue(const char *chunk,const char *name,char **value) { +retvalue chunk_getvalue(const char *chunk, const char *name, char **value) { const char *field; char *val; - const char *b,*e; + const char *b, *e; assert(value != NULL); - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; b = field; /* jump over spaces at the beginning */ - if( xisspace(*b) ) + if (xisspace(*b)) b++; /* search for the end */ e = b; - while( *e != '\n' && *e != '\0' ) + while (*e != '\n' && *e != '\0') e++; /* remove trailing spaces */ - while( e > b && xisspace(*e) ) + while (e > b && xisspace(*e)) e--; - if( !xisspace(*e) ) - val = strndup(b,e-b+1); + if (!xisspace(*e)) + val = strndup(b, e - b + 1); else val = strdup(""); - if( val == NULL ) + if (FAILEDTOALLOC(val)) return RET_ERROR_OOM; *value = val; return RET_OK; } -retvalue chunk_getfirstword(const char *chunk,const char *name,char **value) { - const char *field; - char *val; - const char *b,*e; - - assert(value != NULL); - field = chunk_getfield(name,chunk); - if( field == NULL ) - return RET_NOTHING; - - b = field; - if( xisspace(*b) ) - b++; - e = b; - while( !xisspace(*e) && *e != '\n' && *e != '\0' ) - e++; - val = strndup(b,e-b); - if( val == NULL ) - return RET_ERROR_OOM; - *value = val; - return RET_OK; -} - -retvalue chunk_getextralinelist(const char *chunk,const char *name,struct strlist *strlist) { +retvalue chunk_getextralinelist(const char *chunk, const char *name, struct strlist *strlist) { retvalue r; - const char *f,*b,*e; + const char *f, *b, *e; char *v; - f = chunk_getfield(name,chunk); - if( f == NULL ) + f = chunk_getfield(name, chunk); + if (f == NULL) return RET_NOTHING; strlist_init(strlist); /* walk over the first line */ - while( *f != '\0' && *f != '\n' ) + while (*f != '\0' && *f != '\n') f++; /* nothing there is an emtpy list */ - if( *f == '\0' ) + if (*f == '\0') return RET_OK; f++; /* while lines begin with ' ' or '\t', add them */ - while( *f == ' ' || *f == '\t' ) { - while( *f != '\0' && xisblank(*f) ) + while (*f == ' ' || *f == '\t') { + while (*f != '\0' && xisblank(*f)) f++; b = f; - while( *f != '\0' && *f != '\n' ) + while (*f != '\0' && *f != '\n') f++; e = f; - while( e > b && *e != '\0' && xisspace(*e) ) + while (e > b && *e != '\0' && xisspace(*e)) e--; - if( !xisspace(*e) ) - v = strndup(b,e-b+1); + if (!xisspace(*e)) + v = strndup(b, e - b + 1); else v = strdup(""); - if( v == NULL ) { + if (FAILEDTOALLOC(v)) { strlist_done(strlist); return RET_ERROR_OOM; } - r = strlist_add(strlist,v); - if( !RET_IS_OK(r) ) { + r = strlist_add(strlist, v); + if (!RET_IS_OK(r)) { strlist_done(strlist); return r; } - if( *f == '\0' ) + if (*f == '\0') return RET_OK; f++; } return RET_OK; } -retvalue chunk_getwholedata(const char *chunk,const char *name,char **value) { - const char *f,*p,*e; +retvalue chunk_getwholedata(const char *chunk, const char *name, char **value) { + const char *f, *p, *e; bool afternewline = false; char *v; - f = chunk_getfield(name,chunk); - if( f == NULL ) + f = chunk_getfield(name, chunk); + if (f == NULL) return RET_NOTHING; - for ( e = p = f ; *p != '\0' ; p++ ) { - if( afternewline ) { - if( *p == ' ' || *p == '\t' ) + for (e = p = f ; *p != '\0' ; p++) { + if (afternewline) { + if (*p == ' ' || *p == '\t') afternewline = false; - else if( *p != '\r' ) + else if (*p != '\r') break; } else { - if( *p == '\n' ) { + if (*p == '\n') { e = p; afternewline = true; } } } - if( !afternewline && *p == '\0' ) + if (!afternewline && *p == '\0') e = p; - v = strndup(f,e-f); - if( v == NULL ) + v = strndup(f, e - f); + if (FAILEDTOALLOC(v)) return RET_ERROR_OOM; *value = v; return RET_OK; } -retvalue chunk_getwordlist(const char *chunk,const char *name,struct strlist *strlist) { +retvalue chunk_getwordlist(const char *chunk, const char *name, struct strlist *strlist) { retvalue r; - const char *f,*b; + const char *f, *b; char *v; - f = chunk_getfield(name,chunk); - if( f == NULL ) + f = chunk_getfield(name, chunk); + if (f == NULL) return RET_NOTHING; strlist_init(strlist); - while( *f != '\0' ) { + while (*f != '\0') { /* walk over spaces */ - while( *f != '\0' && xisspace(*f) ) { - if( *f == '\n' ) { + while (*f != '\0' && xisspace(*f)) { + if (*f == '\n') { f++; - if( *f != ' ' && *f != '\t' ) + if (*f != ' ' && *f != '\t') return RET_OK; } else f++; } - if( *f == '\0' ) + if (*f == '\0') return RET_OK; b = f; /* search for end of word */ - while( *f != '\0' && !xisspace(*f) ) + while (*f != '\0' && !xisspace(*f)) f++; - v = strndup(b,f-b); - if( v == NULL ) { + v = strndup(b, f - b); + if (FAILEDTOALLOC(v)) { strlist_done(strlist); return RET_ERROR_OOM; } - r = strlist_add(strlist,v); - if( !RET_IS_OK(r) ) { + r = strlist_add(strlist, v); + if (!RET_IS_OK(r)) { strlist_done(strlist); return r; } @@ -259,38 +236,38 @@ return RET_OK; } -retvalue chunk_getuniqwordlist(const char *chunk,const char *name,struct strlist *strlist) { +retvalue chunk_getuniqwordlist(const char *chunk, const char *name, struct strlist *strlist) { retvalue r; - const char *f,*b; + const char *f, *b; char *v; - f = chunk_getfield(name,chunk); - if( f == NULL ) + f = chunk_getfield(name, chunk); + if (f == NULL) return RET_NOTHING; strlist_init(strlist); - while( *f != '\0' ) { + while (*f != '\0') { /* walk over spaces */ - while( *f != '\0' && xisspace(*f) ) { - if( *f == '\n' ) { + while (*f != '\0' && xisspace(*f)) { + if (*f == '\n') { f++; - if( *f != ' ' && *f != '\t' ) + if (*f != ' ' && *f != '\t') return RET_OK; } else f++; } - if( *f == '\0' ) + if (*f == '\0') return RET_OK; b = f; /* search for end of word */ - while( *f != '\0' && !xisspace(*f) ) + while (*f != '\0' && !xisspace(*f)) f++; - v = strndup(b,f-b); - if( v == NULL ) { + v = strndup(b, f - b); + if (FAILEDTOALLOC(v)) { strlist_done(strlist); return RET_ERROR_OOM; } - r = strlist_adduniq(strlist,v); - if( !RET_IS_OK(r) ) { + r = strlist_adduniq(strlist, v); + if (!RET_IS_OK(r)) { strlist_done(strlist); return r; } @@ -298,34 +275,34 @@ return RET_OK; } -retvalue chunk_gettruth(const char *chunk,const char *name) { +retvalue chunk_gettruth(const char *chunk, const char *name) { const char *field; - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; - while( *field == ' ' || *field == '\t' ) + while (*field == ' ' || *field == '\t') field++; - if( (field[0] == 'f' || field[0] == 'F') && + if ((field[0] == 'f' || field[0] == 'F') && (field[1] == 'a' || field[1] == 'A') && (field[2] == 'l' || field[2] == 'L') && (field[3] == 's' || field[3] == 'S') && - (field[4] == 'e' || field[4] == 'E') ) { + (field[4] == 'e' || field[4] == 'E')) { return RET_NOTHING; } - if( (field[0] == 'n' || field[0] == 'N') && - (field[1] == 'o' || field[1] == 'O') ) { + if ((field[0] == 'n' || field[0] == 'N') && + (field[1] == 'o' || field[1] == 'O')) { return RET_NOTHING; } // TODO: strict check? return RET_OK; } /* return RET_OK, if field is found, RET_NOTHING, if not */ -retvalue chunk_checkfield(const char *chunk,const char *name){ +retvalue chunk_checkfield(const char *chunk, const char *name){ const char *field; - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; return RET_OK; @@ -333,127 +310,133 @@ /* Parse a package/source-field: ' *value( ?\(version\))? *' */ retvalue chunk_getname(const char *chunk, const char *name, char **pkgname, bool allowversion) { - const char *field,*name_end,*p; + const char *field, *name_end, *p; - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; - while( *field != '\0' && *field != '\n' && xisspace(*field) ) + while (*field != '\0' && *field != '\n' && xisspace(*field)) field++; name_end = field; /* this has now checked somewhere else for correctness and * is only a pure separation process: * (as package(version) is possible, '(' must be checked) */ - while( *name_end != '\0' && *name_end != '\n' && *name_end != '(' && !xisspace(*name_end) ) + while (*name_end != '\0' && *name_end != '\n' && *name_end != '(' + && !xisspace(*name_end)) name_end++; p = name_end; - while( *p != '\0' && *p != '\n' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && xisspace(*p)) p++; - if( name_end == field || - ( *p != '\0' && *p != '\n' && - ( !allowversion || *p != '('))) { - if( *field == '\n' || *field == '\0' ) { - fprintf(stderr,"Error: Field '%s' is empty!\n",name); + if (name_end == field || + (*p != '\0' && *p != '\n' && + (!allowversion || *p != '('))) { + if (*field == '\n' || *field == '\0') { + fprintf(stderr, "Error: Field '%s' is empty!\n", name); } else { - fprintf(stderr,"Error: Field '%s' contains unexpected character '%c'!\n",name,*p); + fprintf(stderr, +"Error: Field '%s' contains unexpected character '%c'!\n", + name, *p); } return RET_ERROR; } - if( *p == '(' ) { - while( *p != '\0' && *p != '\n' && *p != ')' ) + if (*p == '(') { + while (*p != '\0' && *p != '\n' && *p != ')') // TODO: perhaps check for wellformed version p++; - if( *p != ')' ) { + if (*p != ')') { fprintf(stderr, "Error: Field '%s' misses closing parenthesis!\n", name); return RET_ERROR; } p++; } - while( *p != '\0' && *p != '\n' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && xisspace(*p)) p++; - if( *p != '\0' && *p != '\n' ) { + if (*p != '\0' && *p != '\n') { fprintf(stderr, "Error: Field '%s' contains trailing junk starting with '%c'!\n", name, *p); return RET_ERROR; } - *pkgname = strndup(field,name_end-field); - if( *pkgname == NULL ) + *pkgname = strndup(field, name_end - field); + if (FAILEDTOALLOC(*pkgname)) return RET_ERROR_OOM; return RET_OK; } /* Parse a package/source-field: ' *value( ?\(version\))? *' */ -retvalue chunk_getnameandversion(const char *chunk,const char *name, - char **pkgname,char **version) { - const char *field,*name_end,*p; +retvalue chunk_getnameandversion(const char *chunk, const char *name, char **pkgname, char **version) { + const char *field, *name_end, *p; char *v; - field = chunk_getfield(name,chunk); - if( field == NULL ) + field = chunk_getfield(name, chunk); + if (field == NULL) return RET_NOTHING; - while( *field != '\0' && *field != '\n' && xisspace(*field) ) + while (*field != '\0' && *field != '\n' && xisspace(*field)) field++; name_end = field; /* this has now checked somewhere else for correctness and * is only a pure separation process: * (as package(version) is possible, '(' must be checked) */ - while( *name_end != '\0' && *name_end != '\n' && *name_end != '(' && !xisspace(*name_end) ) + while (*name_end != '\0' && *name_end != '\n' && *name_end != '(' + && !xisspace(*name_end)) name_end++; p = name_end; - while( *p != '\0' && *p != '\n' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && xisspace(*p)) p++; - if( name_end == field || - ( *p != '\0' && *p != '\n' && - *p != '(')) { - if( *field == '\n' || *field == '\0' ) { - fprintf(stderr,"Error: Field '%s' is empty!\n",name); + if (name_end == field || (*p != '\0' && *p != '\n' && *p != '(')) { + if (*field == '\n' || *field == '\0') { + fprintf(stderr, "Error: Field '%s' is empty!\n", name); } else { - fprintf(stderr,"Error: Field '%s' contains unexpected character '%c'!\n",name,*p); + fprintf(stderr, +"Error: Field '%s' contains unexpected character '%c'!\n", name, *p); } return RET_ERROR; } - if( *p == '(' ) { + if (*p == '(') { const char *version_begin; p++; - while( *p != '\0' && *p != '\n' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && xisspace(*p)) p++; version_begin = p; - while( *p != '\0' && *p != '\n' && *p != ')' && !xisspace(*p) ) + while (*p != '\0' && *p != '\n' && *p != ')' && !xisspace(*p)) // TODO: perhaps check for wellformed version p++; - v = strndup(version_begin,p-version_begin); - if( v == NULL ) + v = strndup(version_begin, p - version_begin); + if (FAILEDTOALLOC(v)) return RET_ERROR_OOM; - while( *p != '\0' && *p != '\n' && *p != ')' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && *p != ')' && xisspace(*p)) p++; - if( *p != ')' ) { + if (*p != ')') { free(v); - if( *p == '\0' || *p == '\n' ) + if (*p == '\0' || *p == '\n') fprintf(stderr, -"Error: Field '%s' misses closing parenthesis!\n", name); +"Error: Field '%s' misses closing parenthesis!\n", + name); else fprintf(stderr, -"Error: Field '%s' has multipe words after '('!\n", name); +"Error: Field '%s' has multipe words after '('!\n", + name); return RET_ERROR; } p++; } else { v = NULL; } - while( *p != '\0' && *p != '\n' && xisspace(*p) ) + while (*p != '\0' && *p != '\n' && xisspace(*p)) p++; - if( *p != '\0' && *p != '\n' ) { + if (*p != '\0' && *p != '\n') { free(v); - fprintf(stderr,"Error: Field '%s' contains trailing junk starting with '%c'!\n",name,*p); + fprintf(stderr, +"Error: Field '%s' contains trailing junk starting with '%c'!\n", + name, *p); return RET_ERROR; } - *pkgname = strndup(field,name_end-field); - if( *pkgname == NULL ) { + *pkgname = strndup(field, name_end - field); + if (FAILEDTOALLOC(*pkgname)) { free(v); return RET_ERROR_OOM; } @@ -466,16 +449,16 @@ * replacing older fields of this name, if they are already there. */ char *chunk_replacefields(const char *chunk, const struct fieldtoadd *toadd, const char *beforethis, bool maybemissing) { - const char *c,*ce; - char *newchunk,*n; - size_t size,len_beforethis; + const char *c, *ce; + char *newchunk, *n; + size_t size, len_beforethis; const struct fieldtoadd *f; retvalue result; bool fieldsadded = false; - assert( chunk != NULL && beforethis != NULL ); + assert (chunk != NULL && beforethis != NULL); - if( toadd == NULL ) + if (toadd == NULL) return NULL; c = chunk; @@ -483,14 +466,14 @@ /* calculate the maximal size we might end up with */ size = 2 + strlen(c); f = toadd; - while( f != NULL ) { - if( f->data != NULL ) + while (f != NULL) { + if (f->data != NULL) size += 3 + f->len_field + f->len_data; f = f->next; } newchunk = n = malloc(size); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return NULL; len_beforethis = strlen(beforethis); @@ -498,17 +481,17 @@ result = RET_NOTHING; do { /* are we at the place to add the fields yet? */ - if(!fieldsadded && strncasecmp(c,beforethis,len_beforethis) == 0 - && c[len_beforethis] == ':' ) { + if (!fieldsadded && strncasecmp(c, beforethis, len_beforethis) == 0 + && c[len_beforethis] == ':') { /* add them now: */ f = toadd; - while( f != NULL ) { - if( f->data != NULL ) { - memcpy(n,f->field,f->len_field); + while (f != NULL) { + if (f->data != NULL) { + memcpy(n, f->field, f->len_field); n += f->len_field; *n = ':'; n++; *n = ' '; n++; - memcpy(n,f->data,f->len_data); + memcpy(n, f->data, f->len_data); n += f->len_data; *n = '\n'; n++; } @@ -519,48 +502,48 @@ } /* is this one of the fields we added/will add? */ f = toadd; - while( f != NULL ) { - if(strncasecmp(c,f->field,f->len_field) == 0 - && c[f->len_field] == ':' ) + while (f != NULL) { + if (strncasecmp(c, f->field, f->len_field) == 0 + && c[f->len_field] == ':') break; f = f->next; } /* search the end of the field */ ce = c; do { - while( *ce != '\n' && *ce != '\0' ) + while (*ce != '\n' && *ce != '\0') ce++; - if( *ce == '\0' ) + if (*ce == '\0') break; ce++; - } while( *ce == ' ' || *ce == '\t' ); + } while (*ce == ' ' || *ce == '\t'); /* copy it, if it is not to be ignored */ - if( f == NULL && ce-c > 0) { + if (f == NULL && ce-c > 0) { // There are reports this might overwrite something, // though I neighter now how not why. - memcpy(n,c,ce-c); + memcpy(n, c, ce -c); n += ce-c; } /* and proceed with the next */ c = ce; - } while( *c != '\0' && *c != '\n' ); + } while (*c != '\0' && *c != '\n'); - if( n > newchunk && *(n-1) != '\n' ) + if (n > newchunk && *(n-1) != '\n') *(n++) = '\n'; - if( maybemissing && !fieldsadded ) { + if (maybemissing && !fieldsadded) { /* add them now, if they are allowed to come later */ f = toadd; - while( f != NULL ) { - if( f->data != NULL ) { - memcpy(n,f->field,f->len_field); + while (f != NULL) { + if (f->data != NULL) { + memcpy(n, f->field, f->len_field); n += f->len_field; *n = ':'; n++; *n = ' '; n++; - memcpy(n,f->data,f->len_data); + memcpy(n, f->data, f->len_data); n += f->len_data; *n = '\n'; n++; } @@ -572,10 +555,12 @@ *n = '\0'; // If the problem still exists, I want to know it! - assert( n-newchunk < 0 || (size_t)(n-newchunk) <= size-1 ); + assert (n-newchunk < 0 || (size_t)(n-newchunk) <= size-1); - if( result == RET_NOTHING ) { - fprintf(stderr,"Could not find field '%s' in chunk '%s'!!!\n",beforethis,chunk); + if (result == RET_NOTHING) { + fprintf(stderr, +"Could not find field '%s' in chunk '%s'!!!\n", + beforethis, chunk); assert(false); } @@ -587,30 +572,30 @@ assert(field != NULL); - n = malloc(sizeof(struct fieldtoadd)); - if( n == NULL ) { - addfield_free(next); - return NULL; - } + n = NEW(struct fieldtoadd); + if (FAILEDTOALLOC(n)) { + addfield_free(next); + return NULL; + } n->field = field; n->len_field = strlen(field); n->data = data; - if( data != NULL ) + if (data != NULL) n->len_data = strlen(data); else n->len_data = 0; n->next = next; return n; } -struct fieldtoadd *addfield_new(const char *field,const char *data,struct fieldtoadd *next) { +struct fieldtoadd *addfield_new(const char *field, const char *data, struct fieldtoadd *next) { struct fieldtoadd *n; assert(field != NULL && data != NULL); - n = malloc(sizeof(struct fieldtoadd)); - if( n == NULL ) { - addfield_free(next); - return NULL; + n = NEW(struct fieldtoadd); + if (FAILEDTOALLOC(n)) { + addfield_free(next); + return NULL; } n->field = field; n->len_field = strlen(field); @@ -619,16 +604,16 @@ n->next = next; return n; } -struct fieldtoadd *deletefield_new(const char *field,struct fieldtoadd *next) { +struct fieldtoadd *deletefield_new(const char *field, struct fieldtoadd *next) { struct fieldtoadd *n; assert(field != NULL); - n = malloc(sizeof(struct fieldtoadd)); - if( n == NULL ) { - addfield_free(next); - return NULL; - } + n = NEW(struct fieldtoadd); + if (FAILEDTOALLOC(n)) { + addfield_free(next); + return NULL; + } n->field = field; n->len_field = strlen(field); n->data = NULL; @@ -636,14 +621,14 @@ n->next = next; return n; } -struct fieldtoadd *addfield_newn(const char *field,const char *data,size_t len,struct fieldtoadd *next) { +struct fieldtoadd *addfield_newn(const char *field, const char *data, size_t len, struct fieldtoadd *next) { struct fieldtoadd *n; - n = malloc(sizeof(struct fieldtoadd)); - if( n == NULL ) { - addfield_free(next); - return NULL; - } + n = NEW(struct fieldtoadd); + if (FAILEDTOALLOC(n)) { + addfield_free(next); + return NULL; + } n->field = field; n->len_field = strlen(field); n->data = data; @@ -654,7 +639,7 @@ void addfield_free(struct fieldtoadd *f) { struct fieldtoadd *g; - while( f != NULL ) { + while (f != NULL) { g = f->next; free(f); f = g; @@ -680,22 +665,31 @@ const char *startofchanges, *endofchanges, *afterchanges; char *p; - assert( start >= buffer); + assert (start >= buffer); p = buffer; startofchanges = start; - while( *startofchanges == ' ' || *startofchanges == '\t' || - *startofchanges == '\r' || *startofchanges =='\n' ) + while (*startofchanges == ' ' || *startofchanges == '\t' || + *startofchanges == '\r' || *startofchanges =='\n') startofchanges++; + /* ignore leading comments (even full paragraphs of them) */ + while (*startofchanges == '#') { + while (*startofchanges != '\n') + startofchanges++; + while (*startofchanges == ' ' || *startofchanges == '\t' || + *startofchanges == '\r' || + *startofchanges =='\n') + startofchanges++; + } endofchanges = startofchanges; afterchanges = NULL; - while( *endofchanges != '\0' ) { - if( *endofchanges == '\n' ) { + while (*endofchanges != '\0') { + if (*endofchanges == '\n') { *(p++) = *(endofchanges++); afterchanges = endofchanges; - while( *afterchanges =='\r' ) + while (*afterchanges =='\r') afterchanges++; - if( *afterchanges == '\n' ) + if (*afterchanges == '\n') break; endofchanges = afterchanges; afterchanges = NULL; @@ -704,17 +698,17 @@ } } - if( afterchanges == NULL ) { + if (afterchanges == NULL) { afterchanges = endofchanges; - assert( *afterchanges == '\0' ); - assert( p <= afterchanges ); + assert (*afterchanges == '\0'); + assert (p <= afterchanges); *p = '\0'; } else { - assert( *afterchanges == '\n' ); + assert (*afterchanges == '\n'); afterchanges++; - assert( p < afterchanges ); + assert (p < afterchanges); *p = '\0'; - while( *afterchanges == '\n' || *afterchanges =='\r' ) + while (*afterchanges == '\n' || *afterchanges =='\r') afterchanges++; } *next = buffer + (afterchanges-buffer); diff -Nru reprepro-4.5.0/chunks.h reprepro-4.6.0/chunks.h --- reprepro-4.5.0/chunks.h 2009-01-24 15:57:04.000000000 +0000 +++ reprepro-4.6.0/chunks.h 2011-05-05 14:42:55.000000000 +0000 @@ -10,21 +10,20 @@ #endif /* look for name in chunk. returns RET_NOTHING if not found */ -retvalue chunk_getvalue(const char *chunk,const char *name,/*@out@*/char **value); -retvalue chunk_getfirstword(const char *chunk,const char *name,/*@out@*/char **value); -retvalue chunk_getextralinelist(const char *chunk,const char *name,/*@out@*/struct strlist *strlist); -retvalue chunk_getwordlist(const char *chunk,const char *name,/*@out@*/struct strlist *strlist); -retvalue chunk_getuniqwordlist(const char *chunk,const char *name,/*@out@*/struct strlist *strlist); -retvalue chunk_getwholedata(const char *chunk,const char *name,/*@out@*/char **value); +retvalue chunk_getvalue(const char *, const char *, /*@out@*/char **); +retvalue chunk_getextralinelist(const char *, const char *, /*@out@*/struct strlist *); +retvalue chunk_getwordlist(const char *, const char *, /*@out@*/struct strlist *); +retvalue chunk_getuniqwordlist(const char *, const char *, /*@out@*/struct strlist *); +retvalue chunk_getwholedata(const char *, const char *, /*@out@*/char **value); /* Parse a package/source-field: ' *value( ?\(version\))? *' */ -retvalue chunk_getname(const char *chunk, const char *name, /*@out@*/char **pkgname, bool allowversion); -retvalue chunk_getnameandversion(const char *chunk,const char *name,/*@out@*/char **pkgname,/*@out@*/char **version); +retvalue chunk_getname(const char *, const char *, /*@out@*/char **, bool /*allowversion*/); +retvalue chunk_getnameandversion(const char *, const char *, /*@out@*/char **, /*@out@*/char **); /* return RET_OK, if field is found, RET_NOTHING, if not (or value indicates false in future variants) */ -retvalue chunk_gettruth(const char *chunk,const char *name); +retvalue chunk_gettruth(const char *, const char *); /* return RET_OK, if field is found, RET_NOTHING, if not */ -retvalue chunk_checkfield(const char *chunk,const char *name); +retvalue chunk_checkfield(const char *, const char *); /* modifications of a chunk: */ struct fieldtoadd { @@ -35,26 +34,23 @@ /*@null@*//*@dependent@*/const char *data; /* how many chars in them (the *exact* len to use * , no \0 allowed within!), */ - size_t len_field,len_data; + size_t len_field, len_data; }; // TODO make this return retvalue.. /* Add this the to before field, * replacing older fields of this name, if they are already there. */ -/*@null@*/ char *chunk_replacefields(const char *chunk, const struct fieldtoadd *toadd, const char *beforethis, bool maybemissing); -/*@null@*/struct fieldtoadd *deletefield_new(/*@dependent@*/const char *field,/*@only@*//*@null@*/struct fieldtoadd *next); -/*@null@*/struct fieldtoadd *aodfield_new(/*@dependent@*/const char *field, /*@dependent@*//*@null@*/const char *data, /*@only@*/struct fieldtoadd *next); -/*@null@*/struct fieldtoadd *addfield_new(/*@dependent@*/const char *field,/*@dependent@*//*@null@*/const char *data,/*@only@*/struct fieldtoadd *next); -/*@null@*/struct fieldtoadd *addfield_newn(/*@dependent@*/const char *field,/*@dependent@*//*@null@*/const char *data,size_t len,/*@only@*/struct fieldtoadd *next); -void addfield_free(/*@only@*//*@null@*/struct fieldtoadd *f); +/*@null@*/ char *chunk_replacefields(const char *, const struct fieldtoadd *, const char * /*beforethis*/, bool /*maybemissing*/); +/*@null@*/struct fieldtoadd *deletefield_new(/*@dependent@*/const char *, /*@only@*//*@null@*/struct fieldtoadd *); +/*@null@*/struct fieldtoadd *aodfield_new(/*@dependent@*/const char *, /*@dependent@*//*@null@*/const char *, /*@only@*/struct fieldtoadd *); +/*@null@*/struct fieldtoadd *addfield_new(/*@dependent@*/const char *, /*@dependent@*//*@null@*/const char *, /*@only@*/struct fieldtoadd *); +/*@null@*/struct fieldtoadd *addfield_newn(/*@dependent@*/const char *, /*@dependent@*//*@null@*/const char *, size_t, /*@only@*/struct fieldtoadd *); +void addfield_free(/*@only@*//*@null@*/struct fieldtoadd *); /* that is chunk_replacefields(chunk,{fieldname,strlen,data,strlen},fieldname); */ -/*@null@*/char *chunk_replacefield(const char *chunk, const char *fieldname, const char *data, bool maybemissing); - -/* check if all field names are in allowedfieldnames */ -retvalue chunk_checkfields(const char *chunk, const char * const *allowedfieldnames, bool commentsallowed); +/*@null@*/char *chunk_replacefield(const char *, const char *, const char *, bool /*maybemissing*/); /* reformat control data, removing leading spaces and CRs */ -size_t chunk_extract(char *buffer, const char *start, /*@out@*/char **next); +size_t chunk_extract(char * /*buffer*/, const char */*start*/, /*@out@*/char ** /*next*/); #endif diff -Nru reprepro-4.5.0/configparser.c reprepro-4.6.0/configparser.c --- reprepro-4.5.0/configparser.c 2011-02-09 14:20:21.000000000 +0000 +++ reprepro-4.6.0/configparser.c 2011-05-05 14:42:55.000000000 +0000 @@ -63,14 +63,14 @@ void config_overline(struct configiterator *iter) { int c; - while( !iter->eol ) { + while (!iter->eol) { c = fgetc(iter->f); - if( c == '#' ) { + if (c == '#') { do { c = fgetc(iter->f); - } while( c != EOF && c != '\n' ); + } while (c != EOF && c != '\n'); } - if( c == EOF || c == '\n' ) + if (c == EOF || c == '\n') iter->eol = true; else iter->column++; @@ -80,18 +80,18 @@ bool config_nextline(struct configiterator *iter) { int c; - assert( iter->eol ); + assert (iter->eol); c = fgetc(iter->f); - while( c == '#' ) { + while (c == '#') { do { c = fgetc(iter->f); - } while( c != EOF && c != '\n' ); + } while (c != EOF && c != '\n'); iter->line++; c = fgetc(iter->f); } - if( c == EOF ) + if (c == EOF) return false; - if( c == ' ' || c == '\t' ) { + if (c == ' ' || c == '\t') { iter->line++; iter->column = 1; iter->eol = false; @@ -110,11 +110,11 @@ size_t i; retvalue r; - if( complete ) - for( i = 0 ; i < fieldcount ; i++ ) { - if( !fields[i].required ) + if (complete) + for (i = 0 ; i < fieldcount ; i++) { + if (!fields[i].required) continue; - if( found[i] ) + if (found[i]) continue; fprintf(stderr, "Error parsing config file %s, line %u:\n" @@ -141,13 +141,13 @@ retvalue result, r; iter.filename = calc_conffile(filename); - if( iter.filename == NULL ) + if (FAILEDTOALLOC(iter.filename)) return RET_ERROR_OOM; iter.line = 0; iter.column = 0; iter.f = fopen(iter.filename, "r"); - if( iter.f == NULL ) { + if (iter.f == NULL) { int e = errno; fprintf(stderr, "Error opening config file '%s': %s(%d)\n", iter.filename, strerror(e), e); @@ -160,48 +160,51 @@ iter.column = 1; c = fgetc(iter.f); - while( c == '#' ) { + while (c == '#') { do { c = fgetc(iter.f); - } while( c != EOF && c != '\n' ); + } while (c != EOF && c != '\n'); iter.line++; c = fgetc(iter.f); } - if( c == '\r' ) { + if (c == '\r') { do { c = fgetc(iter.f); - } while( c == '\r'); - if( c != EOF && c != '\n' ) { - fprintf(stderr, "%s:%u: error parsing configuration file: CR without following LF!\n", + } while (c == '\r'); + if (c != EOF && c != '\n') { + fprintf(stderr, +"%s:%u: error parsing configuration file: CR without following LF!\n", iter.filename, iter.line); result = RET_ERROR; break; } } - if( c == EOF ) + if (c == EOF) break; - if( c == '\n' ) { + if (c == '\n') { /* Ignore multiple emptye lines */ - if( this == NULL ) + if (this == NULL) continue; /* finish this chunk, to get ready for the next: */ r = finishchunk(finishfunc, privdata, &iter, fields, fieldcount, found, &this, &last, true); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } continue; } - if( c == '\0' ) { - fprintf(stderr, "Error parsing %s, line %u: \\000 character not allowed in config files!\n", + if (c == '\0') { + fprintf(stderr, +"Error parsing %s, line %u: \\000 character not allowed in config files!\n", iter.filename, iter.line); result = RET_ERROR; break; } - if( c == '\0' ) { - fprintf(stderr, "Error parsing %s, line %u: unexpected white space before keyword!\n", + if (c == '\0') { + fprintf(stderr, +"Error parsing %s, line %u: unexpected white space before keyword!\n", iter.filename, iter.line); result = RET_ERROR; break; @@ -209,65 +212,72 @@ key[0] = c; keylen = 1; - while( (c = fgetc(iter.f)) != EOF && c != ':' && c != '\n' && c != '#' && c != '\0') { + while ((c = fgetc(iter.f)) != EOF && c != ':' && c != '\n' + && c != '#' && c != '\0') { iter.column++; - if( c == ' ' ) { - fprintf(stderr, "Error parsing %s, line %u: Unexpected space in header name!\n", + if (c == ' ') { + fprintf(stderr, +"Error parsing %s, line %u: Unexpected space in header name!\n", iter.filename, iter.line); result = RET_ERROR; break; } - if( c == '\t' ) { - fprintf(stderr, "Error parsing %s, line %u: Unexpected tabulator character in header name!\n", + if (c == '\t') { + fprintf(stderr, +"Error parsing %s, line %u: Unexpected tabulator character in header name!\n", iter.filename, iter.line); result = RET_ERROR; break; } key[keylen++] = c; - if( keylen >= 100 ) + if (keylen >= 100) break; } - if( c != ':' ) { - if( c != ' ' && c != '\t' ) + if (c != ':') { + if (c != ' ' && c != '\t') /* newline or end-of-file */ - fprintf(stderr, "Error parsing %s, line %u, column %u: Colon expected!\n", + fprintf(stderr, +"Error parsing %s, line %u, column %u: Colon expected!\n", iter.filename, iter.line, iter.column); result = RET_ERROR; break; } - if( this == NULL ) { + if (this == NULL) { /* new chunk, initialize everything */ r = initfunc(privdata, last, &this); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { result = r; break; } - assert( this != NULL ); + assert (this != NULL); iter.startline = iter.line; memset(found, 0, sizeof(found)); } - for( i = 0 ; i < fieldcount ; i++ ) { - if( keylen != fields[i].namelen ) + for (i = 0 ; i < fieldcount ; i++) { + if (keylen != fields[i].namelen) continue; - if( strncasecmp(key, fields[i].name, keylen) != 0 ) + if (strncasecmp(key, fields[i].name, keylen) != 0) continue; break; } - if( i >= fieldcount ) { + if (i >= fieldcount) { key[keylen] = '\0'; - if( !ignoreunknown ) { - fprintf(stderr, "Error parsing %s, line %u: Unknown header '%s'!\n", + if (!ignoreunknown) { + fprintf(stderr, +"Error parsing %s, line %u: Unknown header '%s'!\n", iter.filename, iter.line, key); result = RET_ERROR_UNKNOWNFIELD; break; } - if( verbose >= 0 ) - fprintf(stderr, "Warning parsing %s, line %u: Unknown header '%s'!\n", + if (verbose >= 0) + fprintf(stderr, +"Warning parsing %s, line %u: Unknown header '%s'!\n", iter.filename, iter.line, key); - } else if( found[i] ) { - fprintf(stderr, "Error parsing %s, line %u: Second appearance of '%s' in the same chunk!\n", - iter.filename, iter.line, fields[i].name); + } else if (found[i]) { + fprintf(stderr, +"Error parsing %s, line %u: Second appearance of '%s' in the same chunk!\n", + iter.filename, iter.line, fields[i].name); result = RET_ERROR; break; } else @@ -275,29 +285,29 @@ do { c = fgetc(iter.f); iter.column++; - } while( c == ' ' || c == '\t' ); + } while (c == ' ' || c == '\t'); (void)ungetc(c, iter.f); iter.eol = false; - if( i < fieldcount ) { + if (i < fieldcount) { r = fields[i].setfunc(privdata, fields[i].name, this, &iter); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } /* ignore all data left of this field */ do { config_overline(&iter); - } while( config_nextline(&iter) ); - } while( true ); - if( this != NULL ) { + } while (config_nextline(&iter)); + } while (true); + if (this != NULL) { r = finishchunk(finishfunc, privdata, &iter, fields, fieldcount, found, &this, &last, !RET_WAS_ERROR(result)); RET_UPDATE(result, r); } - if( ferror(iter.f) != 0) { + if (ferror(iter.f) != 0) { int e = errno; fprintf(stderr, "Error reading config file '%s': %s(%d)\n", iter.filename, strerror(e), e); @@ -305,7 +315,7 @@ RET_UPDATE(result, r); } ret = fclose(iter.f); - if( ret != 0 ) { + if (ret != 0) { int e = errno; fprintf(stderr, "Error closing config file '%s': %s(%d)\n", iter.filename, strerror(e), e); @@ -322,34 +332,36 @@ c = fgetc(iter->f); realcolumn = iter->column + 1; - if( c == '#' ) { + if (c == '#') { do { c = fgetc(iter->f); realcolumn++; - } while( c != '\n' && c != EOF && c != '\r' ); + } while (c != '\n' && c != EOF && c != '\r'); } - if( c == '\r' ) { - while( c == '\r' ) { + if (c == '\r') { + while (c == '\r') { realcolumn++; c = fgetc(iter->f); } - if( c != '\n' && c != EOF ) { - fprintf(stderr, "Warning parsing config file '%s', line '%u', column %u: CR not followed by LF!\n", + if (c != '\n' && c != EOF) { + fprintf(stderr, +"Warning parsing config file '%s', line '%u', column %u: CR not followed by LF!\n", config_filename(iter), config_line(iter), realcolumn); } } - if( c == EOF ) { - fprintf(stderr, "Warning parsing config file '%s', line '%u': File ending without final LF!\n", + if (c == EOF) { + fprintf(stderr, +"Warning parsing config file '%s', line '%u': File ending without final LF!\n", config_filename(iter), config_line(iter)); /* fake a proper text file: */ c = '\n'; } iter->column++; - if( c == '\n' ) + if (c == '\n') iter->eol = true; return c; } @@ -360,12 +372,12 @@ do { iter->markerline = iter->line; iter->markercolumn = iter->column; - if( iter->eol ) { - if( !config_nextline(iter) ) + if (iter->eol) { + if (!config_nextline(iter)) return EOF; } c = config_nextchar(iter); - } while( c == '\n' || c == ' ' || c == '\t'); + } while (c == '\n' || c == ' ' || c == '\t'); return c; } @@ -375,20 +387,20 @@ do { iter->markerline = iter->line; iter->markercolumn = iter->column; - if( iter->eol ) + if (iter->eol) return EOF; c = config_nextchar(iter); - if( c == '\n' ) + if (c == '\n') return EOF; - } while( c == '\r' || c == ' ' || c == '\t'); + } while (c == '\r' || c == ' ' || c == '\t'); return c; } -#define configparser_errorlast(iter,message,...) \ +#define configparser_errorlast(iter, message, ...) \ fprintf(stderr, "Error parsing %s, line %u, column %u: " message "\n", \ iter->filename, iter->markerline, \ iter->markercolumn, ## __VA_ARGS__); -#define configparser_error(iter,message,...) \ +#define configparser_error(iter, message, ...) \ fprintf(stderr, "Error parsing %s, line %u, column %u: " message "\n", \ iter->filename, iter->line, \ iter->column, ## __VA_ARGS__); @@ -401,9 +413,9 @@ iter->markerline = iter->line; iter->markercolumn = iter->column; do { - if( len + 2 >= size ) { + if (len + 2 >= size) { nv = realloc(value, size+128); - if( nv == NULL ) { + if (FAILEDTOALLOC(nv)) { free(value); return RET_ERROR_OOM; } @@ -413,14 +425,14 @@ value[len] = c; len++; c = config_nextchar(iter); - if( c == '\n' ) + if (c == '\n') break; - } while( c != ' ' && c != '\t' ); - assert( len > 0 ); - assert( len < size ); + } while (c != ' ' && c != '\t'); + assert (len > 0); + assert (len < size); value[len] = '\0'; nv = realloc(value, len+1); - if( nv == NULL ) + if (nv == NULL) *result_p = value; else *result_p = nv; @@ -431,7 +443,7 @@ int c; c = config_nextnonspaceinline(iter); - if( c == EOF ) + if (c == EOF) return RET_NOTHING; return config_completeword(iter, c, result_p); } @@ -440,7 +452,7 @@ int c; c = config_nextnonspace(iter); - if( c == EOF ) + if (c == EOF) return RET_NOTHING; return config_completeword(iter, c, result_p); } @@ -452,8 +464,8 @@ do { c = config_nextnonspace(iter); - if( c == EOF ) { - if( empty ) { + if (c == EOF) { + if (empty) { configparser_errorlast(iter, "Unexpected end of %s header (value expected).", header); return RET_ERROR; @@ -464,7 +476,7 @@ iter->markerline = iter->line; iter->markercolumn = iter->column; currentnumber = 0; - if( c < '0' || c > '9' ) { + if (c < '0' || c > '9') { configparser_errorlast(iter, "Unexpected character '%c' where a digit was expected in %s header.", (char)c, header); @@ -475,18 +487,18 @@ currentnumber *= 10; currentnumber += (c - '0'); c = config_nextchar(iter); - } while( c >= '0' && c <= '9'); - if( c == ' ' || c == '\t' || c == '\n' ) + } while (c >= '0' && c <= '9'); + if (c == ' ' || c == '\t' || c == '\n') c = config_nextnonspace(iter); - if( c == 'y' ) { + if (c == 'y') { currentnumber *= 365*24*60*60; - } else if( c == 'm' ) { + } else if (c == 'm') { currentnumber *= 31*24*60*60; - } else if( c == 'd' ) { + } else if (c == 'd') { currentnumber *= 24*60*60; } else { currentnumber *= 24*60*60; - if( c != EOF ) { + if (c != EOF) { configparser_errorlast(iter, "Unexpected character '%c' where a 'd','m' or 'y' was expected in %s header.", (char)c, header); @@ -494,7 +506,7 @@ } } currentsum += currentnumber; - } while( true ); + } while (true); } retvalue config_getonlyword(struct configiterator *iter, const char *header, checkfunc check, char **result_p) { @@ -502,22 +514,22 @@ retvalue r; r = config_getword(iter, &value); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected end of %s header (value expected).", header); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( config_nextnonspace(iter) != EOF ) { + if (config_nextnonspace(iter) != EOF) { configparser_error(iter, "End of %s header expected (but trailing garbage).", header); free(value); return RET_ERROR; } - if( check != NULL ) { + if (check != NULL) { const char *errormessage = check(value); - if( errormessage != NULL ) { + if (errormessage != NULL) { configparser_errorlast(iter, "Malformed %s content '%s': %s", header, value, errormessage); free(value); @@ -532,14 +544,14 @@ retvalue config_getscript(struct configiterator *iter, const char *name, char **value_p) { char *value, *fullvalue; retvalue r; r = config_getonlyword(iter, name, NULL, &value); - if( RET_IS_OK(r) ) { - assert( value != NULL && value[0] != '\0' ); - if( value[0] != '/' ) { + if (RET_IS_OK(r)) { + assert (value != NULL && value[0] != '\0'); + if (value[0] != '/') { fullvalue = calc_dirconcat(global.confdir, value); free(value); } else fullvalue = value; - if( fullvalue == NULL ) + if (FAILEDTOALLOC(fullvalue)) return RET_ERROR_OOM; *value_p = fullvalue; } @@ -553,33 +565,33 @@ r = config_getword(iter, &value); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected end of %s header (value expected).", header); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // TODO: think about allowing (escaped) spaces... - if( config_nextnonspace(iter) != EOF ) { + if (config_nextnonspace(iter) != EOF) { configparser_error(iter, "End of %s header expected (but trailing garbage).", header); free(value); return RET_ERROR; } p = value; - while( *p != '\0' && ( *p == '_' || *p == '-' || + while (*p != '\0' && (*p == '_' || *p == '-' || (*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || - (*p>='0' && *p<='9') ) ) { + (*p>='0' && *p<='9'))) { p++; } - if( *p != ':' ) { + if (*p != ':') { configparser_errorlast(iter, "Malformed %s field: no colon (must be method:path).", header); free(value); return RET_ERROR; } - if( p == value ) { + if (p == value) { configparser_errorlast(iter, "Malformed %s field: transport method name expected (colon is not allowed to be the first character)!", header); free(value); @@ -589,7 +601,7 @@ l = strlen(p); /* remove one leading slash, as we always add one and some apt-methods * are confused with //. (end with // if you really want it) */ - if( l > 0 && p[l - 1] == '/' ) + if (l > 0 && p[l - 1] == '/') p[l - 1] = '\0'; *result_p = value; return RET_OK; @@ -602,18 +614,18 @@ const char *errormessage; strlist_init(&data); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } - if( strlist_in(&data, value) ) { + if (strlist_in(&data, value)) { configparser_errorlast(iter, "Unexpected duplicate '%s' within %s header.", value, header); free(value); strlist_done(&data); return RET_ERROR; - } else if( check != NULL && (errormessage = check(value)) != NULL ) { + } else if (check != NULL && (errormessage = check(value)) != NULL) { configparser_errorlast(iter, "Malformed %s element '%s': %s", header, value, errormessage); checkerror_free(errormessage); @@ -622,7 +634,7 @@ return RET_ERROR; } else { r = strlist_add(&data, value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } @@ -640,12 +652,12 @@ atom_t atom; atomlist_init(&data); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } - if( check != NULL && (errormessage = check(value)) != NULL ) { + if (check != NULL && (errormessage = check(value)) != NULL) { configparser_errorlast(iter, "Malformed %s element '%s': %s", header, value, errormessage); checkerror_free(errormessage); @@ -654,10 +666,10 @@ return RET_ERROR; } r = atom_intern(type, value, &atom); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = atomlist_add_uniq(&data, atom); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected duplicate '%s' within %s header.", value, header); free(value); @@ -665,7 +677,7 @@ return RET_ERROR; } free(value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } @@ -680,15 +692,15 @@ atom_t atom; r = config_getword(iter, &value); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected empty '%s' field.", header); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; atom = atom_find(type, value); - if( !atom_defined(atom) ) { + if (!atom_defined(atom)) { configparser_errorlast(iter, "Not previously seen %s '%s' within '%s' field.", atomtypes[type], value, header); free(value); @@ -706,13 +718,13 @@ atom_t atom; atomlist_init(&data); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } atom = atom_find(type, value); - if( !atom_defined(atom) ) { + if (!atom_defined(atom)) { configparser_errorlast(iter, "Not previously seen %s '%s' within '%s' header.", atomtypes[type], value, header); free(value); @@ -720,7 +732,7 @@ return RET_ERROR; } r = atomlist_add_uniq(&data, atom); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected duplicate '%s' within %s header.", value, header); free(value); @@ -728,7 +740,7 @@ return RET_ERROR; } free(value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } @@ -745,21 +757,21 @@ atomlist_init(&data_from); atomlist_init(&data_into); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data_from); atomlist_done(&data_into); return r; } separator = strchr(value, '>'); - if( separator == NULL ) { + if (separator == NULL) { separator = value; destination = atom_find(type, value); origin = destination;; - } else if( separator == value ) { + } else if (separator == value) { destination = atom_find(type, separator + 1); origin = destination;; - } else if( separator[1] == '\0' ) { + } else if (separator[1] == '\0') { *separator = '\0'; separator = value; destination = atom_find(type, value); @@ -770,7 +782,7 @@ origin = atom_find(type, value); destination = atom_find(type, separator); } - if( !atom_defined(origin) ) { + if (!atom_defined(origin)) { configparser_errorlast(iter, "Unknown %s '%s' in %s.", atomtypes[type], value, header); free(value); @@ -778,7 +790,7 @@ atomlist_done(&data_into); return RET_ERROR; } - if( !atom_defined(destination) ) { + if (!atom_defined(destination)) { configparser_errorlast(iter, "Unknown %s '%s' in %s.", atomtypes[type], separator, header); free(value); @@ -788,13 +800,13 @@ } free(value); r = atomlist_add(&data_from, origin); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data_from); atomlist_done(&data_into); return r; } r = atomlist_add(&data_into, destination); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data_from); atomlist_done(&data_into); return r; @@ -812,13 +824,13 @@ atom_t atom; atomlist_init(&data); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } atom = atom_find(type, value); - if( !atom_defined(atom) || !atomlist_in(superset, atom) ) { + if (!atom_defined(atom) || !atomlist_in(superset, atom)) { configparser_errorlast(iter, "'%s' not allowed in %s as it was not in %s.", value, header, superset_header); free(value); @@ -826,7 +838,7 @@ return RET_ERROR; } r = atomlist_add_uniq(&data, atom); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected duplicate '%s' within %s header.", value, header); free(value); @@ -834,7 +846,7 @@ return RET_ERROR; } free(value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { atomlist_done(&data); return r; } @@ -849,13 +861,13 @@ struct strlist data; strlist_init(&data); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } r = strlist_add(&data, value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } @@ -873,24 +885,24 @@ strlist_init(&data); c = config_nextnonspace(iter); - if( c == EOF ) { + if (c == EOF) { configparser_errorlast(iter, "Missing value for %s field.", name); return RET_ERROR; } /* if the first character is a '!', a script to start follows */ - if( c == '!' ) { + if (c == '!') { r = strlist_add_dup(&data, "!"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = config_getscript(iter, name, &value); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } r = strlist_add(&data, value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } @@ -899,19 +911,19 @@ } /* otherwise each word is stored in the strlist */ r = config_completeword(iter, c, &value); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; r = strlist_add(&data, value); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } r = strlist_add(&data, value); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&data); return r; } @@ -927,21 +939,21 @@ strlist_init(&data_from); strlist_init(&data_into); - while( (r = config_getword(iter, &value)) != RET_NOTHING ) { - if( RET_WAS_ERROR(r) ) { + while ((r = config_getword(iter, &value)) != RET_NOTHING) { + if (RET_WAS_ERROR(r)) { strlist_done(&data_from); strlist_done(&data_into); return r; } separator = strchr(value, '>'); - if( separator == NULL ) { + if (separator == NULL) { destination = strdup(value); origin = value; - } else if( separator == value ) { + } else if (separator == value) { destination = strdup(separator+1); origin = strdup(separator+1); free(value); - } else if( separator[1] == '\0' ) { + } else if (separator[1] == '\0') { *separator = '\0'; destination = strdup(value); origin = value; @@ -950,21 +962,21 @@ destination = strdup(separator+1); free(value); } - if( origin == NULL || destination == NULL ) { - free(origin);free(destination); + if (FAILEDTOALLOC(origin) || FAILEDTOALLOC(destination)) { + free(origin); free(destination); strlist_done(&data_from); strlist_done(&data_into); return RET_ERROR_OOM; } r = strlist_add(&data_from, origin); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(destination); strlist_done(&data_from); strlist_done(&data_into); return r; } r = strlist_add(&data_into, destination); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&data_from); strlist_done(&data_into); return r; @@ -980,15 +992,16 @@ char *value; const struct constant *c; - /* that could be done more in-situ, but is not runtime-critical at all */ + /* that could be done more in-situ, + * but is not runtime-critical at all */ r = config_getword(iter, &value); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) return r; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( c = constants ; c->name != NULL ; c++ ) { - if( strcmp(c->name, value) == 0 ) { + for (c = constants ; c->name != NULL ; c++) { + if (strcmp(c->name, value) == 0) { free(value); *result_p = c->value; return RET_OK; @@ -1002,10 +1015,13 @@ retvalue r, result = RET_NOTHING; int option = -1; - while( (r = config_getconstant(iter, constants, &option)) != RET_NOTHING ) { - if( r == RET_ERROR_UNKNOWNFIELD ) { + while (true) { + r = config_getconstant(iter, constants, &option); + if (r == RET_NOTHING) + break; + if (r == RET_ERROR_UNKNOWNFIELD) { // TODO: would be nice to have the wrong flag here to put it in the error message: - if( ignoreunknown ) { + if (ignoreunknown) { fprintf(stderr, "Warning: ignored error parsing config file %s, line %u, column %u:\n" "Unknown flag in %s header.%s\n", @@ -1023,9 +1039,9 @@ config_markercolumn(iter), header, msg); } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( option >= 0 ); + assert (option >= 0); flags[option] = true; result = RET_OK; option = -1; @@ -1039,14 +1055,14 @@ int c; c = config_nextnonspace(iter); - if( c == EOF ) + if (c == EOF) return RET_NOTHING; iter->markerline = iter->line; iter->markercolumn = iter->column; do { - if( len + 2 >= size ) { + if (len + 2 >= size) { nv = realloc(value, size+128); - if( nv == NULL ) { + if (FAILEDTOALLOC(nv)) { free(value); return RET_ERROR_OOM; } @@ -1055,20 +1071,20 @@ } value[len] = c; len++; - if( iter->eol ) { - if( !config_nextline(iter) ) + if (iter->eol) { + if (!config_nextline(iter)) break; } c = config_nextchar(iter); - } while( true ); - assert( len > 0 ); - assert( len < size ); - while( len > 0 && ( value[len-1] == ' ' || value[len-1] == '\t' || - value[len-1] == '\n' || value[len-1] == '\r' ) ) + } while (true); + assert (len > 0); + assert (len < size); + while (len > 0 && (value[len-1] == ' ' || value[len-1] == '\t' || + value[len-1] == '\n' || value[len-1] == '\r')) len--; value[len] = '\0'; nv = realloc(value, len+1); - if( nv == NULL ) + if (nv == NULL) *result_p = value; else *result_p = nv; @@ -1082,30 +1098,30 @@ /* wastefull, but does not happen that often */ r = config_getword(iter, &value); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected empty boolean %s header (something like Yes or No expected).", header); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // TODO: check against trailing garbage - if( strcasecmp(value, "Yes") == 0 ) { + if (strcasecmp(value, "Yes") == 0) { *result_p = true; free(value); return RET_OK; } - if( strcasecmp(value, "No") == 0 ) { + if (strcasecmp(value, "No") == 0) { *result_p = false; free(value); return RET_OK; } - if( strcmp(value, "1") == 0 ) { + if (strcmp(value, "1") == 0) { *result_p = true; free(value); return RET_OK; } - if( strcmp(value, "0") == 0 ) { + if (strcmp(value, "0") == 0) { *result_p = false; free(value); return RET_OK; @@ -1123,16 +1139,16 @@ char *e; r = config_getword(iter, &word); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { configparser_errorlast(iter, "Unexpected end of line (%s number expected).", name); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; value = strtoll(word, &e, 10); - if( e == word ) { + if (e == word) { fprintf(stderr, "Error parsing config file %s, line %u, column %u:\n" "Expected %s number but got '%s'\n", @@ -1141,7 +1157,7 @@ free(word); return RET_ERROR; } - if( e != NULL && *e != '\0' ) { + if (e != NULL && *e != '\0') { unsigned char digit1, digit2, digit3; digit1 = ((unsigned char)(*e))&0x7; digit2 = (((unsigned char)(*e)) >> 3)&0x7; @@ -1156,7 +1172,7 @@ free(word); return RET_ERROR; } - if( value == LLONG_MAX || value > maxval) { + if (value == LLONG_MAX || value > maxval) { fprintf(stderr, "Error parsing config file %s, line %u, column %u:\n" "Too large %s number '%s'\n", @@ -1165,7 +1181,7 @@ free(word); return RET_ERROR; } - if( value == LLONG_MIN || value < minval ) { + if (value == LLONG_MIN || value < minval) { fprintf(stderr, "Error parsing config file %s, line %u, column %u:\n" "Too small %s number '%s'\n", @@ -1185,14 +1201,14 @@ int c; c = config_nextnonspace(iter); - if( c == EOF ) + if (c == EOF) return RET_NOTHING; iter->markerline = iter->line; iter->markercolumn = iter->column; do { - if( len + 2 >= size ) { + if (len + 2 >= size) { nv = realloc(value, size+128); - if( nv == NULL ) { + if (FAILEDTOALLOC(nv)) { free(value); return RET_ERROR_OOM; } @@ -1202,17 +1218,16 @@ value[len] = c; len++; c = config_nextchar(iter); - } while( c != '\n' ); - assert( len > 0 ); - assert( len < size ); - while( len > 0 && - (value[len-1] == ' ' || value[len-1] == '\t' - || value[len-1] == '\r' ) ) + } while (c != '\n'); + assert (len > 0); + assert (len < size); + while (len > 0 && (value[len-1] == ' ' || value[len-1] == '\t' + || value[len-1] == '\r')) len--; - assert( len > 0 ); + assert (len > 0); value[len] = '\0'; nv = realloc(value, len+1); - if( nv == NULL ) + if (nv == NULL) *result_p = value; else *result_p = nv; @@ -1227,19 +1242,19 @@ strlist_init(&list); do { r = config_getline(iter, &line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&list); return r; } - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = strlist_add_dup(&list, ""); else r = strlist_add(&list, line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&list); return r; } - } while( config_nextline(iter) ); + } while (config_nextline(iter)); strlist_move(result, &list); return RET_OK; } diff -Nru reprepro-4.5.0/configparser.h reprepro-4.6.0/configparser.h --- reprepro-4.5.0/configparser.h 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/configparser.h 2011-05-05 14:42:55.000000000 +0000 @@ -13,8 +13,8 @@ struct configiterator; -typedef retvalue configsetfunction(void *,const char *,void *,struct configiterator *); -typedef retvalue configinitfunction(void *,void *,void **); +typedef retvalue configsetfunction(void *, const char *, void *, struct configiterator *); +typedef retvalue configinitfunction(void *, void *, void **); typedef retvalue configfinishfunction(void *, void *, void **, bool, struct configiterator *); retvalue linkedlistfinish(void *, void *, void **, bool, struct configiterator *); @@ -41,10 +41,10 @@ unsigned int config_firstline(const struct configiterator *) __attribute__((pure)); unsigned int config_markerline(const struct configiterator *) __attribute__((pure)); unsigned int config_markercolumn(const struct configiterator *) __attribute__((pure)); -retvalue config_getflags(struct configiterator *, const char *, const struct constant *, bool *, bool, const char *msg); +retvalue config_getflags(struct configiterator *, const char *, const struct constant *, bool *, bool, const char *); int config_nextnonspaceinline(struct configiterator *iter); -retvalue config_getlines(struct configiterator *,struct strlist *); -retvalue config_getwords(struct configiterator *,struct strlist *); +retvalue config_getlines(struct configiterator *, struct strlist *); +retvalue config_getwords(struct configiterator *, struct strlist *); retvalue config_getall(struct configiterator *iter, /*@out@*/char **result_p); retvalue config_getword(struct configiterator *, /*@out@*/char **); retvalue config_getwordinline(struct configiterator *, /*@out@*/char **); @@ -58,24 +58,24 @@ retvalue config_getsplitatoms(struct configiterator *, const char *, enum atom_type, struct atomlist *, struct atomlist *); retvalue config_getsplitwords(struct configiterator *, const char *, struct strlist *, struct strlist *); retvalue config_gettruth(struct configiterator *, const char *, bool *); -retvalue config_getnumber(struct configiterator *, const char *, long long *, long long minval, long long maxval); +retvalue config_getnumber(struct configiterator *, const char *, long long *, long long /*minvalue*/, long long /*maxvalue*/); retvalue config_getconstant(struct configiterator *, const struct constant *, int *); -#define config_getenum(iter,type,constants,result) ({int _val;retvalue _r = config_getconstant(iter, type ## _ ## constants, &_val);*(result) = (enum type)_val;_r;}) +#define config_getenum(iter, type, constants, result) ({int _val;retvalue _r = config_getconstant(iter, type ## _ ## constants, &_val);*(result) = (enum type)_val;_r;}) retvalue config_completeword(struct configiterator *, char, /*@out@*/char **); retvalue config_gettimespan(struct configiterator *, const char *, /*@out@*/time_t *); retvalue config_getscript(struct configiterator *, const char *, /*@out@*/char **); retvalue config_getsignwith(struct configiterator *, const char *, struct strlist *); void config_overline(struct configiterator *); bool config_nextline(struct configiterator *); -retvalue configfile_parse(const char *filename, bool ignoreunknown, configinitfunction, configfinishfunction, const struct configfield *, size_t, void *privdata); +retvalue configfile_parse(const char * /*filename*/, bool /*ignoreunknown*/, configinitfunction, configfinishfunction, const struct configfield *, size_t, void *); #define CFlinkedlistinit(sname) \ static retvalue configparser_ ## sname ## _init(void *rootptr, void *lastitem, void **newptr) { \ struct sname *n, **root_p = rootptr, *last = lastitem; \ n = calloc(1, sizeof(struct sname)); \ - if( n == NULL ) \ + if (n == NULL) \ return RET_ERROR_OOM; \ - if( last == NULL ) \ + if (last == NULL) \ *root_p = n; \ else \ last->next = n; \ @@ -128,7 +128,7 @@ struct sname *item = data; \ retvalue r; \ r = config_getuniqwords(iter, name, checker, &item->field); \ - if( r == RET_NOTHING ) { \ + if (r == RET_NOTHING) { \ fprintf(stderr, \ "Error parsing %s, line %d, column %d:\n" \ " An empty %s-field is not allowed.\n", config_filename(iter), \ @@ -144,7 +144,7 @@ struct sname *item = data; \ retvalue r; \ r = config_getinternatomlist(iter, name, type, checker, &item->field); \ - if( r == RET_NOTHING ) { \ + if (r == RET_NOTHING) { \ fprintf(stderr, \ "Error parsing %s, line %d, column %d:\n" \ " An empty %s-field is not allowed.\n", config_filename(iter), \ @@ -161,7 +161,7 @@ retvalue r; \ item->field ## _set = true; \ r = config_getatomlist(iter, name, type, &item->field); \ - if( r == RET_NOTHING ) { \ + if (r == RET_NOTHING) { \ fprintf(stderr, \ "Error parsing %s, line %d, column %d:\n" \ " An empty %s-field is not allowed.\n", config_filename(iter), \ @@ -182,7 +182,7 @@ struct sname *item = data; \ retvalue r; \ item->field ## _set = true; \ - if( item->superset.count == 0 ) { \ + if (item->superset.count == 0) { \ fprintf(stderr, \ "Error parsing %s, line %d, column %d:\n" \ " A '%s'-field is only allowed after a '%s'-field.\n", config_filename(iter), \ @@ -191,8 +191,9 @@ name, superset_header); \ return RET_ERROR; \ } \ - r = config_getatomsublist(iter, name, type, &item->field, &item->superset, superset_header); \ - if( r == RET_NOTHING ) { \ + r = config_getatomsublist(iter, name, type, &item->field, \ + &item->superset, superset_header); \ + if (r == RET_NOTHING) { \ fprintf(stderr, \ "Error parsing %s, line %d, column %d:\n" \ " An empty %s-field is not allowed.\n", config_filename(iter), \ @@ -240,24 +241,25 @@ struct sname *item = data; \ return exportmode_set(&item->field, iter); \ } -#define CFUSETPROC(sname,field) static retvalue configparser_ ## sname ## _set_ ## field(UNUSED(void *dummy), UNUSED(const char *name), void *thisdata_ ## sname, struct configiterator *iter) -#define CFuSETPROC(sname,field) static retvalue configparser_ ## sname ## _set_ ## field(void *privdata_ ## sname, UNUSED(const char *name), void *thisdata_ ## sname, struct configiterator *iter) -#define CFSETPROC(sname,field) static retvalue configparser_ ## sname ## _set_ ## field(void *privdata_ ## sname, const char *headername, void *thisdata_ ## sname, struct configiterator *iter) -#define CFSETPROCVARS(sname,item,mydata) struct sname *item = thisdata_ ## sname; struct read_ ## sname ## _data *mydata = privdata_ ## sname -#define CFSETPROCVAR(sname,item) struct sname *item = thisdata_ ## sname +#define CFUSETPROC(sname, field) static retvalue configparser_ ## sname ## _set_ ## field(UNUSED(void *dummy), UNUSED(const char *name), void *thisdata_ ## sname, struct configiterator *iter) +#define CFuSETPROC(sname, field) static retvalue configparser_ ## sname ## _set_ ## field(void *privdata_ ## sname, UNUSED(const char *name), void *thisdata_ ## sname, struct configiterator *iter) +#define CFSETPROC(sname, field) static retvalue configparser_ ## sname ## _set_ ## field(void *privdata_ ## sname, const char *headername, void *thisdata_ ## sname, struct configiterator *iter) +#define CFSETPROCVARS(sname, item, mydata) struct sname *item = thisdata_ ## sname; struct read_ ## sname ## _data *mydata = privdata_ ## sname +#define CFSETPROCVAR(sname, item) struct sname *item = thisdata_ ## sname #define CFstartparse(sname) static retvalue startparse ## sname(UNUSED(void *dummyprivdata), UNUSED(void *lastdata), void **result_p_ ##sname) -#define CFstartparseVAR(sname,r) struct sname **r = (void*)result_p_ ## sname +#define CFstartparseVAR(sname, r) struct sname **r = (void*)result_p_ ## sname #define CFfinishparse(sname) static retvalue finishparse ## sname(void *privdata_ ## sname, void *thisdata_ ## sname, void **lastdata_p_ ##sname, bool complete, struct configiterator *iter) -#define CFfinishparseVARS(sname,this,last,mydata) struct sname *this = thisdata_ ## sname, **last = (void*)lastdata_p_ ## sname; struct read_ ## sname ## _data *mydata = privdata_ ## sname -#define CFUfinishparseVARS(sname,this,last,mydata) struct sname *this = thisdata_ ## sname +#define CFfinishparseVARS(sname, this, last, mydata) struct sname *this = thisdata_ ## sname, **last = (void*)lastdata_p_ ## sname; struct read_ ## sname ## _data *mydata = privdata_ ## sname +#define CFUfinishparseVARS(sname, this, last, mydata) struct sname *this = thisdata_ ## sname #define CFhashesSETPROC(sname, field) \ static retvalue configparser_ ## sname ## _set_ ## field(UNUSED(void *dummy), const char *name, void *data, struct configiterator *iter) { \ struct sname *item = data; \ retvalue r; \ item->field ## _set = true; \ - r = config_getflags(iter, name, hashnames, item->field, false, "(allowed values: md5, sha1 and sha256)"); \ - if( !RET_IS_OK(r) ) \ + r = config_getflags(iter, name, hashnames, item->field, false, \ + "(allowed values: md5, sha1 and sha256)"); \ + if (!RET_IS_OK(r)) \ return r; \ return RET_OK; \ } @@ -269,7 +271,7 @@ char *formula; \ retvalue r; \ r = config_getall(iter, &formula); \ - if( ! RET_IS_OK(r) ) \ + if (! RET_IS_OK(r)) \ return r; \ r = term_compilefortargetdecision(&item->field, formula); \ free(formula); \ @@ -281,7 +283,7 @@ char *formula; \ retvalue r; \ r = config_getall(iter, &formula); \ - if( ! RET_IS_OK(r) ) \ + if (! RET_IS_OK(r)) \ return r; \ r = term_compilefortargetdecision(&item->field, formula); \ free(formula); \ diff -Nru reprepro-4.5.0/configure reprepro-4.6.0/configure --- reprepro-4.5.0/configure 2011-02-21 15:35:17.000000000 +0000 +++ reprepro-4.6.0/configure 2011-05-05 14:52:26.000000000 +0000 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.67 for reprepro 4.5.0. +# Generated by GNU Autoconf 2.68 for reprepro 4.6.0. # # Report bugs to . # @@ -91,6 +91,7 @@ IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. +as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -216,11 +217,18 @@ # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV export CONFIG_SHELL - exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -552,8 +560,8 @@ # Identity of this package. PACKAGE_NAME='reprepro' PACKAGE_TARNAME='reprepro' -PACKAGE_VERSION='4.5.0' -PACKAGE_STRING='reprepro 4.5.0' +PACKAGE_VERSION='4.6.0' +PACKAGE_STRING='reprepro 4.6.0' PACKAGE_BUGREPORT='brlink@debian.org' PACKAGE_URL='' @@ -1110,7 +1118,7 @@ $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac @@ -1248,7 +1256,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures reprepro 4.5.0 to adapt to many kinds of systems. +\`configure' configures reprepro 4.6.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1314,7 +1322,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of reprepro 4.5.0:";; + short | recursive ) echo "Configuration of reprepro 4.6.0:";; esac cat <<\_ACEOF @@ -1412,8 +1420,8 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -reprepro configure 4.5.0 -generated by GNU Autoconf 2.67 +reprepro configure 4.6.0 +generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation @@ -1459,7 +1467,7 @@ ac_retval=1 fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile @@ -1496,7 +1504,7 @@ ac_retval=1 fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp @@ -1509,10 +1517,10 @@ ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if eval "test \"\${$3+set}\"" = set; then : + if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if eval "test \"\${$3+set}\"" = set; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 @@ -1579,7 +1587,7 @@ esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if eval "test \"\${$3+set}\"" = set; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" @@ -1588,7 +1596,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel @@ -1629,7 +1637,7 @@ ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run @@ -1643,7 +1651,7 @@ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if eval "test \"\${$3+set}\"" = set; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -1661,7 +1669,7 @@ eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile @@ -1674,7 +1682,7 @@ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if eval "test \"\${$3+set}\"" = set; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" @@ -1715,7 +1723,7 @@ eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type @@ -1760,7 +1768,7 @@ # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link @@ -1773,7 +1781,7 @@ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if eval "test \"\${$3+set}\"" = set; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -1828,15 +1836,15 @@ eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by reprepro $as_me 4.5.0, which was -generated by GNU Autoconf 2.67. Invocation command line was +It was created by reprepro $as_me 4.6.0, which was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2094,7 +2102,7 @@ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi done @@ -2232,7 +2240,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then : +if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2319,11 +2327,11 @@ ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) - as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5 ;; + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) - as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5 ;; + as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; esac # Do `set' in a subshell so we don't clobber the current shell's @@ -2409,7 +2417,7 @@ set dummy ${ac_tool_prefix}strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_STRIP+set}" = set; then : +if ${ac_cv_prog_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$STRIP"; then @@ -2449,7 +2457,7 @@ set dummy strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then : +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_STRIP"; then @@ -2502,7 +2510,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then - if test "${ac_cv_path_mkdir+set}" = set; then : + if ${ac_cv_path_mkdir+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -2553,7 +2561,7 @@ set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_AWK+set}" = set; then : +if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then @@ -2593,7 +2601,7 @@ $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then : +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF @@ -2651,7 +2659,7 @@ # Define the identity of the package. PACKAGE='reprepro' - VERSION='4.5.0' + VERSION='4.6.0' cat >>confdefs.h <<_ACEOF @@ -2789,7 +2797,7 @@ set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then : +if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then @@ -2829,7 +2837,7 @@ set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : +if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then @@ -2882,7 +2890,7 @@ set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then : +if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then @@ -2922,7 +2930,7 @@ set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then : +if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then @@ -2981,7 +2989,7 @@ set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then : +if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then @@ -3025,7 +3033,7 @@ set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : +if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then @@ -3080,7 +3088,7 @@ test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 @@ -3195,7 +3203,7 @@ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } @@ -3238,7 +3246,7 @@ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 @@ -3297,7 +3305,7 @@ $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi fi fi @@ -3308,7 +3316,7 @@ ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } -if test "${ac_cv_objext+set}" = set; then : +if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -3349,7 +3357,7 @@ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi @@ -3359,7 +3367,7 @@ ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } -if test "${ac_cv_c_compiler_gnu+set}" = set; then : +if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -3396,7 +3404,7 @@ ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } -if test "${ac_cv_prog_cc_g+set}" = set; then : +if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag @@ -3474,7 +3482,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } -if test "${ac_cv_prog_cc_c89+set}" = set; then : +if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no @@ -3573,7 +3581,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 $as_echo_n "checking dependency style of $depcc... " >&6; } -if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then : +if ${am_cv_CC_dependencies_compiler_type+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then @@ -3709,7 +3717,7 @@ CPP= fi if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then : + if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded @@ -3825,7 +3833,7 @@ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5 ; } +See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c @@ -3837,7 +3845,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if test "${ac_cv_path_GREP+set}" = set; then : +if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then @@ -3900,7 +3908,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } -if test "${ac_cv_path_EGREP+set}" = set; then : +if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 @@ -3967,7 +3975,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } -if test "${ac_cv_header_stdc+set}" = set; then : +if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -4096,7 +4104,7 @@ ac_fn_c_check_header_mongrel "$LINENO" "minix/config.h" "ac_cv_header_minix_config_h" "$ac_includes_default" -if test "x$ac_cv_header_minix_config_h" = x""yes; then : +if test "x$ac_cv_header_minix_config_h" = xyes; then : MINIX=yes else MINIX= @@ -4118,7 +4126,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5 $as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; } -if test "${ac_cv_safe_to_define___extensions__+set}" = set; then : +if ${ac_cv_safe_to_define___extensions__+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -4163,7 +4171,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5 $as_echo_n "checking for $CC option to accept ISO C99... " >&6; } -if test "${ac_cv_prog_cc_c99+set}" = set; then : +if ${ac_cv_prog_cc_c99+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c99=no @@ -4348,7 +4356,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 $as_echo_n "checking for special C compiler options needed for large files... " >&6; } -if test "${ac_cv_sys_largefile_CC+set}" = set; then : +if ${ac_cv_sys_largefile_CC+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_sys_largefile_CC=no @@ -4399,7 +4407,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 $as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } -if test "${ac_cv_sys_file_offset_bits+set}" = set; then : +if ${ac_cv_sys_file_offset_bits+:} false; then : $as_echo_n "(cached) " >&6 else while :; do @@ -4468,7 +4476,7 @@ if test $ac_cv_sys_file_offset_bits = unknown; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 $as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; } -if test "${ac_cv_sys_large_files+set}" = set; then : +if ${ac_cv_sys_large_files+:} false; then : $as_echo_n "(cached) " >&6 else while :; do @@ -4540,7 +4548,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 $as_echo_n "checking whether byte ordering is bigendian... " >&6; } -if test "${ac_cv_c_bigendian+set}" = set; then : +if ${ac_cv_c_bigendian+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_c_bigendian=unknown @@ -4759,12 +4767,12 @@ ;; #( *) as_fn_error $? "unknown endianness - presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; + presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5 $as_echo_n "checking for stdbool.h that conforms to C99... " >&6; } -if test "${ac_cv_header_stdbool_h+set}" = set; then : +if ${ac_cv_header_stdbool_h+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -4796,7 +4804,7 @@ char b[false == 0 ? 1 : -1]; char c[__bool_true_false_are_defined == 1 ? 1 : -1]; char d[(bool) 0.5 == true ? 1 : -1]; - bool e = &s; + /* See body of main program for 'e'. */ char f[(_Bool) 0.0 == false ? 1 : -1]; char g[true]; char h[sizeof (_Bool)]; @@ -4807,25 +4815,6 @@ _Bool n[m]; char o[sizeof n == m * sizeof n[0] ? 1 : -1]; char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; -# if defined __xlc__ || defined __GNUC__ - /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 - reported by James Lemley on 2005-10-05; see - http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html - This test is not quite right, since xlc is allowed to - reject this program, as the initializer for xlcbug is - not one of the forms that C requires support for. - However, doing the test right would require a runtime - test, and that would make cross-compilation harder. - Let us hope that IBM fixes the xlc bug, and also adds - support for this kind of constant expression. In the - meantime, this test will reject xlc, which is OK, since - our stdbool.h substitute should suffice. We also test - this with GCC, where it should work, to detect more - quickly whether someone messes up the test in the - future. */ - char digs[] = "0123456789"; - int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); -# endif /* Catch a bug in an HP-UX C compiler. See http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html @@ -4837,6 +4826,7 @@ main () { + bool e = &s; *pq |= q; *pq |= ! q; /* Refer to every declared value, to avoid compiler optimizations. */ @@ -4857,7 +4847,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5 $as_echo "$ac_cv_header_stdbool_h" >&6; } ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default" -if test "x$ac_cv_type__Bool" = x""yes; then : +if test "x$ac_cv_type__Bool" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE__BOOL 1 @@ -4901,7 +4891,7 @@ as_fn_error $? "Missing mkstemp or mkostemp" "$LINENO" 5 fi ac_fn_c_check_func "$LINENO" "vasprintf" "ac_cv_func_vasprintf" -if test "x$ac_cv_func_vasprintf" = x""yes; then : +if test "x$ac_cv_func_vasprintf" = xyes; then : else as_fn_error $? "Could not find vasprintf implementation!" "$LINENO" 5 @@ -4912,7 +4902,7 @@ # the only way to find out which is compileable is to look into db.h: ac_fn_c_check_header_mongrel "$LINENO" "db.h" "ac_cv_header_db_h" "$ac_includes_default" -if test "x$ac_cv_header_db_h" = x""yes; then : +if test "x$ac_cv_header_db_h" = xyes; then : else as_fn_error $? "\"no db.h found\"" "$LINENO" 5 @@ -4922,7 +4912,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for db_create in -ldb" >&5 $as_echo_n "checking for db_create in -ldb... " >&6; } -if test "${ac_cv_lib_db_db_create+set}" = set; then : +if ${ac_cv_lib_db_db_create+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -4956,7 +4946,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_db_db_create" >&5 $as_echo "$ac_cv_lib_db_db_create" >&6; } -if test "x$ac_cv_lib_db_db_create" = x""yes; then : +if test "x$ac_cv_lib_db_db_create" = xyes; then : DBLIBS="-ldb $DBLIBS" else @@ -4967,7 +4957,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzopen in -lz" >&5 $as_echo_n "checking for gzopen in -lz... " >&6; } -if test "${ac_cv_lib_z_gzopen+set}" = set; then : +if ${ac_cv_lib_z_gzopen+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5001,7 +4991,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_gzopen" >&5 $as_echo "$ac_cv_lib_z_gzopen" >&6; } -if test "x$ac_cv_lib_z_gzopen" = x""yes; then : +if test "x$ac_cv_lib_z_gzopen" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBZ 1 _ACEOF @@ -5021,7 +5011,7 @@ ;; yes) ac_fn_c_check_header_mongrel "$LINENO" "gpgme.h" "ac_cv_header_gpgme_h" "$ac_includes_default" -if test "x$ac_cv_header_gpgme_h" = x""yes; then : +if test "x$ac_cv_header_gpgme_h" = xyes; then : else as_fn_error $? "\"no gpgme.h found\"" "$LINENO" 5 @@ -5030,7 +5020,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpg_strsource in -lgpg-error" >&5 $as_echo_n "checking for gpg_strsource in -lgpg-error... " >&6; } -if test "${ac_cv_lib_gpg_error_gpg_strsource+set}" = set; then : +if ${ac_cv_lib_gpg_error_gpg_strsource+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5064,7 +5054,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpg_error_gpg_strsource" >&5 $as_echo "$ac_cv_lib_gpg_error_gpg_strsource" >&6; } -if test "x$ac_cv_lib_gpg_error_gpg_strsource" = x""yes; then : +if test "x$ac_cv_lib_gpg_error_gpg_strsource" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPG_ERROR 1 _ACEOF @@ -5077,7 +5067,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpgme_get_protocol_name in -lgpgme" >&5 $as_echo_n "checking for gpgme_get_protocol_name in -lgpgme... " >&6; } -if test "${ac_cv_lib_gpgme_gpgme_get_protocol_name+set}" = set; then : +if ${ac_cv_lib_gpgme_gpgme_get_protocol_name+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5111,7 +5101,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpgme_gpgme_get_protocol_name" >&5 $as_echo "$ac_cv_lib_gpgme_gpgme_get_protocol_name" >&6; } -if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = x""yes; then : +if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPGME 1 _ACEOF @@ -5127,7 +5117,7 @@ CPPFLAGS="$CPPFLAGS -I$withval/include" LIBS="$LIBS -L$withval/lib" ac_fn_c_check_header_mongrel "$LINENO" "gpgme.h" "ac_cv_header_gpgme_h" "$ac_includes_default" -if test "x$ac_cv_header_gpgme_h" = x""yes; then : +if test "x$ac_cv_header_gpgme_h" = xyes; then : else as_fn_error $? "\"no gpgme.h found\"" "$LINENO" 5 @@ -5136,7 +5126,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpg_strsource in -lgpg-error" >&5 $as_echo_n "checking for gpg_strsource in -lgpg-error... " >&6; } -if test "${ac_cv_lib_gpg_error_gpg_strsource+set}" = set; then : +if ${ac_cv_lib_gpg_error_gpg_strsource+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5170,7 +5160,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpg_error_gpg_strsource" >&5 $as_echo "$ac_cv_lib_gpg_error_gpg_strsource" >&6; } -if test "x$ac_cv_lib_gpg_error_gpg_strsource" = x""yes; then : +if test "x$ac_cv_lib_gpg_error_gpg_strsource" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPG_ERROR 1 _ACEOF @@ -5183,7 +5173,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpgme_get_protocol_name in -lgpgme" >&5 $as_echo_n "checking for gpgme_get_protocol_name in -lgpgme... " >&6; } -if test "${ac_cv_lib_gpgme_gpgme_get_protocol_name+set}" = set; then : +if ${ac_cv_lib_gpgme_gpgme_get_protocol_name+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5217,7 +5207,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpgme_gpgme_get_protocol_name" >&5 $as_echo "$ac_cv_lib_gpgme_gpgme_get_protocol_name" >&6; } -if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = x""yes; then : +if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPGME 1 _ACEOF @@ -5233,7 +5223,7 @@ else ac_fn_c_check_header_mongrel "$LINENO" "gpgme.h" "ac_cv_header_gpgme_h" "$ac_includes_default" -if test "x$ac_cv_header_gpgme_h" = x""yes; then : +if test "x$ac_cv_header_gpgme_h" = xyes; then : else as_fn_error $? "\"no gpgme.h found (to disable run with --without-libgpgme)\"" "$LINENO" 5 @@ -5242,7 +5232,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpg_strsource in -lgpg-error" >&5 $as_echo_n "checking for gpg_strsource in -lgpg-error... " >&6; } -if test "${ac_cv_lib_gpg_error_gpg_strsource+set}" = set; then : +if ${ac_cv_lib_gpg_error_gpg_strsource+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5276,7 +5266,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpg_error_gpg_strsource" >&5 $as_echo "$ac_cv_lib_gpg_error_gpg_strsource" >&6; } -if test "x$ac_cv_lib_gpg_error_gpg_strsource" = x""yes; then : +if test "x$ac_cv_lib_gpg_error_gpg_strsource" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPG_ERROR 1 _ACEOF @@ -5289,7 +5279,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gpgme_get_protocol_name in -lgpgme" >&5 $as_echo_n "checking for gpgme_get_protocol_name in -lgpgme... " >&6; } -if test "${ac_cv_lib_gpgme_gpgme_get_protocol_name+set}" = set; then : +if ${ac_cv_lib_gpgme_gpgme_get_protocol_name+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5323,7 +5313,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpgme_gpgme_get_protocol_name" >&5 $as_echo "$ac_cv_lib_gpgme_gpgme_get_protocol_name" >&6; } -if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = x""yes; then : +if test "x$ac_cv_lib_gpgme_gpgme_get_protocol_name" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGPGME 1 _ACEOF @@ -5347,7 +5337,7 @@ yes) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompressInit in -lbz2" >&5 $as_echo_n "checking for BZ2_bzCompressInit in -lbz2... " >&6; } -if test "${ac_cv_lib_bz2_BZ2_bzCompressInit+set}" = set; then : +if ${ac_cv_lib_bz2_BZ2_bzCompressInit+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5381,7 +5371,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompressInit" >&5 $as_echo "$ac_cv_lib_bz2_BZ2_bzCompressInit" >&6; } -if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = x""yes; then : +if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBBZ2 1 _ACEOF @@ -5396,7 +5386,7 @@ *) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompressInit in -lbz2" >&5 $as_echo_n "checking for BZ2_bzCompressInit in -lbz2... " >&6; } -if test "${ac_cv_lib_bz2_BZ2_bzCompressInit+set}" = set; then : +if ${ac_cv_lib_bz2_BZ2_bzCompressInit+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5430,7 +5420,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompressInit" >&5 $as_echo "$ac_cv_lib_bz2_BZ2_bzCompressInit" >&6; } -if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = x""yes; then : +if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBBZ2 1 _ACEOF @@ -5448,7 +5438,7 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzCompressInit in -lbz2" >&5 $as_echo_n "checking for BZ2_bzCompressInit in -lbz2... " >&6; } -if test "${ac_cv_lib_bz2_BZ2_bzCompressInit+set}" = set; then : +if ${ac_cv_lib_bz2_BZ2_bzCompressInit+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5482,7 +5472,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzCompressInit" >&5 $as_echo "$ac_cv_lib_bz2_BZ2_bzCompressInit" >&6; } -if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = x""yes; then : +if test "x$ac_cv_lib_bz2_BZ2_bzCompressInit" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBBZ2 1 _ACEOF @@ -5510,7 +5500,7 @@ yes) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for archive_read_new in -larchive" >&5 $as_echo_n "checking for archive_read_new in -larchive... " >&6; } -if test "${ac_cv_lib_archive_archive_read_new+set}" = set; then : +if ${ac_cv_lib_archive_archive_read_new+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5544,9 +5534,9 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_archive_archive_read_new" >&5 $as_echo "$ac_cv_lib_archive_archive_read_new" >&6; } -if test "x$ac_cv_lib_archive_archive_read_new" = x""yes; then : +if test "x$ac_cv_lib_archive_archive_read_new" = xyes; then : ac_fn_c_check_header_mongrel "$LINENO" "archive.h" "ac_cv_header_archive_h" "$ac_includes_default" -if test "x$ac_cv_header_archive_h" = x""yes; then : +if test "x$ac_cv_header_archive_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBARCHIVE 1 _ACEOF @@ -5567,7 +5557,7 @@ *) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for archive_read_new in -larchive" >&5 $as_echo_n "checking for archive_read_new in -larchive... " >&6; } -if test "${ac_cv_lib_archive_archive_read_new+set}" = set; then : +if ${ac_cv_lib_archive_archive_read_new+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5601,11 +5591,11 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_archive_archive_read_new" >&5 $as_echo "$ac_cv_lib_archive_archive_read_new" >&6; } -if test "x$ac_cv_lib_archive_archive_read_new" = x""yes; then : +if test "x$ac_cv_lib_archive_archive_read_new" = xyes; then : mysave_CPPFLAGS="$CPPFLAGS" CPPFLAGS="-I$withval/include $CPPFLAGS" ac_fn_c_check_header_mongrel "$LINENO" "archive.h" "ac_cv_header_archive_h" "$ac_includes_default" -if test "x$ac_cv_header_archive_h" = x""yes; then : +if test "x$ac_cv_header_archive_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBARCHIVE 1 _ACEOF @@ -5630,7 +5620,7 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for archive_read_new in -larchive" >&5 $as_echo_n "checking for archive_read_new in -larchive... " >&6; } -if test "${ac_cv_lib_archive_archive_read_new+set}" = set; then : +if ${ac_cv_lib_archive_archive_read_new+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5664,9 +5654,9 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_archive_archive_read_new" >&5 $as_echo "$ac_cv_lib_archive_archive_read_new" >&6; } -if test "x$ac_cv_lib_archive_archive_read_new" = x""yes; then : +if test "x$ac_cv_lib_archive_archive_read_new" = xyes; then : ac_fn_c_check_header_mongrel "$LINENO" "archive.h" "ac_cv_header_archive_h" "$ac_includes_default" -if test "x$ac_cv_header_archive_h" = x""yes; then : +if test "x$ac_cv_header_archive_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBARCHIVE 1 _ACEOF @@ -5691,7 +5681,7 @@ *) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for archive_read_new in -lc" >&5 $as_echo_n "checking for archive_read_new in -lc... " >&6; } -if test "${ac_cv_lib_c_archive_read_new+set}" = set; then : +if ${ac_cv_lib_c_archive_read_new+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS @@ -5725,11 +5715,11 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_archive_read_new" >&5 $as_echo "$ac_cv_lib_c_archive_read_new" >&6; } -if test "x$ac_cv_lib_c_archive_read_new" = x""yes; then : +if test "x$ac_cv_lib_c_archive_read_new" = xyes; then : mysave_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$ARCHIVECPP $CPPFLAGS" ac_fn_c_check_header_mongrel "$LINENO" "archive.h" "ac_cv_header_archive_h" "$ac_includes_default" -if test "x$ac_cv_header_archive_h" = x""yes; then : +if test "x$ac_cv_header_archive_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBARCHIVE 1 _ACEOF @@ -5829,10 +5819,21 @@ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then - test "x$cache_file" != "x/dev/null" && + if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} - cat confcache >$cache_file + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} @@ -5889,7 +5890,7 @@ Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -: ${CONFIG_STATUS=./config.status} +: "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" @@ -5990,6 +5991,7 @@ IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. +as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -6296,8 +6298,8 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by reprepro $as_me 4.5.0, which was -generated by GNU Autoconf 2.67. Invocation command line was +This file was extended by reprepro $as_me 4.6.0, which was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -6362,8 +6364,8 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -reprepro config.status 4.5.0 -configured by $0, generated by GNU Autoconf 2.67, +reprepro config.status 4.6.0 +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" Copyright (C) 2010 Free Software Foundation, Inc. @@ -6497,7 +6499,7 @@ "docs/Makefile") CONFIG_FILES="$CONFIG_FILES docs/Makefile" ;; "tests/Makefile") CONFIG_FILES="$CONFIG_FILES tests/Makefile" ;; - *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;; + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done @@ -6520,9 +6522,10 @@ # after its creation but before its name has been assigned to `$tmp'. $debug || { - tmp= + tmp= ac_tmp= trap 'exit_status=$? - { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } @@ -6530,12 +6533,13 @@ { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" + test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. @@ -6557,7 +6561,7 @@ ac_cs_awk_cr=$ac_cr fi -echo 'BEGIN {' >"$tmp/subs1.awk" && +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF @@ -6585,7 +6589,7 @@ rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -cat >>"\$tmp/subs1.awk" <<\\_ACAWK && +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h @@ -6633,7 +6637,7 @@ rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK -cat >>"\$tmp/subs1.awk" <<_ACAWK && +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" @@ -6665,7 +6669,7 @@ sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat -fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF @@ -6699,7 +6703,7 @@ # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then -cat >"$tmp/defines.awk" <<\_ACAWK || +cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF @@ -6711,8 +6715,8 @@ # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do - ac_t=`sed -n "/$ac_delim/p" confdefs.h` - if test -z "$ac_t"; then + ac_tt=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 @@ -6813,7 +6817,7 @@ esac case $ac_mode$ac_tag in :[FHL]*:*);; - :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac @@ -6832,7 +6836,7 @@ for ac_f do case $ac_f in - -) ac_f="$tmp/stdin";; + -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. @@ -6841,7 +6845,7 @@ [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || - as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;; + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" @@ -6867,8 +6871,8 @@ esac case $ac_tag in - *:-:* | *:-) cat >"$tmp/stdin" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac @@ -7004,21 +7008,22 @@ s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " -eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && - { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && - { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} - rm -f "$tmp/stdin" + rm -f "$ac_tmp/stdin" case $ac_file in - -) cat "$tmp/out" && rm -f "$tmp/out";; - *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; @@ -7029,20 +7034,20 @@ if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" - } >"$tmp/config.h" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" + } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 - if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then + if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" - mv "$tmp/config.h" "$ac_file" \ + mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi # Compute "$ac_file"'s index in $config_headers. diff -Nru reprepro-4.5.0/configure.ac reprepro-4.6.0/configure.ac --- reprepro-4.5.0/configure.ac 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/configure.ac 2011-05-05 14:42:55.000000000 +0000 @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script dnl -AC_INIT(reprepro, 4.5.0, brlink@debian.org) +AC_INIT(reprepro, 4.6.0, brlink@debian.org) AC_CONFIG_SRCDIR(main.c) AC_CONFIG_AUX_DIR(ac) AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability]) diff -Nru reprepro-4.5.0/contents.c reprepro-4.6.0/contents.c --- reprepro-4.5.0/contents.c 2008-10-12 17:28:23.000000000 +0000 +++ reprepro-4.6.0/contents.c 2011-05-05 14:42:55.000000000 +0000 @@ -38,7 +38,10 @@ /* options are zerroed when called, when error is returned contentsopions_done * is called by the caller */ retvalue contentsoptions_parse(struct distribution *distribution, struct configiterator *iter) { - enum contentsflags { cf_disable, cf_dummy, cf_udebs, cf_nodebs, cf_uncompressed, cf_gz, cf_bz2, cf_COUNT}; + enum contentsflags { + cf_disable, cf_dummy, cf_udebs, cf_nodebs, + cf_uncompressed, cf_gz, cf_bz2, cf_COUNT + }; bool flags[cf_COUNT]; static const struct constant contentsflags[] = { {"0", cf_disable}, @@ -49,7 +52,7 @@ {".bz2", cf_bz2}, {".gz", cf_gz}, {".", cf_uncompressed}, - {NULL, -1} + {NULL, -1} }; retvalue r; @@ -58,18 +61,18 @@ memset(flags, 0, sizeof(flags)); r = config_getflags(iter, "Contents", contentsflags, flags, IGNORABLE(unknownfield), ""); - if( r == RET_ERROR_UNKNOWNFIELD ) + if (r == RET_ERROR_UNKNOWNFIELD) (void)fputs( "Note that the format of the Contents field has changed with reprepro 3.0.0.\n" "There is no longer a number needed (nor possible) there.\n", stderr); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( flags[cf_dummy] ) { + if (flags[cf_dummy]) { (void)fputs( "Warning: Contents headers in conf/distribution no longer need an\n" "rate argument. Ignoring the number there, this might cause a error\n" "future versions.\n", stderr); - } else if( flags[cf_disable] ) { + } else if (flags[cf_disable]) { (void)fputs( "Warning: Contents headers in conf/distribution no longer need an\n" "rate argument. Treating the '0' as sign to not activate Contents-\n" @@ -78,7 +81,7 @@ } #ifndef HAVE_LIBBZ2 - if( flags[cf_bz2] ) { + if (flags[cf_bz2]) { fprintf(stderr, "Warning: Ignoring request to generate .bz2'ed Contents files.\n" "(bzip2 support disabled at build time.)\n" @@ -88,12 +91,12 @@ } #endif distribution->contents.compressions = 0; - if( flags[cf_uncompressed] ) + if (flags[cf_uncompressed]) distribution->contents.compressions |= IC_FLAG(ic_uncompressed); - if( flags[cf_gz] ) + if (flags[cf_gz]) distribution->contents.compressions |= IC_FLAG(ic_gzip); #ifdef HAVE_LIBBZ2 - if( flags[cf_bz2] ) + if (flags[cf_bz2]) distribution->contents.compressions |= IC_FLAG(ic_bzip2); #endif distribution->contents.flags.udebs = flags[cf_udebs]; @@ -102,181 +105,180 @@ return RET_OK; } -static retvalue addpackagetocontents(struct database *database, UNUSED(struct distribution *di), UNUSED(struct target *ta), const char *packagename, const char *chunk, void *data) { +static retvalue addpackagetocontents(UNUSED(struct distribution *di), UNUSED(struct target *ta), const char *packagename, const char *chunk, void *data) { struct filelist_list *contents = data; retvalue r; char *section, *filekey; - r = chunk_getvalue(chunk,"Section",§ion); + r = chunk_getvalue(chunk, "Section", §ion); /* Ignoring packages without section, as they should not exist anyway */ - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - r = chunk_getvalue(chunk,"Filename",&filekey); + r = chunk_getvalue(chunk, "Filename", &filekey); /* dito with filekey */ - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(section); return r; } - r = filelist_addpackage(contents, database, - packagename, section, filekey); + r = filelist_addpackage(contents, packagename, section, filekey); free(filekey); free(section); return r; } -static retvalue genarchcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) { +static retvalue genarchcontents(struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) { retvalue r; char *contentsfilename; struct filetorelease *file; struct filelist_list *contents; const struct atomlist *components; - if( distribution->contents_components_set ) + if (distribution->contents_components_set) components = &distribution->contents_components; else components = &distribution->components; - if( components->count == 0 ) + if (components->count == 0) return RET_NOTHING; - if( onlyneeded ) { + if (onlyneeded) { struct target *target; - for( target=distribution->targets; target!=NULL; - target=target->next ) { - if( target->saved_wasmodified - && target->architecture_atom == architecture - && target->packagetype_atom == pt_deb - && atomlist_in(components, - target->component_atom) ) + for (target=distribution->targets; target!=NULL; + target=target->next) { + if (target->saved_wasmodified + && target->architecture == architecture + && target->packagetype == pt_deb + && atomlist_in(components, target->component)) break; } - if( target != NULL ) + if (target != NULL) onlyneeded = false; } - contentsfilename = mprintf("Contents-%s", atoms_architectures[architecture]); - if( FAILEDTOALLOC(contentsfilename) ) + contentsfilename = mprintf("Contents-%s", + atoms_architectures[architecture]); + if (FAILEDTOALLOC(contentsfilename)) return RET_ERROR_OOM; r = release_startfile(release, contentsfilename, distribution->contents.compressions, onlyneeded, &file); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(contentsfilename); return r; } - if( verbose > 0 ) { - printf(" generating %s...\n",contentsfilename); + if (verbose > 0) { + printf(" generating %s...\n", contentsfilename); } free(contentsfilename); r = filelist_init(&contents); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(file); return r; } - r = distribution_foreach_package_c(distribution, database, + r = distribution_foreach_package_c(distribution, components, architecture, pt_deb, addpackagetocontents, contents); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = filelist_write(contents, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) release_abortfile(file); else - r = release_finishfile(release,file); + r = release_finishfile(release, file); filelist_free(contents); return r; } -static retvalue genarchudebcontents(struct database *database, struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) { +static retvalue genarchudebcontents(struct distribution *distribution, architecture_t architecture, struct release *release, bool onlyneeded) { retvalue r; char *contentsfilename; struct filetorelease *file; struct filelist_list *contents; const struct atomlist *components; - if( distribution->contents_ucomponents_set ) + if (distribution->contents_ucomponents_set) components = &distribution->contents_ucomponents; else components = &distribution->udebcomponents; - if( components->count == 0 ) + if (components->count == 0) return RET_NOTHING; - if( onlyneeded ) { + if (onlyneeded) { struct target *target; - for( target=distribution->targets; target!=NULL; - target=target->next ) { - if( target->saved_wasmodified - && target->architecture_atom == architecture - && target->packagetype_atom == pt_udeb - && atomlist_in(components, - target->component_atom) ) + for (target=distribution->targets; target!=NULL; + target=target->next) { + if (target->saved_wasmodified + && target->architecture == architecture + && target->packagetype == pt_udeb + && atomlist_in(components, target->component)) break; } - if( target != NULL ) + if (target != NULL) onlyneeded = false; } - contentsfilename = mprintf("uContents-%s", atoms_architectures[architecture]); - if( FAILEDTOALLOC(contentsfilename) ) + contentsfilename = mprintf("uContents-%s", + atoms_architectures[architecture]); + if (FAILEDTOALLOC(contentsfilename)) return RET_ERROR_OOM; r = release_startfile(release, contentsfilename, distribution->contents.compressions, onlyneeded, &file); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(contentsfilename); return r; } - if( verbose > 0 ) { - printf(" generating %s...\n",contentsfilename); + if (verbose > 0) { + printf(" generating %s...\n", contentsfilename); } free(contentsfilename); r = filelist_init(&contents); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - r = distribution_foreach_package_c(distribution, database, + r = distribution_foreach_package_c(distribution, components, architecture, pt_udeb, addpackagetocontents, contents); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = filelist_write(contents, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) release_abortfile(file); else - r = release_finishfile(release,file); + r = release_finishfile(release, file); filelist_free(contents); return r; } -retvalue contents_generate(struct database *database, struct distribution *distribution, struct release *release, bool onlyneeded) { - retvalue result,r; +retvalue contents_generate(struct distribution *distribution, struct release *release, bool onlyneeded) { + retvalue result, r; int i; const struct atomlist *architectures; - if( distribution->contents.compressions == 0 ) + if (distribution->contents.compressions == 0) distribution->contents.compressions = IC_FLAG(ic_gzip); result = RET_NOTHING; - if( distribution->contents_architectures_set ) { + if (distribution->contents_architectures_set) { architectures = &distribution->contents_architectures; } else { architectures = &distribution->architectures; } - for( i = 0 ; i < architectures->count ; i++ ) { + for (i = 0 ; i < architectures->count ; i++) { architecture_t architecture = architectures->atoms[i]; - if( architecture == architecture_source ) + if (architecture == architecture_source) continue; - if( !distribution->contents.flags.nodebs ) { - r = genarchcontents(database, distribution, + if (!distribution->contents.flags.nodebs) { + r = genarchcontents(distribution, architecture, release, onlyneeded); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - if( distribution->contents.flags.udebs ) { - r = genarchudebcontents(database, distribution, + if (distribution->contents.flags.udebs) { + r = genarchudebcontents(distribution, architecture, release, onlyneeded); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } } return result; diff -Nru reprepro-4.5.0/contents.h reprepro-4.6.0/contents.h --- reprepro-4.5.0/contents.h 2007-09-22 11:22:59.000000000 +0000 +++ reprepro-4.6.0/contents.h 2011-05-05 14:42:55.000000000 +0000 @@ -23,7 +23,7 @@ struct distribution; struct configiterator; -retvalue contentsoptions_parse(struct distribution *distribution, struct configiterator *iter); -retvalue contents_generate(struct database *, struct distribution *, struct release *, bool onlyneeded); +retvalue contentsoptions_parse(struct distribution *, struct configiterator *); +retvalue contents_generate(struct distribution *, struct release *, bool /*onlyneeded*/); #endif diff -Nru reprepro-4.5.0/copypackages.c reprepro-4.6.0/copypackages.c --- reprepro-4.5.0/copypackages.c 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/copypackages.c 2011-05-05 14:42:55.000000000 +0000 @@ -65,11 +65,11 @@ int c; t_p = &list->targets; - while( *t_p != NULL && (*t_p)->target != target ) + while (*t_p != NULL && (*t_p)->target != target) t_p = &(*t_p)->next; - if( *t_p == NULL ) { - t = calloc(1, sizeof(struct target_package_list)); - if( FAILEDTOALLOC(t) ) + if (*t_p == NULL) { + t = zNEW(struct target_package_list); + if (FAILEDTOALLOC(t)) return RET_ERROR_OOM; t->target = target; t->next = *t_p; @@ -78,37 +78,37 @@ t = *t_p; p_p = &t->packages; - while( *p_p != NULL && ( c = strcmp(packagename, (*p_p)->name) ) < 0 ) + while (*p_p != NULL && (c = strcmp(packagename, (*p_p)->name)) < 0) p_p = &(*p_p)->next; - if( *p_p != NULL && c == 0 ) { + if (*p_p != NULL && c == 0) { // TODO: improve this message..., or some context elsewhere fprintf(stderr, "Multiple occurences of package '%s'!\n", packagename); return RET_ERROR_EXIST; } - package = calloc(1, sizeof(struct package)); - if( FAILEDTOALLOC(package) ) + package = zNEW(struct package); + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; package->name = strdup(packagename); - if( FAILEDTOALLOC(package->name) ) { + if (FAILEDTOALLOC(package->name)) { free(package); return RET_ERROR_OOM; } package->version = strdup(packageversion); - if( FAILEDTOALLOC(package->version) ) { + if (FAILEDTOALLOC(package->version)) { free(package->name); free(package); return RET_ERROR_OOM; } package->sourcename = strdup(sourcename); - if( FAILEDTOALLOC(package->sourcename) ) { + if (FAILEDTOALLOC(package->sourcename)) { free(package->name); free(package->version); free(package); return RET_ERROR_OOM; } package->sourceversion = strdup(sourceversion); - if( FAILEDTOALLOC(package->sourceversion) ) { + if (FAILEDTOALLOC(package->sourceversion)) { free(package->name); free(package->version); free(package->sourcename); @@ -122,7 +122,7 @@ } static void package_free(/*@only@*/struct package *package) { - if( package == NULL ) + if (package == NULL) return; free(package->name); @@ -139,39 +139,39 @@ struct target_package_list *target; struct package **p_p; - assert( package != NULL ); + assert (package != NULL); - for( target = list->targets ; target != NULL ; target = target->next ) { + for (target = list->targets ; target != NULL ; target = target->next) { p_p = &target->packages; - while( *p_p != NULL && *p_p != package ) + while (*p_p != NULL && *p_p != package) p_p = &(*p_p)->next; - if( *p_p == package ) { + if (*p_p == package) { *p_p = package->next; package_free(package); return; } } - assert( package == NULL ); + assert (package == NULL); } -static retvalue list_prepareadd(struct database *database, struct package_list *list, struct target *target, const char *packagename, /*@null@*/const char *v, architecture_t package_architecture, const char *chunk) { +static retvalue list_prepareadd(struct package_list *list, struct target *target, const char *packagename, /*@null@*/const char *v, architecture_t package_architecture, const char *chunk) { char *version; char *source, *sourceversion; struct package *new IFSTUPIDCC(=NULL); retvalue r; int i; - if( v == NULL ) { + if (v == NULL) { r = target->getversion(chunk, &version); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { return r; } } r = target->getsourceandversion(chunk, packagename, &source, &sourceversion); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(version); return r; } @@ -179,34 +179,34 @@ packagename, (v==NULL)?version:v, &new); free(source); source = NULL; free(sourceversion); sourceversion = NULL; - if( v == NULL ) free(version); version = NULL; - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + if (v == NULL) free(version); version = NULL; + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; new->architecture = package_architecture; r = target->getinstalldata(target, new->name, new->version, package_architecture, chunk, &new->control, &new->filekeys, &new->origfiles); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { list_cancelpackage(list, new); return r; } - assert( new->filekeys.count == new->origfiles.names.count ); - for( i = 0 ; i < new->filekeys.count ; i++ ) { + assert (new->filekeys.count == new->origfiles.names.count); + for (i = 0 ; i < new->filekeys.count ; i++) { const char *newfilekey = new->filekeys.values[i]; const char *oldfilekey = new->origfiles.names.values[i]; const struct checksums *checksums = new->origfiles.checksums[i]; - r = files_canadd(database, newfilekey, checksums); + r = files_canadd(newfilekey, checksums); /* normaly it should just already have that file, * in which case we have nothing to do: */ - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; /* otherwise try to cope with it */ - if( r == RET_ERROR_WRONG_MD5 ) { - if( strcmp(newfilekey, oldfilekey) == 0 ) { + if (r == RET_ERROR_WRONG_MD5) { + if (strcmp(newfilekey, oldfilekey) == 0) { fprintf(stderr, "Error: package %s version %s lists different checksums than in the pool!\n", new->name, new->version); @@ -218,12 +218,12 @@ newfilekey, oldfilekey); } } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { list_cancelpackage(list, new); return r; } - assert( RET_IS_OK(r) ); - if( strcmp(newfilekey, oldfilekey) == 0 ) { + assert (RET_IS_OK(r)); + if (strcmp(newfilekey, oldfilekey) == 0) { fprintf(stderr, "Error: package %s version %s lists file %s not yet in the pool!\n", new->name, new->version, newfilekey); @@ -248,31 +248,30 @@ return RET_OK; } -static retvalue package_add(struct database *database, struct distribution *into, /*@null@*/trackingdb tracks, struct target *target, const struct package *package, /*@null@*/ const char *suitefrom) { +static retvalue package_add(struct distribution *into, /*@null@*/trackingdb tracks, struct target *target, const struct package *package, /*@null@*/ const char *suitefrom) { struct trackingdata trackingdata; retvalue r; - if( verbose >= 1 ) { + if (verbose >= 1) { printf("Adding '%s' '%s' to '%s'.\n", package->name, package->version, target->identifier); } - r = files_expectfiles(database, - &package->filekeys, + r = files_expectfiles(&package->filekeys, package->origfiles.checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - if( tracks != NULL ) { + if (tracks != NULL) { r = trackingdata_summon(tracks, package->sourcename, package->version, &trackingdata); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } r = target_addpackage(target, - into->logger, database, + into->logger, package->name, package->version, package->control, &package->filekeys, true, @@ -281,43 +280,43 @@ package->architecture, NULL, suitefrom); RET_UPDATE(into->status, r); - if( tracks != NULL ) { + if (tracks != NULL) { retvalue r2; - r2 = trackingdata_finish(tracks, &trackingdata, - database); + r2 = trackingdata_finish(tracks, &trackingdata); RET_ENDUPDATE(r, r2); } return r; } -static retvalue packagelist_add(struct database *database, struct distribution *into, const struct package_list *list, /*@null@*/const char *suitefrom) { +static retvalue packagelist_add(struct distribution *into, const struct package_list *list, /*@null@*/const char *suitefrom) { retvalue result, r; struct target_package_list *tpl; struct package *package; trackingdb tracks; r = distribution_prepareforwriting(into); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( into->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, into, false); - if( RET_WAS_ERROR(r) ) + if (into->tracking != dt_NONE) { + r = tracking_initialize(&tracks, into, false); + if (RET_WAS_ERROR(r)) return r; } else tracks = NULL; result = RET_NOTHING; - for( tpl = list->targets; tpl != NULL ; tpl = tpl->next ) { + for (tpl = list->targets; tpl != NULL ; tpl = tpl->next) { struct target *target = tpl->target; - r = target_initpackagesdb(target, database, READWRITE); + r = target_initpackagesdb(target, READWRITE); RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - for( package = tpl->packages; package != NULL ; package = package->next ) { - r = package_add(database, into, tracks, target, + for (package = tpl->packages; package != NULL ; + package = package->next) { + r = package_add(into, tracks, target, package, suitefrom); RET_UPDATE(result, r); } @@ -330,31 +329,31 @@ return result; } -static retvalue copy_by_func(struct package_list *list, struct database *database, struct distribution *into, struct distribution *from, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, retvalue action(struct package_list*, struct database *, struct distribution *, struct distribution *, struct target *, struct target *, void *), void *data) { +static retvalue copy_by_func(struct package_list *list, struct distribution *into, struct distribution *from, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, retvalue action(struct package_list*, struct distribution *, struct distribution *, struct target *, struct target *, void *), void *data) { retvalue result, r; struct target *origtarget, *desttarget; result = RET_NOTHING; - for( origtarget = from->targets ; origtarget != NULL ; - origtarget = origtarget->next ) { - if( !target_matches(origtarget, - components, architectures, packagetypes) ) + for (origtarget = from->targets ; origtarget != NULL ; + origtarget = origtarget->next) { + if (!target_matches(origtarget, + components, architectures, packagetypes)) continue; desttarget = distribution_gettarget(into, - origtarget->component_atom, - origtarget->architecture_atom, - origtarget->packagetype_atom); - if( desttarget == NULL ) { - if( verbose > 2 ) + origtarget->component, + origtarget->architecture, + origtarget->packagetype); + if (desttarget == NULL) { + if (verbose > 2) printf( "Not looking into '%s' as no matching target in '%s'!\n", origtarget->identifier, into->codename); continue; } - r = action(list, database, into, from, desttarget, origtarget, data); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) + r = action(list, into, from, desttarget, origtarget, data); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) return result; } return result; @@ -367,26 +366,28 @@ bool *found; }; -static retvalue by_name(struct package_list *list, struct database *database, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { +static retvalue by_name(struct package_list *list, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { struct namelist *d = data; retvalue result, r; int i, j; - r = target_initpackagesdb(fromtarget, database, READONLY); - if( RET_WAS_ERROR(r) ) + r = target_initpackagesdb(fromtarget, READONLY); + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - for( i = 0 ; i < d->argc ; i++ ) { + for (i = 0 ; i < d->argc ; i++) { const char *name = d->argv[i]; char *chunk; architecture_t package_architecture; - for( j = 0 ; j < i ; j++ ) - if( strcmp(d->argv[i], d->argv[j]) == 0 ) + for (j = 0 ; j < i ; j++) + if (strcmp(d->argv[i], d->argv[j]) == 0) break; - if( j < i ) { - if( verbose >= 0 && ! d->warnedabout[j]) - fprintf(stderr, "Hint: '%s' was listed multiple times, ignoring all but first!\n", d->argv[i]); + if (j < i) { + if (verbose >= 0 && ! d->warnedabout[j]) + fprintf(stderr, +"Hint: '%s' was listed multiple times, ignoring all but first!\n", + d->argv[i]); d->warnedabout[j] = true; /* do not complain second is missing if we ignore it: */ d->found[i] = true; @@ -394,20 +395,20 @@ } r = table_getrecord(fromtarget->packages, name, &chunk); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; r = fromtarget->getarchitecture(chunk, &package_architecture); RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - r = list_prepareadd(database, list, desttarget, + r = list_prepareadd(list, desttarget, name, NULL, package_architecture, chunk); free(chunk); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; d->found[i] = true; } @@ -420,10 +421,10 @@ struct target_package_list *target; struct package *package; - while( (target = list->targets) != NULL ) { + while ((target = list->targets) != NULL) { list->targets = target->next; - while( (package = target->packages) != NULL ) { + while ((package = target->packages) != NULL) { target->packages = package->next; package_free(package); @@ -432,114 +433,117 @@ } } -retvalue copy_by_name(struct database *database, struct distribution *into, struct distribution *from, int argc, const char **argv, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { +retvalue copy_by_name(struct distribution *into, struct distribution *from, int argc, const char **argv, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { struct package_list list; - struct namelist names = { argc, argv, calloc(argc, sizeof(bool)), - calloc(argc, sizeof(bool))}; + struct namelist names = { + argc, argv, nzNEW(argc, bool), nzNEW(argc, bool) + }; retvalue r; - if( FAILEDTOALLOC(names.warnedabout) || FAILEDTOALLOC(names.found) ) { + if (FAILEDTOALLOC(names.warnedabout) || FAILEDTOALLOC(names.found)) { free(names.found); free(names.warnedabout); return RET_ERROR_OOM; } memset(&list, 0, sizeof(list)); - r = copy_by_func(&list, database, into, from, components, architectures, packagetypes, by_name, &names); + r = copy_by_func(&list, into, from, components, + architectures, packagetypes, by_name, &names); free(names.warnedabout); - if( verbose >= 0 && !RET_WAS_ERROR(r) ) { + if (verbose >= 0 && !RET_WAS_ERROR(r)) { int i; bool first = true; assert(names.found != NULL); - for( i = 0 ; i < argc ; i++ ) { - if( names.found[i] ) + for (i = 0 ; i < argc ; i++) { + if (names.found[i]) continue; - if( first ) - (void)fputs("Will not copy as not found: ", stderr); + if (first) + (void)fputs( +"Will not copy as not found: ", stderr); else (void)fputs(", ", stderr); first = false; (void)fputs(argv[i], stderr); } - if( !first ) { + if (!first) { (void)fputc('.', stderr); (void)fputc('\n', stderr); } } free(names.found); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - r = packagelist_add(database, into, &list, from->codename); + r = packagelist_add(into, &list, from->codename); packagelist_done(&list); return r; } -static retvalue by_source(struct package_list *list, struct database *database, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { +static retvalue by_source(struct package_list *list, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { struct namelist *d = data; struct target_cursor iterator IFSTUPIDCC(=TARGET_CURSOR_ZERO); const char *packagename, *chunk; retvalue result, r; - assert( d->argc > 0 ); + assert (d->argc > 0); - r = target_openiterator(fromtarget, database, READONLY, &iterator); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) + r = target_openiterator(fromtarget, READONLY, &iterator); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &packagename, &chunk) ) { + while (target_nextpackage(&iterator, &packagename, &chunk)) { int i; char *source, *sourceversion; architecture_t package_architecture; r = fromtarget->getsourceandversion(chunk, packagename, &source, &sourceversion); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } /* only include if source name matches */ - if( strcmp(source, d->argv[0]) != 0 ) { + if (strcmp(source, d->argv[0]) != 0) { free(source); free(sourceversion); continue; } i = 0; - if( d->argc > 1 ) { + if (d->argc > 1) { int c; i = d->argc; - while( --i > 0 ) { + while (--i > 0) { r = dpkgversions_cmp(sourceversion, d->argv[i], &c); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(source); free(sourceversion); (void)target_closeiterator(&iterator); return r; } - if( c == 0 ) + if (c == 0) break; } /* there are source versions specified and * the source version of this package differs */ - if( i == 0 ) { + if (i == 0) { free(source); free(sourceversion); continue; } } free(source); free(sourceversion); r = fromtarget->getarchitecture(chunk, &package_architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - r = list_prepareadd(database, list, desttarget, + r = list_prepareadd(list, desttarget, packagename, NULL, package_architecture, chunk); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; d->found[0] = true; d->found[i] = true; @@ -549,67 +553,69 @@ return result; } -retvalue copy_by_source(struct database *database, struct distribution *into, struct distribution *from, int argc, const char **argv, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { +retvalue copy_by_source(struct distribution *into, struct distribution *from, int argc, const char **argv, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { struct package_list list; - struct namelist names = { argc, argv, NULL, calloc(argc, sizeof(bool)) }; + struct namelist names = { argc, argv, NULL, nzNEW(argc, bool) }; retvalue r; - if( FAILEDTOALLOC(names.found) ) { + if (FAILEDTOALLOC(names.found)) { free(names.found); return RET_ERROR_OOM; } memset(&list, 0, sizeof(list)); // TODO: implement fast way by looking at source tracking // (also allow copying .changes and .logs) - r = copy_by_func(&list, database, into, from, components, architectures, packagetypes, by_source, &names); - if( argc == 1 && !RET_WAS_ERROR(r) && verbose >= 0 ) { + r = copy_by_func(&list, into, from, components, architectures, + packagetypes, by_source, &names); + if (argc == 1 && !RET_WAS_ERROR(r) && verbose >= 0) { assert(names.found != NULL); - if( !names.found[0] ) { - assert( r == RET_NOTHING ); + if (!names.found[0]) { + assert (r == RET_NOTHING); fprintf(stderr, "Nothing to do as no package with source '%s' found!\n", argv[0]); free(names.found); return RET_NOTHING; } - } else if( !RET_WAS_ERROR(r) && verbose >= 0 ) { + } else if (!RET_WAS_ERROR(r) && verbose >= 0) { int i; bool first = true, anything = false; - for( i = 1 ; i < argc ; i++ ) { - if( names.found[i] ) + for (i = 1 ; i < argc ; i++) { + if (names.found[i]) anything = true; } - if( !anything ) { - assert( r == RET_NOTHING ); + if (!anything) { + assert (r == RET_NOTHING); fprintf(stderr, "Nothing to do as no packages with source '%s' and a requested source version found!\n", argv[0]); free(names.found); return RET_NOTHING; } - for( i = 1 ; i < argc ; i++ ) { - if( names.found[i] ) + for (i = 1 ; i < argc ; i++) { + if (names.found[i]) continue; - if( first ) - (void)fputs("Will not copy as not found: ", stderr); + if (first) + (void)fputs( +"Will not copy as not found: ", stderr); else (void)fputs(", ", stderr); first = false; (void)fputs(argv[i], stderr); } - if( !first ) { + if (!first) { (void)fputc('.', stderr); (void)fputc('\n', stderr); } - if( verbose > 5 ) { + if (verbose > 5) { (void)fputs("Found versions are: ", stderr); first = true; - for( i = 1 ; i < argc ; i++ ) { - if( !names.found[i] ) + for (i = 1 ; i < argc ; i++) { + if (!names.found[i]) continue; - if( !first ) + if (!first) (void)fputs(", ", stderr); first = false; (void)fputs(argv[i], stderr); @@ -619,42 +625,42 @@ } } free(names.found); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - r = packagelist_add(database, into, &list, from->codename); + r = packagelist_add(into, &list, from->codename); packagelist_done(&list); return r; } -static retvalue by_formula(struct package_list *list, struct database *database, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { +static retvalue by_formula(struct package_list *list, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { term *condition = data; struct target_cursor iterator IFSTUPIDCC(=TARGET_CURSOR_ZERO); const char *packagename, *chunk; architecture_t package_architecture; retvalue result, r; - r = target_openiterator(fromtarget, database, READONLY, &iterator); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) + r = target_openiterator(fromtarget, READONLY, &iterator); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &packagename, &chunk) ) { - r = term_decidechunktarget(condition, chunk, desttarget ); - if( r == RET_NOTHING ) + while (target_nextpackage(&iterator, &packagename, &chunk)) { + r = term_decidechunktarget(condition, chunk, desttarget); + if (r == RET_NOTHING) continue; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } r = fromtarget->getarchitecture(chunk, &package_architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - r = list_prepareadd(database, list, desttarget, + r = list_prepareadd(list, desttarget, packagename, NULL, package_architecture, chunk); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } r = target_closeiterator(&iterator); @@ -662,30 +668,30 @@ return result; } -static retvalue by_glob(struct package_list *list, struct database *database, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { +static retvalue by_glob(struct package_list *list, UNUSED(struct distribution *into), UNUSED(struct distribution *from), struct target *desttarget, struct target *fromtarget, void *data) { const char *glob = data; struct target_cursor iterator IFSTUPIDCC(=TARGET_CURSOR_ZERO); const char *packagename, *chunk; architecture_t package_architecture; retvalue result, r; - r = target_openiterator(fromtarget, database, READONLY, &iterator); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) + r = target_openiterator(fromtarget, READONLY, &iterator); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &packagename, &chunk) ) { - if( !globmatch(packagename, glob) ) + while (target_nextpackage(&iterator, &packagename, &chunk)) { + if (!globmatch(packagename, glob)) continue; r = fromtarget->getarchitecture(chunk, &package_architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - r = list_prepareadd(database, list, desttarget, + r = list_prepareadd(list, desttarget, packagename, NULL, package_architecture, chunk); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } r = target_closeiterator(&iterator); @@ -693,21 +699,22 @@ return result; } -retvalue copy_by_glob(struct database *database, struct distribution *into, struct distribution *from, const char *glob, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { +retvalue copy_by_glob(struct distribution *into, struct distribution *from, const char *glob, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { struct package_list list; retvalue r; memset(&list, 0, sizeof(list)); - r = copy_by_func(&list, database, into, from, components, architectures, packagetypes, by_glob, (void*)glob); - if( !RET_IS_OK(r) ) + r = copy_by_func(&list, into, from, components, architectures, + packagetypes, by_glob, (void*)glob); + if (!RET_IS_OK(r)) return r; - r = packagelist_add(database, into, &list, from->codename); + r = packagelist_add(into, &list, from->codename); packagelist_done(&list); return r; } -retvalue copy_by_formula(struct database *database, struct distribution *into, struct distribution *from, const char *filter, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { +retvalue copy_by_formula(struct distribution *into, struct distribution *from, const char *filter, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { struct package_list list; term *condition; retvalue r; @@ -715,14 +722,15 @@ memset(&list, 0, sizeof(list)); r = term_compilefortargetdecision(&condition, filter); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { return r; } - r = copy_by_func(&list, database, into, from, components, architectures, packagetypes, by_formula, condition); + r = copy_by_func(&list, into, from, components, architectures, + packagetypes, by_formula, condition); term_free(condition); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - r = packagelist_add(database, into, &list, from->codename); + r = packagelist_add(into, &list, from->codename); packagelist_done(&list); return r; } @@ -731,11 +739,11 @@ const struct namelist *l = privdata; int i; - for( i = 0 ; i < l->argc ; i++ ) { - if( strcmp(packagename, l->argv[i]) == 0 ) + for (i = 0 ; i < l->argc ; i++) { + if (strcmp(packagename, l->argv[i]) == 0) break; } - if( i >= l->argc ) + if (i >= l->argc) return RET_NOTHING; return RET_OK; } @@ -748,33 +756,33 @@ // TODO: why doesn't this use version? r = target->getsourceandversion(chunk, packagename, &source, &sourceversion); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { return r; } - assert( l->argc > 0 ); + assert (l->argc > 0); /* only include if source name matches */ - if( strcmp(source, l->argv[0]) != 0 ) { + if (strcmp(source, l->argv[0]) != 0) { free(source); free(sourceversion); return RET_NOTHING; } - if( l->argc > 1 ) { + if (l->argc > 1) { int i, c; i = l->argc; - while( --i > 0 ) { + while (--i > 0) { r = dpkgversions_cmp(sourceversion, l->argv[i], &c); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(source); free(sourceversion); return r; } - if( c == 0 ) + if (c == 0) break; } /* there are source versions specified and * the source version of this package differs */ - if( i == 0 ) { + if (i == 0) { free(source); free(sourceversion); return RET_NOTHING; } @@ -792,13 +800,13 @@ static retvalue choose_by_glob(UNUSED(struct target *target), const char *packagename, UNUSED(const char *version), UNUSED(const char *chunk), void *privdata) { const char *glob = privdata; - if( globmatch(packagename, glob) ) + if (globmatch(packagename, glob)) return RET_OK; else return RET_NOTHING; } -retvalue copy_from_file(struct database *database, struct distribution *into, component_t component_atom, architecture_t architecture_atom, packagetype_t packagetype_atom, const char *filename, int argc, const char **argv) { +retvalue copy_from_file(struct distribution *into, component_t component, architecture_t architecture, packagetype_t packagetype, const char *filename, int argc, const char **argv) { struct indexfile *i; retvalue result, r; struct target *target; @@ -808,29 +816,33 @@ architecture_t package_architecture; const char *control; - assert( atom_defined(architecture_atom) ); - assert( atom_defined(component_atom) ); - assert( atom_defined(packagetype_atom) ); + assert (atom_defined(architecture)); + assert (atom_defined(component)); + assert (atom_defined(packagetype)); memset(&list, 0, sizeof(list)); target = distribution_gettarget(into, - component_atom, architecture_atom, packagetype_atom); - if( target == NULL ) { - if( !atomlist_in(&into->architectures, architecture_atom) ) { - fprintf(stderr, "Distribution '%s' does not contain architecture '%s!'\n", - into->codename, atoms_architectures[architecture_atom]); + component, architecture, packagetype); + if (target == NULL) { + if (!atomlist_in(&into->architectures, architecture)) { + fprintf(stderr, +"Distribution '%s' does not contain architecture '%s!'\n", + into->codename, + atoms_architectures[architecture]); } - if( packagetype_atom != pt_udeb ) { - if( !atomlist_in(&into->components, component_atom) ) { + if (packagetype != pt_udeb) { + if (!atomlist_in(&into->components, component)) { fprintf(stderr, "Distribution '%s' does not contain component '%s!'\n", - into->codename, atoms_components[component_atom]); + into->codename, + atoms_components[component]); } } else { - if( !atomlist_in(&into->udebcomponents, component_atom) ) { + if (!atomlist_in(&into->udebcomponents, component)) { fprintf(stderr, "Distribution '%s' does not contain udeb component '%s!'\n", - into->codename, atoms_components[component_atom]); + into->codename, + atoms_components[component]); } } /* -A source needing -T dsc and vice versa already checked @@ -841,34 +853,34 @@ return RET_ERROR; } result = indexfile_open(&i, filename, c_none); - if( !RET_IS_OK(result) ) + if (!RET_IS_OK(result)) return result; result = RET_NOTHING; - while( indexfile_getnext(i, &packagename, &version, &control, - &package_architecture, target, false) ) { + while (indexfile_getnext(i, &packagename, &version, &control, + &package_architecture, target, false)) { r = choose_by_name(target, packagename, version, control, &d); - if( RET_IS_OK(r) ) - r = list_prepareadd(database, &list, target, + if (RET_IS_OK(r)) + r = list_prepareadd(&list, target, packagename, version, package_architecture, control); free(packagename); free(version); RET_UPDATE(result, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } r = indexfile_close(i); RET_ENDUPDATE(result, r); - if( RET_IS_OK(result) ) - result = packagelist_add(database, into, &list, NULL); + if (RET_IS_OK(result)) + result = packagelist_add(into, &list, NULL); packagelist_done(&list); return result; } typedef retvalue chooseaction(struct target *, const char *, const char *, const char *, void *); -static retvalue restore_from_snapshot(struct database *database, struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, chooseaction action, void *d) { +static retvalue restore_from_snapshot(struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, chooseaction action, void *d) { retvalue result, r; struct package_list list; struct target *target; @@ -877,19 +889,19 @@ architecture_t package_architecture; basedir = calc_snapshotbasedir(into->codename, snapshotname); - if( FAILEDTOALLOC(basedir) ) + if (FAILEDTOALLOC(basedir)) return RET_ERROR_OOM; memset(&list, 0, sizeof(list)); result = RET_NOTHING; - for( target = into->targets ; target != NULL ; - target = target->next ) { + for (target = into->targets ; target != NULL ; + target = target->next) { char *filename, *packagename, *version; const char *control; struct indexfile *i; - if( !target_matches(target, - components, architectures, packagetypes) ) + if (!target_matches(target, + components, architectures, packagetypes)) continue; /* we do not know what compressions where used back then @@ -901,7 +913,7 @@ filename = calc_dirconcat3( basedir, target->relativedirectory, target->exportmode->filename); - if( filename != NULL && !isregularfile(filename) ) { + if (filename != NULL && !isregularfile(filename)) { /* no uncompressed file found, try .gz */ free(filename); compression = c_gzip; @@ -910,7 +922,7 @@ target->exportmode->filename); } #ifdef HAVE_LIBBZ2 - if( filename != NULL && !isregularfile(filename) ) { + if (filename != NULL && !isregularfile(filename)) { /* no uncompressed or .gz file found, try .bz2 */ free(filename); compression = c_bzip2; @@ -919,7 +931,7 @@ target->exportmode->filename); } #endif - if( filename != NULL && !isregularfile(filename) ) { + if (filename != NULL && !isregularfile(filename)) { free(filename); fprintf(stderr, "Could not find '%s/%s/%s' nor '%s/%s/%s.gz',\n" @@ -930,72 +942,72 @@ target->exportmode->filename); continue; } - if( FAILEDTOALLOC(filename) ) { + if (FAILEDTOALLOC(filename)) { result = RET_ERROR_OOM; break; } result = indexfile_open(&i, filename, compression); - if( !RET_IS_OK(result) ) + if (!RET_IS_OK(result)) break; - while( indexfile_getnext(i, &packagename, &version, &control, + while (indexfile_getnext(i, &packagename, &version, &control, &package_architecture, - target, false) ) { + target, false)) { result = action(target, packagename, version, control, d); - if( RET_IS_OK(result) ) - result = list_prepareadd(database, &list, target, - packagename, version, + if (RET_IS_OK(result)) + result = list_prepareadd(&list, + target, packagename, version, package_architecture, control); free(packagename); free(version); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } r = indexfile_close(i); RET_ENDUPDATE(result, r); free(filename); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } free(basedir); - if( !RET_IS_OK(result) ) + if (!RET_IS_OK(result)) return result; - r = packagelist_add(database, into, &list, snapshotname); + r = packagelist_add(into, &list, snapshotname); packagelist_done(&list); return r; } -retvalue restore_by_name(struct database *database, struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, int argc, const char **argv) { +retvalue restore_by_name(struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, int argc, const char **argv) { struct namelist d = {argc, argv, NULL, NULL}; - return restore_from_snapshot(database, into, + return restore_from_snapshot(into, components, architectures, packagetypes, snapshotname, choose_by_name, &d); } -retvalue restore_by_source(struct database *database, struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, int argc, const char **argv) { +retvalue restore_by_source(struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, int argc, const char **argv) { struct namelist d = {argc, argv, NULL, NULL}; - return restore_from_snapshot(database, into, + return restore_from_snapshot(into, components, architectures, packagetypes, snapshotname, choose_by_source, &d); } -retvalue restore_by_formula(struct database *database, struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, const char *filter) { +retvalue restore_by_formula(struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, const char *filter) { term *condition; retvalue r; r = term_compilefortargetdecision(&condition, filter); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { return r; } - r = restore_from_snapshot(database, into, + r = restore_from_snapshot(into, components, architectures, packagetypes, snapshotname, choose_by_condition, condition); term_free(condition); return r; } -retvalue restore_by_glob(struct database *database, struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, const char *glob) { - return restore_from_snapshot(database, into, +retvalue restore_by_glob(struct distribution *into, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, const char *snapshotname, const char *glob) { + return restore_from_snapshot(into, components, architectures, packagetypes, snapshotname, choose_by_glob, (void*)glob); } diff -Nru reprepro-4.5.0/copypackages.h reprepro-4.6.0/copypackages.h --- reprepro-4.5.0/copypackages.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/copypackages.h 2011-05-05 14:42:55.000000000 +0000 @@ -5,17 +5,17 @@ #include "strlist.h" #endif -retvalue copy_by_name(struct database *, struct distribution *into, struct distribution *from, int, const char **, const struct atomlist *, const struct atomlist *, const struct atomlist *); -retvalue copy_by_source(struct database *, struct distribution *into, struct distribution *from, int, const char **, const struct atomlist *, const struct atomlist *, const struct atomlist *); -retvalue copy_by_formula(struct database *, struct distribution *into, struct distribution *from, const char *formula, const struct atomlist *, const struct atomlist *, const struct atomlist *); -retvalue copy_by_glob(struct database *, struct distribution *into, struct distribution *from, const char *glob, const struct atomlist *, const struct atomlist *, const struct atomlist *); +retvalue copy_by_name(struct distribution * /*into*/, struct distribution * /*from*/, int, const char **, const struct atomlist *, const struct atomlist *, const struct atomlist *); +retvalue copy_by_source(struct distribution * /*into*/, struct distribution * /*from*/, int, const char **, const struct atomlist *, const struct atomlist *, const struct atomlist *); +retvalue copy_by_formula(struct distribution * /*into*/, struct distribution * /*from*/, const char *formula, const struct atomlist *, const struct atomlist *, const struct atomlist *); +retvalue copy_by_glob(struct distribution * /*into*/, struct distribution * /*from*/, const char * /*glob*/, const struct atomlist *, const struct atomlist *, const struct atomlist *); -retvalue copy_from_file(struct database *, struct distribution *into, component_t, architecture_t, packagetype_t, const char *filename, int, const char **); +retvalue copy_from_file(struct distribution * /*into*/, component_t, architecture_t, packagetype_t, const char * /*filename*/ , int, const char **); /* note that snapshotname must live till logger_wait has run */ -retvalue restore_by_name(struct database *, struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char *snapshotname, int, const char **); -retvalue restore_by_source(struct database *, struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char *snapshotname, int, const char **); -retvalue restore_by_formula(struct database *, struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char *snapshotname, const char *filter); -retvalue restore_by_glob(struct database *, struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char *snapshotname, const char *glob); +retvalue restore_by_name(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char * /*snapshotname*/, int, const char **); +retvalue restore_by_source(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char * /*snapshotname*/, int, const char **); +retvalue restore_by_formula(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char * /*snapshotname*/, const char *filter); +retvalue restore_by_glob(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, const char * /*snapshotname*/, const char * /*glob*/); #endif diff -Nru reprepro-4.5.0/database.c reprepro-4.6.0/database.c --- reprepro-4.5.0/database.c 2011-02-09 14:20:21.000000000 +0000 +++ reprepro-4.6.0/database.c 2011-05-05 14:50:43.000000000 +0000 @@ -52,14 +52,32 @@ #define SETDBT(dbt, datastr) {const char *my = datastr; memset(&dbt, 0, sizeof(dbt)); dbt.data = (void *)my; dbt.size = strlen(my) + 1;} #define SETDBTl(dbt, datastr, datasize) {const char *my = datastr; memset(&dbt, 0, sizeof(dbt)); dbt.data = (void *)my; dbt.size = datasize;} -static void database_free(/*@only@*/ struct database *db) { - if( db == NULL ) +static bool rdb_initialized, rdb_used, rdb_locked, rdb_verbose; +static int rdb_dircreationdepth; +static bool rdb_nopackages, rdb_readonly; +static bool rdb_packagesdatabaseopen; +static bool rdb_trackingdatabaseopen; +static /*@null@*/ char *rdb_version, *rdb_lastsupportedversion, + *rdb_dbversion, *rdb_lastsupporteddbversion; + +struct table *rdb_checksums, *rdb_contents; +struct table *rdb_references; +static struct { + bool createnewtables; +} rdb_capabilities; + +static void database_free(void) { + if (!rdb_initialized) return; - free(db->version); - free(db->lastsupportedversion); - free(db->dbversion); - free(db->lastsupporteddbversion); - free(db); + free(rdb_version); + rdb_version = NULL; + free(rdb_lastsupportedversion); + rdb_lastsupportedversion = NULL; + free(rdb_dbversion); + rdb_dbversion = NULL; + free(rdb_lastsupporteddbversion); + rdb_lastsupporteddbversion = NULL; + rdb_initialized = false; } static inline char *dbfilename(const char *filename) { @@ -70,33 +88,38 @@ /* lock file handling */ /**********************/ -static retvalue database_lock(struct database *db, size_t waitforlock) { +static retvalue database_lock(size_t waitforlock) { char *lockfile; int fd; retvalue r; size_t tries = 0; - assert( !db->locked ); - db->dircreationdepth = 0; - r = dir_create_needed(global.dbdir, &db->dircreationdepth); - if( RET_WAS_ERROR(r) ) + assert (!rdb_locked); + rdb_dircreationdepth = 0; + r = dir_create_needed(global.dbdir, &rdb_dircreationdepth); + if (RET_WAS_ERROR(r)) return r; lockfile = dbfilename("lockfile"); - if( lockfile == NULL ) + if (FAILEDTOALLOC(lockfile)) return RET_ERROR_OOM; - fd = open(lockfile,O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY,S_IRUSR|S_IWUSR); - while( fd < 0 ) { + fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY, + S_IRUSR|S_IWUSR); + while (fd < 0) { int e = errno; - if( e == EEXIST ) { - if( tries < waitforlock && ! interrupted() ) { + if (e == EEXIST) { + if (tries < waitforlock && ! interrupted()) { unsigned int timetosleep = 10; - if( verbose >= 0 ) - printf("Could not aquire lock: %s already exists!\nWaiting 10 seconds before trying again.\n", lockfile); - while( timetosleep > 0 ) + if (verbose >= 0) + printf( +"Could not aquire lock: %s already exists!\nWaiting 10 seconds before trying again.\n", + lockfile); + while (timetosleep > 0) timetosleep = sleep(timetosleep); tries++; - fd = open(lockfile,O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY,S_IRUSR|S_IWUSR); + fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL + |O_NOFOLLOW|O_NOCTTY, + S_IRUSR|S_IWUSR); continue; } @@ -107,78 +130,80 @@ "you are sure no other version is still running!\n", lockfile); } else - fprintf(stderr, "Error %d creating lock file '%s': %s!\n", + fprintf(stderr, +"Error %d creating lock file '%s': %s!\n", e, lockfile, strerror(e)); free(lockfile); return RET_ERRNO(e); } // TODO: do some more locking of this file to avoid problems // with the non-atomity of O_EXCL with nfs-filesystems... - if( close(fd) != 0 ) { + if (close(fd) != 0) { int e = errno; - fprintf(stderr, "(Late) Error %d creating lock file '%s': %s!\n", + fprintf(stderr, +"(Late) Error %d creating lock file '%s': %s!\n", e, lockfile, strerror(e)); (void)unlink(lockfile); free(lockfile); return RET_ERRNO(e); } free(lockfile); - db->locked = true; + rdb_locked = true; return RET_OK; } -static void releaselock(struct database *db) { +static void releaselock(void) { char *lockfile; - assert( db->locked ); + assert (rdb_locked); lockfile = dbfilename("lockfile"); - if( lockfile == NULL ) + if (lockfile == NULL) return; - if( unlink(lockfile) != 0 ) { + if (unlink(lockfile) != 0) { int e = errno; fprintf(stderr, "Error %d deleting lock file '%s': %s!\n", e, lockfile, strerror(e)); (void)unlink(lockfile); } free(lockfile); - dir_remove_new(global.dbdir, db->dircreationdepth); - db->locked = false; + dir_remove_new(global.dbdir, rdb_dircreationdepth); + rdb_locked = false; } -static retvalue writeversionfile(struct database *); +static retvalue writeversionfile(void); -retvalue database_close(struct database *db) { +retvalue database_close(void) { retvalue result = RET_OK, r; - if( db->references != NULL) { - r = table_close(db->references); + if (rdb_references != NULL) { + r = table_close(rdb_references); RET_UPDATE(result, r); - db->references = NULL; + rdb_references = NULL; } - if( db->checksums != NULL ) { - r = table_close(db->checksums); + if (rdb_checksums != NULL) { + r = table_close(rdb_checksums); RET_UPDATE(result, r); - db->checksums = NULL; + rdb_checksums = NULL; } - if( db->contents != NULL ) { - r = table_close(db->contents); + if (rdb_contents != NULL) { + r = table_close(rdb_contents); RET_UPDATE(result, r); - db->contents = NULL; + rdb_contents = NULL; } - r = writeversionfile(db); + r = writeversionfile(); RET_UPDATE(result, r); - if( db->locked ) - releaselock(db); - database_free(db); + if (rdb_locked) + releaselock(); + database_free(); return result; } -static retvalue database_hasdatabasefile(UNUSED(const struct database *database), const char *filename, /*@out@*/bool *exists_p) { +static retvalue database_hasdatabasefile(const char *filename, /*@out@*/bool *exists_p) { char *fullfilename; fullfilename = dbfilename(filename); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; *exists_p = isregularfile(fullfilename); free(fullfilename); @@ -199,33 +224,33 @@ static int paireddatacompare(UNUSED(DB *db), const DBT *a, const DBT *b); -static retvalue database_opentable(UNUSED(struct database *database), const char *filename, /*@null@*/const char *subtable, enum database_type type, uint32_t flags, /*@out@*/DB **result) { +static retvalue database_opentable(const char *filename, /*@null@*/const char *subtable, enum database_type type, uint32_t flags, /*@out@*/DB **result) { char *fullfilename; DB *table; int dbret; fullfilename = dbfilename(filename); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; dbret = db_create(&table, NULL, 0); - if ( dbret != 0) { + if (dbret != 0) { fprintf(stderr, "db_create: %s\n", db_strerror(dbret)); free(fullfilename); return RET_DBERR(dbret); } - if( type == dbt_BTREEDUP || type == dbt_BTREEPAIRS ) { + if (type == dbt_BTREEDUP || type == dbt_BTREEPAIRS) { dbret = table->set_flags(table, DB_DUPSORT); - if( dbret != 0 ) { + if (dbret != 0) { table->err(table, dbret, "db_set_flags(DB_DUPSORT):"); (void)table->close(table, 0); free(fullfilename); return RET_DBERR(dbret); } } - if( type == dbt_BTREEPAIRS ) { + if (type == dbt_BTREEPAIRS) { dbret = table->set_dup_compare(table, paireddatacompare); - if( dbret != 0 ) { + if (dbret != 0) { table->err(table, dbret, "db_set_dup_compare:"); (void)table->close(table, 0); free(fullfilename); @@ -233,23 +258,30 @@ } } +#if DB_VERSION_MAJOR == 5 +#define DB_OPEN(database, filename, name, type, flags) \ + database->open(database, NULL, filename, name, type, flags, 0664) +#else #if DB_VERSION_MAJOR == 4 -#define DB_OPEN(database,filename,name,type,flags) database->open(database,NULL,filename,name,type,flags,0664) +#define DB_OPEN(database, filename, name, type, flags) \ + database->open(database, NULL, filename, name, type, flags, 0664) #else #if DB_VERSION_MAJOR == 3 -#define DB_OPEN(database,filename,name,type,flags) database->open(database,filename,name,type,flags,0664) +#define DB_OPEN(database, filename, name, type, flags) \ + database->open(database, filename, name, type, flags, 0664) #else #error Unexpected DB_VERSION_MAJOR! #endif #endif +#endif dbret = DB_OPEN(table, fullfilename, subtable, types[type], flags); - if( dbret == ENOENT && !ISSET(flags, DB_CREATE) ) { + if (dbret == ENOENT && !ISSET(flags, DB_CREATE)) { (void)table->close(table, 0); free(fullfilename); return RET_NOTHING; } if (dbret != 0) { - if( subtable != NULL ) + if (subtable != NULL) table->err(table, dbret, "db_open(%s:%s)[%d]", fullfilename, subtable, dbret); else @@ -264,23 +296,23 @@ return RET_OK; } -retvalue database_listsubtables(struct database *database,const char *filename,struct strlist *result) { +retvalue database_listsubtables(const char *filename, struct strlist *result) { DB *table; DBC *cursor; - DBT key,data; + DBT key, data; int dbret; - retvalue ret,r; + retvalue ret, r; struct strlist ids; - r = database_opentable(database, filename, NULL, + r = database_opentable(filename, NULL, dbt_QUERY, DB_RDONLY, &table); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; cursor = NULL; - if( (dbret = table->cursor(table, NULL, &cursor, 0)) != 0 ) { + if ((dbret = table->cursor(table, NULL, &cursor, 0)) != 0) { table->err(table, dbret, "cursor(%s):", filename); - (void)table->close(table,0); + (void)table->close(table, 0); return RET_ERROR; } CLEARDBT(key); @@ -289,30 +321,31 @@ strlist_init(&ids); ret = RET_NOTHING; - while( (dbret=cursor->c_get(cursor,&key,&data,DB_NEXT)) == 0 ) { + while ((dbret=cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) { char *identifier = strndup(key.data, key.size); - if( identifier == NULL ) { + if (FAILEDTOALLOC(identifier)) { (void)table->close(table, 0); strlist_done(&ids); return RET_ERROR_OOM; } r = strlist_add(&ids, identifier); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)table->close(table, 0); strlist_done(&ids); return r; } + ret = RET_OK; CLEARDBT(key); CLEARDBT(data); } - if( dbret != 0 && dbret != DB_NOTFOUND ) { + if (dbret != 0 && dbret != DB_NOTFOUND) { table->err(table, dbret, "c_get(%s):", filename); (void)table->close(table, 0); strlist_done(&ids); return RET_DBERR(dbret); } - if( (dbret = cursor->c_close(cursor)) != 0 ) { + if ((dbret = cursor->c_close(cursor)) != 0) { table->err(table, dbret, "c_close(%s):", filename); (void)table->close(table, 0); strlist_done(&ids); @@ -320,37 +353,38 @@ } dbret = table->close(table, 0); - if( dbret != 0 ) { + if (dbret != 0) { table->err(table, dbret, "close(%s):", filename); strlist_done(&ids); return RET_DBERR(dbret); } else { strlist_move(result, &ids); - return RET_OK; + return ret; } } -retvalue database_dropsubtable(UNUSED(struct database *database), const char *table, const char *subtable) { +retvalue database_dropsubtable(const char *table, const char *subtable) { char *filename; DB *db; int dbret; filename = dbfilename(table); - if( filename == NULL ) + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; if ((dbret = db_create(&db, NULL, 0)) != 0) { - fprintf(stderr, "db_create: %s %s\n", filename, db_strerror(dbret)); + fprintf(stderr, "db_create: %s %s\n", + filename, db_strerror(dbret)); free(filename); return RET_DBERR(dbret); } dbret = db->remove(db, filename, subtable, 0); - if( dbret == ENOENT ) { + if (dbret == ENOENT) { free(filename); return RET_NOTHING; } if (dbret != 0) { - fprintf(stderr,"Error removing '%s' from %s!\n", + fprintf(stderr, "Error removing '%s' from %s!\n", subtable, filename); free(filename); return RET_DBERR(dbret); @@ -364,9 +398,9 @@ struct distribution *d; struct target *t; - for( d = distributions ; d != NULL ; d = d->next ) { - for( t = d->targets; t != NULL ; t = t->next ) { - if( strcmp(t->identifier, identifier) == 0 ) { + for (d = distributions ; d != NULL ; d = d->next) { + for (t = d->targets; t != NULL ; t = t->next) { + if (strcmp(t->identifier, identifier) == 0) { t->existed = true; return true; } @@ -375,57 +409,60 @@ return false; } -static retvalue warnidentifers(struct database *db, const struct strlist *identifiers, struct distribution *distributions, bool readonly) { +static retvalue warnidentifers(const struct strlist *identifiers, struct distribution *distributions, bool readonly) { struct distribution *d; struct target *t; const char *identifier; retvalue r; int i; - for( i = 0; i < identifiers->count ; i++ ) { + for (i = 0; i < identifiers->count ; i++) { identifier = identifiers->values[i]; - if( targetisdefined(identifier, distributions) ) + if (targetisdefined(identifier, distributions)) continue; fprintf(stderr, "Error: packages database contains unused '%s' database.\n", identifier); - if( ignored[IGN_undefinedtarget] == 0 ) { + if (ignored[IGN_undefinedtarget] == 0) { (void)fputs( "This either means you removed a distribution, component or architecture from\n" "the distributions config file without calling clearvanished, or your config\n" "does not belong to this database.\n", stderr); } - if( IGNORABLE(undefinedtarget) ) { - (void)fputs("Ignoring as --ignore=undefinedtarget given.\n", + if (IGNORABLE(undefinedtarget)) { + (void)fputs( +"Ignoring as --ignore=undefinedtarget given.\n", stderr); ignored[IGN_undefinedtarget]++; continue; } - (void)fputs("To ignore use --ignore=undefinedtarget.\n", stderr); + (void)fputs( +"To ignore use --ignore=undefinedtarget.\n", + stderr); return RET_ERROR; } - if( readonly ) + if (readonly) return RET_OK; - for( d = distributions ; d != NULL ; d = d->next ) { + for (d = distributions ; d != NULL ; d = d->next) { bool architecture_existed[d->architectures.count]; bool have_old = false; /* check for new architectures */ memset(architecture_existed, 0, sizeof(architecture_existed)); - for( t = d->targets; t != NULL ; t = t->next ) { + for (t = d->targets; t != NULL ; t = t->next) { int o; - if( !t->existed ) + if (!t->existed) continue; o = atomlist_ofs(&d->architectures, - t->architecture_atom); - assert( o >= 0 ); - if( o >= 0 ) { + t->architecture); + assert (o >= 0); + if (o >= 0) { architecture_existed[o] = true; /* only warn about new ones if there * is at least one old one, otherwise @@ -433,10 +470,10 @@ have_old = true; } } - for( i = 0 ; have_old && i < d->architectures.count ; i++ ) { + for (i = 0 ; have_old && i < d->architectures.count ; i++) { architecture_t a; - if( architecture_existed[i] ) + if (architecture_existed[i]) continue; a = d->architectures.atoms[i]; @@ -450,17 +487,17 @@ } /* create databases, so we know next time what is new */ - for( t = d->targets; t != NULL ; t = t->next ) { - if( t->existed ) + for (t = d->targets; t != NULL ; t = t->next) { + if (t->existed) continue; /* create database now, to test it can be created * early, and to know when new architectures * arrive in the future. */ - r = target_initpackagesdb(t, db, READWRITE); - if( RET_WAS_ERROR(r) ) + r = target_initpackagesdb(t, READWRITE); + if (RET_WAS_ERROR(r)) return r; r = target_closepackagesdb(t); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } @@ -472,19 +509,19 @@ const struct distribution *d; int i; - for( i = 0; i < codenames->count ; i++ ) { + for (i = 0; i < codenames->count ; i++) { codename = codenames->values[i]; d = distributions; - while( d != NULL && strcmp(d->codename, codename) != 0 ) + while (d != NULL && strcmp(d->codename, codename) != 0) d = d->next; - if( d != NULL && d->tracking != dt_NONE ) + if (d != NULL && d->tracking != dt_NONE) continue; fprintf(stderr, "Error: tracking database contains unused '%s' database.\n", codename); - if( ignored[IGN_undefinedtracking] == 0 ) { - if( d == NULL ) + if (ignored[IGN_undefinedtracking] == 0) { + if (d == NULL) (void)fputs( "This either means you removed a distribution from the distributions config\n" "file without calling clearvanished (or at least removealltracks), you\n" @@ -497,14 +534,16 @@ "calling removealltracks for it, or your config does not belong to this database.\n", stderr); } - if( IGNORABLE(undefinedtracking) ) { - (void)fputs("Ignoring as --ignore=undefinedtracking given.\n", + if (IGNORABLE(undefinedtracking)) { + (void)fputs( +"Ignoring as --ignore=undefinedtracking given.\n", stderr); ignored[IGN_undefinedtracking]++; continue; } - (void)fputs("To ignore use --ignore=undefinedtracking.\n", stderr); + (void)fputs("To ignore use --ignore=undefinedtracking.\n", + stderr); return RET_ERROR; } return RET_OK; @@ -514,10 +553,11 @@ char buffer[21]; size_t l; - if( fgets(buffer, 20, f) == NULL ) { + if (fgets(buffer, 20, f) == NULL) { int e = errno; - if( e == 0 ) { - fprintf(stderr, "Error reading '%s': unexpected empty file\n", + if (e == 0) { + fprintf(stderr, +"Error reading '%s': unexpected empty file\n", versionfilename); return RET_ERROR; } else { @@ -527,78 +567,78 @@ } } l = strlen(buffer); - while( l > 0 && ( buffer[l-1] == '\r' || buffer[l-1] == '\n' ) ) { + while (l > 0 && (buffer[l-1] == '\r' || buffer[l-1] == '\n')) { buffer[--l] = '\0'; } - if( l == 0 ) { + if (l == 0) { fprintf(stderr, "Error reading '%s': unexpcted empty line.\n", versionfilename); return RET_ERROR; } *result = strdup(buffer); - if( *result == NULL ) + if (FAILEDTOALLOC(*result)) return RET_ERROR_OOM; return RET_OK; } -static retvalue readversionfile(struct database *db, bool nopackagesyet) { +static retvalue readversionfile(bool nopackagesyet) { char *versionfilename; FILE *f; retvalue r; int c; versionfilename = dbfilename("version"); - if( versionfilename == NULL ) + if (FAILEDTOALLOC(versionfilename)) return RET_ERROR_OOM; f = fopen(versionfilename, "r"); - if( f == NULL ) { + if (f == NULL) { int e = errno; - if( e != ENOENT ) { + if (e != ENOENT) { fprintf(stderr, "Error opening '%s': %s(errno is %d)\n", versionfilename, strerror(e), e); free(versionfilename); return RET_ERRNO(e); } free(versionfilename); - if( nopackagesyet ) { + if (nopackagesyet) { /* set to default for new packages.db files: */ - db->version = strdup(VERSION); - if( db->version == NULL ) + rdb_version = strdup(VERSION); + if (FAILEDTOALLOC(rdb_version)) return RET_ERROR_OOM; - db->capabilities.createnewtables = true; + rdb_capabilities.createnewtables = true; } else - db->version = NULL; - db->lastsupportedversion = NULL; - db->dbversion = NULL; - db->lastsupporteddbversion = NULL; + rdb_version = NULL; + rdb_lastsupportedversion = NULL; + rdb_dbversion = NULL; + rdb_lastsupporteddbversion = NULL; return RET_NOTHING; } /* first line is the version creating this database */ - r = readline(&db->version, f, versionfilename); - if( RET_WAS_ERROR(r) ) { + r = readline(&rdb_version, f, versionfilename); + if (RET_WAS_ERROR(r)) { (void)fclose(f); free(versionfilename); return r; } /* second line says which versions of reprepro will be able to cope * with this database */ - r = readline(&db->lastsupportedversion, f, versionfilename); - if( RET_WAS_ERROR(r) ) { + r = readline(&rdb_lastsupportedversion, f, versionfilename); + if (RET_WAS_ERROR(r)) { (void)fclose(f); free(versionfilename); return r; } /* next line is the version of the underlying database library */ - r = readline(&db->dbversion, f, versionfilename); - if( RET_WAS_ERROR(r) ) { + r = readline(&rdb_dbversion, f, versionfilename); + if (RET_WAS_ERROR(r)) { (void)fclose(f); free(versionfilename); return r; } /* and then the minimum version of this library needed. */ - r = readline(&db->lastsupporteddbversion, f, versionfilename); - if( RET_WAS_ERROR(r) ) { + r = readline(&rdb_lastsupporteddbversion, f, versionfilename); + if (RET_WAS_ERROR(r)) { (void)fclose(f); free(versionfilename); return r; @@ -608,18 +648,18 @@ /* check for enabled capabilities in the version */ - r = dpkgversions_cmp(db->version, "3", &c); - if( RET_WAS_ERROR(r) ) + r = dpkgversions_cmp(rdb_version, "3", &c); + if (RET_WAS_ERROR(r)) return r; - if( c >= 0 ) - db->capabilities.createnewtables = true; + if (c >= 0) + rdb_capabilities.createnewtables = true; /* ensure we can understand it */ - r = dpkgversions_cmp(VERSION, db->lastsupportedversion, &c); - if( RET_WAS_ERROR(r) ) + r = dpkgversions_cmp(VERSION, rdb_lastsupportedversion, &c); + if (RET_WAS_ERROR(r)) return r; - if( c < 0 ) { + if (c < 0) { fprintf(stderr, "According to %s/version this database was created with a future version\n" "and uses features this version cannot understand. Aborting...\n", @@ -629,86 +669,89 @@ /* ensure it's a libdb database: */ - if( strncmp(db->dbversion, "bdb", 3) != 0 ) { + if (strncmp(rdb_dbversion, "bdb", 3) != 0) { fprintf(stderr, "According to %s/version this database was created with a yet unsupported\n" "database library. Aborting...\n", global.dbdir); return RET_ERROR; } - if( strncmp(db->lastsupporteddbversion, "bdb", 3) != 0 ) { + if (strncmp(rdb_lastsupporteddbversion, "bdb", 3) != 0) { fprintf(stderr, "According to %s/version this database was created with a yet unsupported\n" "database library. Aborting...\n", global.dbdir); return RET_ERROR; } - r = dpkgversions_cmp(LIBDB_VERSION_STRING, db->lastsupporteddbversion, &c); - if( RET_WAS_ERROR(r) ) + r = dpkgversions_cmp(LIBDB_VERSION_STRING, + rdb_lastsupporteddbversion, &c); + if (RET_WAS_ERROR(r)) return r; - if( c < 0 ) { + if (c < 0) { fprintf(stderr, "According to %s/version this database was created with a future version\n" "%s of libdb. The libdb version this binary is linked against cannot yet\n" "handle this format. Aborting...\n", - global.dbdir, db->dbversion+3); + global.dbdir, rdb_dbversion + 3); return RET_ERROR; } return RET_OK; } -static retvalue writeversionfile(struct database *db) { +static retvalue writeversionfile(void) { char *versionfilename, *finalversionfilename; FILE *f; int i, e; versionfilename = dbfilename("version.new"); - if( versionfilename == NULL ) + if (FAILEDTOALLOC(versionfilename)) return RET_ERROR_OOM; f = fopen(versionfilename, "w"); - if( f == NULL ) { + if (f == NULL) { e = errno; fprintf(stderr, "Error creating '%s': %s(errno is %d)\n", versionfilename, strerror(e), e); free(versionfilename); return RET_ERRNO(e); } - if( db->version == NULL ) + if (rdb_version == NULL) (void)fputs("0\n", f); else { - (void)fputs(db->version, f); + (void)fputs(rdb_version, f); (void)fputc('\n', f); } - if( db->lastsupportedversion == NULL ) { + if (rdb_lastsupportedversion == NULL) { (void)fputs("3.3.0\n", f); } else { int c; retvalue r; - r = dpkgversions_cmp(db->lastsupportedversion, "3.3.0", &c); - if( !RET_IS_OK(r) || c < 0 ) + r = dpkgversions_cmp(rdb_lastsupportedversion, + "3.3.0", &c); + if (!RET_IS_OK(r) || c < 0) (void)fputs("3.3.0\n", f); else { - (void)fputs(db->lastsupportedversion, f); + (void)fputs(rdb_lastsupportedversion, f); (void)fputc('\n', f); } } - if( db->dbversion == NULL ) - fprintf(f, "bdb%d.%d.%d\n", DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH); + if (rdb_dbversion == NULL) + fprintf(f, "bdb%d.%d.%d\n", DB_VERSION_MAJOR, DB_VERSION_MINOR, + DB_VERSION_PATCH); else { - (void)fputs(db->dbversion, f); + (void)fputs(rdb_dbversion, f); (void)fputc('\n', f); } - if( db->lastsupporteddbversion == NULL ) + if (rdb_lastsupporteddbversion == NULL) fprintf(f, "bdb%d.%d.0\n", DB_VERSION_MAJOR, DB_VERSION_MINOR); else { - (void)fputs(db->lastsupporteddbversion, f); + (void)fputs(rdb_lastsupporteddbversion, f); (void)fputc('\n', f); } e = ferror(f); - if( e != 0 ) { + if (e != 0) { fprintf(stderr, "Error writing '%s': %s(errno is %d)\n", versionfilename, strerror(e), e); (void)fclose(f); @@ -716,7 +759,7 @@ free(versionfilename); return RET_ERRNO(e); } - if( fclose(f) != 0 ) { + if (fclose(f) != 0) { e = errno; fprintf(stderr, "Error writing '%s': %s(errno is %d)\n", versionfilename, strerror(e), e); @@ -725,14 +768,14 @@ return RET_ERRNO(e); } finalversionfilename = dbfilename("version"); - if( finalversionfilename == NULL ) { + if (FAILEDTOALLOC(finalversionfilename)) { unlink(versionfilename); free(versionfilename); return RET_ERROR_OOM; } i = rename(versionfilename, finalversionfilename); - if( i != 0 ) { + if (i != 0) { e = errno; fprintf(stderr, "Error %d moving '%s' to '%s': %s\n", e, versionfilename, finalversionfilename, @@ -747,22 +790,22 @@ return RET_OK; } -static retvalue createnewdatabase(struct database *db, struct distribution *distributions) { +static retvalue createnewdatabase(struct distribution *distributions) { struct distribution *d; struct target *t; retvalue result = RET_NOTHING, r; - for( d = distributions ; d != NULL ; d = d->next ) { - for( t = d->targets ; t != NULL ; t = t->next ) { - r = target_initpackagesdb(t, db, READWRITE); + for (d = distributions ; d != NULL ; d = d->next) { + for (t = d->targets ; t != NULL ; t = t->next) { + r = target_initpackagesdb(t, READWRITE); RET_UPDATE(result, r); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = target_closepackagesdb(t); RET_UPDATE(result, r); } } } - r = writeversionfile(db); + r = writeversionfile(); RET_UPDATE(result, r); return result; } @@ -772,118 +815,127 @@ * - if readonly, do not create but return with RET_NOTHING * - lock database, waiting a given amount of time if already locked */ -retvalue database_create(struct database **result, struct distribution *alldistributions, bool fast, bool nopackages, bool allowunused, bool readonly, size_t waitforlock, bool verbosedb) { - struct database *n; +retvalue database_create(struct distribution *alldistributions, bool fast, bool nopackages, bool allowunused, bool readonly, size_t waitforlock, bool verbosedb) { retvalue r; bool packagesfileexists, trackingfileexists, nopackagesyet; - if( readonly && !isdir(global.dbdir) ) { - if( verbose >= 0 ) - fprintf(stderr, "Exiting without doing anything, as there is no database yet that could result in other actions.\n"); + if (rdb_initialized || rdb_used) { + fputs("Internal Error: database initialized a 2nd time!\n", + stderr); + return RET_ERROR_INTERNAL; + } + + if (readonly && !isdir(global.dbdir)) { + if (verbose >= 0) + fprintf(stderr, +"Exiting without doing anything, as there is no database yet that could result in other actions.\n"); return RET_NOTHING; } - n = calloc(1, sizeof(struct database)); - if( n == NULL ) - return RET_ERROR_OOM; + rdb_initialized = true; + rdb_used = true; - r = database_lock(n, waitforlock); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) { - database_free(n); + r = database_lock(waitforlock); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) { + database_free(); return r; } - n->readonly = readonly; - n->verbose = verbosedb; + rdb_readonly = readonly; + rdb_verbose = verbosedb; - r = database_hasdatabasefile(n, "packages.db", &packagesfileexists); - if( RET_WAS_ERROR(r) ) + r = database_hasdatabasefile("packages.db", &packagesfileexists); + if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; - r = database_hasdatabasefile(n, "tracking.db", &trackingfileexists); - if( RET_WAS_ERROR(r) ) + } + r = database_hasdatabasefile("tracking.db", &trackingfileexists); + if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; + } nopackagesyet = !packagesfileexists && !trackingfileexists; - r = readversionfile(n, nopackagesyet); - if( RET_WAS_ERROR(r) ) { - releaselock(n); - database_free(n); + r = readversionfile(nopackagesyet); + if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; } - if( nopackages ) { - n->nopackages = true; - *result = n; + if (nopackages) { + rdb_nopackages = true; return RET_OK; } - if( nopackagesyet ) { + if (nopackagesyet) { // TODO: handle readonly, but only once packages files may no // longer be generated when it is active... - r = createnewdatabase(n, alldistributions); - if( RET_WAS_ERROR(r) ) { - releaselock(n); - database_free(n); + r = createnewdatabase(alldistributions); + if (RET_WAS_ERROR(r)) { + database_close(); return r; } } - /* from now on we should call database_close, as other stuff was handled, + /* after this point we should call database_close, + * as other stuff was handled, * so writing the version file cannot harm (and not doing so could) */ - if( !allowunused && !fast && packagesfileexists ) { + if (!allowunused && !fast && packagesfileexists) { struct strlist identifiers; - r = database_listpackages(n, &identifiers); - if( RET_WAS_ERROR(r) ) { - database_close(n); + r = database_listpackages(&identifiers); + if (RET_WAS_ERROR(r)) { + database_close(); return r; } - if( RET_IS_OK(r) ) { - r = warnidentifers(n, &identifiers, - alldistributions, readonly); - if( RET_WAS_ERROR(r) ) { - strlist_done(&identifiers); - database_close(n); - return r; - } + if (r == RET_NOTHING) + strlist_init(&identifiers); + r = warnidentifers(&identifiers, + alldistributions, readonly); + if (RET_WAS_ERROR(r)) { strlist_done(&identifiers); + database_close(); + return r; } + strlist_done(&identifiers); } - if( !allowunused && !fast && trackingfileexists ) { + if (!allowunused && !fast && trackingfileexists) { struct strlist codenames; - r = tracking_listdistributions(n, &codenames); - if( RET_WAS_ERROR(r) ) { - database_close(n); + r = tracking_listdistributions(&codenames); + if (RET_WAS_ERROR(r)) { + database_close(); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = warnunusedtracking(&codenames, alldistributions); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&codenames); - database_close(n); + database_close(); return r; } strlist_done(&codenames); } } - *result = n; return RET_OK; } -/******************************************************************************** - * Stuff string parts * - ********************************************************************************/ +/**************************************************************************** + * Stuff string parts * + ****************************************************************************/ static const char databaseerror[] = "Internal error of the underlying BerkeleyDB database:\n"; -/******************************************************************************** - * Stuff to handle data in tables * - ******************************************************************************** +/**************************************************************************** + * Stuff to handle data in tables * + **************************************************************************** There is nothing that connot be solved by another layer of indirection, except too many levels of indirection. (Source forgotten) */ @@ -895,7 +947,7 @@ }; static void table_printerror(struct table *table, int dbret, const char *action) { - if( table->subname != NULL ) + if (table->subname != NULL) table->berkeleydb->err(table->berkeleydb, dbret, "%sWithin %s subtable %s at %s", databaseerror, table->name, table->subname, @@ -910,16 +962,16 @@ int dbret; retvalue result; - if( table == NULL ) + if (table == NULL) return RET_NOTHING; - if( table->flagreset != NULL ) + if (table->flagreset != NULL) *table->flagreset = false; - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + if (table->berkeleydb == NULL) { + assert (table->readonly); dbret = 0; } else dbret = table->berkeleydb->close(table->berkeleydb, 0); - if( dbret != 0 ) { + if (dbret != 0) { fprintf(stderr, "db_close(%s, %s): %s\n", table->name, table->subname, db_strerror(dbret)); @@ -936,9 +988,9 @@ int dbret; DBT Key, Data; - assert( table != NULL ); - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + assert (table != NULL); + if (table->berkeleydb == NULL) { + assert (table->readonly); return RET_NOTHING; } @@ -949,17 +1001,17 @@ dbret = table->berkeleydb->get(table->berkeleydb, NULL, &Key, &Data, 0); // TODO: find out what error code means out of memory... - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return RET_NOTHING; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "get"); return RET_DBERR(dbret); } - if( Data.data == NULL ) + if (FAILEDTOALLOC(Data.data)) return RET_ERROR_OOM; - if( Data.size <= 0 || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + if (Data.size <= 0 || + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not null-terminated) data!", table->name, table->subname); @@ -979,9 +1031,9 @@ DBT Key, Data; size_t valuelen = strlen(value); - assert( table != NULL ); - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + assert (table != NULL); + if (table->berkeleydb == NULL) { + assert (table->readonly); return RET_NOTHING; } @@ -990,17 +1042,17 @@ dbret = table->berkeleydb->get(table->berkeleydb, NULL, &Key, &Data, DB_GET_BOTH); - if( dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY ) + if (dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY) return RET_NOTHING; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "get(BOTH)"); return RET_DBERR(dbret); } - if( Data.data == NULL ) + if (FAILEDTOALLOC(Data.data)) return RET_ERROR_OOM; - if( Data.size < valuelen + 2 || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + if (Data.size < valuelen + 2 || + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not paired) data!", table->name, table->subname); @@ -1019,9 +1071,9 @@ int dbret; DBT Key, Data; - assert( table != NULL ); - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + assert (table != NULL); + if (table->berkeleydb == NULL) { + assert (table->readonly); return RET_NOTHING; } @@ -1031,21 +1083,21 @@ dbret = table->berkeleydb->get(table->berkeleydb, NULL, &Key, &Data, 0); // TODO: find out what error code means out of memory... - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return RET_NOTHING; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "get"); return RET_DBERR(dbret); } - if( Data.data == NULL ) + if (FAILEDTOALLOC(Data.data)) return RET_ERROR_OOM; - if( data_p == NULL ) { - assert( datalen_p == NULL ); + if (data_p == NULL) { + assert (datalen_p == NULL); return RET_OK; } - if( Data.size <= 0 || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + if (Data.size <= 0 || + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not null-terminated) data!", table->name, table->subname); @@ -1056,7 +1108,7 @@ return RET_ERROR; } *data_p = Data.data; - if( datalen_p != NULL ) + if (datalen_p != NULL) *datalen_p = Data.size - 1; return RET_OK; } @@ -1070,14 +1122,14 @@ SETDBT(Key, key); SETDBT(Data, data); dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); return RET_DBERR(dbret); } dbret=cursor->c_get(cursor, &Key, &Data, DB_GET_BOTH); - if( dbret == 0 ) { + if (dbret == 0) { r = RET_OK; - } else if( dbret == DB_NOTFOUND ) { + } else if (dbret == DB_NOTFOUND) { r = RET_NOTHING; } else { table_printerror(table, dbret, "c_get"); @@ -1085,7 +1137,7 @@ return RET_DBERR(dbret); } dbret = cursor->c_close(cursor); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_close"); return RET_DBERR(dbret); } @@ -1101,18 +1153,18 @@ SETDBT(Key, key); SETDBT(Data, data); dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); return RET_DBERR(dbret); } dbret=cursor->c_get(cursor, &Key, &Data, DB_GET_BOTH); - if( dbret == 0 ) + if (dbret == 0) dbret = cursor->c_del(cursor, 0); - if( dbret == 0 ) { + if (dbret == 0) { r = RET_OK; - } else if( dbret == DB_NOTFOUND ) { + } else if (dbret == DB_NOTFOUND) { r = RET_NOTHING; } else { table_printerror(table, dbret, "c_get"); @@ -1120,7 +1172,7 @@ return RET_DBERR(dbret); } dbret = cursor->c_close(cursor); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_close"); return RET_DBERR(dbret); } @@ -1138,19 +1190,19 @@ int dbret; DBT Key, Data; - assert( table != NULL ); - assert( !table->readonly && table->berkeleydb != NULL ); + assert (table != NULL); + assert (!table->readonly && table->berkeleydb != NULL); SETDBT(Key, key); SETDBTl(Data, data, datalen + 1); dbret = table->berkeleydb->put(table->berkeleydb, NULL, &Key, &Data, DB_NODUPDATA); - if( dbret != 0 && !(ignoredups && dbret == DB_KEYEXIST) ) { + if (dbret != 0 && !(ignoredups && dbret == DB_KEYEXIST)) { table_printerror(table, dbret, "put"); return RET_DBERR(dbret); } - if( table->verbose ) { - if( table->subname != NULL ) + if (table->verbose) { + if (table->subname != NULL) printf("db: '%s' added to %s(%s).\n", key, table->name, table->subname); else @@ -1164,24 +1216,24 @@ int dbret; DBT Key, Data; - assert( table != NULL ); - assert( !table->readonly && table->berkeleydb != NULL ); - assert( data_size > 0 && data[data_size-1] == '\0' ); + assert (table != NULL); + assert (!table->readonly && table->berkeleydb != NULL); + assert (data_size > 0 && data[data_size-1] == '\0'); SETDBT(Key, key); SETDBTl(Data, data, data_size); dbret = table->berkeleydb->put(table->berkeleydb, NULL, &Key, &Data, allowoverwrite?0:DB_NOOVERWRITE); - if( nooverwrite && dbret == DB_KEYEXIST ) { + if (nooverwrite && dbret == DB_KEYEXIST) { /* if nooverwrite is set, do nothing and ignore: */ return RET_NOTHING; } - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "put(uniq)"); return RET_DBERR(dbret); } - if( table->verbose ) { - if( table->subname != NULL ) + if (table->verbose) { + if (table->subname != NULL) printf("db: '%s' added to %s(%s).\n", key, table->name, table->subname); else @@ -1199,22 +1251,22 @@ int dbret; DBT Key; - assert( table != NULL ); - assert( !table->readonly && table->berkeleydb != NULL ); + assert (table != NULL); + assert (!table->readonly && table->berkeleydb != NULL); SETDBT(Key, key); dbret = table->berkeleydb->del(table->berkeleydb, NULL, &Key, 0); - if( dbret != 0 ) { - if( dbret == DB_NOTFOUND && ignoremissing ) + if (dbret != 0) { + if (dbret == DB_NOTFOUND && ignoremissing) return RET_NOTHING; table_printerror(table, dbret, "del"); - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return RET_ERROR_MISSING; else return RET_DBERR(dbret); } - if( table->verbose ) { - if( table->subname != NULL ) + if (table->verbose) { + if (table->subname != NULL) printf("db: '%s' removed from %s(%s).\n", key, table->name, table->subname); else @@ -1228,7 +1280,7 @@ retvalue r; r = table_deleterecord(table, key, false); - if( r != RET_ERROR_MISSING && RET_WAS_ERROR(r) ) + if (r != RET_ERROR_MISSING && RET_WAS_ERROR(r)) return r; return table_adduniqrecord(table, key, data); } @@ -1243,14 +1295,14 @@ struct cursor *cursor; int dbret; - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + if (table->berkeleydb == NULL) { + assert (table->readonly); *cursor_p = NULL; return RET_OK; } - cursor = calloc(1, sizeof(struct cursor)); - if( cursor == NULL ) + cursor = zNEW(struct cursor); + if (FAILEDTOALLOC(cursor)) return RET_ERROR_OOM; cursor->cursor = NULL; @@ -1258,7 +1310,7 @@ cursor->r = RET_OK; dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor->cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); free(cursor); return RET_DBERR(dbret); @@ -1270,10 +1322,10 @@ static inline retvalue parse_pair(struct table *table, DBT Key, DBT Data, /*@null@*//*@out@*/const char **key_p, /*@out@*/const char **value_p, /*@out@*/const char **data_p, /*@out@*/size_t *datalen_p) { /*@dependant@*/ const char *separator; - if( Key.size == 0 || Data.size == 0 || + if (Key.size == 0 || Data.size == 0 || ((const char*)Key.data)[Key.size-1] != '\0' || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not null-terminated) data!", table->name, table->subname); @@ -1284,8 +1336,8 @@ return RET_ERROR; } separator = memchr(Data.data, '\0', Data.size-1); - if( separator == NULL ) { - if( table->subname != NULL ) + if (separator == NULL) { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted data!", table->name, table->subname); @@ -1295,7 +1347,7 @@ table->name); return RET_ERROR; } - if( key_p != NULL ) + if (key_p != NULL) *key_p = Key.data; *value_p = Data.data; *data_p = separator + 1; @@ -1309,14 +1361,14 @@ DBT Key, Data; retvalue r; - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + if (table->berkeleydb == NULL) { + assert (table->readonly); *cursor_p = NULL; return RET_NOTHING; } - cursor = calloc(1, sizeof(struct cursor)); - if( cursor == NULL ) + cursor = zNEW(struct cursor); + if (FAILEDTOALLOC(cursor)) return RET_ERROR_OOM; cursor->cursor = NULL; @@ -1324,7 +1376,7 @@ cursor->r = RET_OK; dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor->cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); free(cursor); return RET_DBERR(dbret); @@ -1332,20 +1384,20 @@ SETDBT(Key, key); CLEARDBT(Data); dbret = cursor->cursor->c_get(cursor->cursor, &Key, &Data, DB_SET); - if( dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY ) { + if (dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY) { (void)cursor->cursor->c_close(cursor->cursor); free(cursor); return RET_NOTHING; } - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_get(DB_SET)"); (void)cursor->cursor->c_close(cursor->cursor); free(cursor); return RET_DBERR(dbret); } r = parse_pair(table, Key, Data, NULL, value_p, data_p, datalen_p); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { (void)cursor->cursor->c_close(cursor->cursor); free(cursor); return r; @@ -1362,14 +1414,14 @@ retvalue r; size_t valuelen = strlen(value); - if( table->berkeleydb == NULL ) { - assert( table->readonly ); + if (table->berkeleydb == NULL) { + assert (table->readonly); *cursor_p = NULL; return RET_NOTHING; } - cursor = calloc(1, sizeof(struct cursor)); - if( cursor == NULL ) + cursor = zNEW(struct cursor); + if (FAILEDTOALLOC(cursor)) return RET_ERROR_OOM; cursor->cursor = NULL; @@ -1378,7 +1430,7 @@ cursor->r = RET_OK; dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor->cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); free(cursor); return RET_DBERR(dbret); @@ -1386,8 +1438,8 @@ SETDBT(Key, key); SETDBTl(Data, value, valuelen + 1); dbret = cursor->cursor->c_get(cursor->cursor, &Key, &Data, DB_GET_BOTH); - if( dbret != 0 ) { - if( dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY ) { + if (dbret != 0) { + if (dbret == DB_NOTFOUND || dbret == DB_KEYEMPTY) { table_printerror(table, dbret, "c_get(DB_GET_BOTH)"); r = RET_DBERR(dbret); } else @@ -1396,9 +1448,9 @@ free(cursor); return r; } - if( Data.size < valuelen + 2 || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + if (Data.size < valuelen + 2 || + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not paired) data!", table->name, table->subname); @@ -1410,9 +1462,9 @@ free(cursor); return RET_ERROR; } - if( data_p != NULL ) + if (data_p != NULL) *data_p = ((const char*)Data.data) + valuelen + 1; - if( datalen_p != NULL ) + if (datalen_p != NULL) *datalen_p = Data.size - valuelen - 2; *cursor_p = cursor; return RET_OK; @@ -1422,14 +1474,14 @@ int dbret; retvalue r; - if( cursor == NULL ) + if (cursor == NULL) return RET_OK; r = cursor->r; dbret = cursor->cursor->c_close(cursor->cursor); cursor->cursor = NULL; free(cursor); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_close"); RET_UPDATE(r, RET_DBERR(dbret)); } @@ -1440,25 +1492,25 @@ DBT Key, Data; int dbret; - if( cursor == NULL ) + if (cursor == NULL) return false; CLEARDBT(Key); CLEARDBT(Data); dbret = cursor->cursor->c_get(cursor->cursor, &Key, &Data, DB_NEXT); - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return false; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_get(DB_NEXT)"); cursor->r = RET_DBERR(dbret); return false; } - if( Key.size <= 0 || Data.size <= 0 || + if (Key.size <= 0 || Data.size <= 0 || ((const char*)Key.data)[Key.size-1] != '\0' || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not null-terminated) data!", table->name, table->subname); @@ -1478,25 +1530,25 @@ DBT Key, Data; int dbret; - if( cursor == NULL ) + if (cursor == NULL) return false; CLEARDBT(Key); CLEARDBT(Data); dbret = cursor->cursor->c_get(cursor->cursor, &Key, &Data, DB_NEXT); - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return false; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_get(DB_NEXT)"); cursor->r = RET_DBERR(dbret); return false; } - if( Key.size <= 0 || Data.size <= 0 || + if (Key.size <= 0 || Data.size <= 0 || ((const char*)Key.data)[Key.size-1] != '\0' || - ((const char*)Data.data)[Data.size-1] != '\0' ) { - if( table->subname != NULL ) + ((const char*)Data.data)[Data.size-1] != '\0') { + if (table->subname != NULL) fprintf(stderr, "Database %s(%s) returned corrupted (not null-terminated) data!", table->name, table->subname); @@ -1507,7 +1559,7 @@ cursor->r = RET_ERROR; return false; } - if( key != NULL ) + if (key != NULL) *key = Key.data; *data = Data.data; *len_p = Data.size - 1; @@ -1519,7 +1571,7 @@ int dbret; retvalue r; - if( cursor == NULL ) + if (cursor == NULL) return false; CLEARDBT(Key); @@ -1527,19 +1579,21 @@ dbret = cursor->cursor->c_get(cursor->cursor, &Key, &Data, cursor->flags); - if( dbret == DB_NOTFOUND ) + if (dbret == DB_NOTFOUND) return false; - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, - (cursor->flags==DB_NEXT)?"c_get(DB_NEXT)": - (cursor->flags==DB_NEXT_DUP)?"c_get(DB_NEXT_DUP)": - "c_get(DB_???NEXT)"); + (cursor->flags==DB_NEXT) + ? "c_get(DB_NEXT)" + : (cursor->flags==DB_NEXT_DUP) + ? "c_get(DB_NEXT_DUP)" + : "c_get(DB_???NEXT)"); cursor->r = RET_DBERR(dbret); return false; } r = parse_pair(table, Key, Data, key_p, value_p, data_p, datalen_p); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cursor->r = r; return false; } @@ -1550,15 +1604,15 @@ DBT Key, Data; int dbret; - assert( cursor != NULL ); - assert( !table->readonly ); + assert (cursor != NULL); + assert (!table->readonly); CLEARDBT(Key); SETDBTl(Data, data, datalen + 1); dbret = cursor->cursor->c_put(cursor->cursor, &Key, &Data, DB_CURRENT); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_put(DB_CURRENT)"); return RET_DBERR(dbret); } @@ -1568,31 +1622,31 @@ retvalue cursor_delete(struct table *table, struct cursor *cursor, const char *key, const char *value) { int dbret; - assert( cursor != NULL ); - assert( !table->readonly ); + assert (cursor != NULL); + assert (!table->readonly); dbret = cursor->cursor->c_del(cursor->cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_del"); return RET_DBERR(dbret); } - if( table->verbose ) { - if( value != NULL ) - if( table->subname != NULL ) + if (table->verbose) { + if (value != NULL) + if (table->subname != NULL) printf("db: '%s' '%s' removed from %s(%s).\n", - key, value, - table->name, table->subname); + key, value, + table->name, table->subname); else printf("db: '%s' '%s' removed from %s.\n", - key, value, table->name); + key, value, table->name); else - if( table->subname != NULL ) + if (table->subname != NULL) printf("db: '%s' removed from %s(%s).\n", - key, table->name, table->subname); + key, table->name, table->subname); else printf("db: '%s' removed from %s.\n", - key, table->name); + key, table->name); } return RET_OK; } @@ -1604,7 +1658,7 @@ dbret = table->berkeleydb->cursor(table->berkeleydb, NULL, &cursor, 0); - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "cursor"); return true; } @@ -1612,40 +1666,40 @@ CLEARDBT(Data); dbret = cursor->c_get(cursor, &Key, &Data, DB_NEXT); - if( dbret == DB_NOTFOUND ) { + if (dbret == DB_NOTFOUND) { (void)cursor->c_close(cursor); return true; } - if( dbret != 0 ) { + if (dbret != 0) { table_printerror(table, dbret, "c_get(DB_NEXT)"); (void)cursor->c_close(cursor); return true; } dbret = cursor->c_close(cursor); - if( dbret != 0 ) + if (dbret != 0) table_printerror(table, dbret, "c_close"); return false; } -/******************************************************************************** - * Open the different types of tables with their needed flags: * - ********************************************************************************/ -static retvalue database_table(struct database *database, const char *filename, const char *subtable, enum database_type type, uint32_t flags, /*@out@*/struct table **table_p) { +/**************************************************************************** + * Open the different types of tables with their needed flags: * + ****************************************************************************/ +static retvalue database_table(const char *filename, const char *subtable, enum database_type type, uint32_t flags, /*@out@*/struct table **table_p) { struct table *table; retvalue r; - table = calloc(1, sizeof(struct table)); - if( table == NULL ) + table = zNEW(struct table); + if (FAILEDTOALLOC(table)) return RET_ERROR_OOM; /* TODO: is filename always an static constant? then we could drop the dup */ table->name = strdup(filename); - if( table->name == NULL ) { + if (FAILEDTOALLOC(table->name)) { free(table); return RET_ERROR_OOM; } - if( subtable != NULL ) { + if (subtable != NULL) { table->subname = strdup(subtable); - if( table->subname == NULL ) { + if (FAILEDTOALLOC(table->subname)) { free(table->name); free(table); return RET_ERROR_OOM; @@ -1653,16 +1707,17 @@ } else table->subname = NULL; table->readonly = ISSET(flags, DB_RDONLY); - table->verbose = database->verbose; - r = database_opentable(database, filename, subtable, type, flags, &table->berkeleydb); - if( RET_WAS_ERROR(r) ) { + table->verbose = rdb_verbose; + r = database_opentable(filename, subtable, type, flags, + &table->berkeleydb); + if (RET_WAS_ERROR(r)) { free(table->subname); free(table->name); free(table); return r; } - if( r == RET_NOTHING ) { - if( ISSET(flags, DB_RDONLY) ) { + if (r == RET_NOTHING) { + if (ISSET(flags, DB_RDONLY)) { /* sometimes we don't want a return here, when? */ table->berkeleydb = NULL; r = RET_OK; @@ -1678,125 +1733,135 @@ return r; } -retvalue database_openreferences(struct database *db) { +retvalue database_openreferences(void) { retvalue r; - assert( db->references == NULL ); - r = database_table(db, "references.db", "references", - dbt_BTREEDUP, DB_CREATE, &db->references); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { - db->references = NULL; + assert (rdb_references == NULL); + r = database_table("references.db", "references", + dbt_BTREEDUP, DB_CREATE, &rdb_references); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { + rdb_references = NULL; return r; } else - db->references->verbose = false; + rdb_references->verbose = false; return RET_OK; } /* only compare the first 0-terminated part of the data */ static int paireddatacompare(UNUSED(DB *db), const DBT *a, const DBT *b) { - if( a->size < b->size ) + if (a->size < b->size) return strncmp(a->data, b->data, a->size); else return strncmp(a->data, b->data, b->size); } -retvalue database_opentracking(struct database *database, const char *codename, bool readonly, struct table **table_p) { +retvalue database_opentracking(const char *codename, bool readonly, struct table **table_p) { struct table *table IFSTUPIDCC(=NULL); retvalue r; - if( database->nopackages ) { - (void)fputs("Internal Error: Accessing packages databse while that was not prepared!\n", stderr); + if (rdb_nopackages) { + (void)fputs( +"Internal Error: Accessing packages databse while that was not prepared!\n", + stderr); return RET_ERROR; } - if( database->trackingdatabaseopen ) { - (void)fputs("Internal Error: Trying to open multiple tracking databases at the same time.\nThis should normaly not happen (to avoid triggering bugs in the underlying BerkeleyDB)\n", stderr); + if (rdb_trackingdatabaseopen) { + (void)fputs( +"Internal Error: Trying to open multiple tracking databases at the same time.\nThis should normaly not happen (to avoid triggering bugs in the underlying BerkeleyDB)\n", + stderr); return RET_ERROR; } - r = database_table(database, "tracking.db", codename, + r = database_table("tracking.db", codename, dbt_BTREEPAIRS, readonly?DB_RDONLY:DB_CREATE, &table); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - table->flagreset = &database->trackingdatabaseopen; - database->trackingdatabaseopen = true; + table->flagreset = &rdb_trackingdatabaseopen; + rdb_trackingdatabaseopen = true; *table_p = table; return RET_OK; } -retvalue database_openpackages(struct database *database, const char *identifier, bool readonly, struct table **table_p) { +retvalue database_openpackages(const char *identifier, bool readonly, struct table **table_p) { struct table *table IFSTUPIDCC(=NULL); retvalue r; - if( database->nopackages ) { - (void)fputs("Internal Error: Accessing packages databse while that was not prepared!\n", stderr); + if (rdb_nopackages) { + (void)fputs( +"Internal Error: Accessing packages databse while that was not prepared!\n", + stderr); return RET_ERROR; } - if( database->packagesdatabaseopen ) { - (void)fputs("Internal Error: Trying to open multiple packages databases at the same time.\nThis should normaly not happen (to avoid triggering bugs in the underlying BerkeleyDB)\n", stderr); + if (rdb_packagesdatabaseopen) { + (void)fputs( +"Internal Error: Trying to open multiple packages databases at the same time.\n" +"This should normaly not happen (to avoid triggering bugs in the underlying BerkeleyDB)\n", + stderr); return RET_ERROR; } - r = database_table(database, "packages.db", identifier, + r = database_table("packages.db", identifier, dbt_BTREE, readonly?DB_RDONLY:DB_CREATE, &table); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - table->flagreset = &database->packagesdatabaseopen; - database->packagesdatabaseopen = true; + table->flagreset = &rdb_packagesdatabaseopen; + rdb_packagesdatabaseopen = true; *table_p = table; return RET_OK; } /* Get a list of all identifiers having a package list */ -retvalue database_listpackages(struct database *database, struct strlist *identifiers) { - return database_listsubtables(database, "packages.db", identifiers); +retvalue database_listpackages(struct strlist *identifiers) { + return database_listsubtables("packages.db", identifiers); } /* drop a database */ -retvalue database_droppackages(struct database *database, const char *identifier) { - return database_dropsubtable(database, "packages.db", identifier); +retvalue database_droppackages(const char *identifier) { + return database_dropsubtable("packages.db", identifier); } -retvalue database_openfiles(struct database *db) { +retvalue database_openfiles(void) { retvalue r; struct strlist identifiers; bool checksumsexisted, oldfiles; - assert( db->checksums == NULL ); - assert( db->contents == NULL ); + assert (rdb_checksums == NULL); + assert (rdb_contents == NULL); - r = database_listsubtables(db, "contents.cache.db", &identifiers); - if( RET_IS_OK(r) ) { - if( strlist_in(&identifiers, "filelists") ) { + r = database_listsubtables("contents.cache.db", &identifiers); + if (RET_IS_OK(r)) { + if (strlist_in(&identifiers, "filelists")) { fprintf(stderr, "Your %s/contents.cache.db file still contains a table of cached file lists\n" "in the old (pre 3.0.0) format. You have to either delete that file (and lose\n" "all caches of file lists) or run reprepro with argument translatefilelists\n" -"to translate the old caches into the new format.\n", global.dbdir); +"to translate the old caches into the new format.\n", + global.dbdir); strlist_done(&identifiers); return RET_ERROR; } strlist_done(&identifiers); } - r = database_hasdatabasefile(db, "checksums.db", &checksumsexisted); - r = database_table(db, "checksums.db", "pool", + r = database_hasdatabasefile("checksums.db", &checksumsexisted); + r = database_table("checksums.db", "pool", dbt_BTREE, DB_CREATE, - &db->checksums); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { - db->checksums = NULL; + &rdb_checksums); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { + rdb_checksums = NULL; return r; } - r = database_hasdatabasefile(db, "files.db", &oldfiles); - if( RET_WAS_ERROR(r) ) { - (void)table_close(db->checksums); - db->checksums = NULL; + r = database_hasdatabasefile("files.db", &oldfiles); + if (RET_WAS_ERROR(r)) { + (void)table_close(rdb_checksums); + rdb_checksums = NULL; return r; } - if( oldfiles ) { + if (oldfiles) { fprintf(stderr, "Error: database uses deprecated format.\n" "Please run translatelegacychecksums to update to the new format first.\n"); @@ -1804,18 +1869,18 @@ } // TODO: only create this file once it is actually needed... - r = database_table(db, "contents.cache.db", "compressedfilelists", - dbt_BTREE, DB_CREATE, &db->contents); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { - (void)table_close(db->checksums); - db->checksums = NULL; - db->contents = NULL; + r = database_table("contents.cache.db", "compressedfilelists", + dbt_BTREE, DB_CREATE, &rdb_contents); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { + (void)table_close(rdb_checksums); + rdb_checksums = NULL; + rdb_contents = NULL; } return r; } -retvalue database_openreleasecache(struct database *database, const char *codename, struct table **cachedb_p) { +retvalue database_openreleasecache(const char *codename, struct table **cachedb_p) { retvalue r; char *oldcachefilename; @@ -1829,17 +1894,17 @@ * */ oldcachefilename = dbfilename("release.cache.db"); - if( oldcachefilename == NULL ) + if (FAILEDTOALLOC(oldcachefilename)) return RET_ERROR_OOM; - if( isregularfile(oldcachefilename) ) { + if (isregularfile(oldcachefilename)) { char *newcachefilename; newcachefilename = dbfilename("release.caches.db"); - if( newcachefilename == NULL ) { + if (FAILEDTOALLOC(newcachefilename)) { free(oldcachefilename); return RET_ERROR_OOM; } - if( isregularfile(newcachefilename) + if (isregularfile(newcachefilename) || rename(oldcachefilename, newcachefilename) != 0) { fprintf(stderr, "Deleting old-style export cache file %s!\n" @@ -1848,7 +1913,7 @@ "happen once while migration from pre-3.1.0 to later versions.\n", oldcachefilename); - if( unlink(oldcachefilename) != 0 ) { + if (unlink(oldcachefilename) != 0) { int e = errno; fprintf(stderr, "Cannot delete '%s': %s!", oldcachefilename, @@ -1863,9 +1928,9 @@ } free(oldcachefilename); - r = database_table(database, "release.caches.db", codename, + r = database_table("release.caches.db", codename, dbt_HASH, DB_CREATE, cachedb_p); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) (*cachedb_p)->verbose = false; return r; } @@ -1877,29 +1942,28 @@ size_t data_len; r = table_newglobalcursor(oldtable, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - while( cursor_nexttempdata(oldtable, cursor, &filekey, - &data, &data_len) ) { + while (cursor_nexttempdata(oldtable, cursor, &filekey, + &data, &data_len)) { r = table_adduniqsizedrecord(newtable, filekey, data, data_len+1, false, true); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; } -retvalue database_translate_filelists(struct database *database) { +retvalue database_translate_filelists(void) { char *dbname, *tmpdbname; struct table *oldtable, *newtable; struct strlist identifiers; int ret; retvalue r, r2; - r = database_listsubtables(database, "contents.cache.db", - &identifiers); - if( RET_IS_OK(r) ) { - if( !strlist_in(&identifiers, "filelists") ) { + r = database_listsubtables("contents.cache.db", &identifiers); + if (RET_IS_OK(r)) { + if (!strlist_in(&identifiers, "filelists")) { fprintf(stderr, "Your %s/contents.cache.db file does not contain an old style database!\n", global.dbdir); @@ -1910,15 +1974,15 @@ } dbname = dbfilename("contents.cache.db"); - if( dbname == NULL ) + if (FAILEDTOALLOC(dbname)) return RET_ERROR_OOM; tmpdbname = dbfilename("old.contents.cache.db"); - if( tmpdbname == NULL ) { + if (FAILEDTOALLOC(tmpdbname)) { free(dbname); return RET_ERROR_OOM; } ret = rename(dbname, tmpdbname); - if( ret != 0 ) { + if (ret != 0) { int e = errno; fprintf(stderr, "Could not rename '%s' into '%s': %s(%d)\n", dbname, tmpdbname, strerror(e), e); @@ -1927,51 +1991,51 @@ return RET_ERRNO(e); } newtable = NULL; - r = database_table(database, "contents.cache.db", - "compressedfilelists", + r = database_table("contents.cache.db", "compressedfilelists", dbt_BTREE, DB_CREATE, &newtable); - assert( r != RET_NOTHING ); + assert (r != RET_NOTHING); oldtable = NULL; - if( RET_IS_OK(r) ) { - r = database_table(database, "old.contents.cache.db", "filelists", + if (RET_IS_OK(r)) { + r = database_table("old.contents.cache.db", "filelists", dbt_BTREE, DB_RDONLY, &oldtable); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Could not find old-style database!\n"); r = RET_ERROR; } } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = filelists_translate(oldtable, newtable); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = RET_OK; } r2 = table_close(oldtable); RET_ENDUPDATE(r, r2); oldtable = NULL; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { /* copy the new-style database, */ - r = database_table(database, "old.contents.cache.db", "compressedfilelists", + r = database_table("old.contents.cache.db", "compressedfilelists", dbt_BTREE, DB_RDONLY, &oldtable); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { /* if there is one... */ r = table_copy(oldtable, newtable); r2 = table_close(oldtable); RET_ENDUPDATE(r, r2); } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { r = RET_OK; } } r2 = table_close(newtable); RET_ENDUPDATE(r, r2); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) (void)unlink(tmpdbname); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { ret = rename(tmpdbname, dbname); - if( ret != 0 ) { + if (ret != 0) { int e = errno; - fprintf(stderr, "Could not rename '%s' back into '%s': %s(%d)\n", + fprintf(stderr, +"Could not rename '%s' back into '%s': %s(%d)\n", dbname, tmpdbname, strerror(e), e); free(tmpdbname); free(dbname); @@ -2002,27 +2066,27 @@ /* first add all md5sums to checksums if not there yet */ r = table_newglobalcursor(oldmd5sums, &cursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( cursor_nexttemp(oldmd5sums, cursor, - &filekey, &md5sum) ) { + while (cursor_nexttemp(oldmd5sums, cursor, + &filekey, &md5sum)) { struct checksums *n = NULL; const char *combined; size_t combinedlen; r = table_gettemprecord(newchecksums, filekey, &all, &alllen); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = checksums_setall(&n, all, alllen); - if( RET_IS_OK(r) ) { - if( checksums_matches(n, cs_md5sum, md5sum) ) { + if (RET_IS_OK(r)) { + if (checksums_matches(n, cs_md5sum, md5sum)) { /* already there, nothing to do */ checksums_free(n); numnew++; continue; } /* new item does not match */ - if( verbose > 0 ) + if (verbose > 0) printf( "Overwriting stale new-checksums entry '%s'!\n", filekey); @@ -2030,50 +2094,50 @@ checksums_free(n); n = NULL; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)cursor_close(oldmd5sums, cursor); return r; } /* parse and recreate, to only have sanitized strings * in the database */ r = checksums_parse(&n, md5sum); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { (void)cursor_close(oldmd5sums, cursor); return r; } r = checksums_getcombined(n, &combined, &combinedlen); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) { + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) { (void)cursor_close(oldmd5sums, cursor); return r; } numold++; r = table_adduniqsizedrecord(newchecksums, filekey, combined, combinedlen + 1, true, false); - assert( r != RET_NOTHING); - if( !RET_IS_OK(r) ) { + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) { (void)cursor_close(oldmd5sums, cursor); return r; } } r = cursor_close(oldmd5sums, cursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* then delete everything from checksums that is not in md5sums */ r = table_newglobalcursor(oldmd5sums, &cursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = table_newglobalcursor(newchecksums, &newcursor); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cursor_close(oldmd5sums, cursor); return r; } - while( cursor_nexttemp(oldmd5sums, cursor, - &filekey, &md5sum) ) { + while (cursor_nexttemp(oldmd5sums, cursor, + &filekey, &md5sum)) { bool more; int cmp; const char *newfilekey, *dummy; @@ -2082,52 +2146,52 @@ more = cursor_nexttemp(newchecksums, newcursor, &newfilekey, &dummy); /* should have been added in the last step */ - assert( more ); + assert (more); cmp = strcmp(filekey, newfilekey); /* should have been added in the last step */ - assert( cmp >= 0 ); + assert (cmp >= 0); more = cmp > 0; - if( more ) { + if (more) { numretro++; - if( verbose > 0 ) + if (verbose > 0) printf( "Deleting stale new-checksums entry '%s'!\n", newfilekey); r = cursor_delete(newchecksums, newcursor, newfilekey, dummy); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cursor_close(oldmd5sums, cursor); cursor_close(newchecksums, newcursor); return r; } } - } while( more ); + } while (more); } r = cursor_close(oldmd5sums, cursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = cursor_close(newchecksums, newcursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( verbose >= 0 ) { + if (verbose >= 0) { printf("%ld packages were already in the new checksums.db\n", numnew); printf("%ld packages were added to the new checksums.db\n", numold - numreplace); - if( numretro != 0 ) + if (numretro != 0) printf( "%ld were only in checksums.db and not in files.db\n" "This should only have happened if you added them with a newer version\n" "and then deleted them with an older version of reprepro.\n", numretro); - if( numreplace != 0 ) + if (numreplace != 0) printf( "%ld were different checksums.db and not in files.db\n" "This should only have happened if you added them with a newer version\n" "and then deleted them with an older version of reprepro and\n" "then readded them with a old version.\n", numreplace); - if( numretro != 0 || numreplace != 0 ) + if (numretro != 0 || numreplace != 0) printf( "If you never run a old version after a new version,\n" "you might want to check with check and checkpool if something went wrong.\n"); @@ -2136,96 +2200,102 @@ } retvalue database_translate_legacy_checksums(bool verbosedb) { - struct database *n; struct table *newchecksums, *oldmd5sums; char *fullfilename; retvalue r; int e; - if( !isdir(global.dbdir) ) { + if (rdb_initialized || rdb_used) { + fputs("Internal Error: database initialized a 2nd time!\n", + stderr); + return RET_ERROR_INTERNAL; + } + + if (!isdir(global.dbdir)) { fprintf(stderr, "Cannot find directory '%s'!\n", global.dbdir); return RET_ERROR; } - n = calloc(1, sizeof(struct database)); - if( n == NULL ) - return RET_ERROR_OOM; + rdb_initialized = true; + rdb_used = true; - r = database_lock(n, 0); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) { - database_free(n); + r = database_lock(0); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) { + database_free(); return r; } - n->readonly = READWRITE; - n->verbose = verbosedb; + rdb_readonly = READWRITE; + rdb_verbose = verbosedb; - r = readversionfile(n, false); - if( RET_WAS_ERROR(r) ) { - releaselock(n); - database_free(n); + r = readversionfile(false); + if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; } - r = database_table(n, "files.db", "md5sums", - dbt_BTREE, 0, &oldmd5sums); - if( r == RET_NOTHING ) { + r = database_table("files.db", "md5sums", dbt_BTREE, 0, &oldmd5sums); + if (r == RET_NOTHING) { fprintf(stderr, "There is no old files.db in %s. Nothing to translate!\n", global.dbdir); - releaselock(n); - database_free(n); + releaselock(); + database_free(); return RET_NOTHING; - } else if( RET_WAS_ERROR(r) ) { - releaselock(n); - database_free(n); + } else if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; } - r = database_table(n, "checksums.db", "pool", - dbt_BTREE, DB_CREATE, + r = database_table("checksums.db", "pool", dbt_BTREE, DB_CREATE, &newchecksums); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { (void)table_close(oldmd5sums); - releaselock(n); - database_free(n); + releaselock(); + database_free(); return r; } r = translate(oldmd5sums, newchecksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)table_close(oldmd5sums); (void)table_close(newchecksums); - releaselock(n); - database_free(n); + releaselock(); + database_free(); return r; } (void)table_close(oldmd5sums); r = table_close(newchecksums); - if( RET_WAS_ERROR(r) ) { - releaselock(n); - database_free(n); + if (RET_WAS_ERROR(r)) { + releaselock(); + database_free(); return r; } fullfilename = dbfilename("files.db"); - if( fullfilename == NULL ) { - releaselock(n); - database_free(n); + if (FAILEDTOALLOC(fullfilename)) { + releaselock(); + database_free(); return RET_ERROR_OOM; } e = deletefile(fullfilename); - if( e != 0 ) { + if (e != 0) { fprintf(stderr, "Could not delete '%s'!\n" "It can now savely be deleted and it all that is left to be done!\n", fullfilename); - database_free(n); + database_free(); return RET_ERRNO(e); } - r = writeversionfile(n); - releaselock(n); - database_free(n); + r = writeversionfile(); + releaselock(); + database_free(); return r; } + +bool database_allcreated(void) { + return rdb_capabilities.createnewtables; +} diff -Nru reprepro-4.5.0/database.h reprepro-4.6.0/database.h --- reprepro-4.5.0/database.h 2009-09-14 13:44:24.000000000 +0000 +++ reprepro-4.6.0/database.h 2011-05-05 14:42:55.000000000 +0000 @@ -11,23 +11,23 @@ #include "strlist.h" #endif -struct database; struct distribution; struct table; struct cursor; -retvalue database_create(/*@out@*/struct database **, struct distribution *, bool fast, bool nopackages, bool allowunused, bool readonly, size_t waitforlock, bool verbosedb); -retvalue database_close(/*@only@*/struct database *); +retvalue database_create(struct distribution *, bool fast, bool /*nopackages*/, bool /*allowunused*/, bool /*readonly*/, size_t /*waitforlock*/, bool /*verbosedb*/); +retvalue database_close(void); -retvalue database_openfiles(struct database *); -retvalue database_openreferences(struct database *); -retvalue database_listpackages(struct database *, /*@out@*/struct strlist *); -retvalue database_droppackages(struct database *, const char *); -retvalue database_openpackages(struct database *, const char *identifier, bool readonly, /*@out@*/struct table **); -retvalue database_openreleasecache(struct database *, const char *codename, /*@out@*/struct table **); -retvalue database_opentracking(struct database *, const char *codename, bool readonly, /*@out@*/struct table **); -retvalue database_translate_filelists(struct database *); -retvalue database_translate_legacy_checksums(bool verbosedb); +retvalue database_openfiles(void); +retvalue database_openreferences(void); +retvalue database_listpackages(/*@out@*/struct strlist *); +retvalue database_droppackages(const char *); +retvalue database_openpackages(const char *, bool /*readonly*/, /*@out@*/struct table **); +retvalue database_openreleasecache(const char *, /*@out@*/struct table **); +retvalue database_opentracking(const char *, bool /*readonly*/, /*@out@*/struct table **); +retvalue database_translate_filelists(void); +retvalue database_translate_legacy_checksums(bool /*verbosedb*/); +bool database_allcreated(void); retvalue table_close(/*@only@*/struct table *); @@ -39,9 +39,9 @@ retvalue table_gettemprecord(struct table *, const char *, /*@out@*//*@null@*/const char **, /*@out@*//*@null@*/size_t *); retvalue table_getpair(struct table *, const char *, const char *, /*@out@*/const char **, /*@out@*/size_t *); -retvalue table_adduniqsizedrecord(struct table *, const char *key, const char *data, size_t data_size, bool allowoverwrote, bool nooverwrite); -retvalue table_adduniqrecord(struct table *, const char *key, const char *data); -retvalue table_addrecord(struct table *, const char *key, const char *data, size_t len, bool ignoredups); +retvalue table_adduniqsizedrecord(struct table *, const char * /*key*/, const char * /*data*/, size_t /*data_size*/, bool /*allowoverwrote*/, bool /*nooverwrite*/); +retvalue table_adduniqrecord(struct table *, const char * /*key*/, const char * /*data*/); +retvalue table_addrecord(struct table *, const char * /*key*/, const char * /*data*/, size_t /*len*/, bool /*ignoredups*/); retvalue table_replacerecord(struct table *, const char *key, const char *data); retvalue table_deleterecord(struct table *, const char *key, bool ignoremissing); retvalue table_checkrecord(struct table *, const char *key, const char *data); diff -Nru reprepro-4.5.0/database_p.h reprepro-4.6.0/database_p.h --- reprepro-4.5.0/database_p.h 2009-09-14 13:44:24.000000000 +0000 +++ reprepro-4.6.0/database_p.h 2011-05-05 14:42:55.000000000 +0000 @@ -5,26 +5,10 @@ #include "database.h" #endif -struct references; -struct filesdb; +extern /*@null@*/ struct table *rdb_checksums, *rdb_contents; +extern /*@null@*/ struct table *rdb_references; -struct database { - /*@null@*/ struct table *checksums, *contents; - /* for the references database: */ - /*@null@*/ struct table *references; - /* internal stuff: */ - bool locked, verbose; - int dircreationdepth; - bool nopackages, readonly, - packagesdatabaseopen, trackingdatabaseopen; - /*@null@*/ char *version, *lastsupportedversion, - *dbversion, *lastsupporteddbversion; - struct { - bool createnewtables; - } capabilities ; -}; - -retvalue database_listsubtables(struct database *,const char *,/*@out@*/struct strlist *); -retvalue database_dropsubtable(struct database *, const char *table, const char *subtable); +retvalue database_listsubtables(const char *, /*@out@*/struct strlist *); +retvalue database_dropsubtable(const char *, const char *); #endif diff -Nru reprepro-4.5.0/debfile.c reprepro-4.6.0/debfile.c --- reprepro-4.5.0/debfile.c 2010-02-16 15:29:01.000000000 +0000 +++ reprepro-4.6.0/debfile.c 2011-05-05 14:42:55.000000000 +0000 @@ -44,50 +44,59 @@ ssize_t got; size = archive_entry_size(entry); - if( size <= 0 ) { - fprintf(stderr, "Error: Empty control file within %s!\n", debfile); + if (size <= 0) { + fprintf(stderr, "Error: Empty control file within %s!\n", + debfile); return RET_ERROR; } - if( size > 10*1024*1024 ) { - fprintf(stderr, "Error: Ridiculously long control file within %s!\n", debfile); + if (size > 10*1024*1024) { + fprintf(stderr, +"Error: Ridiculously long control file within %s!\n", + debfile); return RET_ERROR; } - buffer = malloc(size+2); + buffer = malloc(size + 2); + if (FAILEDTOALLOC(buffer)) + return RET_ERROR_OOM; len = 0; - while( (got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0 - && !interrupted() ) { + while ((got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0 + && !interrupted()) { len += got; - if( len > (size_t)size ) { - fprintf(stderr, "Internal Error: libarchive miscalculated length of the control file inside '%s',\n" - " perhaps the file is corrupt, perhaps libarchive!\n", debfile); + if (len > (size_t)size) { + fprintf(stderr, +"Internal Error: libarchive miscalculated length of the control file inside '%s',\n" +" perhaps the file is corrupt, perhaps libarchive!\n", debfile); free(buffer); return RET_ERROR; } } - if( interrupted() ) { + if (interrupted()) { free(buffer); return RET_ERROR_INTERRUPTED; } - if( got < 0 ) { + if (got < 0) { free(buffer); - fprintf(stderr, "Error reading control file from %s\n", debfile); + fprintf(stderr, "Error reading control file from %s\n", + debfile); return RET_ERROR; } - if( len < (size_t)size ) - fprintf(stderr, "Warning: libarchive miscalculated length of the control file inside '%s'.\n" - "Maybe the file is corrupt, perhaps libarchive!\n", debfile); + if (len < (size_t)size) + fprintf(stderr, +"Warning: libarchive miscalculated length of the control file inside '%s'.\n" +"Maybe the file is corrupt, perhaps libarchive!\n", debfile); buffer[len] = '\0'; controllen = chunk_extract(buffer, buffer, &afterchanges); - if( controllen == 0 ) { - fprintf(stderr,"Could only find spaces within control file of '%s'!\n", + if (controllen == 0) { + fprintf(stderr, +"Could only find spaces within control file of '%s'!\n", debfile); free(buffer); return RET_ERROR; } - if( (size_t)(afterchanges - buffer) < len ) { - if( *afterchanges == '\0' ) + if ((size_t)(afterchanges - buffer) < len) { + if (*afterchanges == '\0') fprintf(stderr, "Unexpected \\0 character within control file of '%s'!\n", debfile); else @@ -96,9 +105,9 @@ free(buffer); return RET_ERROR; } - assert( buffer[controllen] == '\0' ); + assert (buffer[controllen] == '\0'); n = realloc(buffer, controllen+1); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { free(buffer); return RET_ERROR_OOM; } @@ -117,82 +126,86 @@ ar_archivemember_open, ar_archivemember_read, ar_archivemember_close); - if( a != ARCHIVE_OK ) { - fprintf(stderr,"open control.tar.gz within '%s' failed: %d:%d:%s\n", + if (a != ARCHIVE_OK) { + fprintf(stderr, +"open control.tar.gz within '%s' failed: %d:%d:%s\n", debfile, - a,archive_errno(tar), + a, archive_errno(tar), archive_error_string(tar)); return RET_ERROR; } - while( (a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK ) { - if( strcmp(archive_entry_pathname(entry),"./control") != 0 && - strcmp(archive_entry_pathname(entry),"control") != 0 ) { + while ((a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK) { + if (strcmp(archive_entry_pathname(entry), "./control") != 0 && + strcmp(archive_entry_pathname(entry), "control") != 0) { a = archive_read_data_skip(tar); - if( a != ARCHIVE_OK ) { + if (a != ARCHIVE_OK) { int e = archive_errno(tar); - printf("Error skipping %s within data.tar.gz from %s: %d=%s\n", + printf( +"Error skipping %s within data.tar.gz from %s: %d=%s\n", archive_entry_pathname(entry), debfile, e, archive_error_string(tar)); return (e!=0)?(RET_ERRNO(e)):RET_ERROR; } - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; } else { r = read_control_file(control, debfile, tar, entry); - if( r != RET_NOTHING ) + if (r != RET_NOTHING) return r; } } - if( a != ARCHIVE_EOF ) { + if (a != ARCHIVE_EOF) { int e = archive_errno(tar); printf("Error reading control.tar.gz from %s: %d=%s\n", debfile, e, archive_error_string(tar)); return (e!=0)?(RET_ERRNO(e)):RET_ERROR; } - fprintf(stderr,"Could not find a control file within control.tar.gz within '%s'!\n",debfile); + fprintf(stderr, +"Could not find a control file within control.tar.gz within '%s'!\n", + debfile); return RET_ERROR_MISSING; } -retvalue extractcontrol(char **control,const char *debfile) { +retvalue extractcontrol(char **control, const char *debfile) { struct ar_archive *ar; retvalue r; bool hadcandidate = false; - r = ar_open(&ar,debfile); - if( RET_WAS_ERROR(r) ) + r = ar_open(&ar, debfile); + if (RET_WAS_ERROR(r)) return r; - assert( r != RET_NOTHING); + assert (r != RET_NOTHING); do { char *filename; enum compression c; r = ar_nextmember(ar, &filename); - if( RET_IS_OK(r) ) { - if( strncmp(filename, "control.tar", 11) != 0 ) { + if (RET_IS_OK(r)) { + if (strncmp(filename, "control.tar", 11) != 0) { free(filename); continue; } hadcandidate = true; - for( c = 0 ; c < c_COUNT ; c++ ) { - if( strcmp(filename + 11, + for (c = 0 ; c < c_COUNT ; c++) { + if (strcmp(filename + 11, uncompression_suffix[c]) == 0) break; } - if( c >= c_COUNT ) { + if (c >= c_COUNT) { free(filename); continue; } ar_archivemember_setcompression(ar, c); - if( uncompression_supported(c) ) { + if (uncompression_supported(c)) { struct archive *tar; tar = archive_read_new(); r = read_control_tar(control, debfile, ar, tar); // TODO run archive_read_close to get error messages? archive_read_finish(tar); - if( r != RET_NOTHING ) { + if (r != RET_NOTHING) { ar_close(ar); free(filename); return r; @@ -201,9 +214,9 @@ } free(filename); } - } while( RET_IS_OK(r) ); + } while (RET_IS_OK(r)); ar_close(ar); - if( hadcandidate ) + if (hadcandidate) fprintf(stderr, "Could not find a suitable control.tar file within '%s'!\n", debfile); else diff -Nru reprepro-4.5.0/debfilecontents.c reprepro-4.6.0/debfilecontents.c --- reprepro-4.5.0/debfilecontents.c 2008-09-11 09:44:43.000000000 +0000 +++ reprepro-4.6.0/debfilecontents.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,19 +43,19 @@ int a, e; r = filelistcompressor_setup(&c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; archive_read_support_format_tar(tar); archive_read_support_format_gnutar(tar); - a = archive_read_open(tar,ar, + a = archive_read_open(tar, ar, ar_archivemember_open, ar_archivemember_read, ar_archivemember_close); - if( a != ARCHIVE_OK ) { + if (a != ARCHIVE_OK) { filelistcompressor_cancel(&c); e = archive_errno(tar); - if( e == -EINVAL) /* special code to say there is none */ + if (e == -EINVAL) /* special code to say there is none */ fprintf(stderr, "open data.tar within '%s' failed: %s\n", debfile, archive_error_string(tar)); @@ -65,32 +65,32 @@ archive_error_string(tar)); return RET_ERROR; } - while( (a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK ) { + while ((a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK) { const char *name = archive_entry_pathname(entry); mode_t mode; - if( name[0] == '.' ) + if (name[0] == '.') name++; - if( name[0] == '/' ) + if (name[0] == '/') name++; - if( name[0] == '\0' ) + if (name[0] == '\0') continue; mode = archive_entry_mode(entry); - if( !S_ISDIR(mode) ) { + if (!S_ISDIR(mode)) { r = filelistcompressor_add(&c, name, strlen(name)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { filelistcompressor_cancel(&c); return r; } } - if( interrupted() ) { + if (interrupted()) { filelistcompressor_cancel(&c); return RET_ERROR_INTERRUPTED; } a = archive_read_data_skip(tar); - if( a != ARCHIVE_OK ) { + if (a != ARCHIVE_OK) { e = archive_errno(tar); - if( e == -EINVAL ) { + if (e == -EINVAL) { r = RET_ERROR; fprintf(stderr, "Error skipping %s within data.tar from %s: %s\n", @@ -101,7 +101,7 @@ "Error %d skipping %s within data.tar from %s: %s\n", e, archive_entry_pathname(entry), debfile, archive_error_string(tar)); - if( e != 0 ) + if (e != 0) r = RET_ERRNO(e); else r = RET_ERROR; @@ -110,9 +110,9 @@ return r; } } - if( a != ARCHIVE_EOF ) { + if (a != ARCHIVE_EOF) { e = archive_errno(tar); - if( e == -EINVAL ) { + if (e == -EINVAL) { r = RET_ERROR; fprintf(stderr, "Error reading data.tar from %s: %s\n", debfile, archive_error_string(tar)); @@ -120,7 +120,7 @@ fprintf(stderr, "Error %d reading data.tar from %s: %s\n", e, debfile, archive_error_string(tar)); - if( e != 0 ) + if (e != 0) r = RET_ERRNO(e); else r = RET_ERROR; @@ -137,32 +137,32 @@ retvalue r; bool hadcandidate = false; - r = ar_open(&ar,debfile); - if( RET_WAS_ERROR(r) ) + r = ar_open(&ar, debfile); + if (RET_WAS_ERROR(r)) return r; - assert( r != RET_NOTHING); + assert (r != RET_NOTHING); do { char *filename; enum compression c; r = ar_nextmember(ar, &filename); - if( RET_IS_OK(r) ) { - if( strncmp(filename, "data.tar", 8) != 0 ) { + if (RET_IS_OK(r)) { + if (strncmp(filename, "data.tar", 8) != 0) { free(filename); continue; } hadcandidate = true; - for( c = 0 ; c < c_COUNT ; c++ ) { - if( strcmp(filename + 8, + for (c = 0 ; c < c_COUNT ; c++) { + if (strcmp(filename + 8, uncompression_suffix[c]) == 0) break; } - if( c >= c_COUNT ) { + if (c >= c_COUNT) { free(filename); continue; } ar_archivemember_setcompression(ar, c); - if( uncompression_supported(c) ) { + if (uncompression_supported(c)) { struct archive *tar; tar = archive_read_new(); @@ -170,7 +170,7 @@ debfile, ar, tar); // TODO: check how to get an error message here.. archive_read_finish(tar); - if( r != RET_NOTHING ) { + if (r != RET_NOTHING) { ar_close(ar); free(filename); return r; @@ -179,9 +179,9 @@ } free(filename); } - } while( RET_IS_OK(r) ); + } while (RET_IS_OK(r)); ar_close(ar); - if( hadcandidate ) + if (hadcandidate) fprintf(stderr, "Could not find a suitable data.tar file within '%s'!\n", debfile); else diff -Nru reprepro-4.5.0/debfile.h reprepro-4.6.0/debfile.h --- reprepro-4.5.0/debfile.h 2008-03-25 10:37:02.000000000 +0000 +++ reprepro-4.6.0/debfile.h 2011-05-05 14:42:55.000000000 +0000 @@ -6,11 +6,10 @@ #warning "What's hapening here?" #endif -/* Read the control information of and put it's only chunk - * into */ -retvalue extractcontrol(/*@out@*/char **control,const char *debfile); +/* Read the control information of a .deb file */ +retvalue extractcontrol(/*@out@*/char **, const char *); -/* Read a list of files of */ -retvalue getfilelist(/*@out@*/char **filelist, /*@out@*/ size_t *size, const char *debfile); +/* Read a list of files from a .deb file */ +retvalue getfilelist(/*@out@*/char **, /*@out@*/ size_t *, const char *); #endif diff -Nru reprepro-4.5.0/debian/changelog reprepro-4.6.0/debian/changelog --- reprepro-4.5.0/debian/changelog 2011-09-14 18:50:20.000000000 +0000 +++ reprepro-4.6.0/debian/changelog 2011-12-09 11:23:31.000000000 +0000 @@ -1,14 +1,26 @@ -reprepro (4.5.0-3) oneiric; urgency=low +reprepro (4.6.0-1ubuntu1) oneiric; urgency=low - * Change bdb version + * Fix message for when changes file is not GPG signed - -- Thomas Hervé Wed, 14 Sep 2011 14:49:57 -0400 + -- Thomas Hervé Fri, 09 Dec 2011 12:01:18 +0100 -reprepro (4.5.0-2) oneiric; urgency=low +reprepro (4.6.0-1) unstable; urgency=low - * Rebuild for oneiric + * new release + - general cleanup + - new FilterSrcList + * increase Standards-Version, no changes needed + + -- Bernhard R. Link Thu, 05 May 2011 16:34:23 +0200 + +reprepro (4.5.1-1) unstable; urgency=low + + * new bugfix release + - build with libdb5 + - fix not refusing wrong architecture packages with pull + - add checks against wrong architecture in check (Closes: 613229) - -- Thomas Hervé Wed, 14 Sep 2011 14:25:30 -0400 + -- Bernhard R. Link Tue, 01 Mar 2011 18:11:57 +0100 reprepro (4.5.0-1) unstable; urgency=low diff -Nru reprepro-4.5.0/debian/control reprepro-4.6.0/debian/control --- reprepro-4.5.0/debian/control 2011-09-14 18:49:53.000000000 +0000 +++ reprepro-4.6.0/debian/control 2011-05-05 14:55:13.000000000 +0000 @@ -2,8 +2,8 @@ Section: utils Priority: extra Maintainer: Bernhard R. Link -Build-Depends: debhelper (>= 7), libgpgme11-dev, libdb4.8-dev, libz-dev, libbz2-dev, libarchive-dev -Standards-Version: 3.9.1 +Build-Depends: debhelper (>= 7), libgpgme11-dev, libdb-dev, libz-dev, libbz2-dev, libarchive-dev +Standards-Version: 3.9.2 Vcs-Browser: http://alioth.debian.org/scm/viewvc.php/mirrorer/?root=mirrorer Vcs-Cvs: :pserver:anonymous@cvs.alioth.debian.org:/cvsroot/mirrorer reprepro Homepage: http://mirrorer.alioth.debian.org/ diff -Nru reprepro-4.5.0/debian/patches/data-not-signed-message-fix reprepro-4.6.0/debian/patches/data-not-signed-message-fix --- reprepro-4.5.0/debian/patches/data-not-signed-message-fix 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/debian/patches/data-not-signed-message-fix 2011-12-09 09:45:06.000000000 +0000 @@ -0,0 +1,15 @@ +Index: reprepro-4.6.0/signature.c +=================================================================== +--- reprepro-4.6.0.orig/signature.c 2011-12-09 10:44:44.032200314 +0100 ++++ reprepro-4.6.0/signature.c 2011-12-09 10:45:04.900200290 +0100 +@@ -742,8 +742,8 @@ + + /* fast-track unsigned chunks: */ + if (startofchanges[0] != '-' && *afterchanges == '\0') { +- if (verbose > 5 && strncmp(startofchanges, "Format:", 7) != 0 +- && strncmp(startofchanges, "Source:", 7) != 0) ++ if (verbose > 5 && (strncmp(startofchanges, "Format:", 7) != 0 ++ || strncmp(startofchanges, "Source:", 7) != 0)) + fprintf(stderr, + "Data seems not to be signed trying to use directly...\n"); + len = chunk_extract(chunk, chunk, &afterchunk); diff -Nru reprepro-4.5.0/debian/patches/series reprepro-4.6.0/debian/patches/series --- reprepro-4.5.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/debian/patches/series 2011-12-09 09:44:35.000000000 +0000 @@ -0,0 +1 @@ +data-not-signed-message-fix diff -Nru reprepro-4.5.0/diffindex.c reprepro-4.6.0/diffindex.c --- reprepro-4.5.0/diffindex.c 2009-03-01 16:30:08.000000000 +0000 +++ reprepro-4.6.0/diffindex.c 2011-05-05 14:42:55.000000000 +0000 @@ -31,10 +31,10 @@ void diffindex_free(struct diffindex *diffindex) { int i; - if( diffindex == NULL ) + if (diffindex == NULL) return; checksums_free(diffindex->destination); - for( i = 0 ; i < diffindex->patchcount ; i ++ ) { + for (i = 0 ; i < diffindex->patchcount ; i ++) { checksums_free(diffindex->patches[i].frompackages); free(diffindex->patches[i].name); checksums_free(diffindex->patches[i].checksums); @@ -46,17 +46,17 @@ memset(hashes, 0, sizeof(struct hashes)); hashes->hashes[cs_sha1sum].start = p; - while( (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F') - || (*p >= '0' && *p <= '9') ) + while ((*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F') + || (*p >= '0' && *p <= '9')) p++; hashes->hashes[cs_sha1sum].len = p - hashes->hashes[cs_sha1sum].start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; hashes->hashes[cs_length].start = p; - while( *p >= '0' && *p <= '9' ) + while (*p >= '0' && *p <= '9') p++; hashes->hashes[cs_length].len = p - hashes->hashes[cs_length].start; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; *rest = p; } @@ -67,14 +67,14 @@ retvalue r; parse_sha1line(current, &hashes, &p); - if( hashes.hashes[cs_sha1sum].len == 0 + if (hashes.hashes[cs_sha1sum].len == 0 || hashes.hashes[cs_length].len == 0 - || *p != '\0' ) { + || *p != '\0') { r = RET_ERROR; } else r = checksums_initialize(&n->destination, hashes.hashes); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) fprintf(stderr, "Error parsing SHA1-Current in '%s'!\n", diffindexfile); return r; @@ -83,70 +83,71 @@ static inline retvalue add_patches(const char *diffindexfile, struct diffindex *n, const struct strlist *patches) { int i; - assert( patches->count == n->patchcount ); + assert (patches->count == n->patchcount); - for( i = 0 ; i < n->patchcount; i++ ) { + for (i = 0 ; i < n->patchcount; i++) { struct hashes hashes; const char *patchname; retvalue r; parse_sha1line(patches->values[i], &hashes, &patchname); - if( hashes.hashes[cs_sha1sum].len == 0 + if (hashes.hashes[cs_sha1sum].len == 0 || hashes.hashes[cs_length].len == 0 - || *patchname == '\0' ) { + || *patchname == '\0') { r = RET_ERROR; } else r = checksums_initialize(&n->patches[i].checksums, hashes.hashes); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error parsing SHA1-Patches line %d in '%s':!\n'%s'\n", i, diffindexfile, patches->values[i]); return r; } n->patches[i].name = strdup(patchname); - if( FAILEDTOALLOC(n) ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; } return RET_OK; } static inline retvalue add_history(const char *diffindexfile, struct diffindex *n, const struct strlist *history) { - int i,j; + int i, j; - for( i = 0 ; i < history->count ; i++ ) { + for (i = 0 ; i < history->count ; i++) { struct hashes hashes; const char *patchname; struct checksums *checksums; retvalue r; parse_sha1line(history->values[i], &hashes, &patchname); - if( hashes.hashes[cs_sha1sum].len == 0 + if (hashes.hashes[cs_sha1sum].len == 0 || hashes.hashes[cs_length].len == 0 - || *patchname == '\0' ) { + || *patchname == '\0') { r = RET_ERROR; } else r = checksums_initialize(&checksums, hashes.hashes); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error parsing SHA1-History line %d in '%s':!\n'%s'\n", i, diffindexfile, history->values[i]); return r; } j = 0; - while( j < n->patchcount && strcmp(n->patches[j].name, - patchname) != 0 ) + while (j < n->patchcount && strcmp(n->patches[j].name, + patchname) != 0) j++; - if( j >= n->patchcount ) { - fprintf(stderr, "'%s' lists '%s' in history but not in patches!\n", + if (j >= n->patchcount) { + fprintf(stderr, +"'%s' lists '%s' in history but not in patches!\n", diffindexfile, patchname); checksums_free(checksums); continue; } - if( n->patches[j].frompackages != NULL ) { + if (n->patches[j].frompackages != NULL) { fprintf(stderr, "Warning: '%s' lists multiple histories for '%s'!\nOnly using last one!\n", diffindexfile, patchname); @@ -165,44 +166,44 @@ r = readtextfile(diffindexfile, diffindexfile, &chunk, NULL); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = chunk_getextralinelist(chunk, "SHA1-History", &history); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "'%s' misses SHA1-History field\n", diffindexfile); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(chunk); return r; } r = chunk_getextralinelist(chunk, "SHA1-Patches", &patches); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "'%s' misses SHA1-Patches field\n", diffindexfile); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(chunk); strlist_done(&history); return r; } r = chunk_getvalue(chunk, "SHA1-Current", ¤t); free(chunk); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "'%s' misses SHA1-Current field\n", diffindexfile); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&history); strlist_done(&patches); return r; } n = calloc(1, sizeof(struct diffindex) + patches.count * sizeof(struct diffindex_patch)); - if( FAILEDTOALLOC(n) ) { + if (FAILEDTOALLOC(n)) { strlist_done(&history); strlist_done(&patches); free(current); @@ -210,15 +211,15 @@ } n->patchcount = patches.count; r = add_current(diffindexfile, n, current); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = add_patches(diffindexfile, n, &patches); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = add_history(diffindexfile, n, &history); ASSERT_NOT_NOTHING(r); strlist_done(&history); strlist_done(&patches); free(current); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *out_p = n; else diffindex_free(n); diff -Nru reprepro-4.5.0/dirs.c reprepro-4.6.0/dirs.c --- reprepro-4.5.0/dirs.c 2009-02-15 11:52:01.000000000 +0000 +++ reprepro-4.6.0/dirs.c 2011-05-05 14:42:55.000000000 +0000 @@ -33,12 +33,12 @@ retvalue dirs_create(const char *dirname) { int ret, e; - ret = mkdir(dirname,0775); - if( ret == 0 ) { - if( verbose > 1) - printf("Created directory \"%s\"\n",dirname); + ret = mkdir(dirname, 0775); + if (ret == 0) { + if (verbose > 1) + printf("Created directory \"%s\"\n", dirname); return RET_OK; - } else if( ret < 0 && ( e = errno ) != EEXIST ) { + } else if (ret < 0 && (e = errno) != EEXIST) { fprintf(stderr, "Error %d creating directory \"%s\": %s\n", e, dirname, strerror(e)); return RET_ERROR; @@ -53,11 +53,13 @@ int i; retvalue r; - for( p = filename+1, i = 1 ; *p != '\0' ; p++,i++) { - if( *p == '/' ) { - h = strndup(filename,i); + for (p = filename+1, i = 1 ; *p != '\0' ; p++, i++) { + if (*p == '/') { + h = strndup(filename, i); + if (FAILEDTOALLOC(h)) + return RET_ERROR_OOM; r = dirs_create(h); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(h); return r; } @@ -69,14 +71,14 @@ /* create dirname and any '/'-separated part of it */ retvalue dirs_make_recursive(const char *directory) { - retvalue r,result; + retvalue r, result; - if( interrupted() ) { + if (interrupted()) { return RET_ERROR_INTERRUPTED; } r = dirs_make_parent(directory); result = dirs_create(directory); - RET_UPDATE(result,r); + RET_UPDATE(result, r); return result; } @@ -89,54 +91,55 @@ char *this; int e; - if( interrupted() ) { + if (interrupted()) { return RET_ERROR_INTERRUPTED; } - while( len > 0 && directory[len-1] == '/' ) + while (len > 0 && directory[len-1] == '/') len--; - while( len > 0 ) { + while (len > 0) { this = strndup(directory, len); - if( this == NULL ) + if (FAILEDTOALLOC(this)) return RET_ERROR_OOM; ret = mkdir(this, 0777); e = errno; - if( ret == 0 ) { - if( verbose > 1) + if (ret == 0) { + if (verbose > 1) printf("Created directory \"%s\"\n", this); - } else if( e == EEXIST ) { + } else if (e == EEXIST) { free(this); break; - /* normaly ENOENT should be the only problem, but check the others - * to be nice to annoying filesystems */ - } else if( e != ENOENT && e != EACCES && e != EPERM ) { - fprintf(stderr, "Cannot create directory \"%s\": %s(%d)\n", + /* normaly ENOENT should be the only problem, + * but check the others to be nice to annoying filesystems */ + } else if (e != ENOENT && e != EACCES && e != EPERM) { + fprintf(stderr, +"Cannot create directory \"%s\": %s(%d)\n", this, strerror(e), e); free(this); return RET_ERRNO(e); } free(this); depth++; - while( len > 0 && directory[len-1] != '/' ) + while (len > 0 && directory[len-1] != '/') len--; - while( len > 0 && directory[len-1] == '/' ) + while (len > 0 && directory[len-1] == '/') len--; } check = depth; - while( directory[len] == '/' ) + while (directory[len] == '/') len++; - while( directory[len] != '\0' ) { - while( directory[len] != '\0' && directory[len] != '/' ) + while (directory[len] != '\0') { + while (directory[len] != '\0' && directory[len] != '/') len++; this = strndup(directory, len); - if( this == NULL ) + if (FAILEDTOALLOC(this)) return RET_ERROR_OOM; r = dirs_create(this); free(this); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // TODO: if we get RET_NOTHING here, reduce depth? check--; - while( directory[len] == '/' ) + while (directory[len] == '/') len++; } assert(check == 0); @@ -149,20 +152,23 @@ char *this; int ret; - while( len > 0 && directory[len-1] == '/' ) + while (len > 0 && directory[len-1] == '/') len--; - while( created > 0 && len > 0 ) { + while (created > 0 && len > 0) { this = strndup(directory, len); - if( this == NULL ) + if (FAILEDTOALLOC(this)) return; ret = rmdir(this); - if( ret == 0 ) { - if( verbose > 1) - printf("Removed empty directory \"%s\"\n", this); + if (ret == 0) { + if (verbose > 1) + printf( +"Removed empty directory \"%s\"\n", + this); } else { int e = errno; - if( e != ENOTEMPTY ) { - fprintf(stderr, "Error removing directory \"%s\": %s(%d)\n", + if (e != ENOTEMPTY) { + fprintf(stderr, +"Error removing directory \"%s\": %s(%d)\n", this, strerror(e), e); } free(this); @@ -170,35 +176,35 @@ } free(this); created--; - while( len > 0 && directory[len-1] != '/' ) + while (len > 0 && directory[len-1] != '/') len--; - while( len > 0 && directory[len-1] == '/' ) + while (len > 0 && directory[len-1] == '/') len--; } return; } -retvalue dirs_getdirectory(const char *filename,char **directory) { +retvalue dirs_getdirectory(const char *filename, char **directory) { size_t len; - assert( filename != NULL && *filename != '\0' ); + assert (filename != NULL && *filename != '\0'); len = strlen(filename); - while( len > 1 && filename[len-1] == '/' ) { + while (len > 1 && filename[len-1] == '/') { len--; } - while( len > 0 && filename[len-1] != '/' ) { + while (len > 0 && filename[len-1] != '/') { len--; } - if( len == 0 ) { + if (len == 0) { *directory = strdup("."); } else { - if( len == 1 ) + if (len == 1) *directory = strdup("/"); else - *directory = strndup(filename,len-1); + *directory = strndup(filename, len-1); } - if( *directory == NULL ) + if (FAILEDTOALLOC(*directory)) return RET_ERROR_OOM; else return RET_OK; @@ -207,8 +213,8 @@ const char *dirs_basename(const char *filename) { const char *bn; - bn = strrchr(filename,'/'); - if( bn == NULL ) + bn = strrchr(filename, '/'); + if (bn == NULL) return filename; // not really suited for the basename of directories, // things like /bla/blub/ will give emtpy string... diff -Nru reprepro-4.5.0/dirs.h reprepro-4.6.0/dirs.h --- reprepro-4.5.0/dirs.h 2009-02-15 11:52:01.000000000 +0000 +++ reprepro-4.6.0/dirs.h 2011-05-05 14:42:55.000000000 +0000 @@ -13,17 +13,17 @@ /* create a directory, return RET_NOTHING if already existing */ retvalue dirs_create(const char *); /* create recursively all parent directories before the last '/' */ -retvalue dirs_make_parent(const char *filename); +retvalue dirs_make_parent(const char *); /* create dirname and any '/'-separated part of it */ -retvalue dirs_make_recursive(const char *directory); +retvalue dirs_make_recursive(const char *); /* create directory and parents as needed, and save count to remove them later */ -retvalue dir_create_needed(const char *directory, int *createddepth); -void dir_remove_new(const char *directory, int created); +retvalue dir_create_needed(const char *, int *); +void dir_remove_new(const char *, int); /* Behave like dirname(3) */ -retvalue dirs_getdirectory(const char *filename,/*@out@*/char **directory); +retvalue dirs_getdirectory(const char *, /*@out@*/char **); -const char *dirs_basename(const char *filename); +const char *dirs_basename(const char *); bool isdir(const char *); #endif diff -Nru reprepro-4.5.0/distribution.c reprepro-4.6.0/distribution.c --- reprepro-4.5.0/distribution.c 2011-02-09 14:20:22.000000000 +0000 +++ reprepro-4.6.0/distribution.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,10 +43,10 @@ #include "distribution.h" static retvalue distribution_free(struct distribution *distribution) { - retvalue result,r; + retvalue result, r; bool needsretrack = false; - if( distribution != NULL ) { + if (distribution != NULL) { free(distribution->suite); free(distribution->fakecomponentprefix); free(distribution->version); @@ -76,23 +76,23 @@ override_free(distribution->overrides.udeb); override_free(distribution->overrides.dsc); logger_free(distribution->logger); - if( distribution->uploaderslist != NULL ) { + if (distribution->uploaderslist != NULL) { uploaders_unlock(distribution->uploaderslist); } byhandhooks_free(distribution->byhandhooks); result = RET_OK; - while( distribution->targets != NULL ) { + while (distribution->targets != NULL) { struct target *next = distribution->targets->next; - if( distribution->targets->staletracking ) + if (distribution->targets->staletracking) needsretrack = true; r = target_free(distribution->targets); - RET_UPDATE(result,r); + RET_UPDATE(result, r); distribution->targets = next; } - if( distribution->tracking != dt_NONE && needsretrack ) { + if (distribution->tracking != dt_NONE && needsretrack) { fprintf(stderr, "WARNING: Tracking data of '%s' might have become out of date.\n" "Consider running retrack to avoid getting funny effects.\n", @@ -118,21 +118,21 @@ /* create all contained targets... */ static retvalue createtargets(struct distribution *distribution) { retvalue r; - int i,j; + int i, j; struct target *t; struct target *last = NULL; bool has_source = false; - for( i = 0 ; i < distribution->components.count ; i++ ) { + for (i = 0 ; i < distribution->components.count ; i++) { component_t c = distribution->components.atoms[i]; - for( j = 0 ; j < distribution->architectures.count ; j++ ) { + for (j = 0 ; j < distribution->architectures.count ; j++) { architecture_t a = distribution->architectures.atoms[j]; - if( a == architecture_source ) { + if (a == architecture_source) { has_source = true; continue; } - if( a == architecture_all ) { + if (a == architecture_all) { fprintf(stderr, "Error: Distribution %s contains an architecture called 'all'.\n", distribution->codename); @@ -146,17 +146,17 @@ distribution->readonly, distribution->fakecomponentprefix, &t); - if( RET_IS_OK(r) ) { - if( last != NULL ) { + if (RET_IS_OK(r)) { + if (last != NULL) { last->next = t; } else { distribution->targets = t; } last = t; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( atomlist_in(&distribution->udebcomponents, c) ) { + if (atomlist_in(&distribution->udebcomponents, c)) { r = target_initialize_ubinary( distribution, c, a, @@ -164,15 +164,15 @@ distribution->readonly, distribution->fakecomponentprefix, &t); - if( RET_IS_OK(r) ) { - if( last != NULL ) { + if (RET_IS_OK(r)) { + if (last != NULL) { last->next = t; } else { distribution->targets = t; } last = t; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } @@ -180,18 +180,18 @@ /* check if this distribution contains source * (yes, yes, source is not really an architecture, but * the .changes files started with this...) */ - if( has_source ) { + if (has_source) { r = target_initialize_source(distribution, c, &distribution->dsc, distribution->readonly, distribution->fakecomponentprefix, &t); - if( last != NULL ) { + if (last != NULL) { last->next = t; } else { distribution->targets = t; } last = t; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } @@ -207,22 +207,22 @@ struct distribution *n; retvalue r; - n = calloc(1, sizeof(struct distribution)); - if( n == NULL ) + n = zNEW(struct distribution); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; /* set some default value: */ r = exportmode_init(&n->udeb, true, NULL, "Packages"); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_free(n); return r; } r = exportmode_init(&n->deb, true, "Release", "Packages"); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_free(n); return r; } r = exportmode_init(&n->dsc, false, "Release", "Sources"); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_free(n); return r; } @@ -230,13 +230,10 @@ return RET_OK; } -static bool notpropersuperset(const struct atomlist *allowed, const char *allowedname, - const struct atomlist *check, const char *checkname, - const char **atoms, - const struct configiterator *iter, const struct distribution *d) { +static bool notpropersuperset(const struct atomlist *allowed, const char *allowedname, const struct atomlist *check, const char *checkname, const char **atoms, const struct configiterator *iter, const struct distribution *d) { atom_t missing; - if( !atomlist_subset(allowed, check, &missing) ) { + if (!atomlist_subset(allowed, check, &missing)) { fprintf(stderr, "In distribution description of '%s' (line %u to %u in %s):\n" "%s contains '%s' not found in %s!\n", @@ -253,28 +250,28 @@ size_t l; int i, j; - if( d->fakecomponentprefix == NULL ) + if (d->fakecomponentprefix == NULL) return RET_OK; l = strlen(d->fakecomponentprefix); - for( i = 0 ; i < d->components.count ; i++ ) { + for (i = 0 ; i < d->components.count ; i++) { const char *c1 = atoms_components[d->components.atoms[i]]; - if( strncmp(c1, d->fakecomponentprefix, l) != 0 ) + if (strncmp(c1, d->fakecomponentprefix, l) != 0) continue; - if( d->fakecomponentprefix[l] != '/' ) + if (d->fakecomponentprefix[l] != '/') continue; - for( j = 0 ; i < d->components.count ; j++ ) { + for (j = 0 ; i < d->components.count ; j++) { const char *c2; - if( j == i ) + if (j == i) continue; c2 = atoms_components[d->components.atoms[j]]; - if( strcmp(c1 + l + 1, c2) == 0) { + if (strcmp(c1 + l + 1, c2) == 0) { fprintf(stderr, "ERROR: distribution '%s' has components '%s' and '%s',\n" "which would be output to the same place due to FakeComponentPrefix '%s'.\n", @@ -288,11 +285,11 @@ } CFfinishparse(distribution) { - CFfinishparseVARS(distribution,n,last_p,mydata); + CFfinishparseVARS(distribution, n, last_p, mydata); struct distribution *d; retvalue r; - if( !complete ) { + if (!complete) { distribution_free(n); return RET_NOTHING; } @@ -300,8 +297,8 @@ n->lastline = config_line(iter) - 1; /* Do some consitency checks */ - for( d = mydata->distributions; d != NULL; d = d->next ) { - if( strcmp(d->codename, n->codename) == 0 ) { + for (d = mydata->distributions; d != NULL; d = d->next) { + if (strcmp(d->codename, n->codename) == 0) { fprintf(stderr, "Multiple distributions with the common codename: '%s'!\n" "First was in %s line %u to %u, another in lines %u to %u", @@ -313,7 +310,7 @@ } } - if( notpropersuperset(&n->architectures, "Architectures", + if (notpropersuperset(&n->architectures, "Architectures", &n->contents_architectures, "ContentsArchitectures", atoms_architectures, iter, n) || @@ -330,36 +327,36 @@ notpropersuperset(&n->components, "Components", &n->udebcomponents, "UDebComponents", atoms_components, - iter, n) ) { + iter, n)) { (void)distribution_free(n); return RET_ERROR; } /* overwrite creation of contents files based on given lists: */ - if( n->contents_components_set ) { - if ( n->contents_components.count > 0 ) { + if (n->contents_components_set) { + if (n->contents_components.count > 0) { n->contents.flags.enabled = true; n->contents.flags.nodebs = false; } else { n->contents.flags.nodebs = true; } } - if( n->contents_ucomponents_set ) { - if ( n->contents_ucomponents.count > 0 ) { + if (n->contents_ucomponents_set) { + if (n->contents_ucomponents.count > 0) { n->contents.flags.enabled = true; n->contents.flags.udebs = true; } else { n->contents.flags.udebs = false; } } - if( n->contents_architectures_set ) { - if( n->contents_architectures.count > 0 ) + if (n->contents_architectures_set) { + if (n->contents_architectures.count > 0) n->contents.flags.enabled = true; else n->contents.flags.enabled = false; } r = checkcomponentsequalduetofake(n); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_free(n); return r; } @@ -367,7 +364,7 @@ /* prepare substructures */ r = createtargets(n); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_free(n); return r; } @@ -376,7 +373,7 @@ n->selected = false; /* put in linked list */ - if( *last_p == NULL ) + if (*last_p == NULL) mydata->distributions = n; else (*last_p)->next = n; @@ -478,10 +475,10 @@ // TODO: readd some way to tell about -b or --confdir here? /* result = regularfileexists(fn); - if( RET_WAS_ERROR(result) ) { - fprintf(stderr,"Could not find '%s'!\n" + if (RET_WAS_ERROR(result)) { + fprintf(stderr, "Could not find '%s'!\n" "(Have you forgotten to specify a basedir by -b?\n" -"To only set the conf/ dir use --confdir)\n",fn); +"To only set the conf/ dir use --confdir)\n", fn); free(mydata.filter.found); free(fn); return RET_ERROR_MISSING; @@ -494,14 +491,16 @@ distributionconfigfields, ARRAYCOUNT(distributionconfigfields), &mydata); - if( result == RET_ERROR_UNKNOWNFIELD ) - fprintf(stderr, "Use --ignore=unknownfield to ignore unknown fields\n"); - if( RET_WAS_ERROR(result) ) { + if (result == RET_ERROR_UNKNOWNFIELD) + fprintf(stderr, +"Use --ignore=unknownfield to ignore unknown fields\n"); + if (RET_WAS_ERROR(result)) { distribution_freelist(mydata.distributions); return result; } - if( mydata.distributions == NULL ) { - fprintf(stderr, "No distribution definitions found in %s/distributions!\n", + if (mydata.distributions == NULL) { + fprintf(stderr, +"No distribution definitions found in %s/distributions!\n", global.confdir); distribution_freelist(mydata.distributions); return RET_ERROR_MISSING; @@ -511,71 +510,69 @@ } /* call for each package */ -retvalue distribution_foreach_package(struct distribution *distribution, struct database *database, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, each_package_action action, each_target_action target_action, void *data) { - retvalue result,r; +retvalue distribution_foreach_package(struct distribution *distribution, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, each_package_action action, each_target_action target_action, void *data) { + retvalue result, r; struct target *t; struct target_cursor iterator IFSTUPIDCC(=TARGET_CURSOR_ZERO); const char *package, *control; result = RET_NOTHING; - for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, components, architectures, packagetypes) ) + for (t = distribution->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, components, architectures, packagetypes)) continue; - if( target_action != NULL ) { - r = target_action(database, distribution, t, data); - if( RET_WAS_ERROR(r) ) + if (target_action != NULL) { + r = target_action(distribution, t, data); + if (RET_WAS_ERROR(r)) return result; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; } - r = target_openiterator(t, database, READONLY, &iterator); + r = target_openiterator(t, READONLY, &iterator); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return result; - while( target_nextpackage(&iterator, &package, &control) ) { - r = action(database, distribution, t, - package, control, data); + while (target_nextpackage(&iterator, &package, &control)) { + r = action(distribution, t, package, control, data); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } r = target_closeiterator(&iterator); RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; } return result; } -retvalue distribution_foreach_package_c(struct distribution *distribution, struct database *database, const struct atomlist *components, architecture_t architecture, packagetype_t packagetype, each_package_action action, void *data) { - retvalue result,r; +retvalue distribution_foreach_package_c(struct distribution *distribution, const struct atomlist *components, architecture_t architecture, packagetype_t packagetype, each_package_action action, void *data) { + retvalue result, r; struct target *t; const char *package, *control; struct target_cursor iterator IFSTUPIDCC(=TARGET_CURSOR_ZERO); result = RET_NOTHING; - for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( components != NULL && - !atomlist_in(components, t->component_atom) ) + for (t = distribution->targets ; t != NULL ; t = t->next) { + if (components != NULL && + !atomlist_in(components, t->component)) continue; - if( limitation_missed(architecture, t->architecture_atom) ) + if (limitation_missed(architecture, t->architecture)) continue; - if( limitation_missed(packagetype, t->packagetype_atom) ) + if (limitation_missed(packagetype, t->packagetype)) continue; - r = target_openiterator(t, database, READONLY, &iterator); + r = target_openiterator(t, READONLY, &iterator); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return result; - while( target_nextpackage(&iterator, &package, &control) ) { - r = action(database, distribution, t, - package, control, data); + while (target_nextpackage(&iterator, &package, &control)) { + r = action(distribution, t, package, control, data); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } r = target_closeiterator(&iterator); RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; } return result; @@ -584,16 +581,16 @@ struct target *distribution_gettarget(const struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype) { struct target *t = distribution->targets; - assert( atom_defined(component) ); - assert( atom_defined(architecture) ); - assert( atom_defined(packagetype) ); + assert (atom_defined(component)); + assert (atom_defined(architecture)); + assert (atom_defined(packagetype)); // TODO: think about making read only access and only alowing readwrite when lookedat is set - while( t != NULL && - ( t->component_atom != component || - t->architecture_atom != architecture || - t->packagetype_atom != packagetype )) { + while (t != NULL && + (t->component != component || + t->architecture != architecture || + t->packagetype != packagetype)) { t = t->next; } return t; @@ -602,18 +599,19 @@ struct target *distribution_getpart(const struct distribution *distribution, component_t component, architecture_t architecture, packagetype_t packagetype) { struct target *t = distribution->targets; - assert( atom_defined(component) ); - assert( atom_defined(architecture) ); - assert( atom_defined(packagetype) ); - - while( t != NULL && - ( t->component_atom != component || - t->architecture_atom != architecture || - t->packagetype_atom != packagetype )) { + assert (atom_defined(component)); + assert (atom_defined(architecture)); + assert (atom_defined(packagetype)); + + while (t != NULL && + (t->component != component || + t->architecture != architecture || + t->packagetype != packagetype)) { t = t->next; } - if( t == NULL ) { - fprintf(stderr, "Internal error in distribution_getpart: Bogus request for c='%s' a='%s' t='%s' in '%s'!\n", + if (t == NULL) { + fprintf(stderr, +"Internal error in distribution_getpart: Bogus request for c='%s' a='%s' t='%s' in '%s'!\n", atoms_components[component], atoms_architectures[architecture], atoms_packagetypes[packagetype], @@ -630,11 +628,11 @@ struct distribution *has_suite[argc]; int i; - assert( alldistributions != NULL ); + assert (alldistributions != NULL); - if( argc <= 0 ) { - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !allowreadonly && d->readonly ) + if (argc <= 0) { + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!allowreadonly && d->readonly) continue; d->selected = true; d->lookedat = lookedat; @@ -645,46 +643,46 @@ memset(unusable_as_suite, 0, sizeof(unusable_as_suite)); memset(has_suite, 0, sizeof(has_suite)); - for( d = alldistributions ; d != NULL ; d = d->next ) { - for( i = 0 ; i < argc ; i++ ) { - if( strcmp(argv[i], d->codename) == 0 ) { - assert( !found[i] ); + for (d = alldistributions ; d != NULL ; d = d->next) { + for (i = 0 ; i < argc ; i++) { + if (strcmp(argv[i], d->codename) == 0) { + assert (!found[i]); found[i] = true; d->selected = true; - if( lookedat ) + if (lookedat) d->lookedat = lookedat; - if( !allowreadonly && d->readonly ) { + if (!allowreadonly && d->readonly) { fprintf(stderr, "Error: %s is readonly, so operation not allowed!\n", d->codename); return RET_ERROR; } - } else if( d->suite != NULL && - strcmp(argv[i], d->suite) == 0 ) { - if( has_suite[i] != NULL ) + } else if (d->suite != NULL && + strcmp(argv[i], d->suite) == 0) { + if (has_suite[i] != NULL) unusable_as_suite[i] = true; has_suite[i] = d; } } } - for( i = 0 ; i < argc ; i++ ) { - if( !found[i] ) { - if( has_suite[i] != NULL && !unusable_as_suite[i] ) { - if( !allowreadonly && has_suite[i]->readonly ) { + for (i = 0 ; i < argc ; i++) { + if (!found[i]) { + if (has_suite[i] != NULL && !unusable_as_suite[i]) { + if (!allowreadonly && has_suite[i]->readonly) { fprintf(stderr, "Error: %s is readonly, so operation not allowed!\n", has_suite[i]->codename); return RET_ERROR; } has_suite[i]->selected = true; - if( lookedat ) + if (lookedat) has_suite[i]->lookedat = lookedat; continue; } fprintf(stderr, "No distribution definition of '%s' found in '%s/distributions'!\n", argv[i], global.confdir); - if( unusable_as_suite[i] ) + if (unusable_as_suite[i]) fprintf(stderr, "(It is not the codename of any distribution and there are multiple\n" "distributions with this as suite name.)\n"); @@ -698,15 +696,15 @@ struct distribution *d, *d2; d = alldistributions; - while( d != NULL && strcmp(name, d->codename) != 0 ) + while (d != NULL && strcmp(name, d->codename) != 0) d = d->next; - if( d == NULL ) { - for( d2 = alldistributions; d2 != NULL ; d2 = d2->next ) { - if( d2->suite == NULL ) + if (d == NULL) { + for (d2 = alldistributions; d2 != NULL ; d2 = d2->next) { + if (d2->suite == NULL) continue; - if( strcmp(name, d2->suite) != 0 ) + if (strcmp(name, d2->suite) != 0) continue; - if( d != NULL ) { + if (d != NULL) { fprintf(stderr, "No distribution has '%s' as codename, but multiple as suite name,\n" "thus it cannot be used to determine a distribution.\n", name); @@ -715,351 +713,383 @@ d = d2; } } - if( d == NULL ) { - fprintf(stderr, "Cannot find definition of distribution '%s'!\n", name); + if (d == NULL) { + fprintf(stderr, +"Cannot find definition of distribution '%s'!\n", + name); return RET_ERROR_MISSING; } d->selected = true; - if( lookedat ) + if (lookedat) d->lookedat = true; *distribution = d; return RET_OK; } -retvalue distribution_snapshot(struct distribution *distribution, struct database *database, const char *name) { +retvalue distribution_snapshot(struct distribution *distribution, const char *name) { struct target *target; - retvalue result,r; + retvalue result, r; struct release *release; char *id; - assert( distribution != NULL ); + assert (distribution != NULL); r = release_initsnapshot(distribution->codename, name, &release); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - for( target=distribution->targets; target != NULL ; target = target->next ) { + for (target=distribution->targets; target != NULL ; + target = target->next) { r = release_mkdir(release, target->relativedirectory); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - r = target_export(target, database, false, true, release); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = target_export(target, false, true, release); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - if( target->exportmode->release != NULL ) { - r = release_directorydescription(release, distribution, target, target->exportmode->release, false); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + if (target->exportmode->release != NULL) { + r = release_directorydescription(release, distribution, + target, target->exportmode->release, + false); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } } - if( !RET_WAS_ERROR(result) ) { + if (!RET_WAS_ERROR(result)) { result = release_prepare(release, distribution, false); - assert( result != RET_NOTHING ); + assert (result != RET_NOTHING); } - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { release_free(release); return result; } result = release_finish(release, distribution); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return r; id = mprintf("s=%s=%s", distribution->codename, name); - if( id == NULL ) + if (FAILEDTOALLOC(id)) return RET_ERROR_OOM; - r = distribution_foreach_package(distribution, database, + r = distribution_foreach_package(distribution, atom_unknown, atom_unknown, atom_unknown, package_referenceforsnapshot, NULL, id); free(id); - RET_UPDATE(result,r); + RET_UPDATE(result, r); return result; } -static retvalue export(struct distribution *distribution, struct database *database, bool onlyneeded) { +static retvalue export(struct distribution *distribution, bool onlyneeded) { struct target *target; - retvalue result,r; + retvalue result, r; struct release *release; - assert( distribution != NULL ); + assert (distribution != NULL); - if( distribution->readonly ) { - fprintf(stderr, "Error: trying to re-export read-only distribution %s\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: trying to re-export read-only distribution %s\n", distribution->codename); return RET_ERROR; } - r = release_init(&release, database, - distribution->codename, distribution->suite, + r = release_init(&release, distribution->codename, distribution->suite, distribution->fakecomponentprefix); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - for( target=distribution->targets; target != NULL ; target = target->next ) { + for (target=distribution->targets; target != NULL ; + target = target->next) { r = release_mkdir(release, target->relativedirectory); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - r = target_export(target, database, onlyneeded, false, release); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = target_export(target, onlyneeded, false, release); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - if( target->exportmode->release != NULL ) { - r = release_directorydescription(release,distribution,target,target->exportmode->release,onlyneeded); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + if (target->exportmode->release != NULL) { + r = release_directorydescription(release, distribution, + target, target->exportmode->release, + onlyneeded); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } } - if( !RET_WAS_ERROR(result) && distribution->contents.flags.enabled ) { - r = contents_generate(database, distribution, - release, onlyneeded); - } - if( !RET_WAS_ERROR(result) ) { - result = release_prepare(release,distribution,onlyneeded); - if( result == RET_NOTHING ) { + if (!RET_WAS_ERROR(result) && distribution->contents.flags.enabled) { + r = contents_generate(distribution, release, onlyneeded); + } + if (!RET_WAS_ERROR(result)) { + result = release_prepare(release, distribution, onlyneeded); + if (result == RET_NOTHING) { release_free(release); return result; } } - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { bool workleft = false; release_free(release); - fprintf(stderr, "ERROR: Could not finish exporting '%s'!\n", distribution->codename); - for( target=distribution->targets; target != NULL ; target = target->next ) { + fprintf(stderr, "ERROR: Could not finish exporting '%s'!\n", + distribution->codename); + for (target=distribution->targets; target != NULL ; + target = target->next) { workleft |= target->saved_wasmodified; } - if( workleft ) { + if (workleft) { (void)fputs( "This means that from outside your repository will still look like before (and\n" "should still work if this old state worked), but the changes intended with this\n" "call will not be visible until you call export directly (via reprepro export)\n" "Changes will also get visible when something else changes the same file and\n" "thus creates a new export of that file, but even changes to other parts of the\n" -"same distribution will not!\n", stderr); +"same distribution will not!\n", + stderr); } } else { - r = release_finish(release,distribution); - RET_UPDATE(result,r); + r = release_finish(release, distribution); + RET_UPDATE(result, r); } - if( RET_IS_OK(result) ) + if (RET_IS_OK(result)) distribution->status = RET_NOTHING; return result; } -retvalue distribution_fullexport(struct distribution *distribution, struct database *database) { - return export(distribution, database, false); +retvalue distribution_fullexport(struct distribution *distribution) { + return export(distribution, false); } retvalue distribution_freelist(struct distribution *distributions) { - retvalue result,r; + retvalue result, r; result = RET_NOTHING; - while( distributions != NULL ) { + while (distributions != NULL) { struct distribution *d = distributions->next; r = distribution_free(distributions); - RET_UPDATE(result,r); + RET_UPDATE(result, r); distributions = d; } return result; } -retvalue distribution_exportlist(enum exportwhen when, struct distribution *distributions, struct database *database) { - retvalue result,r; +retvalue distribution_exportlist(enum exportwhen when, struct distribution *distributions) { + retvalue result, r; bool todo = false; struct distribution *d; - if( when == EXPORT_NEVER ) { - if( verbose > 10 ) - fprintf(stderr, "Not exporting anything as --export=never specified\n"); + if (when == EXPORT_SILENT_NEVER) { + for (d = distributions ; d != NULL ; d = d->next) { + struct target *t; + + for (t = d->targets ; t != NULL ; t = t->next) + t->wasmodified = false; + } + return RET_NOTHING; + } + if (when == EXPORT_NEVER) { + if (verbose > 10) + fprintf(stderr, +"Not exporting anything as --export=never specified\n"); return RET_NOTHING; } - for( d=distributions; d != NULL; d = d->next ) { - if( d->omitted || !d->selected ) + for (d=distributions; d != NULL; d = d->next) { + if (d->omitted || !d->selected) continue; - if( d->lookedat && (RET_IS_OK(d->status) || - ( d->status == RET_NOTHING && when != EXPORT_CHANGED) || + if (d->lookedat && (RET_IS_OK(d->status) || + (d->status == RET_NOTHING && when != EXPORT_CHANGED) || when == EXPORT_FORCE)) { todo = true; } } - if( verbose >= 0 && todo ) + if (verbose >= 0 && todo) printf("Exporting indices...\n"); result = RET_NOTHING; - for( d=distributions; d != NULL; d = d->next ) { - if( d->omitted || !d->selected ) + for (d=distributions; d != NULL; d = d->next) { + if (d->omitted || !d->selected) continue; - if( !d->lookedat ) { - if( verbose >= 30 ) + if (!d->lookedat) { + if (verbose >= 30) printf( " Not exporting %s because not looked at.\n", d->codename); - } else if( (RET_WAS_ERROR(d->status)||interrupted()) && - when != EXPORT_FORCE ) { - if( verbose >= 10 ) + } else if ((RET_WAS_ERROR(d->status)||interrupted()) && + when != EXPORT_FORCE) { + if (verbose >= 10) 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 ) { + } else if (d->status==RET_NOTHING && when==EXPORT_CHANGED) { struct target *t; - if( verbose >= 10 ) + if (verbose >= 10) printf( " Not exporting %s because of no recorded changes and --export=changed.\n", d->codename); /* some paranoid check */ - for( t = d->targets ; t != NULL ; t = t->next ) { - if( t->wasmodified ) { + for (t = d->targets ; t != NULL ; t = t->next) { + if (t->wasmodified) { fprintf(stderr, "A paranoid check found distribution %s would not have been exported,\n" "despite having parts that are marked changed by deeper code.\n" "Please report this and how you got this message as bugreport. Thanks.\n" "Doing a export despite --export=changed....\n", d->codename); - r = export(d, database, true); - RET_UPDATE(result,r); + r = export(d, true); + RET_UPDATE(result, r); break; } } } 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, database, true); - RET_UPDATE(result,r); + r = export(d, true); + RET_UPDATE(result, r); } } return result; } -retvalue distribution_export(enum exportwhen when, struct distribution *distribution, struct database *database) { - if( when == EXPORT_NEVER ) { - if( verbose >= 10 ) +retvalue distribution_export(enum exportwhen when, struct distribution *distribution) { + if (when == EXPORT_SILENT_NEVER) { + struct target *t; + + for (t = distribution->targets ; t != NULL ; t = t->next) + t->wasmodified = false; + return RET_NOTHING; + } + if (when == EXPORT_NEVER) { + if (verbose >= 10) 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 ) + if (when != EXPORT_FORCE && + (RET_WAS_ERROR(distribution->status)||interrupted())) { + if (verbose >= 10) 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; } - if( when == EXPORT_CHANGED && distribution->status == RET_NOTHING ) { + if (when == EXPORT_CHANGED && distribution->status == RET_NOTHING) { struct target *t; - if( verbose >= 10 ) + if (verbose >= 10) fprintf(stderr, "Not exporting %s because of no recorded changes and --export=changed.\n", distribution->codename); /* some paranoid check */ - for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( t->wasmodified ) { + for (t = distribution->targets ; t != NULL ; t = t->next) { + if (t->wasmodified) { fprintf(stderr, "A paranoid check found distribution %s would not have been exported,\n" "despite having parts that are marked changed by deeper code.\n" "Please report this and how you got this message as bugreport. Thanks.\n" "Doing a export despite --export=changed....\n", distribution->codename); - return export(distribution, database, true); + return export(distribution, true); break; } } return RET_NOTHING; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Exporting indices...\n"); - return export(distribution, database, true); + return export(distribution, 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 ) + while (d != NULL && strcmp(d->codename, name) != 0) d = d->next; - if( d != NULL ) + if (d != NULL) return d; d = distributions; - while( d != NULL && !strlist_in(&d->alsoaccept, name) ) + while (d != NULL && !strlist_in(&d->alsoaccept, name)) d = d->next; r = d; - if( r != NULL ) { + if (r != NULL) { d = d->next; - while( d != NULL && ! strlist_in(&d->alsoaccept, name) ) + while (d != NULL && ! strlist_in(&d->alsoaccept, name)) d = d->next; - if( d == NULL ) + if (d == NULL) return r; - fprintf(stderr, "No distribution has codename '%s' and multiple have it in AlsoAcceptFor!\n", name); + fprintf(stderr, +"No distribution has codename '%s' and multiple have it in AlsoAcceptFor!\n", + name); return NULL; } d = distributions; - while( d != NULL && ( d->suite == NULL || strcmp(d->suite, name) != 0 )) + while (d != NULL && (d->suite == NULL || strcmp(d->suite, name) != 0)) d = d->next; r = d; - if( r == NULL ) { + if (r == NULL) { fprintf(stderr, "No distribution named '%s' found!\n", name); return NULL; } d = d->next; - while( d != NULL && ( d->suite == NULL || strcmp(d->suite, name) != 0 )) + while (d != NULL && (d->suite == NULL || strcmp(d->suite, name) != 0)) d = d->next; - if( d == NULL ) + if (d == NULL) return r; - fprintf(stderr, "No distribution has codename '%s' and multiple have it as suite-name!\n", name); + fprintf(stderr, +"No distribution has codename '%s' and multiple have it as suite-name!\n", + name); return NULL; } retvalue distribution_loadalloverrides(struct distribution *distribution) { retvalue r; - if( distribution->overrides.deb == NULL ) { + if (distribution->overrides.deb == NULL) { r = override_read(distribution->deb_override, &distribution->overrides.deb, false); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { distribution->overrides.deb = NULL; return r; } } - if( distribution->overrides.udeb == NULL ) { + if (distribution->overrides.udeb == NULL) { r = override_read(distribution->udeb_override, &distribution->overrides.udeb, false); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { distribution->overrides.udeb = NULL; return r; } } - if( distribution->overrides.dsc == NULL ) { + if (distribution->overrides.dsc == NULL) { r = override_read(distribution->dsc_override, &distribution->overrides.dsc, true); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { distribution->overrides.dsc = NULL; return r; } } - if( distribution->overrides.deb != NULL || + if (distribution->overrides.deb != NULL || distribution->overrides.udeb != NULL || - distribution->overrides.dsc != NULL ) + distribution->overrides.dsc != NULL) return RET_OK; else return RET_NOTHING; } retvalue distribution_loaduploaders(struct distribution *distribution) { - if( distribution->uploaders != NULL ) { - if( distribution->uploaderslist != NULL ) + if (distribution->uploaders != NULL) { + if (distribution->uploaderslist != NULL) return RET_OK; return uploaders_get(&distribution->uploaderslist, distribution->uploaders); @@ -1070,7 +1100,7 @@ } void distribution_unloaduploaders(struct distribution *distribution) { - if( distribution->uploaderslist != NULL ) { + if (distribution->uploaderslist != NULL) { uploaders_unlock(distribution->uploaderslist); distribution->uploaderslist = NULL; } @@ -1079,15 +1109,17 @@ retvalue distribution_prepareforwriting(struct distribution *distribution) { retvalue r; - if( distribution->readonly ) { - fprintf(stderr, "Error: distribution %s is read-only. Current operation not possible because it needs write access.\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: distribution %s is read-only.\n" +"Current operation not possible because it needs write access.\n", distribution->codename); return RET_ERROR; } - if( distribution->logger != NULL ) { + if (distribution->logger != NULL) { r = logger_prepare(distribution->logger); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } distribution->lookedat = true; @@ -1095,43 +1127,43 @@ } /* delete every package decider returns RET_OK for */ -retvalue distribution_remove_packages(struct distribution *distribution, struct database *database, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, each_package_action decider, struct trackingdata *trackingdata, void *data) { - retvalue result,r; +retvalue distribution_remove_packages(struct distribution *distribution, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes, each_package_action decider, struct trackingdata *trackingdata, void *data) { + retvalue result, r; struct target *t; struct target_cursor iterator; const char *package, *control; - if( distribution->readonly ) { - fprintf(stderr, "Error: trying to delete packages in read-only distribution %s.\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: trying to delete packages in read-only distribution %s.\n", distribution->codename); return RET_ERROR; } result = RET_NOTHING; - for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, components, architectures, packagetypes) ) + for (t = distribution->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, components, architectures, packagetypes)) continue; - r = target_openiterator(t, database, READWRITE, &iterator); + r = target_openiterator(t, READWRITE, &iterator); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return result; - while( target_nextpackage(&iterator, &package, &control) ) { - r = decider(database, distribution, t, + while (target_nextpackage(&iterator, &package, &control)) { + r = decider(distribution, t, package, control, data); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = target_removepackage_by_cursor(&iterator, - distribution->logger, database, - trackingdata); + distribution->logger, trackingdata); RET_UPDATE(result, r); RET_UPDATE(distribution->status, r); } } r = target_closeiterator(&iterator); RET_ENDUPDATE(result, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; } return result; diff -Nru reprepro-4.5.0/distribution.h reprepro-4.6.0/distribution.h --- reprepro-4.5.0/distribution.h 2011-02-09 14:20:22.000000000 +0000 +++ reprepro-4.6.0/distribution.h 2011-05-05 14:42:55.000000000 +0000 @@ -34,7 +34,7 @@ /* additional information for the Release-file to be * generated, may be NULL. only suite is sometimes used * (and only for sanity checks) */ - /*@null@*/char *suite,*version; + /*@null@*/char *suite, *version; /*@null@*/char *origin, *label, *description, *notautomatic, *butautomaticupgrades; /* What architectures and components are there */ @@ -46,18 +46,20 @@ /* the key to sign with, may have no entries to mean unsigned: */ struct strlist signwith; /* the override file to use by default */ - /*@null@*/char *deb_override,*udeb_override,*dsc_override; + /*@null@*/char *deb_override, *udeb_override, *dsc_override; /* fake component prefix (and codename antisuffix) for Release files: */ /*@null@*/char *fakecomponentprefix; /* only loaded when you've done it yourself: */ struct { /*@null@*/struct overridefile *dsc, *deb, *udeb; } overrides; - /* the list of components containing a debian-installer dir, normally only "main" */ + /* the list of components containing a debian-installer dir, + * normally only "main" */ struct atomlist udebcomponents; /* what kind of index files to generate */ - struct exportmode dsc,deb,udeb; - /* is tracking enabled for this distribution? (NONE must be 0 so it is the default) */ + struct exportmode dsc, deb, udeb; + /* is tracking enabled for this distribution? + * (NONE must be 0 so it is the default) */ enum trackingtype { dt_NONE=0, dt_KEEP, dt_ALL, dt_MINIMAL } tracking; struct trackingoptions { bool includechanges:1; bool includebyhand:1; @@ -107,48 +109,44 @@ bool omitted; }; -retvalue distribution_get(struct distribution *all, const char *name, bool lookedat, /*@out@*/struct distribution **); +retvalue distribution_get(struct distribution * /*all*/, const char *, bool /*lookedat*/, /*@out@*/struct distribution **); /* set lookedat, start logger, ... */ -retvalue distribution_prepareforwriting(struct distribution *distribution); +retvalue distribution_prepareforwriting(struct distribution *); -typedef retvalue distribution_each_action(void *data, struct target *t, struct distribution *d); - -typedef retvalue each_target_action(struct database *, struct distribution *, struct target *, void *); -typedef retvalue each_package_action(struct database *, struct distribution *, struct target *, const char *, const char *, void *); +typedef retvalue each_target_action(struct distribution *, struct target *, void *); +typedef retvalue each_package_action(struct distribution *, struct target *, const char *, const char *, void *); /* call for each package of */ -retvalue distribution_foreach_package(struct distribution *, struct database *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, each_package_action, /*@null@*/each_target_action, void *); -retvalue distribution_foreach_package_c(struct distribution *, struct database *, /*@null@*/const struct atomlist *, architecture_t, packagetype_t, each_package_action, void *); +retvalue distribution_foreach_package(struct distribution *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, each_package_action, /*@null@*/each_target_action, void *); +retvalue distribution_foreach_package_c(struct distribution *, /*@null@*/const struct atomlist *, architecture_t, packagetype_t, each_package_action, void *); /* delete every package decider returns RET_OK for */ -retvalue distribution_remove_packages(struct distribution *, struct database *, const struct atomlist *, const struct atomlist *, const struct atomlist *, each_package_action decider, struct trackingdata *, void *); +retvalue distribution_remove_packages(struct distribution *, const struct atomlist *, const struct atomlist *, const struct atomlist *, each_package_action decider, struct trackingdata *, void *); /*@dependent@*/struct target *distribution_getpart(const struct distribution *distribution, component_t, architecture_t, packagetype_t); /* like distribtion_getpart, but returns NULL if there is no such target */ /*@null@*//*@dependent@*/struct target *distribution_gettarget(const struct distribution *distribution, component_t, architecture_t, packagetype_t); -// /*@null@*//*@dependent@*/struct target *distribution_gettarget(const struct distribution *distribution,const char *component,const char *architecture,const char *packagetype); -retvalue distribution_fullexport(struct distribution *distribution, struct database *); +retvalue distribution_fullexport(struct distribution *distribution); -enum exportwhen {EXPORT_NEVER, EXPORT_CHANGED, EXPORT_NORMAL, EXPORT_FORCE }; -retvalue distribution_export(enum exportwhen, struct distribution *, struct database *); +enum exportwhen {EXPORT_NEVER, EXPORT_SILENT_NEVER, EXPORT_CHANGED, EXPORT_NORMAL, EXPORT_FORCE }; +retvalue distribution_export(enum exportwhen, struct distribution *); -retvalue distribution_snapshot(struct distribution *distribution, struct database *, const char *name); +retvalue distribution_snapshot(struct distribution *distribution, const char *name); /* read the configuration from all distributions */ retvalue distribution_readall(/*@out@*/struct distribution **distributions); -/* mark all dists from fitting in the filter given in */ -retvalue distribution_match(struct distribution *alldistributions, int argc, const char *argv[], bool lookedat, bool readonly); +/* mark all dists from fitting in the filter given in */ +retvalue distribution_match(struct distribution * /*alldistributions*/, int /*argc*/, const char * /*argv*/ [], bool /*lookedat*/, bool /*readonly*/); /* get a pointer to the apropiate part of the linked list */ -struct distribution *distribution_find(struct distribution *distributions, const char *name); +struct distribution *distribution_find(struct distribution *, const char *); retvalue distribution_freelist(/*@only@*/struct distribution *distributions); -retvalue distribution_exportandfreelist(enum exportwhen when, /*@only@*/struct distribution *distributions, struct database *); -retvalue distribution_exportlist(enum exportwhen when, /*@only@*/struct distribution *distributions, struct database *); +retvalue distribution_exportlist(enum exportwhen when, /*@only@*/struct distribution *distributions); retvalue distribution_loadalloverrides(struct distribution *); void distribution_unloadoverrides(struct distribution *distribution); diff -Nru reprepro-4.5.0/docs/manual.html reprepro-4.6.0/docs/manual.html --- reprepro-4.5.0/docs/manual.html 2011-02-09 14:20:26.000000000 +0000 +++ reprepro-4.6.0/docs/manual.html 2011-05-05 14:42:55.000000000 +0000 @@ -26,7 +26,7 @@

Table of contents

Sections of this document: @@ -1286,7 +1286,7 @@ This file contains the information of the source package tracking.

Disaster recovery

TO BE DOCUMENTED (see the -recovery +recovery file until then)

Paranoia

As all software, reprepro might have bugs. @@ -1385,7 +1385,8 @@ places reprepro does not consider their canonical ones.
Having different files with the same name
-take a look in the FAQ (currently question 1.2) why and how to avoid the problem. +take a look in the FAQ (currently question 1.2) why and how to avoid the problem. +
diff -Nru reprepro-4.5.0/docs/reprepro.1 reprepro-4.6.0/docs/reprepro.1 --- reprepro-4.5.0/docs/reprepro.1 2011-02-21 15:34:29.000000000 +0000 +++ reprepro-4.6.0/docs/reprepro.1 2011-05-05 14:42:55.000000000 +0000 @@ -170,7 +170,7 @@ Note that architecture \fBall\fP packages can be included to each architecture but are then handled separately. -Thus using \fB\-A\fP correctly allows to have different versions of +Thus by using \fB\-A\fP in a specific way one can have different versions of an architecture \fBall\fP package in different architectures of the same distribution. .TP @@ -446,6 +446,29 @@ give .B \-\-noonlysmalldeletes to override it. +.TP +.B \-\-restrict \fIsrc\fP\fR[\fP=\fIversion\fP\fR|\fP:\fItype\fP\fR]\fP +Restrict a \fBpull\fP or \fBupdate\fP to only act on packages belonging +to source-package \fIsrc\fP. +Any other package will not be updated (unless it matches a \fB\-\-restrict\-bin\fP). +Only packages that would otherwise be updated or are at least marked with \fBhold\fP +in a \fBFilterList\fP or \fBFilerSrcList\fP will be updated. + +The action can be restricted to a source version using a equal sign or +changed to another type (see FilterList) using a colon. + +This option can be given multiple times to list multiple packages, but each +package may only be named once (even when there are different versions or types). +.TP +.B \-\-restrict\-binary \fIname\fP\fR[\fP=\fIversion\fP\fR|\fP:\fItype\fP\fR]\fP +Like \fB\-\-restrict\fP but restrict to binary packages (\fB.deb\fP and \fB.udeb\fP). +Source packages are not upgraded unless they appear in a \fB\-\-restrict\fP. +.TP +.B \-\-restrict\-file \fIfilename\fP +Like \fB\-\-restrict\fP but read a whole file in the \fBFilterSrcList\fP format. +.TP +.B \-\-restrict\-file\-bin \fIfilename\fP +Like \fB\-\-restrict\-bin\fP but read a whole file in the \fBFilterList\fP format. .SH COMMANDS .TP .BR export " [ " \fIcodenames\fP " ]" @@ -1002,7 +1025,7 @@ .B _listdbidentifiers \fIidentifier\fP \fR[\fP \fIdistributions...\fP \fR]\fP Print - one per line - all identifiers of subdatabases in the current database. -This will be a subset of the ones printed by \fB_listconfidentifiers\dP or +This will be a subset of the ones printed by \fB_listconfidentifiers\fP or most commands but \fBclearvanished\fP will refuse to run, and depending on the database compatibility version, will include all those if reprepro was run since the config was last changed. @@ -1541,10 +1564,10 @@ "architecture (== all)", to get only at least important packages use "priority (==required) | priority (==important)". .TP -.B FilterList -This takes at least two arguments: The first one is the default action -when something is not found in the list, then a list of -filenames (relative to +.B FilterList\fR, \fPFilterSrcList +These take at least two arguments: +The first one is the default action when something is not found in the list, +then a list of filenames (relative to .B \-\-confdir\fR, if not starting with a slash), in the format of dpkg \-\-get\-selections and only packages listed in @@ -1567,6 +1590,18 @@ delete rules. To abort the whole upgrade/pull if a package is available, use .B error\fR. +Instead of a keyword you can also use "\fB= \fP\fIversion\fP" which +is treated like \fBinstall\fP if the version matches and like no +entry if it does not match. +Only one such entry per package is currently supported and the version +is currently compared as string. + +If there is both \fBFilterList\fP and \fBFilterSrcList\fP then +the first is used for \fB.deb\fP and \fB.udeb\fP and the second for +\fB.dsc\fP packages. +If there is only \fBFilterList\fP that is applied to everything. +If there is only \fBFilterSrcList\fP that is applied to everything, too, +but the source package name (and source version) is used to do the lookup. .TP .B ListHook If this is given, it is executed for all downloaded index files @@ -1671,6 +1706,8 @@ .B FilterFormula .TP .B FilterList +.TP +.B FilterSrcList The same as with update rules. .SH "OVERRIDE FILES" The format of override files used by reprepro diff -Nru reprepro-4.5.0/donefile.c reprepro-4.6.0/donefile.c --- reprepro-4.5.0/donefile.c 2008-08-23 15:42:41.000000000 +0000 +++ reprepro-4.6.0/donefile.c 2011-05-05 14:42:55.000000000 +0000 @@ -47,22 +47,22 @@ retvalue markdone_create(const char *codename, struct markdonefile **done_p) { struct markdonefile *done; - done = malloc(sizeof(struct markdonefile)); - if( FAILEDTOALLOC(done) ) + done = NEW(struct markdonefile); + if (FAILEDTOALLOC(done)) return RET_ERROR_OOM; done->finalfilename = donefilename(codename); - if( FAILEDTOALLOC(done->finalfilename) ) { + if (FAILEDTOALLOC(done->finalfilename)) { free(done); return RET_ERROR_OOM; } done->tempfilename = calc_addsuffix(done->finalfilename, "new"); - if( FAILEDTOALLOC(done->tempfilename) ) { + if (FAILEDTOALLOC(done->tempfilename)) { free(done->finalfilename); free(done); return RET_ERROR_OOM; } done->file = fopen(done->tempfilename, "w+"); - if( done->file == NULL ) { + if (done->file == NULL) { int e = errno; fprintf(stderr, "Error %d creating '%s': %s\n", e, done->tempfilename, strerror(e)); @@ -79,31 +79,32 @@ void markdone_finish(struct markdonefile *done) { bool error = false; - if( done == NULL ) + if (done == NULL) return; - if( done->file == NULL ) + if (done->file == NULL) error = true; else { - if( ferror(done->file) != 0 ) { + if (ferror(done->file) != 0) { fprintf(stderr, "An error occured writing to '%s'!\n", done->tempfilename); (void)fclose(done->file); error = true; - } else if( fclose(done->file) != 0 ) { + } else if (fclose(done->file) != 0) { int e = errno; - fprintf(stderr, "Error %d occured writing to '%s': %s!\n", + fprintf(stderr, +"Error %d occured writing to '%s': %s!\n", e, done->tempfilename, strerror(e)); error = true; } done->file = NULL; } - if( error ) + if (error) (void)unlink(done->tempfilename); else { int i; i = rename(done->tempfilename, done->finalfilename); - if( i != 0 ) { + if (i != 0) { int e = errno; fprintf(stderr, "Error %d moving '%s' to '%s': %s!\n", e, done->tempfilename, @@ -125,7 +126,7 @@ const char *data; r = checksums_getcombined(checksums, &data, &s); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return; fprintf(done->file, "Index %s %s\n", file, data); } @@ -147,23 +148,23 @@ struct donefile *done; ssize_t s; - done = calloc(1, sizeof(struct donefile)); - if( FAILEDTOALLOC(done) ) + done = zNEW(struct donefile); + if (FAILEDTOALLOC(done)) return RET_ERROR_OOM; done->filename = donefilename(codename); - if( FAILEDTOALLOC(done->filename) ) { + if (FAILEDTOALLOC(done->filename)) { free(done); return RET_ERROR_OOM; } done->file = fopen(done->filename, "r"); - if( done->file == NULL ) { + if (done->file == NULL) { donefile_close(done); return RET_NOTHING; } s = getline(&done->linebuffer, &done->linebuffer_size, done->file); - if( s <= 0 || done->linebuffer[s-1] != '\n' ) { + if (s <= 0 || done->linebuffer[s-1] != '\n') { /* if it cannot be read or is empty or not a text file, * delete it, and do as if it never existed... */ unlink(done->filename); @@ -177,11 +178,11 @@ } void donefile_close(struct donefile *done) { - if( done == NULL ) + if (done == NULL) return; // TODO: check return, only print a warning, though, // no need to interrupt anything. - if( done->file != NULL ) + if (done->file != NULL) fclose(done->file); free(done->linebuffer); free(done->filename); @@ -191,9 +192,10 @@ retvalue donefile_nexttarget(struct donefile *done, const char **identifier_p) { ssize_t s; - while( strncmp(done->linebuffer, "Target ", 7) != 0 ) { - s = getline(&done->linebuffer, &done->linebuffer_size, done->file); - if( s <= 0 || done->linebuffer[s-1] != '\n' ) + while (strncmp(done->linebuffer, "Target ", 7) != 0) { + s = getline(&done->linebuffer, &done->linebuffer_size, + done->file); + if (s <= 0 || done->linebuffer[s-1] != '\n') /* Malformed line, ignore the rest... */ return RET_NOTHING; done->linebuffer[s-1] = '\0'; @@ -211,17 +213,17 @@ retvalue r; s = getline(&done->linebuffer, &done->linebuffer_size, done->file); - if( s <= 0 || done->linebuffer[s-1] != '\n' ) { + if (s <= 0 || done->linebuffer[s-1] != '\n') { done->linebuffer[0] = '\0'; return false; } done->linebuffer[s-1] = '\0'; - if( strncmp(done->linebuffer, "Index ", 6) != 0 ) + if (strncmp(done->linebuffer, "Index ", 6) != 0) return false; p = done->linebuffer + 6; *filename_p = p; p = strchr(p, ' '); - if( p == NULL ) + if (p == NULL) return false; *(p++) = '\0'; r = checksums_parse(checksums_p, p); @@ -232,7 +234,7 @@ ssize_t s; s = getline(&done->linebuffer, &done->linebuffer_size, done->file); - if( s <= 0 || done->linebuffer[s-1] != '\n' ) { + if (s <= 0 || done->linebuffer[s-1] != '\n') { done->linebuffer[0] = '\0'; return false; } diff -Nru reprepro-4.5.0/donefile.h reprepro-4.6.0/donefile.h --- reprepro-4.5.0/donefile.h 2008-08-23 15:42:41.000000000 +0000 +++ reprepro-4.6.0/donefile.h 2011-05-05 14:42:55.000000000 +0000 @@ -6,7 +6,6 @@ #endif struct checksums; -retvalue donefile_isold(const char *filename, const struct checksums *expected); struct markdonefile; retvalue markdone_create(const char *, /*@out@*/struct markdonefile **); diff -Nru reprepro-4.5.0/downloadcache.c reprepro-4.6.0/downloadcache.c --- reprepro-4.5.0/downloadcache.c 2009-10-09 11:10:34.000000000 +0000 +++ reprepro-4.6.0/downloadcache.c 2011-05-05 14:42:55.000000000 +0000 @@ -32,7 +32,7 @@ struct downloaditem { /*@dependent@*//*@null@*/struct downloaditem *parent; - /*@null@*/struct downloaditem *left,*right; + /*@null@*/struct downloaditem *left, *right; char *filekey; struct checksums *checksums; bool done; @@ -43,11 +43,11 @@ struct downloadcache *cache; retvalue r; - cache = calloc(1, sizeof(struct downloadcache)); - if( cache == NULL ) + cache = zNEW(struct downloadcache); + if (FAILEDTOALLOC(cache)) return RET_ERROR_OOM; r = space_prepare(&cache->devices, mode, reserveddb, reservedother); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(cache); return r; } @@ -57,7 +57,7 @@ /* free all memory */ static void freeitem(/*@null@*//*@only@*/struct downloaditem *item) { - if( item == NULL ) + if (item == NULL) return; freeitem(item->left); freeitem(item->right); @@ -67,7 +67,7 @@ } retvalue downloadcache_free(struct downloadcache *download) { - if( download == NULL ) + if (download == NULL) return RET_NOTHING; freeitem(download->items); @@ -79,53 +79,53 @@ static retvalue downloaditem_callback(enum queue_action action, void *privdata, void *privdata2, const char *uri, const char *gotfilename, const char *wantedfilename, /*@null@*/const struct checksums *checksums, const char *method) { struct downloaditem *d = privdata; struct downloadcache *cache = privdata2; - struct database *database = cache->database; struct checksums *read_checksums = NULL; retvalue r; bool improves; - if( action != qa_got ) + if (action != qa_got) // TODO: instead store in downloaditem? return RET_ERROR; /* if the file is somewhere else, copy it: */ - if( strcmp(gotfilename, wantedfilename) != 0 ) { - if( verbose > 1 ) + if (strcmp(gotfilename, wantedfilename) != 0) { + if (verbose > 1) fprintf(stderr, "Linking file '%s' to '%s'...\n", gotfilename, wantedfilename); r = checksums_linkorcopyfile(wantedfilename, gotfilename, &read_checksums); - if( r == RET_NOTHING ) { - fprintf(stderr, "Cannot open '%s', obtained from '%s' method.\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"Cannot open '%s', obtained from '%s' method.\n", gotfilename, method); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { // TODO: instead store in downloaditem? return r; } - if( read_checksums != NULL ) + if (read_checksums != NULL) checksums = read_checksums; } - if( checksums == NULL || !checksums_iscomplete(checksums) ) { + if (checksums == NULL || !checksums_iscomplete(checksums)) { assert(read_checksums == NULL); r = checksums_read(wantedfilename, &read_checksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot open '%s', though '%s' method claims to have put it there!\n", wantedfilename, method); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { // TODO: instead store in downloaditem? return r; } checksums = read_checksums; } - assert( checksums != NULL ); + assert (checksums != NULL); - if( !checksums_check(d->checksums, checksums, &improves) ) { + if (!checksums_check(d->checksums, checksums, &improves)) { fprintf(stderr, "Wrong checksum during receive of '%s':\n", uri); checksums_printdifferences(stderr, d->checksums, checksums); @@ -134,22 +134,22 @@ // TODO: instead store in downloaditem? return RET_ERROR_WRONG_MD5; } - if( improves ) { + if (improves) { r = checksums_combine(&d->checksums, checksums, NULL); checksums_free(read_checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } else checksums_free(read_checksums); - if( global.showdownloadpercent > 0 ) { + if (global.showdownloadpercent > 0) { unsigned int percent; cache->size_done += checksums_getfilesize(d->checksums); percent = (100 * cache->size_done) / cache->size_todo; - if( global.showdownloadpercent > 1 - || percent > cache->last_percent ) { + if (global.showdownloadpercent > 1 + || percent > cache->last_percent) { unsigned long long all = cache->size_done; int kb, mb, gb, tb, b, groups = 0; @@ -165,29 +165,29 @@ gb = all & 1023; all = all >> 10; tb = all; - if( tb != 0 ) { + if (tb != 0) { printf("%dT ", tb); groups++; } - if( groups < 2 && (groups > 0 || gb != 0 ) ) { + if (groups < 2 && (groups > 0 || gb != 0)) { printf("%dG ", gb); groups++; } - if( groups < 2 && (groups > 0 || mb != 0 ) ) { + if (groups < 2 && (groups > 0 || mb != 0)) { printf("%dM ", mb); groups++; } - if( groups < 2 && (groups > 0 || kb != 0 ) ) { + if (groups < 2 && (groups > 0 || kb != 0)) { printf("%dK ", kb); groups++; } - if( groups < 2 && (groups > 0 || b != 0 ) ) + if (groups < 2 && (groups > 0 || b != 0)) printf("%d ", b); puts("bytes"); } } - r = files_add_checksums(database, d->filekey, d->checksums); - if( RET_WAS_ERROR(r) ) + r = files_add_checksums(d->filekey, d->checksums); + if (RET_WAS_ERROR(r)) return r; d->done = true; return RET_OK; @@ -203,12 +203,12 @@ *h = &list->items; *p = NULL; item = list->items; - while( item != NULL ) { + while (item != NULL) { *p = item; c = strcmp(filekey, item->filekey); - if( c == 0 ) + if (c == 0) return item; - else if( c < 0 ) { + else if (c < 0) { *h = &item->left; item = item->left; } else { @@ -222,66 +222,65 @@ /* queue a new file to be downloaded: * results in RET_ERROR_WRONG_MD5, if someone else already asked * for the same destination with other md5sum created. */ -retvalue downloadcache_add(struct downloadcache *cache, struct database *database, struct aptmethod *method, const char *orig, const char *filekey, const struct checksums *checksums) { +retvalue downloadcache_add(struct downloadcache *cache, struct aptmethod *method, const char *orig, const char *filekey, const struct checksums *checksums) { struct downloaditem *i; - struct downloaditem *item,**h,*parent; + struct downloaditem *item, **h, *parent; char *fullfilename; retvalue r; - assert( cache != NULL && method != NULL ); - r = files_expect(database, filekey, checksums, false); - if( r != RET_NOTHING ) + assert (cache != NULL && method != NULL); + r = files_expect(filekey, checksums, false); + if (r != RET_NOTHING) return r; - i = searchforitem(cache,filekey,&parent,&h); - if( i != NULL ) { + i = searchforitem(cache, filekey, &parent, &h); + if (i != NULL) { bool improves; - assert( i->filekey != NULL ); - if( !checksums_check(i->checksums, checksums, &improves) ) { + assert (i->filekey != NULL); + if (!checksums_check(i->checksums, checksums, &improves)) { fprintf(stderr, "ERROR: Same file is requested with conflicting checksums:\n"); checksums_printdifferences(stderr, i->checksums, checksums); return RET_ERROR_WRONG_MD5; } - if( improves ) { + if (improves) { r = checksums_combine(&i->checksums, checksums, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_NOTHING; } - item = calloc(1, sizeof(struct downloaditem)); - if( FAILEDTOALLOC(item) ) + item = zNEW(struct downloaditem); + if (FAILEDTOALLOC(item)) return RET_ERROR_OOM; item->done = false; item->filekey = strdup(filekey); item->checksums = checksums_dup(checksums); - if( FAILEDTOALLOC(item->filekey) || FAILEDTOALLOC(item->checksums) ) { + if (FAILEDTOALLOC(item->filekey) || FAILEDTOALLOC(item->checksums)) { freeitem(item); return RET_ERROR_OOM; } fullfilename = files_calcfullfilename(filekey); - if( FAILEDTOALLOC(fullfilename) ) { + if (FAILEDTOALLOC(fullfilename)) { freeitem(item); return RET_ERROR_OOM; } (void)dirs_make_parent(fullfilename); r = space_needed(cache->devices, fullfilename, checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); freeitem(item); return r; } - cache->database = database; r = aptmethod_enqueue(method, orig, fullfilename, downloaditem_callback, item, cache); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { freeitem(item); return r; } @@ -296,25 +295,21 @@ } /* some as above, only for more files... */ -retvalue downloadcache_addfiles(struct downloadcache *cache, - struct database *database, - struct aptmethod *method, - const struct checksumsarray *origfiles, - const struct strlist *filekeys) { - retvalue result,r; +retvalue downloadcache_addfiles(struct downloadcache *cache, struct aptmethod *method, const struct checksumsarray *origfiles, const struct strlist *filekeys) { + retvalue result, r; int i; - assert( origfiles != NULL && filekeys != NULL - && origfiles->names.count == filekeys->count ); + assert (origfiles != NULL && filekeys != NULL + && origfiles->names.count == filekeys->count); result = RET_NOTHING; - for( i = 0 ; i < filekeys->count ; i++ ) { - r = downloadcache_add(cache, database, method, + for (i = 0 ; i < filekeys->count ; i++) { + r = downloadcache_add(cache, method, origfiles->names.values[i], filekeys->values[i], origfiles->checksums[i]); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } return result; } diff -Nru reprepro-4.5.0/downloadcache.h reprepro-4.6.0/downloadcache.h --- reprepro-4.5.0/downloadcache.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/downloadcache.h 2011-05-05 14:42:55.000000000 +0000 @@ -28,27 +28,22 @@ /*@null@*/struct downloaditem *items; /*@null@*/struct devices *devices; - struct database *database; - /* for showing what percentage was downloaded */ long long size_todo, size_done; unsigned int last_percent; }; /* Initialize a new download session */ -retvalue downloadcache_initialize(enum spacecheckmode, off_t reserveddb, off_t reservedother, /*@out@*/struct downloadcache **download); +retvalue downloadcache_initialize(enum spacecheckmode, off_t /*reserveddb*/, off_t /*reservedother*/, /*@out@*/struct downloadcache **); /* free all memory */ -retvalue downloadcache_free(/*@null@*//*@only@*/struct downloadcache *download); +retvalue downloadcache_free(/*@null@*//*@only@*/struct downloadcache *); /* queue a new file to be downloaded: * results in RET_ERROR_WRONG_MD5, if someone else already asked * for the same destination with other md5sum created. */ -retvalue downloadcache_add(struct downloadcache *, struct database *, struct aptmethod *, const char *orig, const char *filekey, const struct checksums *); +retvalue downloadcache_add(struct downloadcache *, struct aptmethod *, const char * /*orig*/, const char * /*filekey*/, const struct checksums *); /* some as above, only for more files... */ -retvalue downloadcache_addfiles(struct downloadcache *cache,struct database *, - struct aptmethod *method, - const struct checksumsarray *origfiles, - const struct strlist *filekeys); +retvalue downloadcache_addfiles(struct downloadcache *, struct aptmethod *, const struct checksumsarray * /*origfiles*/, const struct strlist * /*filekeys*/); #endif diff -Nru reprepro-4.5.0/dpkgversions.c reprepro-4.6.0/dpkgversions.c --- reprepro-4.5.0/dpkgversions.c 2005-09-24 15:42:31.000000000 +0000 +++ reprepro-4.6.0/dpkgversions.c 2011-05-05 14:42:55.000000000 +0000 @@ -56,19 +56,19 @@ if (!*string) return _("version string is empty"); /* trim leading and trailing space */ - while (*string && (*string == ' ' || *string == '\t') ) string++; + while (*string && (*string == ' ' || *string == '\t')) string++; /* string now points to the first non-whitespace char */ end = string; /* find either the end of the string, or a whitespace char */ - while (*end && *end != ' ' && *end != '\t' ) end++; + while (*end && *end != ' ' && *end != '\t') end++; /* check for extra chars after trailing space */ ptr = end; - while (*ptr && ( *ptr == ' ' || *ptr == '\t' ) ) ptr++; + while (*ptr && (*ptr == ' ' || *ptr == '\t')) ptr++; if (*ptr) return _("version string has embedded spaces"); - colon= strchr(string,':'); + colon= strchr(string, ':'); if (colon) { - epoch= strtoul(string,&eepochcolon,10); + epoch= strtoul(string, &eepochcolon, 10); if (colon != eepochcolon) return _("epoch in version is not number"); if (!*++colon) return _("nothing after colon in version number"); string= colon; @@ -76,7 +76,7 @@ } else { rversion->epoch= 0; } - rversion->version= strndup(string,end-string); + rversion->version= strndup(string, end - string); hyphen= strrchr(rversion->version,'-'); if (hyphen) *hyphen++= 0; rversion->revision= hyphen ? hyphen : ""; @@ -100,14 +100,14 @@ while (*val || *ref) { int first_diff= 0; - while ( (*val && !cisdigit(*val)) || (*ref && !cisdigit(*ref)) ) { + while ((*val && !cisdigit(*val)) || (*ref && !cisdigit(*ref))) { int vc= order(*val), rc= order(*ref); if (vc != rc) return vc - rc; val++; ref++; } - while ( *val == '0' ) val++; - while ( *ref == '0' ) ref++; + while (*val == '0') val++; + while (*ref == '0') ref++; while (cisdigit(*val) && cisdigit(*ref)) { if (!first_diff) first_diff= *val - *ref; val++; ref++; @@ -136,11 +136,11 @@ struct versionrevision v1,v2; const char *m; - if( (m = parseversion(&v1,first)) != NULL ) { + if ((m = parseversion(&v1,first)) != NULL) { fprintf(stderr,"Error while parsing '%s' as version: %s\n",first,m); return RET_ERROR; } - if( (m = parseversion(&v2,second)) != NULL ) { + if ((m = parseversion(&v2,second)) != NULL) { fprintf(stderr,"Error while parsing '%s' as version: %s\n",second,m); return RET_ERROR; } diff -Nru reprepro-4.5.0/dpkgversions.h reprepro-4.6.0/dpkgversions.h --- reprepro-4.5.0/dpkgversions.h 2005-02-20 21:25:48.000000000 +0000 +++ reprepro-4.6.0/dpkgversions.h 2011-05-05 14:42:55.000000000 +0000 @@ -8,6 +8,6 @@ /* return error if those are not proper versions, * otherwise RET_OK and result is <0, ==0 or >0, if first is smaller, equal or larger */ -retvalue dpkgversions_cmp(const char *first,const char *second,/*@out@*/int *result); +retvalue dpkgversions_cmp(const char *, const char *, /*@out@*/int *); #endif diff -Nru reprepro-4.5.0/error.h reprepro-4.6.0/error.h --- reprepro-4.5.0/error.h 2009-08-24 13:35:07.000000000 +0000 +++ reprepro-4.6.0/error.h 2011-05-05 14:42:55.000000000 +0000 @@ -36,10 +36,10 @@ /* update a return value, so that it contains the first error-code * and otherwise is RET_OK, if anything was RET_OK */ -#define RET_UPDATE(ret,update) { if( (update)!=RET_NOTHING && RET_WAS_NO_ERROR(ret) ) ret=update;} +#define RET_UPDATE(ret, update) { if ((update)!=RET_NOTHING && RET_WAS_NO_ERROR(ret)) ret=update;} -/* like RET_UPDATE, but RET_ENDUPDATE(RET_NOTHING,RET_OK) keeps RET_NOTHING */ -#define RET_ENDUPDATE(ret,update) {if(RET_WAS_ERROR(update)&&RET_WAS_NO_ERROR(ret)) ret=update;} +/* like RET_UPDATE, but RET_ENDUPDATE(RET_NOTHING, RET_OK) keeps RET_NOTHING */ +#define RET_ENDUPDATE(ret, update) {if (RET_WAS_ERROR(update) && RET_WAS_NO_ERROR(ret)) ret=update;} /* code a errno in a error */ #define RET_ERRNO(err) ((err>0)?((retvalue)-err):RET_ERROR) @@ -48,7 +48,7 @@ // TODO: to be implemented... #define RET_DBERR(e) RET_ERROR -#define ASSERT_NOT_NOTHING(r) {assert( r != RET_NOTHING ); if ( r == RET_NOTHING ) r = RET_ERROR_INTERNAL; } +#define ASSERT_NOT_NOTHING(r) {assert (r != RET_NOTHING); if (r == RET_NOTHING) r = RET_ERROR_INTERNAL;} #define EXIT_RET(ret) (RET_WAS_NO_ERROR(ret)?((nothingiserror&&ret==RET_NOTHING)?EXIT_FAILURE:EXIT_SUCCESS):(int)ret) diff -Nru reprepro-4.5.0/exports.c reprepro-4.6.0/exports.c --- reprepro-4.5.0/exports.c 2010-02-16 15:29:02.000000000 +0000 +++ reprepro-4.6.0/exports.c 2011-05-05 14:42:55.000000000 +0000 @@ -38,7 +38,7 @@ #include "configparser.h" #include "filecntl.h" -static const char *exportdescription(const struct exportmode *mode,char *buffer,size_t buffersize) { +static const char *exportdescription(const struct exportmode *mode, char *buffer, size_t buffersize) { char *result = buffer; enum indexcompression ic; static const char* compression_names[ic_count] = { @@ -51,14 +51,14 @@ bool needcomma = false, needellipsis = false; - assert( buffersize > 50 ); + assert (buffersize > 50); *buffer++ = ' '; buffersize--; *buffer++ = '('; buffersize--; - for( ic = ic_first ; ic < ic_count ; ic++ ) { - if( (mode->compressions & IC_FLAG(ic)) != 0 ) { + for (ic = ic_first ; ic < ic_count ; ic++) { + if ((mode->compressions & IC_FLAG(ic)) != 0) { size_t l = strlen(compression_names[ic]); - assert( buffersize > l+3 ); - if( needcomma ) { + assert (buffersize > l+3); + if (needcomma) { *buffer++ = ','; buffersize--; } memcpy(buffer, compression_names[ic], l); @@ -67,31 +67,30 @@ } } /* should be long enough for the previous things in all cases */ - assert( buffersize > 10 ); - if( mode->hooks.count > 0 ) { + assert (buffersize > 10); + if (mode->hooks.count > 0) { int i, left; - if( needcomma ) { + if (needcomma) { *buffer++ = ','; buffersize--; } strcpy(buffer, "script: "); buffer += 8; buffersize -= 8; needcomma = false; - for( i = 0 ; i < mode->hooks.count ; i++ ) { + for (i = 0 ; i < mode->hooks.count ; i++) { const char *hook = dirs_basename(mode->hooks.values[i]); size_t l = strlen(hook); - left = buffersize - 2 - (mode->hooks.count - i - 1); - if( buffersize < 6 ) { + if (buffersize < 6) { needellipsis = true; break; } - if( needcomma ) { + if (needcomma) { *buffer++ = ','; buffersize--; } - if( l > buffersize - 5 ) { + if (l > buffersize - 5) { memcpy(buffer, hook, buffersize-5); buffer += (buffersize-5); buffersize -= (buffersize-5); @@ -100,14 +99,14 @@ } else { memcpy(buffer, hook, l); buffer += l; buffersize -= l; - assert( buffersize >= 2 ); + assert (buffersize >= 2); } needcomma = true; } } - if( needellipsis ) { + if (needellipsis) { /* moveing backward here is easier than checking above */ - if( buffersize < 5 ) { + if (buffersize < 5) { buffer -= (5 - buffersize); buffersize = 5; } @@ -115,7 +114,7 @@ *buffer++ = '.'; buffersize--; *buffer++ = '.'; buffersize--; } - assert( buffersize >= 2 ); + assert (buffersize >= 2); *buffer++ = ')'; buffersize--; *buffer = '\0'; return result; @@ -123,15 +122,16 @@ retvalue exportmode_init(/*@out@*/struct exportmode *mode, bool uncompressed, /*@null@*/const char *release, const char *indexfile) { strlist_init(&mode->hooks); - mode->compressions = IC_FLAG(ic_gzip) | (uncompressed?IC_FLAG(ic_uncompressed):0); + mode->compressions = IC_FLAG(ic_gzip) | (uncompressed + ? IC_FLAG(ic_uncompressed) : 0); mode->filename = strdup(indexfile); - if( mode->filename == NULL ) + if (FAILEDTOALLOC(mode->filename)) return RET_ERROR_OOM; - if( release == NULL ) + if (release == NULL) mode->release = NULL; else { mode->release = strdup(release); - if( mode->release == NULL ) + if (FAILEDTOALLOC(mode->release)) return RET_ERROR_OOM; } return RET_OK; @@ -143,9 +143,9 @@ char *word; r = config_getword(iter, &word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error parsing %s, line %u, column %u: Unexpected end of field!\n" "Filename to use for index files (Packages, Sources, ...) missing.\n", @@ -153,9 +153,9 @@ config_markerline(iter), config_markercolumn(iter)); return RET_ERROR_MISSING; } - assert( word[0] != '\0' ); + assert (word[0] != '\0'); - if( word[0] == '.' ) { + if (word[0] == '.') { free(word); fprintf(stderr, "Error parsing %s, line %u, column %u: filename for index files expected!\n", @@ -168,19 +168,19 @@ mode->filename = word; r = config_getword(iter, &word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) word = NULL; - if( r != RET_NOTHING && word[0] != '.' ) { - assert( word[0] != '\0' ); + if (r != RET_NOTHING && word[0] != '.') { + assert (word[0] != '\0'); free(mode->release); mode->release = word; r = config_getword(iter, &word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error parsing %s, line %u, column %u: Unexpected end of field!\n" "Compression identifiers ('.', '.gz' or '.bz2') missing.\n", @@ -188,7 +188,7 @@ config_markerline(iter), config_markercolumn(iter)); return RET_ERROR; } - if( word[0] != '.' ) { + if (word[0] != '.') { fprintf(stderr, "Error parsing %s, line %u, column %u:\n" "Compression extension ('.', '.gz' or '.bz2') expected.\n", @@ -198,14 +198,14 @@ return RET_ERROR; } mode->compressions = 0; - while( r != RET_NOTHING && word[0] == '.' ) { - if( word[1] == '\0' ) + while (r != RET_NOTHING && word[0] == '.') { + if (word[1] == '\0') mode->compressions |= IC_FLAG(ic_uncompressed); - else if( word[1] == 'g' && word[2] == 'z' && + else if (word[1] == 'g' && word[2] == 'z' && word[3] == '\0') mode->compressions |= IC_FLAG(ic_gzip); #ifdef HAVE_LIBBZ2 - else if( word[1] == 'b' && word[2] == 'z' && word[3] == '2' && + else if (word[1] == 'b' && word[2] == 'z' && word[3] == '2' && word[4] == '\0') mode->compressions |= IC_FLAG(ic_bzip2); #endif @@ -222,11 +222,11 @@ } free(word); r = config_getword(iter, &word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - while( r != RET_NOTHING ) { - if( word[0] == '.' ) { + while (r != RET_NOTHING) { + if (word[0] == '.') { fprintf(stderr, "Error parsing %s, line %u, column %u:\n" "Scripts starting with dot are forbidden to avoid ambiguity ('%s')!\n" @@ -237,21 +237,21 @@ word); free(word); return RET_ERROR; - } else if( word[0] == '/' ) { + } else if (word[0] == '/') { r = strlist_add(&mode->hooks, word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } else { char *fullfilename = calc_conffile(word); free(word); - if( FAILEDTOALLOC(fullfilename) ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; r = strlist_add(&mode->hooks, fullfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } r = config_getword(iter, &word); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -259,69 +259,70 @@ static retvalue gotfilename(const char *relname, size_t l, struct release *release) { - if( l > 12 && memcmp(relname+l-12,".tobedeleted",12) == 0) { + if (l > 12 && memcmp(relname+l-12, ".tobedeleted", 12) == 0) { char *filename; - filename = strndup(relname,l-12); - if( filename == NULL ) + filename = strndup(relname, l - 12); + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; - return release_adddel(release,filename); + return release_adddel(release, filename); - } else if( l > 4 && memcmp(relname+(l-4),".new",4) == 0 ) { - char *filename,*tmpfilename; + } else if (l > 4 && memcmp(relname+(l-4), ".new", 4) == 0) { + char *filename, *tmpfilename; - filename = strndup(relname,l-4); - if( filename == NULL ) + filename = strndup(relname, l - 4); + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; - tmpfilename = strndup(relname,l); - if( tmpfilename == NULL ) { + tmpfilename = strndup(relname, l); + if (FAILEDTOALLOC(tmpfilename)) { free(filename); return RET_ERROR_OOM; } - return release_addnew(release,tmpfilename,filename); - } else if( l > 5 && memcmp(relname + (l-5), ".new.", 5) == 0 ) { + return release_addnew(release, tmpfilename, filename); + } else if (l > 5 && memcmp(relname + (l-5), ".new.", 5) == 0) { char *filename, *tmpfilename; filename = strndup(relname, l-5); - if( FAILEDTOALLOC(filename) ) + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; tmpfilename = strndup(relname, l-1); - if( FAILEDTOALLOC(tmpfilename) ) { + if (FAILEDTOALLOC(tmpfilename)) { free(filename); return RET_ERROR_OOM; } return release_addsilentnew(release, tmpfilename, filename); - } else if( l > 5 && memcmp(relname + (l-5), ".keep", 5) == 0 ) { + } else if (l > 5 && memcmp(relname + (l-5), ".keep", 5) == 0) { return RET_OK; } else { char *filename; - filename = strndup(relname,l); - if( filename == NULL ) + filename = strndup(relname, l); + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; - return release_addold(release,filename); + return release_addold(release, filename); } } static retvalue callexporthook(/*@null@*/const char *hook, const char *relfilename, const char *mode, struct release *release) { - pid_t f,c; + pid_t f, c; int status; int io[2]; char buffer[1000]; int already = 0; - if( hook == NULL ) + if (hook == NULL) return RET_NOTHING; status = pipe(io); - if( status < 0 ) { + if (status < 0) { int e = errno; - fprintf(stderr, "Error %d creating pipe: %s!\n", e, strerror(e)); + fprintf(stderr, "Error %d creating pipe: %s!\n", + e, strerror(e)); return RET_ERRNO(e); } f = fork(); - if( f < 0 ) { + if (f < 0) { int e = errno; (void)close(io[0]); (void)close(io[1]); @@ -329,25 +330,25 @@ e, strerror(e)); return RET_ERRNO(e); } - if( f == 0 ) { + if (f == 0) { char *reltmpfilename; int e; - if( dup2(io[1],3) < 0 ) { + if (dup2(io[1], 3) < 0) { e = errno; fprintf(stderr, "Error %d dup2'ing fd %d to 3: %s\n", e, io[1], strerror(e)); exit(255); } /* "Doppelt haelt besser": */ - if( io[0] != 3 ) + if (io[0] != 3) (void)close(io[0]); - if( io[1] != 3 ) + if (io[1] != 3) (void)close(io[1]); closefrom(4); /* backward compatibilty */ - reltmpfilename = calc_addsuffix(relfilename,"new"); - if( reltmpfilename == NULL ) { + reltmpfilename = calc_addsuffix(relfilename, "new"); + if (reltmpfilename == NULL) { exit(255); } setenv("REPREPRO_BASE_DIR", global.basedir, true); @@ -366,91 +367,98 @@ close(io[1]); markcloseonexec(io[0]); - if( verbose > 6 ) + if (verbose > 6) printf("Called %s '%s' '%s.new' '%s' '%s'\n", - hook,release_dirofdist(release),relfilename,relfilename,mode); + hook, release_dirofdist(release), + relfilename, relfilename, mode); /* read what comes from the client */ - while( true ) { + while (true) { ssize_t r; - int last,j; + int last, j; - r = read(io[0],buffer+already,999-already); - if( r < 0 ) { + r = read(io[0], buffer + already, 999 - already); + if (r < 0) { int e = errno; - fprintf(stderr, "Error %d reading from exporthook: %s!\n", + fprintf(stderr, +"Error %d reading from exporthook: %s!\n", e, strerror(e)); break; } already += r; - if( r == 0 ) { + if (r == 0) { buffer[already] = '\0'; already++; } last = 0; - for( j = 0 ; j < already ; j++ ) { - if( buffer[j] == '\n' || buffer[j] == '\0' ) { + for (j = 0 ; j < already ; j++) { + if (buffer[j] == '\n' || buffer[j] == '\0') { int next = j+1; int e = (j>0)?(j-1):j; retvalue ret; - while( last < j && xisspace(buffer[last]) ) + while (last < j && xisspace(buffer[last])) last++; - if( last >= j ) { + if (last >= j) { last = next; continue; } - while( xisspace(buffer[e]) ) { + while (xisspace(buffer[e])) { e--; - assert( e >= last ); + assert (e >= last); } - ret = gotfilename(buffer+last,e-last+1,release); - if( RET_WAS_ERROR(ret) ) { + ret = gotfilename(buffer + last, e - last + 1, + release); + if (RET_WAS_ERROR(ret)) { (void)close(io[0]); return ret; } last = next; } } - if( last > 0 ) { - if( already > last ) - memmove(buffer,buffer+last,already-last); + if (last > 0) { + if (already > last) + memmove(buffer, buffer + last, already - last); already -= last; } - if( r == 0 ) + if (r == 0) break; } (void)close(io[0]); do { - c = waitpid(f,&status,WUNTRACED); - if( c < 0 ) { + c = waitpid(f, &status, WUNTRACED); + if (c < 0) { int e = errno; fprintf(stderr, "Error %d while waiting for hook '%s' to finish: %s\n", e, hook, strerror(e)); return RET_ERRNO(e); } - } while( c != f ); - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0 ) { - if( verbose > 6 ) + } while (c != f); + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) { + if (verbose > 6) printf("Exporthook successfully returned!\n"); return RET_OK; } else { - fprintf(stderr,"Exporthook failed with exitcode %d!\n",(int)WEXITSTATUS(status)); + fprintf(stderr, +"Exporthook failed with exitcode %d!\n", + (int)WEXITSTATUS(status)); return RET_ERROR; } - } else if( WIFSIGNALED(status) ) { - fprintf(stderr,"Exporthook killed by signal %d!\n", + } else if (WIFSIGNALED(status)) { + fprintf(stderr, "Exporthook killed by signal %d!\n", (int)(WTERMSIG(status))); return RET_ERROR; } else { - fprintf(stderr,"Exporthook terminated abnormally. (status is %x)!\n",status); + fprintf(stderr, +"Exporthook terminated abnormally. (status is %x)!\n", + status); return RET_ERROR; } } -retvalue export_target(const char *relativedir, struct target *target, struct database *database, const struct exportmode *exportmode, struct release *release, bool onlyifmissing, bool snapshot) { +retvalue export_target(const char *relativedir, struct target *target, const struct exportmode *exportmode, struct release *release, bool onlyifmissing, bool snapshot) { retvalue r; struct filetorelease *file; const char *status; @@ -460,70 +468,71 @@ size_t chunk_len; struct target_cursor iterator; - relfilename = calc_dirconcat(relativedir,exportmode->filename); - if( relfilename == NULL ) + relfilename = calc_dirconcat(relativedir, exportmode->filename); + if (FAILEDTOALLOC(relfilename)) return RET_ERROR_OOM; - r = release_startfile(release,relfilename,exportmode->compressions,onlyifmissing,&file); - if( RET_WAS_ERROR(r) ) { + r = release_startfile(release, relfilename, exportmode->compressions, + onlyifmissing, &file); + if (RET_WAS_ERROR(r)) { free(relfilename); return r; } - if( RET_IS_OK(r) ) { - if( release_oldexists(file) ) { - if( verbose > 5 ) + if (RET_IS_OK(r)) { + if (release_oldexists(file)) { + if (verbose > 5) printf(" replacing '%s/%s'%s\n", release_dirofdist(release), relfilename, exportdescription(exportmode, buffer, 100)); status = "change"; } else { - if( verbose > 5 ) + if (verbose > 5) printf(" creating '%s/%s'%s\n", release_dirofdist(release), relfilename, exportdescription(exportmode, buffer, 100)); status = "new"; } - r = target_openiterator(target, database, READONLY, &iterator); - if( RET_WAS_ERROR(r) ) { + r = target_openiterator(target, READONLY, &iterator); + if (RET_WAS_ERROR(r)) { release_abortfile(file); free(relfilename); return r; } - while( target_nextpackage_len(&iterator, NULL, - &chunk, &chunk_len) ) { - if( chunk_len == 0 ) + while (target_nextpackage_len(&iterator, NULL, + &chunk, &chunk_len)) { + if (chunk_len == 0) continue; (void)release_writedata(file, chunk, chunk_len); (void)release_writestring(file, "\n"); - if( chunk[chunk_len-1] != '\n' ) + if (chunk[chunk_len-1] != '\n') (void)release_writestring(file, "\n"); } r = target_closeiterator(&iterator); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(file); free(relfilename); return r; } - r = release_finishfile(release,file); - if( RET_WAS_ERROR(r) ) { + r = release_finishfile(release, file); + if (RET_WAS_ERROR(r)) { free(relfilename); return r; } } else { - if( verbose > 9 ) + if (verbose > 9) printf(" keeping old '%s/%s'%s\n", release_dirofdist(release), relfilename, exportdescription(exportmode, buffer, 100)); status = "old"; } - if( !snapshot ) { + if (!snapshot) { int i; - for( i = 0 ; i < exportmode->hooks.count ; i++ ) { + for (i = 0 ; i < exportmode->hooks.count ; i++) { const char *hook = exportmode->hooks.values[i]; r = callexporthook(hook, relfilename, status, release); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(relfilename); return r; } @@ -534,7 +543,7 @@ } void exportmode_done(struct exportmode *mode) { - assert( mode != NULL); + assert (mode != NULL); free(mode->filename); strlist_done(&mode->hooks); free(mode->release); diff -Nru reprepro-4.5.0/exports.h reprepro-4.6.0/exports.h --- reprepro-4.5.0/exports.h 2008-08-16 15:27:20.000000000 +0000 +++ reprepro-4.6.0/exports.h 2011-05-05 14:42:55.000000000 +0000 @@ -17,10 +17,10 @@ struct strlist hooks; }; -retvalue exportmode_init(/*@out@*/struct exportmode *mode, bool uncompressed, /*@null@*/const char *release, const char *indexfile); +retvalue exportmode_init(/*@out@*/struct exportmode *, bool /*uncompressed*/, /*@null@*/const char * /*release*/, const char * /*indexfile*/); struct configiterator; -retvalue exportmode_set(struct exportmode *mode, struct configiterator *iter); -void exportmode_done(struct exportmode *mode); +retvalue exportmode_set(struct exportmode *, struct configiterator *); +void exportmode_done(struct exportmode *); -retvalue export_target(const char *relativedir, struct target *, struct database *, const struct exportmode *, struct release *, bool onlyifmissing, bool snapshot); +retvalue export_target(const char * /*relativedir*/, struct target *, const struct exportmode *, struct release *, bool /*onlyifmissing*/, bool /*snapshot*/); #endif diff -Nru reprepro-4.5.0/extractcontrol.c reprepro-4.6.0/extractcontrol.c --- reprepro-4.5.0/extractcontrol.c 2008-07-25 08:41:13.000000000 +0000 +++ reprepro-4.6.0/extractcontrol.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,46 +43,46 @@ int pipe1[2]; int pipe2[2]; int ret; - pid_t ar,tar,pid; + pid_t ar, tar, pid; int status; char *controlchunk; - retvalue result,r; + retvalue result, r; result = RET_OK; ret = pipe(pipe1); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); return RET_ERRNO(e); } ret = pipe(pipe2); - if( ret < 0 ) { + if (ret < 0) { int e = errno; - close(pipe1[0]);close(pipe1[1]); + close(pipe1[0]); close(pipe1[1]); fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); return RET_ERRNO(e); } ar = fork(); - if( ar < 0 ) { + if (ar < 0) { int e = errno; fprintf(stderr, "Error %d forking: %s\n", e, strerror(e)); result = RET_ERRNO(e); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); return result; } - if( ar == 0 ) { + if (ar == 0) { int e; /* calling ar */ - if( dup2(pipe1[1],1) < 0 ) + if (dup2(pipe1[1], 1) < 0) exit(255); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); //TODO without explicit path ret = execl("/usr/bin/ar", "ar", "p", debfile, "control.tar.gz", @@ -94,22 +94,22 @@ } tar = fork(); - if( tar < 0 ) { + if (tar < 0) { int e = errno; result = RET_ERRNO(e); fprintf(stderr, "Error %d forking: %s\n", e, strerror(e)); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); tar = -1; - } else if( tar == 0 ) { + } else if (tar == 0) { int e; /* calling tar */ - if( dup2(pipe1[0],0) < 0 ) + if (dup2(pipe1[0], 0) < 0) exit(255); - if( dup2(pipe2[1],1) < 0 ) + if (dup2(pipe2[1], 1) < 0) exit(255); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); //TODO without explicit path execl("/bin/tar", "tar", "-xOzf", "-", brokentar?"control":"./control", @@ -127,19 +127,20 @@ controlchunk = NULL; /* read data: */ - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { size_t len; char *afterchanges; r = readtextfilefd(pipe2[0], brokentar? - "output from ar p control.tar.gz | tar -XOzf - control": - "output from ar p control.tar.gz | tar -XOzf - ./control", +"output from ar p control.tar.gz | tar -XOzf - control": +"output from ar p control.tar.gz | tar -XOzf - ./control", &controlchunk, NULL); - if( RET_IS_OK(r) ) { - len = chunk_extract(controlchunk, controlchunk, &afterchanges); - if( len == 0 ) + if (RET_IS_OK(r)) { + len = chunk_extract(controlchunk, controlchunk, + &afterchanges); + if (len == 0) r = RET_NOTHING; - if( *afterchanges != '\0' ) { + if (*afterchanges != '\0') { fprintf(stderr, "Unexpected emtpy line in control information within '%s'\n" "(obtained via 'ar p %s control.tar.gz | tar -XOzf - %scontrol')\n", @@ -150,57 +151,63 @@ r = RET_ERROR; } } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { free(controlchunk); controlchunk = NULL; - fprintf(stderr, "No control information found in .deb!\n"); - /* only report error now if we haven't try everything yet */ - if( brokentar ) + fprintf(stderr, +"No control information found in .deb!\n"); + /* only report error now, + * if we haven't try everything yet */ + if (brokentar) r = RET_ERROR_MISSING; } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - while( ar != -1 || tar != -1 ) { + while (ar != -1 || tar != -1) { pid=wait(&status); - if( pid < 0 ) { - if( errno != EINTR ) - RET_UPDATE(result,RET_ERRNO(errno)); + if (pid < 0) { + if (errno != EINTR) + RET_UPDATE(result, RET_ERRNO(errno)); } else { - if( pid == ar ) { + if (pid == ar) { ar = -1; - if( !WIFEXITED(status) ) { - fprintf(stderr,"Ar exited unnaturally!\n"); + if (!WIFEXITED(status)) { + fprintf(stderr, +"Ar exited unnaturally!\n"); result = RET_ERROR; - } else if( WEXITSTATUS(status) != 0) { - fprintf(stderr,"Error from ar for '%s': %d\n", - debfile, WEXITSTATUS(status)); + } else if (WEXITSTATUS(status) != 0) { + fprintf(stderr, +"Error from ar for '%s': %d\n", debfile, WEXITSTATUS(status)); result = RET_ERROR; } - } else if( pid == tar ) { + } else if (pid == tar) { tar = -1; - if( !WIFEXITED(status) ) { - fprintf(stderr,"Tar exited unnaturally!\n"); + if (!WIFEXITED(status)) { + fprintf(stderr, +"Tar exited unnaturally!\n"); result = RET_ERROR; - } else if( !brokentar && WEXITSTATUS(status) == 2 ) { - if( RET_IS_OK(result) ) + } else if (!brokentar && WEXITSTATUS(status) == 2) { + if (RET_IS_OK(result)) result = RET_NOTHING; - } else if( WEXITSTATUS(status) != 0 ) { - fprintf(stderr,"Error from tar for control.tar.gz within '%s': %d\n", + } else if (WEXITSTATUS(status) != 0) { + fprintf(stderr, +"Error from tar for control.tar.gz within '%s': %d\n", debfile, WEXITSTATUS(status)); result = RET_ERROR; } } else { // WTH? - fprintf(stderr,"Who is %d, and why does this bother me?\n",(int)pid); + fprintf(stderr, +"Who is %d, and why does this bother me?\n", (int)pid); } } } - if( RET_IS_OK(result) ) { - if( controlchunk == NULL ) + if (RET_IS_OK(result)) { + if (controlchunk == NULL) /* we got not data but tar gave not error.. */ return RET_ERROR_MISSING; else @@ -210,31 +217,34 @@ return result; } -retvalue extractcontrol(char **control,const char *debfile) { +retvalue extractcontrol(char **control, const char *debfile) { retvalue r; r = try_extractcontrol(control, debfile, false); - if( r != RET_NOTHING ) + if (r != RET_NOTHING) return r; /* perhaps the control.tar.gz is packaged by hand wrongly, * try again: */ r = try_extractcontrol(control, debfile, true); - if( RET_IS_OK(r) ) { - fprintf(stderr, "WARNING: '%s' contains a broken/unusual control.tar.gz.\n" - "reprepro was able to work around this but other tools or versions might not.\n", debfile); + if (RET_IS_OK(r)) { + fprintf(stderr, +"WARNING: '%s' contains a broken/unusual control.tar.gz.\n" +"reprepro was able to work around this but other tools or versions might not.\n", + debfile); } - assert( r != RET_NOTHING ); + assert (r != RET_NOTHING); return r; } retvalue getfilelist(/*@out@*/char **filelist, /*@out@*/size_t *size, const char *debfile) { - fprintf(stderr, "Extraction of file list without libarchive currently not implemented.\n"); + fprintf(stderr, +"Extraction of file list without libarchive currently not implemented.\n"); return RET_ERROR; #if 0 int pipe1[2]; int pipe2[2]; int ret; - pid_t ar,tar,pid; + pid_t ar, tar, pid; int status; struct filelistcompressor c; size_t last = 0; @@ -242,13 +252,13 @@ #error this still needs to be reimplemented... result = filelistcompressor_setup(&c); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; result = RET_OK; ret = pipe(pipe1); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); filelistcompressor_cancel(&c); @@ -256,32 +266,32 @@ } ret = pipe(pipe2); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); - close(pipe1[0]);close(pipe1[1]); + close(pipe1[0]); close(pipe1[1]); filelistcompressor_cancel(&c); return RET_ERRNO(e); } ar = fork(); - if( ar < 0 ) { + if (ar < 0) { int e = errno; fprintf(stderr, "Error %d forking: %s\n", e, strerror(e)); result = RET_ERRNO(e); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); filelistcompressor_cancel(&c); return result; } - if( ar == 0 ) { + if (ar == 0) { int e; /* calling ar */ - if( dup2(pipe1[1],1) < 0 ) + if (dup2(pipe1[1], 1) < 0) exit(255); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); //TODO without explicit path ret = execl("/usr/bin/ar", "ar", "p", debfile, "data.tar.gz", @@ -293,22 +303,22 @@ } tar = fork(); - if( tar < 0 ) { + if (tar < 0) { int e = errno; result = RET_ERRNO(e); fprintf(stderr, "Error %d forking: %s\n", e, strerror(e)); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); tar = -1; - } else if( tar == 0 ) { + } else if (tar == 0) { int e; /* calling tar */ - if( dup2(pipe1[0],0) < 0 ) + if (dup2(pipe1[0], 0) < 0) exit(255); - if( dup2(pipe2[1],1) < 0 ) + if (dup2(pipe2[1], 1) < 0) exit(255); - close(pipe1[0]);close(pipe1[1]); - close(pipe2[0]);close(pipe2[1]); + close(pipe1[0]); close(pipe1[1]); + close(pipe2[0]); close(pipe2[1]); //TODO without explicit path execl("/bin/tar", "tar", "-tzf", "-", ENDOFARGUMENTS); e = errno; @@ -318,20 +328,20 @@ } - close(pipe1[0]);close(pipe1[1]); + close(pipe1[0]); close(pipe1[1]); close(pipe2[1]); /* read data: */ - if( RET_IS_OK(result) ) do { + if (RET_IS_OK(result)) do { ssize_t bytes_read; size_t ignore; - if( listsize <= len + 512 ) { + if (listsize <= len + 512) { char *n; listsize = len + 1024; n = realloc(list, listsize); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { result = RET_ERROR_OOM; break; } @@ -340,22 +350,22 @@ ignore = 0; bytes_read = read(pipe2[0], list+len, listsize-len-1); - if( bytes_read < 0 ) { + if (bytes_read < 0) { int e = errno; fprintf(stderr, "Error %d reading from pipe: %s\n", e, strerror(e)); result = RET_ERRNO(e); break; - } else if( bytes_read == 0 ) + } else if (bytes_read == 0) break; - else while( bytes_read > 0 ) { - if( list[len] == '\0' ) { + else while (bytes_read > 0) { + if (list[len] == '\0') { fprintf(stderr, "Unexpected NUL character from tar while getting file list from %s!\n", debfile); result = RET_ERROR; break; - } else if( list[len] == '\n' ) { - if( len > last+ignore && list[len-1] != '/' ) { + } else if (list[len] == '\n') { + if (len > last+ignore && list[len-1] != '/') { list[len] = '\0'; len++; bytes_read--; @@ -367,10 +377,10 @@ bytes_read--; ignore = len-last; } - } else if( list[len] == '.' && len == last+ignore ) { + } else if (list[len] == '.' && len == last+ignore) { len++; ignore++; bytes_read--; - } else if( list[len] == '/' && len == last+ignore ) { + } else if (list[len] == '/' && len == last+ignore) { len++; ignore++; bytes_read--; } else { @@ -378,8 +388,8 @@ bytes_read--; } } - if( ignore > 0 ) { - if( len <= last+ignore ) + if (ignore > 0) { + if (len <= last+ignore) len = last; else { memmove(list+last, list+last+ignore, @@ -387,8 +397,8 @@ len -= ignore; } } - } while( true ); - if( len != last ) { + } while (true); + if (len != last) { fprintf(stderr, "WARNING: unterminated output from tar pipe while extracting file list of %s\n", debfile); list[len] = '\0'; @@ -396,8 +406,8 @@ list+last); result = RET_ERROR; } else { - char *n = realloc(list,len+1); - if( n == NULL ) + char *n = realloc(list, len+1); + if (FAILEDTOALLOC(n)) result = RET_ERROR_OOM; else { list = n; @@ -406,37 +416,38 @@ } close(pipe2[0]); - while( ar != -1 || tar != -1 ) { + while (ar != -1 || tar != -1) { pid=wait(&status); - if( pid < 0 ) { - if( errno != EINTR ) - RET_UPDATE(result,RET_ERRNO(errno)); + if (pid < 0) { + if (errno != EINTR) + RET_UPDATE(result, RET_ERRNO(errno)); } else { - if( pid == ar ) { + if (pid == ar) { ar = -1; - if( !WIFEXITED(status) || + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - fprintf(stderr,"Error from ar for '%s': %d\n", - debfile, - WEXITSTATUS(status)); + fprintf(stderr, +"Error from ar for '%s': %d\n", debfile, WEXITSTATUS(status)); result = RET_ERROR; } - } else if( pid == tar ) { + } else if (pid == tar) { tar = -1; - if( !WIFEXITED(status) || - WEXITSTATUS(status) != 0 ) { - fprintf(stderr,"Error from tar for data.tar.gz within '%s': %d\n", + if (!WIFEXITED(status) || + WEXITSTATUS(status) != 0) { + fprintf(stderr, +"Error from tar for data.tar.gz within '%s': %d\n", debfile, WEXITSTATUS(status)); result = RET_ERROR; } } else { // WTH? - fprintf(stderr,"Who is %d, and why does this bother me?\n",pid); + fprintf(stderr, +"Who is %d, and why does this bother me?\n", pid); } } } - if( RET_IS_OK(result) ) + if (RET_IS_OK(result)) return filelistcompressor_finish(&c, filelist); else filelistcompressor_cancel(&c); diff -Nru reprepro-4.5.0/filecntl.c reprepro-4.6.0/filecntl.c --- reprepro-4.5.0/filecntl.c 2010-10-24 08:59:10.000000000 +0000 +++ reprepro-4.6.0/filecntl.c 2011-05-05 14:42:55.000000000 +0000 @@ -27,15 +27,15 @@ int fd; # ifdef F_CLOSEM - if( fcntl(lowfd, F_CLOSEM, NULL) == 0 ) + if (fcntl(lowfd, F_CLOSEM, NULL) == 0) return; # endif maxopen = sysconf(_SC_OPEN_MAX); - if( maxopen > INT_MAX ) + if (maxopen > INT_MAX) maxopen = INT_MAX; - if( maxopen < 0 ) + if (maxopen < 0) maxopen = 1024; - for( fd = lowfd ; fd <= maxopen ; fd++ ) + for (fd = lowfd ; fd <= maxopen ; fd++) (void)close(fd); } #endif @@ -43,7 +43,7 @@ void markcloseonexec(int fd) { long l; l = fcntl(fd, F_GETFD, 0); - if( l >= 0 ) { + if (l >= 0) { (void)fcntl(fd, F_SETFD, l|FD_CLOEXEC); } } @@ -52,13 +52,13 @@ int ret, e; ret = unlink(fullfilename); - if( ret != 0 ) { + if (ret != 0) { e = errno; fprintf(stderr, "error %d unlinking %s: %s\n", e, fullfilename, strerror(e)); return (e != 0)?e:EINVAL; } - return 0;; + return 0; } bool isregularfile(const char *fullfilename) { @@ -66,7 +66,7 @@ int i; assert(fullfilename != NULL); - i = stat(fullfilename,&s); + i = stat(fullfilename, &s); return i == 0 && S_ISREG(s.st_mode); } @@ -75,6 +75,6 @@ int i; assert(fullfilename != NULL); - i = stat(fullfilename,&s); + i = stat(fullfilename, &s); return i == 0 && S_ISDIR(s.st_mode); } diff -Nru reprepro-4.5.0/filelist.c reprepro-4.6.0/filelist.c --- reprepro-4.5.0/filelist.c 2009-07-14 14:34:08.000000000 +0000 +++ reprepro-4.6.0/filelist.c 2011-05-05 14:42:55.000000000 +0000 @@ -49,7 +49,7 @@ struct dirlist *subdirs; struct filelist *files; /*@dependant@*/struct filelist *lastfile; - size_t len; + size_t len; char name[]; }; @@ -61,11 +61,11 @@ retvalue filelist_init(struct filelist_list **list) { struct filelist_list *filelist; - filelist = calloc(1,sizeof(struct filelist_list)); - if( filelist == NULL ) + filelist = zNEW(struct filelist_list); + if (FAILEDTOALLOC(filelist)) return RET_ERROR_OOM; - filelist->root = calloc(1,sizeof(struct dirlist)); - if( filelist->root == NULL ) { + filelist->root = zNEW(struct dirlist); + if (FAILEDTOALLOC(filelist->root)) { free(filelist); return RET_ERROR_OOM; } @@ -73,7 +73,7 @@ return RET_OK; }; static void files_free(/*@only@*/struct filelist *list) { - if( list == NULL ) + if (list == NULL) return; files_free(list->nextl); files_free(list->nextr); @@ -81,7 +81,7 @@ free(list); } static void dirlist_free(/*@only@*/struct dirlist *list) { - if( list == NULL ) + if (list == NULL) return; files_free(list->files); dirlist_free(list->subdirs); @@ -91,10 +91,10 @@ } void filelist_free(struct filelist_list *list) { - if( list == NULL ) + if (list == NULL) return; dirlist_free(list->root); - while( list->packages != NULL ) { + while (list->packages != NULL) { struct filelist_package *package = list->packages; list->packages = package->next; free(package); @@ -108,7 +108,7 @@ size_t section_len = strlen(section); p = malloc(sizeof(struct filelist_package)+name_len+section_len+2); - if( p == NULL ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->next = filelist->packages; memcpy(p->name, section, section_len); @@ -127,17 +127,17 @@ stack[stackpointer++] = &parent->files; file = parent->files; - while( file != NULL ) { + while (file != NULL) { int c = strncmp(basefilename, file->name, namelen); - if( c == 0 && file->name[namelen] == '\0' ) { - n = realloc(file,sizeof(struct filelist)+ + if (c == 0 && file->name[namelen] == '\0') { + n = realloc(file, sizeof(struct filelist)+ (file->count+1)*sizeof(const char*)); - if( n == NULL ) + if (n == NULL) return false; n->packages[n->count++] = packagename; *(stack[--stackpointer]) = n; return true; - } else if ( c > 0 ) { + } else if (c > 0) { stack[stackpointer++] = &file->nextr; file = file->nextr; } else { @@ -146,7 +146,7 @@ } } n = malloc(sizeof(struct filelist)+sizeof(const char*)); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return false; n->name = strndup(basefilename, namelen); n->nextl = NULL; @@ -154,22 +154,22 @@ n->balance = 0; n->count = 1; n->packages[0] = packagename; - if( n->name == NULL ) { + if (FAILEDTOALLOC(n->name)) { free(n); return false; } *(stack[--stackpointer]) = n; - while( stackpointer > 0 ) { + while (stackpointer > 0) { file = *(stack[--stackpointer]); - if( file->nextl == n ) { + if (file->nextl == n) { file->balance--; - if( file->balance > -1 ) + if (file->balance > -1) break; - if( file->balance == -1 ) { + if (file->balance == -1) { n = file; continue; } - if( n->balance == -1 ) { + if (n->balance == -1) { file->nextl = n->nextr; file->balance = 0; n->nextr = file; @@ -183,10 +183,10 @@ last->nextr = file; n->nextr = last->nextl; last->nextl = n; - if( last->balance == 0 ) { + if (last->balance == 0) { file->balance = 0; n->balance = 0; - } else if( last->balance < 0 ) { + } else if (last->balance < 0) { file->balance = 1; n->balance = 0; } else { @@ -198,13 +198,13 @@ } } else { file->balance++; - if( file->balance < 1 ) + if (file->balance < 1) break; - if( file->balance == 1 ) { + if (file->balance == 1) { n = file; continue; } - if( n->balance == 1 ) { + if (n->balance == 1) { file->nextr = n->nextl; file->balance = 0; n->nextl = file; @@ -218,10 +218,10 @@ last->nextl = file; n->nextl = last->nextr; last->nextr = n; - if( last->balance == 0 ) { + if (last->balance == 0) { file->balance = 0; n->balance = 0; - } else if( last->balance > 0 ) { + } else if (last->balance > 0) { file->balance = -1; n->balance = 0; } else { @@ -246,12 +246,12 @@ stack[stackpointer++] = &dir->subdirs; d = dir->subdirs; - while( d != NULL ) { + while (d != NULL) { int c; - if( namelen < d->len ) { + if (namelen < d->len) { c = memcmp(name, d->name, namelen); - if( c <= 0 ) { + if (c <= 0) { stack[stackpointer++] = &d->nextl; d = d->nextl; } else { @@ -260,9 +260,9 @@ } } else { c = memcmp(name, d->name, d->len); - if( c == 0 && d->len == namelen ) { + if (c == 0 && d->len == namelen) { return d; - } else if( c >= 0) { + } else if (c >= 0) { stack[stackpointer++] = &d->nextr; d = d->nextr; } else { @@ -272,8 +272,8 @@ } } /* not found, create it and rebalance */ - d = malloc(sizeof(struct dirlist) + namelen ); - if( d == NULL ) + d = malloc(sizeof(struct dirlist) + namelen); + if (FAILEDTOALLOC(d)) return d; d->subdirs = NULL; d->nextl = NULL; @@ -285,17 +285,17 @@ memcpy(d->name, name, namelen); *(stack[--stackpointer]) = d; this = d; - while( stackpointer > 0 ) { + while (stackpointer > 0) { parent = *(stack[--stackpointer]); - if( parent->nextl == this ) { + if (parent->nextl == this) { parent->balance--; - if( parent->balance > -1 ) + if (parent->balance > -1) break; - if( parent->balance == -1 ) { + if (parent->balance == -1) { this = parent; continue; } - if( this->balance == -1 ) { + if (this->balance == -1) { parent->nextl = this->nextr; parent->balance = 0; this->nextr = parent; @@ -309,10 +309,10 @@ h->nextr = parent; this->nextr = h->nextl; h->nextl = this; - if( h->balance == 0 ) { + if (h->balance == 0) { parent->balance = 0; this->balance = 0; - } else if( h->balance < 0 ) { + } else if (h->balance < 0) { parent->balance = 1; this->balance = 0; } else { @@ -324,13 +324,13 @@ } } else { parent->balance++; - if( parent->balance < 1 ) + if (parent->balance < 1) break; - if( parent->balance == 1 ) { + if (parent->balance == 1) { this = parent; continue; } - if( this->balance == 1 ) { + if (this->balance == 1) { parent->nextr = this->nextl; parent->balance = 0; this->nextl = parent; @@ -344,10 +344,10 @@ h->nextl = parent; this->nextl = h->nextr; h->nextr = this; - if( h->balance == 0 ) { + if (h->balance == 0) { parent->balance = 0; this->balance = 0; - } else if( h->balance > 0 ) { + } else if (h->balance > 0) { parent->balance = -1; this->balance = 0; } else { @@ -366,10 +366,10 @@ struct dirlist *curdir = list->root; const unsigned char *data = (const unsigned char *)datastart; - while( *data != '\0' ) { + while (*data != '\0') { int d; - if( (size_t)(data - (const unsigned char *)datastart) >= size-1 ) { + if ((size_t)(data - (const unsigned char *)datastart) >= size-1) { /* This might not catch everything, but we are only * accessing it readonly */ fprintf(stderr, "Corrupted file list data for %s\n", @@ -377,29 +377,29 @@ return RET_ERROR; } d = *(data++); - if( d == 1 ) { + if (d == 1) { size_t len = 0; - while( *data == 255 ) { + while (*data == 255) { data++; len += 255; } - if( *data == 0 ) { + if (*data == 0) { fprintf(stderr, "Corrupted file list data for %s\n", filekey); return RET_ERROR; } len += *(data++); - if( !findfile(curdir, package->name, (const char*)data, len) ) + if (!findfile(curdir, package->name, (const char*)data, len)) return RET_ERROR_OOM; data += len; - } else if( d == 2 ) { + } else if (d == 2) { size_t len = 0; - while( *data == 255 ) { + while (*data == 255) { data++; len += 255; } - if( *data == 0 ) { + if (*data == 0) { fprintf(stderr, "Corrupted file list data for %s\n", filekey); @@ -407,26 +407,28 @@ } len += *(data++); curdir = finddir(curdir, data, len); - if( curdir == NULL ) + if (FAILEDTOALLOC(curdir)) return RET_ERROR_OOM; data += len; } else { d -= 2; - while( d-- > 0 && curdir->parent != NULL ) + while (d-- > 0 && curdir->parent != NULL) curdir = curdir->parent; } } - if( (size_t)(data - (const unsigned char *)datastart) != size-1 ) { - fprintf(stderr, "Corrupted file list data for %s (format suggest %llu, is %llu)\n", + if ((size_t)(data - (const unsigned char *)datastart) != size-1) { + fprintf(stderr, +"Corrupted file list data for %s (format suggest %llu, is %llu)\n", filekey, - (unsigned long long)(data - (const unsigned char *)datastart), + (unsigned long long)(data - + (const unsigned char *)datastart), (unsigned long long)(size-1)); return RET_ERROR; } return RET_OK; } -retvalue filelist_addpackage(struct filelist_list *list, struct database *database, const char *packagename, const char *section, const char *filekey) { +retvalue filelist_addpackage(struct filelist_list *list, const char *packagename, const char *section, const char *filekey) { const struct filelist_package *package IFSTUPIDCC(=NULL); char *debfilename, *contents = NULL; retvalue r; @@ -434,35 +436,34 @@ size_t len; r = filelist_newpackage(list, packagename, section, &package); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - r = table_gettemprecord(database->contents, filekey, &c, &len); - if( r == RET_NOTHING ) { - if( verbose > 3 ) + r = table_gettemprecord(rdb_contents, filekey, &c, &len); + if (r == RET_NOTHING) { + if (verbose > 3) printf("Reading filelist for %s\n", filekey); debfilename = files_calcfullfilename(filekey); - if( debfilename == NULL ) { + if (FAILEDTOALLOC(debfilename)) return RET_ERROR_OOM; - } r = getfilelist(&contents, &len, debfilename); len--; free(debfilename); c = contents; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = filelist_addfiles(list, package, filekey, c, len + 1); - if( contents != NULL ) - r = table_adduniqsizedrecord(database->contents, filekey, + if (contents != NULL) + r = table_adduniqsizedrecord(rdb_contents, filekey, contents, len + 1, true, false); } free(contents); return r; } -retvalue fakefilelist(struct database *database, const char *filekey) { - return table_adduniqsizedrecord(database->contents, filekey, +retvalue fakefilelist(const char *filekey) { + return table_adduniqsizedrecord(rdb_contents, filekey, "", 1, true, false); } @@ -474,41 +475,41 @@ unsigned int i; bool first; - if( files == NULL ) + if (files == NULL) return; - filelist_writefiles(dir,len,files->nextl,file); - (void)release_writedata(file,dir,len); - (void)release_writestring(file,files->name); - (void)release_writedata(file, separator_chars, - sizeof(separator_chars) - 1); - first = true; - for( i = 0 ; i < files->count ; i ++ ) { - if( !first ) - (void)release_writestring(file,","); - first = false; - (void)release_writestring(file,files->packages[i]); - } - (void)release_writestring(file,"\n"); - filelist_writefiles(dir,len,files->nextr,file); + filelist_writefiles(dir, len, files->nextl, file); + (void)release_writedata(file, dir, len); + (void)release_writestring(file, files->name); + (void)release_writedata(file, separator_chars, + sizeof(separator_chars) - 1); + first = true; + for (i = 0 ; i < files->count ; i ++) { + if (!first) + (void)release_writestring(file, ","); + first = false; + (void)release_writestring(file, files->packages[i]); + } + (void)release_writestring(file, "\n"); + filelist_writefiles(dir, len, files->nextr, file); } static retvalue filelist_writedirs(char **buffer_p, size_t *size_p, size_t ofs, struct dirlist *dir, struct filetorelease *file) { - if( dir->nextl != NULL ) { + if (dir->nextl != NULL) { retvalue r; r = filelist_writedirs(buffer_p, size_p, ofs, dir->nextl, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } { size_t len = dir->len; register retvalue r; - if( ofs+len+2 >= *size_p ) { + if (ofs+len+2 >= *size_p) { char *n; *size_p += 1024*(1+(len/1024)); n = realloc(*buffer_p, *size_p); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { free(*buffer_p); *buffer_p = NULL; return RET_ERROR_OOM; @@ -519,14 +520,14 @@ (*buffer_p)[ofs + len] = '/'; // TODO: output files and directories sorted together instead filelist_writefiles(*buffer_p, ofs+len+1, dir->files, file); - if( dir->subdirs == NULL ) + if (dir->subdirs == NULL) r = RET_OK; else r = filelist_writedirs(buffer_p, size_p, ofs+len+1, dir->subdirs, file); - if( dir->nextr == NULL ) + if (dir->nextr == NULL) return r; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return filelist_writedirs(buffer_p, size_p, ofs, dir->nextr, file); @@ -537,13 +538,13 @@ char *buffer = malloc(size); retvalue r; - if( buffer == NULL ) + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; - (void)release_writedata(file,header,sizeof(header)-1); + (void)release_writedata(file, header, sizeof(header) - 1); buffer[0] = '\0'; - filelist_writefiles(buffer,0,list->root->files,file); - if( list->root->subdirs != NULL ) + filelist_writefiles(buffer, 0, list->root->files, file); + if (list->root->subdirs != NULL) r = filelist_writedirs(&buffer, &size, 0, list->root->subdirs, file); else @@ -557,23 +558,23 @@ retvalue filelistcompressor_setup(/*@out@*/struct filelistcompressor *c) { c->size = 2000; c->len = 0; c->filelist = malloc(c->size); - if( c->filelist == NULL ) + if (FAILEDTOALLOC(c->filelist)) return RET_ERROR_OOM; c->dirdepth = 0; return RET_OK; } static inline bool filelistcompressor_space(struct filelistcompressor *c, size_t len) { - if( c->len + len + 2 >= c->size ) { + if (c->len + len + 2 >= c->size) { char *n; - if( c->size > 1024*1024*1024 ) { + if (c->size > 1024*1024*1024) { fprintf(stderr, "Ridiculously long file list!\n"); return false; } c->size = c->len + len + 2048; n = realloc(c->filelist, c->size); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return false; c->filelist = n; } @@ -585,45 +586,45 @@ const char *separator; /* check if it is already in the current dir or a subdir of that: */ - if( name_len > 0 && *name == '.' ) { + if (name_len > 0 && *name == '.') { name++; name_len--; } - while( name_len > 0 && *name == '/' ) { + while (name_len > 0 && *name == '/') { name++; name_len--; } - for( depth = 0; depth < c->dirdepth ; depth++ ) { + for (depth = 0; depth < c->dirdepth ; depth++) { const unsigned char *u =(unsigned char *)c->filelist + c->offsets[depth]; size_t dir_len = 0; - while( *u == 255 ) { + while (*u == 255) { dir_len += 255; u++; } dir_len += *(u++); - if( dir_len >= name_len ) + if (dir_len >= name_len) break; - if( memcmp(u, name, dir_len) != 0 || name[dir_len] != '/' ) + if (memcmp(u, name, dir_len) != 0 || name[dir_len] != '/') break; name += dir_len + 1; name_len -= dir_len + 1; } - if( depth < c->dirdepth ) { - if( !filelistcompressor_space(c, 1) ) + if (depth < c->dirdepth) { + if (!filelistcompressor_space(c, 1)) return RET_ERROR_OOM; c->filelist[c->len++] = (unsigned char)2 + c->dirdepth - depth; c->dirdepth = depth; } - while( (separator = memchr(name, '/', name_len)) != NULL ) { + while ((separator = memchr(name, '/', name_len)) != NULL) { size_t dirlen = separator - name; /* ignore files within directories with more than 255 chars */ - if( dirlen >= 255 ) + if (dirlen >= 255) return RET_NOTHING; /* ignore too deep paths */ - if( c->dirdepth > 252 ) + if (c->dirdepth > 252) return RET_NOTHING; /* add directory */ - if( !filelistcompressor_space(c, 2 + dirlen) ) + if (!filelistcompressor_space(c, 2 + dirlen)) return RET_ERROR_OOM; c->filelist[c->len++] = 2; c->offsets[c->dirdepth++] = c->len; @@ -632,14 +633,14 @@ c->len += dirlen; name += dirlen+1; name_len -= dirlen+1; - while( name_len > 0 && *name == '/' ) { + while (name_len > 0 && *name == '/') { name++; name_len--; } } - if( name_len >= 255 ) + if (name_len >= 255) return RET_NOTHING; /* all directories created, now only the file is left */ - if( !filelistcompressor_space(c, 2 + name_len) ) + if (!filelistcompressor_space(c, 2 + name_len)) return RET_ERROR_OOM; c->filelist[c->len++] = 1; c->filelist[c->len++] = name_len; @@ -648,15 +649,15 @@ return RET_OK; } -retvalue filelistcompressor_finish(struct filelistcompressor *c, /*@out@*/char **list,/*@out@*/size_t *size) { +retvalue filelistcompressor_finish(struct filelistcompressor *c, /*@out@*/char **list, /*@out@*/size_t *size) { char *l; l = realloc(c->filelist, c->len+1); - if( l == NULL ) { + if (FAILEDTOALLOC(l)) { free(c->filelist); return RET_ERROR_OOM; } - c->filelist[c->len] = '\0'; + l[c->len] = '\0'; *list = l; *size = c->len+1; return RET_OK; @@ -674,42 +675,42 @@ char *newdata; r = table_newglobalcursor(oldtable, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - while( cursor_nexttempdata(oldtable, cursor, &filekey, - &olddata, &olddata_len) ) { + while (cursor_nexttempdata(oldtable, cursor, &filekey, + &olddata, &olddata_len)) { const char *p; size_t l; struct filelistcompressor c; r = filelistcompressor_setup(&c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - for( p = olddata ; (l = strlen(p)) != 0 ; p += l + 1 ) { + for (p = olddata ; (l = strlen(p)) != 0 ; p += l + 1) { r = filelistcompressor_add(&c, p, l); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { filelistcompressor_cancel(&c); break; } r = filelistcompressor_finish(&c, &newdata, &newdata_size); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) break; r = table_adduniqsizedrecord(newtable, filekey, newdata, newdata_size, false, false); free(newdata); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)cursor_close(oldtable, cursor); return r; } r = cursor_close(oldtable, cursor); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } diff -Nru reprepro-4.5.0/filelist.h reprepro-4.6.0/filelist.h --- reprepro-4.5.0/filelist.h 2007-09-21 16:04:10.000000000 +0000 +++ reprepro-4.6.0/filelist.h 2011-05-05 14:42:55.000000000 +0000 @@ -9,13 +9,13 @@ retvalue filelist_init(struct filelist_list **list); -retvalue filelist_addpackage(struct filelist_list *, struct database *, const char *package, const char *section, const char *filekey); +retvalue filelist_addpackage(struct filelist_list *, const char *package, const char *section, const char *filekey); retvalue filelist_write(struct filelist_list *list, struct filetorelease *file); void filelist_free(/*@only@*/struct filelist_list *); -retvalue fakefilelist(struct database *, const char *filekey); +retvalue fakefilelist(const char *filekey); retvalue filelists_translate(struct table *, struct table *); /* for use in routines reading the data: */ diff -Nru reprepro-4.5.0/files.c reprepro-4.6.0/files.c --- reprepro-4.5.0/files.c 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/files.c 2011-05-05 14:42:55.000000000 +0000 @@ -39,55 +39,55 @@ #include "pool.h" #include "database_p.h" -static retvalue files_get_checksums(struct database *database, const char *filekey, /*@out@*/struct checksums **checksums_p) { +static retvalue files_get_checksums(const char *filekey, /*@out@*/struct checksums **checksums_p) { const char *checksums; size_t checksumslen; retvalue r; - r = table_gettemprecord(database->checksums, filekey, + r = table_gettemprecord(rdb_checksums, filekey, &checksums, &checksumslen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; return checksums_setall(checksums_p, checksums, checksumslen); } -retvalue files_add_checksums(struct database *database, const char *filekey, const struct checksums *checksums) { +retvalue files_add_checksums(const char *filekey, const struct checksums *checksums) { retvalue r; const char *combined; size_t combinedlen; - assert( database->checksums != NULL ); + assert (rdb_checksums != NULL); r = checksums_getcombined(checksums, &combined, &combinedlen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - r = table_adduniqsizedrecord(database->checksums, filekey, + r = table_adduniqsizedrecord(rdb_checksums, filekey, combined, combinedlen + 1, true, false); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; return pool_markadded(filekey); } -static retvalue files_replace_checksums(struct database *database, const char *filekey, const struct checksums *checksums) { +static retvalue files_replace_checksums(const char *filekey, const struct checksums *checksums) { retvalue r; const char *combined; size_t combinedlen; - assert( database->checksums != NULL ); + assert (rdb_checksums != NULL); r = checksums_getcombined(checksums, &combined, &combinedlen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - return table_adduniqsizedrecord(database->checksums, filekey, + return table_adduniqsizedrecord(rdb_checksums, filekey, combined, combinedlen + 1, true, false); } /* remove file's md5sum from database */ -retvalue files_removesilent(struct database *database, const char *filekey) { +retvalue files_removesilent(const char *filekey) { retvalue r; - if( database->contents != NULL ) - (void)table_deleterecord(database->contents, filekey, true); - r = table_deleterecord(database->checksums, filekey, true); - if( r == RET_NOTHING ) { + if (rdb_contents != NULL) + (void)table_deleterecord(rdb_contents, filekey, true); + r = table_deleterecord(rdb_checksums, filekey, true); + if (r == RET_NOTHING) { fprintf(stderr, "Unable to forget unknown filekey '%s'.\n", filekey); return RET_ERROR_MISSING; @@ -95,44 +95,44 @@ return r; } -retvalue files_remove(struct database *database, const char *filekey) { +retvalue files_remove(const char *filekey) { retvalue r; - r = files_removesilent(database, filekey); - if( RET_IS_OK(r) ) + r = files_removesilent(filekey); + if (RET_IS_OK(r)) return pool_markdeleted(filekey); return r; } /* hardlink file with known checksums and add it to database */ -retvalue files_hardlinkandadd(struct database *database, const char *tempfile, const char *filekey, const struct checksums *checksums) { +retvalue files_hardlinkandadd(const char *tempfile, const char *filekey, const struct checksums *checksums) { retvalue r; /* an additional check to make sure nothing tricks us into * overwriting it by another file */ - r = files_canadd(database, filekey, checksums); - if( !RET_IS_OK(r) ) + r = files_canadd(filekey, checksums); + if (!RET_IS_OK(r)) return r; r = checksums_hardlink(global.outdir, filekey, tempfile, checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - return files_add_checksums(database, filekey, checksums); + return files_add_checksums(filekey, checksums); } /* 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_canadd(struct database *database, const char *filekey, const struct checksums *checksums) { + * or RET_ERROR_WRONG_MD5SUM if filekey already has different md5sum */ +retvalue files_canadd(const char *filekey, const struct checksums *checksums) { retvalue r; struct checksums *indatabase; bool improves; - r = files_get_checksums(database, filekey, &indatabase); - if( r == RET_NOTHING ) + r = files_get_checksums(filekey, &indatabase); + if (r == RET_NOTHING) return RET_OK; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( !checksums_check(indatabase, checksums, &improves) ) { + if (!checksums_check(indatabase, checksums, &improves)) { fprintf(stderr, "File \"%s\" is already registered with different checksums!\n", filekey); @@ -150,31 +150,31 @@ /* check for file in the database and if not found there, if it can be detected */ -retvalue files_expect(struct database *database, const char *filekey, const struct checksums *checksums, bool warnifadded) { +retvalue files_expect(const char *filekey, const struct checksums *checksums, bool warnifadded) { retvalue r; char *filename; struct checksums *improvedchecksums = NULL; - r = files_canadd(database, filekey, checksums); - if( r == RET_NOTHING ) + r = files_canadd(filekey, checksums); + if (r == RET_NOTHING) return RET_OK; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* ready to add means missing, so have to look for the file itself: */ filename = files_calcfullfilename(filekey); - if( filename == NULL ) + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; /* first check if a possible manually put (or left over from previous * downloads attepts) file is there and is correct */ r = checksums_test(filename, checksums, &improvedchecksums); - if( r == RET_ERROR_WRONG_MD5) { + if (r == RET_ERROR_WRONG_MD5) { fprintf(stderr, "Deleting unexpected file '%s'!\n" "(not in database and wrong in pool)\n ", filename); - if( unlink(filename) == 0 ) + if (unlink(filename) == 0) r = RET_NOTHING; else { int e = errno; @@ -183,38 +183,40 @@ } } free(filename); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - if( warnifadded ) - fprintf(stderr, "Warning: readded existing file '%s' mysteriously missing from the checksum database.\n", filekey); + if (warnifadded) + fprintf(stderr, +"Warning: readded existing file '%s' mysteriously missing from the checksum database.\n", + filekey); // TODO: some callers might want the updated checksum when // improves is true, how to get them there? /* add found file to database */ - if( improvedchecksums != NULL ) { - r = files_add_checksums(database, filekey, improvedchecksums); + if (improvedchecksums != NULL) { + r = files_add_checksums(filekey, improvedchecksums); checksums_free(improvedchecksums); } else - r = files_add_checksums(database, filekey, checksums); - assert( r != RET_NOTHING ); + r = files_add_checksums(filekey, checksums); + assert (r != RET_NOTHING); return r; } /* check for several files in the database and in the pool if missing */ -retvalue files_expectfiles(struct database *database, const struct strlist *filekeys, struct checksums *checksumsarray[]) { +retvalue files_expectfiles(const struct strlist *filekeys, struct checksums *checksumsarray[]) { int i; retvalue r; - for( i = 0 ; i < filekeys->count ; i++ ) { + for (i = 0 ; i < filekeys->count ; i++) { const char *filekey = filekeys->values[i]; const struct checksums *checksums = checksumsarray[i]; - r = files_expect(database, filekey, checksums, verbose >= 0); - if( RET_WAS_ERROR(r) ) + r = files_expect(filekey, checksums, verbose >= 0); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { /* File missing */ fprintf(stderr, "Missing file %s\n", filekey); return RET_ERROR_MISSING; @@ -223,146 +225,119 @@ return RET_OK; } -/* check for several files in the database and update information */ -retvalue files_checkorimprove(struct database *database, const struct strlist *filekeys, struct checksums *checksumsarray[]) { - int i; +static inline retvalue checkorimprove(const char *filekey, struct checksums **checksums_p) { + const struct checksums *checksums = *checksums_p; + struct checksums *indatabase; + bool improves; retvalue r; - for( i = 0 ; i < filekeys->count ; i++ ) { - const char *filekey = filekeys->values[i]; - const struct checksums *checksums = checksumsarray[i]; - struct checksums *indatabase; - bool improves; - - r = files_get_checksums(database, filekey, &indatabase); - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing file %s\n", filekey); - return RET_ERROR_MISSING; - } - if( RET_WAS_ERROR(r) ) - return r; - if( !checksums_check(checksums, indatabase, &improves) ) { - fprintf(stderr, + r = files_get_checksums(filekey, &indatabase); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing file %s\n", filekey); + return RET_ERROR_MISSING; + } + if (RET_WAS_ERROR(r)) + return r; + if (!checksums_check(checksums, indatabase, &improves)) { + fprintf(stderr, "File \"%s\" is already registered with different checksums!\n", filekey); - checksums_printdifferences(stderr, indatabase, checksums); - r = RET_ERROR_WRONG_MD5; - } else if( improves ) { - r = checksums_combine(&checksumsarray[i], indatabase, NULL); - } - checksums_free(indatabase); - if( RET_WAS_ERROR(r) ) - return r; + checksums_printdifferences(stderr, indatabase, checksums); + r = RET_ERROR_WRONG_MD5; + } else if (improves) { + r = checksums_combine(checksums_p, indatabase, NULL); } - return RET_OK; + checksums_free(indatabase); + return r; } -/* print missing files */ -retvalue files_printmissing(struct database *database, const struct strlist *filekeys, const struct checksumsarray *origfiles) { - int i; - retvalue ret,r; - ret = RET_NOTHING; - assert( filekeys->count == origfiles->names.count ); - for( i = 0 ; i < filekeys->count ; i++ ) { - const char *filekey = filekeys->values[i]; - const char *origfile = origfiles->names.values[i]; - const struct checksums *checksums = origfiles->checksums[i]; +/* check for several files in the database and update information */ +retvalue files_checkorimprove(const struct strlist *filekeys, struct checksums *checksumsarray[]) { + int i; + retvalue r; - r = files_expect(database, filekey, checksums, false); - if( RET_WAS_ERROR(r) ) { + for (i = 0 ; i < filekeys->count ; i++) { + r = checkorimprove(filekeys->values[i], + &checksumsarray[i]); + if (RET_WAS_ERROR(r)) return r; - } - if( r == RET_NOTHING ) { - /* File missing */ - (void)fputs(origfile, stdout); - (void)putchar(' '); - (void)fputs(global.outdir, stdout); - (void)putchar('/'); - (void)fputs(filekey, stdout); - (void)putchar('\n'); - RET_UPDATE(ret,RET_OK); - } else - RET_UPDATE(ret,r); } - return ret; + return RET_OK; } /* dump out all information */ -retvalue files_printmd5sums(struct database *database) { +retvalue files_printmd5sums(void) { retvalue result, r; struct cursor *cursor; const char *filekey, *checksum; - r = table_newglobalcursor(database->checksums, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_checksums, &cursor); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nexttemp(database->checksums, cursor, - &filekey, &checksum) ) { + while (cursor_nexttemp(rdb_checksums, cursor, &filekey, &checksum)) { result = RET_OK; (void)fputs(filekey, stdout); (void)putchar(' '); - while( *checksum == ':' ) { - while( *checksum != ' ' && *checksum != '\0' ) + while (*checksum == ':') { + while (*checksum != ' ' && *checksum != '\0') checksum++; - if( *checksum == ' ' ) + if (*checksum == ' ') checksum++; } (void)fputs(checksum, stdout); (void)putchar('\n'); } - r = cursor_close(database->checksums, cursor); + r = cursor_close(rdb_checksums, cursor); RET_ENDUPDATE(result, r); return result; } -retvalue files_printchecksums(struct database *database) { +retvalue files_printchecksums(void) { retvalue result, r; struct cursor *cursor; const char *filekey, *checksum; - r = table_newglobalcursor(database->checksums, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_checksums, &cursor); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nexttemp(database->checksums, cursor, - &filekey, &checksum) ) { + while (cursor_nexttemp(rdb_checksums, cursor, &filekey, &checksum)) { result = RET_OK; (void)fputs(filekey, stdout); (void)putchar(' '); (void)fputs(checksum, stdout); (void)putchar('\n'); - if( interrupted() ) { + if (interrupted()) { result = RET_ERROR_INTERRUPTED; break; } } - r = cursor_close(database->checksums, cursor); + r = cursor_close(rdb_checksums, cursor); RET_ENDUPDATE(result, r); return result; } /* callback for each registered file */ -retvalue files_foreach(struct database *database,per_file_action action,void *privdata) { +retvalue files_foreach(per_file_action action, void *privdata) { retvalue result, r; struct cursor *cursor; const char *filekey, *checksum; - r = table_newglobalcursor(database->checksums, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_checksums, &cursor); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nexttemp(database->checksums, cursor, - &filekey, &checksum) ) { - if( interrupted() ) { + while (cursor_nexttemp(rdb_checksums, cursor, &filekey, &checksum)) { + if (interrupted()) { RET_UPDATE(result, RET_ERROR_INTERRUPTED); break; } r = action(privdata, filekey); RET_UPDATE(result, r); } - r = cursor_close(database->checksums, cursor); + r = cursor_close(rdb_checksums, cursor); RET_ENDUPDATE(result, r); return result; } @@ -373,20 +348,20 @@ bool improves; r = checksums_read(fullfilename, &actual); - if( RET_IS_OK(r) ) { - if( !checksums_check(expected, actual, &improves) ) { + if (RET_IS_OK(r)) { + if (!checksums_check(expected, actual, &improves)) { fprintf(stderr, "WRONG CHECKSUMS of '%s':\n", fullfilename); checksums_printdifferences(stderr, expected, actual); r = RET_ERROR_WRONG_MD5; - } else if( improves ) + } else if (improves) *improveable = true; checksums_free(actual); } return r; } -retvalue files_checkpool(struct database *database, bool fast) { +retvalue files_checkpool(bool fast) { retvalue result, r; struct cursor *cursor; const char *filekey, *combined; @@ -396,27 +371,27 @@ bool improveable = false; result = RET_NOTHING; - r = table_newglobalcursor(database->checksums, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_checksums, &cursor); + if (!RET_IS_OK(r)) return r; - while( cursor_nexttempdata(database->checksums, cursor, - &filekey, &combined, &combinedlen) ) { + while (cursor_nexttempdata(rdb_checksums, cursor, + &filekey, &combined, &combinedlen)) { r = checksums_setall(&expected, combined, combinedlen); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { RET_UPDATE(result, r); continue; } fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { result = RET_ERROR_OOM; checksums_free(expected); break; } - if( fast ) + if (fast) r = checksums_cheaptest(fullfilename, expected, true); else r = checkpoolfile(fullfilename, expected, &improveable); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Missing file '%s'!\n", fullfilename); r = RET_ERROR_MISSING; } @@ -424,16 +399,16 @@ checksums_free(expected); RET_UPDATE(result, r); } - r = cursor_close(database->checksums, cursor); + r = cursor_close(rdb_checksums, cursor); RET_ENDUPDATE(result, r); - if( improveable && verbose >= 0 ) + if (improveable && verbose >= 0) printf( "There were files with only some of the checksums this version of reprepro\n" "can compute recorded. To add those run reprepro collectnewchecksums.\n"); return result; } -retvalue files_collectnewchecksums(struct database *database) { +retvalue files_collectnewchecksums(void) { retvalue result, r; struct cursor *cursor; const char *filekey, *all; @@ -442,79 +417,75 @@ char *fullfilename; result = RET_NOTHING; - r = table_newglobalcursor(database->checksums, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_checksums, &cursor); + if (!RET_IS_OK(r)) return r; - while( cursor_nexttempdata(database->checksums, cursor, - &filekey, &all, &alllen) ) { + while (cursor_nexttempdata(rdb_checksums, cursor, + &filekey, &all, &alllen)) { r = checksums_setall(&expected, all, alllen); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { RET_UPDATE(result, r); continue; } - if( checksums_iscomplete(expected) ) { + if (checksums_iscomplete(expected)) { checksums_free(expected); continue; } fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { result = RET_ERROR_OOM; checksums_free(expected); break; } r = checksums_complete(&expected, fullfilename); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Missing file '%s'!\n", fullfilename); r = RET_ERROR_MISSING; } - if( r == RET_ERROR_WRONG_MD5 ) { + if (r == RET_ERROR_WRONG_MD5) { fprintf(stderr, "ERROR: Cannot collect missing checksums for '%s'\n" "as the file in the pool does not match the already recorded checksums\n", filekey); } free(fullfilename); - if( RET_IS_OK(r) ) - r = files_replace_checksums(database, - filekey, expected); + if (RET_IS_OK(r)) + r = files_replace_checksums(filekey, expected); checksums_free(expected); RET_UPDATE(result, r); } - r = cursor_close(database->checksums, cursor); + r = cursor_close(rdb_checksums, cursor); RET_ENDUPDATE(result, r); return result; } -retvalue files_detect(struct database *database, const char *filekey) { +retvalue files_detect(const char *filekey) { struct checksums *checksums; char *fullfilename; retvalue r; fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; r = checksums_read(fullfilename, &checksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error opening '%s'!\n", fullfilename); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } free(fullfilename); - r = files_add_checksums(database, filekey, checksums); + r = files_add_checksums(filekey, checksums); checksums_free(checksums); return r; } -struct rfd { bool reread; - /*@temp@*/struct database *database; -}; +struct rfd { bool reread; }; static retvalue regenerate_filelist(void *data, const char *filekey) { - struct database *database = ((struct rfd*)data)->database; bool reread = ((struct rfd*)data)->reread; size_t l = strlen(filekey); char *debfilename; @@ -522,84 +493,81 @@ size_t fls; retvalue r; - if( l <= 4 || memcmp(filekey+l-4, ".deb", 4) != 0 ) + if (l <= 4 || memcmp(filekey+l-4, ".deb", 4) != 0) return RET_NOTHING; - if( !reread && !table_recordexists(database->contents, filekey) ) + if (!reread && !table_recordexists(rdb_contents, filekey)) return RET_NOTHING; debfilename = files_calcfullfilename(filekey); - if( debfilename == NULL ) + if (FAILEDTOALLOC(debfilename)) return RET_ERROR_OOM; r = getfilelist(&filelist, &fls, debfilename); free(debfilename); - if( RET_IS_OK(r) ) { - if( verbose > 0 ) + if (RET_IS_OK(r)) { + if (verbose > 0) (void)puts(filekey); - if( verbose > 6 ) { + if (verbose > 6) { const char *p = filelist; - while( *p != '\0' ) { + while (*p != '\0') { (void)putchar(' '); (void)puts(p); p += strlen(p)+1; } } - r = table_adduniqsizedrecord( - database->contents, - filekey, filelist, fls, - true, true); + r = table_adduniqsizedrecord(rdb_contents, + filekey, filelist, fls, true, true); free(filelist); } return r; } -retvalue files_regenerate_filelist(struct database *database, bool reread) { +retvalue files_regenerate_filelist(bool reread) { struct rfd d; - d.database = database; d.reread = reread; - return files_foreach(database, regenerate_filelist, &d); + return files_foreach(regenerate_filelist, &d); } /* Include a yet unknown file into the pool */ -retvalue files_preinclude(struct database *database, const char *sourcefilename, const char *filekey, struct checksums **checksums_p) { +retvalue files_preinclude(const char *sourcefilename, const char *filekey, struct checksums **checksums_p) { retvalue r; struct checksums *checksums, *realchecksums; bool improves; char *fullfilename; - r = files_get_checksums(database, filekey, &checksums); - if( RET_WAS_ERROR(r) ) + r = files_get_checksums(filekey, &checksums); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = checksums_read(sourcefilename, &realchecksums); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = RET_ERROR_MISSING; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(checksums); return r; } - if( !checksums_check(checksums, realchecksums, &improves) ) { + if (!checksums_check(checksums, realchecksums, &improves)) { fprintf(stderr, "ERROR: '%s' cannot be included as '%s'.\n" "Already existing files can only be included again, if they are the same, but:\n", sourcefilename, filekey); - checksums_printdifferences(stderr, checksums, realchecksums); + checksums_printdifferences(stderr, checksums, + realchecksums); checksums_free(checksums); checksums_free(realchecksums); return RET_ERROR_WRONG_MD5; } - if( improves ) { + if (improves) { r = checksums_combine(&checksums, realchecksums, NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(realchecksums); checksums_free(checksums); return r; } - r = files_replace_checksums(database, filekey, - checksums); - if( RET_WAS_ERROR(r) ) { + r = files_replace_checksums(filekey, checksums); + if (RET_WAS_ERROR(r)) { checksums_free(realchecksums); checksums_free(checksums); return r; @@ -607,38 +575,39 @@ } checksums_free(realchecksums); // args, this breaks retvalue semantics! - if( checksums_p != NULL ) + if (checksums_p != NULL) *checksums_p = checksums; else checksums_free(checksums); return RET_NOTHING; } - assert( sourcefilename != NULL ); + assert (sourcefilename != NULL); fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; (void)dirs_make_parent(fullfilename); r = checksums_copyfile(fullfilename, sourcefilename, true, &checksums); - if( r == RET_ERROR_EXIST ) { + if (r == RET_ERROR_EXIST) { // TODO: deal with already existing files! - fprintf(stderr, "File '%s' does already exist!\n", fullfilename); + fprintf(stderr, "File '%s' does already exist!\n", + fullfilename); } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Could not open '%s'!\n", sourcefilename); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } free(fullfilename); - r = files_add_checksums(database, filekey, checksums); - if( RET_WAS_ERROR(r) ) { + r = files_add_checksums(filekey, checksums); + if (RET_WAS_ERROR(r)) { checksums_free(checksums); return r; } - if( checksums_p != NULL ) + if (checksums_p != NULL) *checksums_p = checksums; else checksums_free(checksums); @@ -651,26 +620,26 @@ bool improves, copied = false; char *fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; - if( checksums_iscomplete(*checksums_p) ) { + if (checksums_iscomplete(*checksums_p)) { r = checksums_cheaptest(fullfilename, *checksums_p, true); - if( r != RET_NOTHING ) { + if (r != RET_NOTHING) { free(fullfilename); return r; } } else { r = checksums_read(fullfilename, &checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { char *sourcefilename = calc_dirconcat(sourcedir, basefilename); - if( sourcefilename == NULL ) { + if (FAILEDTOALLOC(sourcefilename)) { free(fullfilename); return RET_ERROR_OOM; } @@ -683,27 +652,29 @@ (void)dirs_make_parent(fullfilename); r = checksums_copyfile(fullfilename, sourcefilename, false, &checksums); - if( r == RET_ERROR_EXIST ) { + if (r == RET_ERROR_EXIST) { fprintf(stderr, "File '%s' seems to be missing and existing at the same time!\n" -"To confused to continue...\n", fullfilename); +"To confused to continue...\n", + fullfilename); } - if( r == RET_NOTHING ) { - fprintf(stderr, "Could not open '%s'!\n", sourcefilename); + if (r == RET_NOTHING) { + fprintf(stderr, "Could not open '%s'!\n", + sourcefilename); r = RET_ERROR_MISSING; } free(sourcefilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } copied = true; } - assert( checksums != NULL ); + assert (checksums != NULL); - if( !checksums_check(*checksums_p, checksums, &improves) ) { - if( copied ) { + if (!checksums_check(*checksums_p, checksums, &improves)) { + if (copied) { deletefile(fullfilename); fprintf(stderr, "ERROR: Unexpected content of file '%s/%s'!\n", sourcedir, basefilename); @@ -722,9 +693,9 @@ checksums_printdifferences(stderr, *checksums_p, checksums); r = RET_ERROR_WRONG_MD5; } - if( improves ) { + if (improves) { r = checksums_combine(checksums_p, checksums, NULL); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *improving = true; } checksums_free(checksums); @@ -732,18 +703,18 @@ return r; } -retvalue files_checkincludefile(struct database *database, const char *sourcedir, const char *basefilename, const char *filekey, struct checksums **checksums_p) { +retvalue files_checkincludefile(const char *sourcedir, const char *basefilename, const char *filekey, struct checksums **checksums_p) { char *sourcefilename, *fullfilename; struct checksums *checksums; retvalue r; bool improves; - assert( *checksums_p != NULL ); + assert (*checksums_p != NULL); - r = files_get_checksums(database, filekey, &checksums); - if( RET_WAS_ERROR(r) ) + r = files_get_checksums(filekey, &checksums); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { /* there are three sources now: * - the checksums from the database (may have some we * do not even know about, and may miss some we can @@ -757,25 +728,25 @@ * And it can happen the file got lost in the pool, then * this is the best place to replace it. */ - if( !checksums_check(checksums, *checksums_p, &improves) ) { + if (!checksums_check(checksums, *checksums_p, &improves)) { fprintf(stderr, "ERROR: '%s/%s' cannot be included as '%s'.\n" "Already existing files can only be included again, if they are the same, but:\n", sourcedir, basefilename, filekey); - checksums_printdifferences(stderr, checksums, *checksums_p); + checksums_printdifferences(stderr, checksums, + *checksums_p); checksums_free(checksums); return RET_ERROR_WRONG_MD5; } r = RET_NOTHING; - if( improves ) + if (improves) r = checksums_combine(&checksums, *checksums_p, NULL); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) r = checkimproveorinclude(sourcedir, basefilename, filekey, &checksums, &improves); - if( !RET_WAS_ERROR(r) && improves ) - r = files_replace_checksums(database, filekey, - checksums); - if( RET_IS_OK(r) ) + if (!RET_WAS_ERROR(r) && improves) + r = files_replace_checksums(filekey, checksums); + if (RET_IS_OK(r)) r = RET_NOTHING; /* return the combined checksum */ checksums_free(*checksums_p); @@ -783,56 +754,57 @@ return r; } - assert( sourcedir != NULL ); + assert (sourcedir != NULL); sourcefilename = calc_dirconcat(sourcedir, basefilename); - if( sourcefilename == NULL ) + if (FAILEDTOALLOC(sourcefilename)) return RET_ERROR_OOM; fullfilename = files_calcfullfilename(filekey); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { free(sourcefilename); return RET_ERROR_OOM; } (void)dirs_make_parent(fullfilename); r = checksums_copyfile(fullfilename, sourcefilename, true, &checksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Could not open '%s'!\n", sourcefilename); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); free(sourcefilename); return r; } - if( !checksums_check(*checksums_p, checksums, &improves) ) { + if (!checksums_check(*checksums_p, checksums, &improves)) { deletefile(fullfilename); - fprintf(stderr, "ERROR: Unexpected content of file '%s'!\n", sourcefilename); + fprintf(stderr, "ERROR: Unexpected content of file '%s'!\n", + sourcefilename); checksums_printdifferences(stderr, *checksums_p, checksums); r = RET_ERROR_WRONG_MD5; } free(sourcefilename); free(fullfilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } - if( improves ) { + if (improves) { r = checksums_combine(checksums_p, checksums, NULL); checksums_free(checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } else checksums_free(checksums); - return files_add_checksums(database, filekey, *checksums_p); + return files_add_checksums(filekey, *checksums_p); } -off_t files_getsize(struct database *database, const char *filekey) { +off_t files_getsize(const char *filekey) { retvalue r; off_t s; struct checksums *checksums; - r = files_get_checksums(database, filekey, &checksums); + r = files_get_checksums(filekey, &checksums); if (!RET_IS_OK(r)) return -1; s = checksums_getfilesize(checksums); diff -Nru reprepro-4.5.0/files.h reprepro-4.6.0/files.h --- reprepro-4.5.0/files.h 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/files.h 2011-05-05 14:42:55.000000000 +0000 @@ -16,23 +16,20 @@ struct checksumsarray; /* Add file's md5sum to database */ -retvalue files_add_checksums(struct database *, const char *, const struct checksums *); +retvalue files_add_checksums(const char *, const struct checksums *); /* remove file's md5sum from database */ -retvalue files_remove(struct database *, const char *filekey); +retvalue files_remove(const char * /*filekey*/); /* same but do not call pool_markremoved */ -retvalue files_removesilent(struct database *, const char *filekey); +retvalue files_removesilent(const char * /*filekey*/); /* check for file in the database and if not found there in the pool */ -retvalue files_expect(struct database *, const char *, const struct checksums *, bool warnifreadded); +retvalue files_expect(const char *, const struct checksums *, bool warnifreadded); /* same for multiple files */ -retvalue files_expectfiles(struct database *, const struct strlist *, struct checksums **); +retvalue files_expectfiles(const struct strlist *, struct checksums **); /* check for several files in the database and update information */ -retvalue files_checkorimprove(struct database *, const struct strlist *, struct checksums **); - -/* print missing files */ -retvalue files_printmissing(struct database *, const struct strlist *filekeys, const struct checksumsarray *); +retvalue files_checkorimprove(const struct strlist *, struct checksums **); /* what to do with files */ /* file should already be there, just make sure it is in the database */ @@ -51,38 +48,39 @@ * return RET_ERROR_WRONG_MD5 if wrong md5sum. * (the original file is not deleted in that case, even if delete is positive) */ -retvalue files_preinclude(struct database *, const char *sourcefilename, const char *filekey, /*@null@*//*@out@*/struct checksums **); -retvalue files_checkincludefile(struct database *, const char *directory, const char *sourcefilename, const char *filekey, struct checksums **); +retvalue files_preinclude(const char *sourcefilename, const char *filekey, /*@null@*//*@out@*/struct checksums **); +retvalue files_checkincludefile(const char *directory, const char *sourcefilename, const char *filekey, struct checksums **); typedef retvalue per_file_action(void *data, const char *filekey); /* callback for each registered file */ -retvalue files_foreach(struct database *,per_file_action action,void *data); +retvalue files_foreach(per_file_action, void *); /* check if all files are corect. (skip md5sum if fast is true) */ -retvalue files_checkpool(struct database *, bool fast); +retvalue files_checkpool(bool /*fast*/); /* calculate all missing hashes */ -retvalue files_collectnewchecksums(struct database *); +retvalue files_collectnewchecksums(void); /* dump out all information */ -retvalue files_printmd5sums(struct database *); -retvalue files_printchecksums(struct database *); +retvalue files_printmd5sums(void); +retvalue files_printchecksums(void); /* look for the given filekey and add it into the filesdatabase */ -retvalue files_detect(struct database *,const char *filekey); +retvalue files_detect(const char *); -retvalue files_regenerate_filelist(struct database *, bool redo); +retvalue files_regenerate_filelist(bool redo); /* hardlink file with known checksums and add it to database */ -retvalue files_hardlinkandadd(struct database *, const char *tempfile, const char *filekey, const struct checksums *); +retvalue files_hardlinkandadd(const char * /*tempfile*/, const char * /*filekey*/, const struct checksums *); -/* 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_canadd(struct database *, const char *filekey, const struct checksums *); +/* RET_NOTHING: file is already there + * RET_OK : could be added + * RET_ERROR_WRONG_MD5SUM: filekey is already there with different md5sum */ +retvalue files_canadd(const char *filekey, const struct checksums *); /* make a filekey to a fullfilename. return NULL if OutOfMemory */ static inline char *files_calcfullfilename(const char *filekey) { return calc_dirconcat(global.outdir, filekey); } -off_t files_getsize(struct database *, const char*); +off_t files_getsize(const char *); #endif diff -Nru reprepro-4.5.0/filterlist.c reprepro-4.6.0/filterlist.c --- reprepro-4.5.0/filterlist.c 2009-03-06 12:24:21.000000000 +0000 +++ reprepro-4.6.0/filterlist.c 2011-05-05 14:42:55.000000000 +0000 @@ -49,12 +49,14 @@ /*@owned@*//*@null@*/ struct filterlistitem *next; char *packagename; + char *version; enum filterlisttype what; }; static void filterlistitems_free(/*@null@*//*@only@*/struct filterlistitem *list) { - while( list != NULL ) { + while (list != NULL) { struct filterlistitem *next = list->next; + free(list->version); free(list->packagename); free(list); list = next; @@ -62,19 +64,19 @@ } static void filterlistfile_unlock(struct filterlistfile *list) { - assert( list != NULL ); + assert (list != NULL); - if( list->reference_count <= 1 ) { + if (list->reference_count <= 1) { struct filterlistfile **p = &listfiles; - assert( list->reference_count == 1 ); - if( list->reference_count == 0 ) + assert (list->reference_count == 1); + if (list->reference_count == 0) return; - while( *p != NULL && *p != list ) + while (*p != NULL && *p != list) p = &(*p)->next; - assert( p != NULL ); - if( *p == list ) { + assert (p != NULL); + if (*p == list) { *p = list->next; filterlistitems_free(list->root); free(list->filename); @@ -85,7 +87,7 @@ } static inline retvalue filterlistfile_parse(struct filterlistfile *n, const char *filename, FILE *f) { - char *lineend,*namestart,*nameend,*what; + char *lineend, *namestart, *nameend, *what, *version; int cmp; enum filterlisttype type; struct filterlistitem *h; @@ -93,69 +95,103 @@ int lineno = 0; struct filterlistitem **last = &n->root; - while( fgets(line,1000,f) != NULL ) { + while (fgets(line, 1000, f) != NULL) { lineno++; - lineend = strchr(line,'\n'); - if( lineend == NULL ) { - fprintf(stderr,"Overlong line in '%s'!\n",filename); + lineend = strchr(line, '\n'); + if (lineend == NULL) { + fprintf(stderr, "Overlong line in '%s'!\n", filename); return RET_ERROR; } - while( lineend >= line && xisspace(*lineend) ) + while (lineend >= line && xisspace(*lineend)) *(lineend--) = '\0'; /* Ignore line only containing whitespace */ - if( line[0] == '\0' ) + if (line[0] == '\0') continue; namestart = line; - while( *namestart != '\0' && xisspace(*namestart) ) + while (*namestart != '\0' && xisspace(*namestart)) namestart++; nameend=namestart; - while( *nameend != '\0' && !xisspace(*nameend) ) + while (*nameend != '\0' && !xisspace(*nameend)) nameend++; what = nameend; - while( *what != '\0' && xisspace(*what) ) + while (*what != '\0' && xisspace(*what)) *(what++)='\0'; - if( *what == '\0' ) { - fprintf(stderr,"Malformed line in '%s': %d!\n",filename,lineno); + if (*what == '\0') { + fprintf(stderr, +"Malformed line in '%s': %d!\n", filename, lineno); return RET_ERROR; } - if( strcmp(what,"install") == 0 ) { + version = NULL; + if (strcmp(what, "install") == 0) { type = flt_install; - } else if( strcmp(what,"deinstall") == 0 ) { + } else if (strcmp(what, "deinstall") == 0) { type = flt_deinstall; - } else if( strcmp(what,"purge") == 0 ) { + } else if (strcmp(what, "purge") == 0) { type = flt_purge; - } else if( strcmp(what,"hold") == 0 ) { + } else if (strcmp(what, "hold") == 0) { type = flt_hold; - } else if( strcmp(what, "upgradeonly") == 0 ) { + } else if (strcmp(what, "upgradeonly") == 0) { type = flt_upgradeonly; - } else if( strcmp(what, "warning") == 0 ) { + } else if (strcmp(what, "warning") == 0) { type = flt_warning; - } else if( strcmp(what,"error") == 0 ) { + } else if (strcmp(what, "error") == 0) { type = flt_error; + } else if (what[0] == '=') { + what++; + while (*what != '\0' && xisspace(*what)) + what++; + version = what; + if (*version == '\0') { + fprintf(stderr, +"Malformed line %d in '%s': missing version after '='!\n", + lineno, filename); + return RET_ERROR; + } + while (*what != '\0' && !xisspace(*what)) + what++; + while (*what != '\0' && xisspace(*what)) + *(what++) = '\0'; + if (*what != '\0') { + fprintf(stderr, +"Malformed line %d in '%s': space in version!\n", + lineno, filename); + return RET_ERROR; + } + type = flt_install; } else { - fprintf(stderr,"Unknown status in '%s':%d: '%s'!\n",filename,lineno,what); + fprintf(stderr, +"Unknown status in '%s':%d: '%s'!\n", filename, lineno, what); return RET_ERROR; } - if( *last == NULL || strcmp(namestart,(*last)->packagename) < 0 ) + if (*last == NULL || strcmp(namestart, (*last)->packagename) < 0) last = &n->root; cmp = -1; - while( *last != NULL && (cmp=strcmp(namestart,(*last)->packagename)) > 0 ) + while (*last != NULL && + (cmp=strcmp(namestart, (*last)->packagename)) > 0) last = &((*last)->next); - if( cmp == 0 ) { - fprintf(stderr,"Two lines describing '%s' in '%s'!\n",namestart,filename); + if (cmp == 0) { + fprintf(stderr, +"Two lines describing '%s' in '%s'!\n", namestart, filename); return RET_ERROR; } - h = calloc(1,sizeof(*h)); - if( h == NULL ) { + h = zNEW(struct filterlistitem); + if (FAILEDTOALLOC(h)) { return RET_ERROR_OOM; } h->next = *last; *last = h; h->what = type; h->packagename = strdup(namestart); - if( h->packagename == NULL ) { + if (FAILEDTOALLOC(h->packagename)) { return RET_ERROR_OOM; } + if (version == NULL) + h->version = NULL; + else { + h->version = strdup(version); + if (FAILEDTOALLOC(h->version)) + return RET_ERROR_OOM; + } } n->last = *last; return RET_OK; @@ -166,8 +202,8 @@ FILE *f; retvalue r; - f = fopen(filename,"r"); - if( f == NULL ) { + f = fopen(filename, "r"); + if (f == NULL) { fprintf(stderr, "Cannot open %s for reading: %s!\n", filename, strerror(errno)); return RET_ERROR; @@ -183,27 +219,27 @@ struct filterlistfile *p; retvalue r; - for( p = listfiles ; p != NULL ; p = p->next ) { - if( p->filename_len == len && - strncmp(p->filename, filename, len) == 0 ) { + for (p = listfiles ; p != NULL ; p = p->next) { + if (p->filename_len == len && + strncmp(p->filename, filename, len) == 0) { p->reference_count++; *list = p; return RET_OK; } } - p = calloc(1,sizeof(struct filterlistfile)); - if( p == NULL ) + p = zNEW(struct filterlistfile); + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->reference_count = 1; p->filename = strndup(filename, len); p->filename_len = len; - if( p->filename == NULL ) { + if (FAILEDTOALLOC(p->filename)) { free(p); return RET_ERROR_OOM; } - if( p->filename[0] != '/' ) { + if (p->filename[0] != '/') { char *fullfilename = calc_conffile(p->filename); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) r = RET_ERROR_OOM; else { r = filterlistfile_read(p, fullfilename); @@ -212,7 +248,7 @@ } else r = filterlistfile_read(p, p->filename); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { p->next = listfiles; listfiles = p; *list = p; @@ -229,30 +265,30 @@ retvalue r; size_t len = strlen(filename); - for( p = listfiles ; p != NULL ; p = p->next ) { - if( p->filename_len == len && - strncmp(p->filename, filename, len) == 0 ) { + for (p = listfiles ; p != NULL ; p = p->next) { + if (p->filename_len == len && + strncmp(p->filename, filename, len) == 0) { p->reference_count++; *list = p; free(filename); return RET_OK; } } - p = calloc(1,sizeof(struct filterlistfile)); - if( p == NULL ) { + p = zNEW(struct filterlistfile); + if (FAILEDTOALLOC(p)) { free(filename); return RET_ERROR_OOM; } p->reference_count = 1; p->filename = filename; p->filename_len = len; - if( p->filename == NULL ) { + if (FAILEDTOALLOC(p->filename)) { free(p); return RET_ERROR_OOM; } - if( p->filename[0] != '/' ) { + if (p->filename[0] != '/') { char *fullfilename = calc_conffile(p->filename); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) r = RET_ERROR_OOM; else { r = filterlistfile_read(p, fullfilename); @@ -261,7 +297,7 @@ } else r = filterlistfile_read(p, p->filename); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { p->next = listfiles; listfiles = p; *list = p; @@ -278,13 +314,13 @@ assert(list != NULL); - if( list->files != NULL ) { - for( i = 0 ; i < list->count ; i++ ) + if (list->files != NULL) { + for (i = 0 ; i < list->count ; i++) filterlistfile_unlock(list->files[i]); free(list->files); list->files = NULL; } else { - assert( list->count == 0 ); + assert (list->count == 0); } } @@ -307,7 +343,7 @@ char *filename; r = config_getenum(iter, filterlisttype, listtypes, &defaulttype); - if( r == RET_NOTHING || r == RET_ERROR_UNKNOWNFIELD ) { + if (r == RET_NOTHING || r == RET_ERROR_UNKNOWNFIELD) { fprintf(stderr, "Error parsing %s, line %u, column %u: Expected default action as first argument to FilterList: (one of install, purge, hold, ...)\n", config_filename(iter), @@ -315,17 +351,17 @@ config_markercolumn(iter)); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; count = 0; files = NULL; - while( (r = config_getword(iter, &filename)) != RET_NOTHING ) { + while ((r = config_getword(iter, &filename)) != RET_NOTHING) { struct filterlistfile **n; n = realloc(files, (count+1)* sizeof(struct filterlistfile *)); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { free(filename); r = RET_ERROR_OOM; } else { @@ -333,11 +369,11 @@ files = n; // TODO: make filename only r = filterlistfile_get(filename, &files[count]); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) count++; } - if( RET_WAS_ERROR(r) ) { - while( count > 0 ) { + if (RET_WAS_ERROR(r)) { + while (count > 0) { count--; filterlistfile_unlock(files[count]); } @@ -353,40 +389,40 @@ } static inline bool find(const char *name, /*@null@*/struct filterlistfile *list) { - int cmp; + int cmp IFSTUPIDCC(= 0); /*@dependent@*/const struct filterlistitem *last = list->last; - assert( last != NULL ); + assert (last != NULL); - if( last->next != NULL ) { - cmp = strcmp(name,last->next->packagename); - if( cmp == 0 ) { + if (last->next != NULL) { + cmp = strcmp(name, last->next->packagename); + if (cmp == 0) { list->last = last->next; return true; } } - if( last->next == NULL || cmp < 0 ) { - cmp = strcmp(name,last->packagename); - if( cmp == 0 ) { + if (last->next == NULL || cmp < 0) { + cmp = strcmp(name, last->packagename); + if (cmp == 0) { return true; - } else if( cmp > 0 ) + } else if (cmp > 0) return false; last = list->root; - cmp = strcmp(name,last->packagename); - if( cmp == 0 ) { + cmp = strcmp(name, last->packagename); + if (cmp == 0) { list->last = list->root; return true; - } else if( cmp < 0 ) + } else if (cmp < 0) return false; } /* now we are after last */ - while( last->next != NULL ) { - cmp = strcmp(name,last->next->packagename); - if( cmp == 0 ) { + while (last->next != NULL) { + cmp = strcmp(name, last->next->packagename); + if (cmp == 0) { list->last = last->next; return true; } - if( cmp < 0 ) { + if (cmp < 0) { list->last = last; return false; } @@ -396,11 +432,169 @@ return false; } -enum filterlisttype filterlist_find(const char *name, const struct filterlist *list) { +enum filterlisttype filterlist_find(const char *name, const char *version, const struct filterlist *list) { size_t i; - for( i = 0 ; i < list->count ; i++ ) { - if( list->files[i]->root != NULL && find(name,list->files[i]) ) + for (i = 0 ; i < list->count ; i++) { + if (list->files[i]->root == NULL) + continue; + if (!find(name, list->files[i])) + continue; + if (list->files[i]->last->version == NULL) + return list->files[i]->last->what; + if (strcmp(list->files[i]->last->version, version) == 0) return list->files[i]->last->what; } return list->defaulttype; } + +struct filterlist cmdline_bin_filter = { + .count = 0, + .files = NULL, + /* as long as nothing added, this does not change anything. + * Once something is added, that will be auto_hold */ + .defaulttype = flt_unchanged, + .set = false, +}; +struct filterlist cmdline_src_filter = { + .count = 0, + .files = NULL, + /* as long as nothing added, this does not change anything. + * Once something is added, that will be auto_hold */ + .defaulttype = flt_unchanged, + .set = false, +}; + +static retvalue filterlist_cmdline_init(struct filterlist *l) { + if (l->count == 0) { + l->files = nzNEW(2, struct filterlistfile *); + if (FAILEDTOALLOC(l->files)) + return RET_ERROR_OOM; + l->files[0] = zNEW(struct filterlistfile); + if (FAILEDTOALLOC(l->files[0])) + return RET_ERROR_OOM; + l->files[0]->reference_count = 1; + l->count = 1; + } + return RET_OK; +} + +retvalue filterlist_cmdline_add_file(bool src, const char *filename) { + retvalue r; + struct filterlist *l = src ? &cmdline_src_filter : &cmdline_bin_filter; + char *name; + + r = filterlist_cmdline_init(l); + if (RET_WAS_ERROR(r)) + return r; + l->set = true; + l->defaulttype = flt_auto_hold; + + if (strcmp(filename, "-") == 0) + filename = "/dev/stdin"; + name = strdup(filename); + if (FAILEDTOALLOC(name)) + return RET_ERROR_OOM; + if (l->count > 1) { + struct filterlistfile **n; + + n = realloc(l->files, (l->count + 1) * + sizeof(struct filterlistfile *)); + if (FAILEDTOALLOC(n)) { + free(name); + return RET_ERROR_OOM; + } + n[l->count++] = NULL; + l->files = n; + } else { + /* already allocated in _init */ + assert (l->count == 1); + l->count++; + } + + return filterlistfile_get(name, &l->files[l->count - 1]); +} + +retvalue filterlist_cmdline_add_pkg(bool src, const char *package) { + retvalue r; + enum filterlisttype what; + struct filterlist *l = src ? &cmdline_src_filter : &cmdline_bin_filter; + struct filterlistfile *f; + struct filterlistitem **p, *h; + char *name, *version; + const char *c; + int cmp; + + r = filterlist_cmdline_init(l); + if (RET_WAS_ERROR(r)) + return r; + l->set = true; + l->defaulttype = flt_auto_hold; + + c = strchr(package, '='); + if (c != NULL) { + what = flt_install; + name = strndup(package, c - package); + if (FAILEDTOALLOC(name)) + return RET_ERROR_OOM; + version = strdup(c + 1); + if (FAILEDTOALLOC(version)) { + free(name); + return RET_ERROR_OOM; + } + } else { + version = NULL; + c = strchr(package, ':'); + if (c == NULL) { + what = flt_install; + name = strndup(package, c - package); + if (FAILEDTOALLOC(name)) + return RET_ERROR_OOM; + } else { + const struct constant *t = filterlisttype_listtypes; + while (t->name != NULL) { + if (strcmp(c + 1, t->name) == 0) { + what = t->value; + break; + } + t++; + } + if (t->name == NULL) { + fprintf(stderr, +"Error: unknown filter-outcome '%s' (expected 'install' or ...)\n", + c + 1); + return RET_ERROR; + } + + } + name = strndup(package, c - package); + if (FAILEDTOALLOC(name)) + return RET_ERROR_OOM; + } + f = l->files[0]; + assert (f != NULL); + p = &f->root; + cmp = -1; + while (*p != NULL && (cmp = strcmp(name, (*p)->packagename)) > 0) + p = &((*p)->next); + if (cmp == 0) { + fprintf(stderr, +"Package in command line filter two times: '%s'\n", + name); + free(name); + free(version); + return RET_ERROR; + } + h = zNEW(struct filterlistitem); + if (FAILEDTOALLOC(h)) { + free(name); + free(version); + return RET_ERROR_OOM; + } + h->next = *p; + *p = h; + h->what = what; + h->packagename = name; + h->version = version; + f->last = h; + return RET_OK; +} diff -Nru reprepro-4.5.0/filterlist.h reprepro-4.6.0/filterlist.h --- reprepro-4.5.0/filterlist.h 2009-03-06 12:24:21.000000000 +0000 +++ reprepro-4.6.0/filterlist.h 2011-05-05 14:42:55.000000000 +0000 @@ -4,6 +4,8 @@ enum filterlisttype { /* must be 0, so it is the default, when there is no list */ flt_install = 0, + flt_unchanged, /* special value used by the cmdline lists */ + flt_auto_hold, /* special value used by the cmdline lists */ flt_purge, flt_warning, flt_deinstall, @@ -29,6 +31,10 @@ void filterlist_release(struct filterlist *list); -enum filterlisttype filterlist_find(const char *name, const struct filterlist *root); +enum filterlisttype filterlist_find(const char *name, const char *version, const struct filterlist *); + +extern struct filterlist cmdline_bin_filter, cmdline_src_filter; +retvalue filterlist_cmdline_add_pkg(bool, const char *); +retvalue filterlist_cmdline_add_file(bool, const char *); #endif diff -Nru reprepro-4.5.0/freespace.c reprepro-4.6.0/freespace.c --- reprepro-4.5.0/freespace.c 2009-07-14 14:34:08.000000000 +0000 +++ reprepro-4.6.0/freespace.c 2011-05-05 14:42:55.000000000 +0000 @@ -54,10 +54,10 @@ void space_free(struct devices *devices) { struct device *d; - if( devices == NULL ) + if (devices == NULL) return; - while( (d = devices->root) != NULL ) { + while ((d = devices->root) != NULL) { devices->root = d->next; free(d->somepath); @@ -73,16 +73,16 @@ d = devices->root; - while( d != NULL && d->id != id ) + while (d != NULL && d->id != id) d = d->next; - if( d != NULL ) { + if (d != NULL) { *result = d; return RET_OK; } ret = statvfs(dirname, &s); - if( ret != 0 ) { + if (ret != 0) { int e = errno; fprintf(stderr, "Error judging free space for the fileystem '%s' belongs to: %d=%s\n" @@ -91,13 +91,13 @@ return RET_ERRNO(e); } - d = malloc(sizeof(struct device)); - if( d == NULL ) + d = NEW(struct device); + if (FAILEDTOALLOC(d)) return RET_ERROR_OOM; d->next = devices->root; d->id = id; d->somepath = strdup(dirname); - if( d->somepath == NULL ) { + if (FAILEDTOALLOC(d->somepath)) { free(d); return RET_ERROR_OOM; } @@ -119,19 +119,19 @@ int ret; retvalue r; - if( mode == scm_NONE ) { + if (mode == scm_NONE) { *devices = NULL; return RET_OK; } - assert( mode == scm_FULL ); - n = malloc(sizeof(struct devices)); - if( n == NULL ) + assert (mode == scm_FULL); + n = NEW(struct devices); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->root = NULL; n->reserved = reservedforothers; ret = stat(global.dbdir, &s); - if( ret != 0 ) { + if (ret != 0) { int e = errno; fprintf(stderr, "Error stat'ing %s: %d=%s\n", global.dbdir, e, strerror(e)); @@ -139,7 +139,7 @@ return RET_ERRNO(e); } r = device_find_or_create(n, s.st_dev, global.dbdir, &d); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { space_free(n); return r; } @@ -158,24 +158,24 @@ fsblkcnt_t blocks; off_t filesize; - if( devices == NULL ) + if (devices == NULL) return RET_NOTHING; - while( l > 0 && filename[l-1] != '/' ) + while (l > 0 && filename[l-1] != '/') l--; - assert( l > 0 ); + assert (l > 0); memcpy(buffer, filename, l); buffer[l] = '\0'; - ret = stat(buffer ,&s); - if( ret != 0 ) { + ret = stat(buffer, &s); + if (ret != 0) { int e = errno; fprintf(stderr, "Error stat'ing %s: %d=%s\n", filename, e, strerror(e)); return RET_ERRNO(e); } r = device_find_or_create(devices, s.st_dev, buffer, &device); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; filesize = checksums_getfilesize(checksums); blocks = (filesize + device->blocksize - 1) / device->blocksize; @@ -191,15 +191,15 @@ retvalue result = RET_OK; - if( devices == NULL ) + if (devices == NULL) return RET_NOTHING; - for( device = devices->root ; device != NULL ; device = device->next ) { + for (device = devices->root ; device != NULL ; device = device->next) { /* recalculate free space, as created directories * and other stuff might have changed it */ ret = statvfs(device->somepath, &s); - if( ret != 0 ) { + if (ret != 0) { int e = errno; fprintf(stderr, "Error judging free space for the fileystem '%s' belongs to: %d=%s\n" @@ -208,7 +208,7 @@ e, strerror(e)); return RET_ERRNO(e); } - if( device->blocksize != s.f_bsize ) { + if (device->blocksize != s.f_bsize) { fprintf(stderr, "The block size of the filesystem belonging to '%s' has changed.\n" "Either something was mounted or unmounted while reprepro was running,\n" @@ -216,7 +216,7 @@ device->somepath); } device->available = s.f_bavail; - if( device->needed >= device->available ) { + if (device->needed >= device->available) { fprintf(stderr, "NOT ENOUGH FREE SPACE on filesystem 0x%lx (the filesystem '%s' is on)\n" "available blocks %llu, needed blocks %llu, block size is %llu.\n", @@ -225,8 +225,8 @@ (unsigned long long)device->needed, (unsigned long long)device->blocksize); result = RET_ERROR; - } else if( device->reserved >= device->available || - device->needed >= device->available - device->reserved ) { + } else if (device->reserved >= device->available || + device->needed >= device->available - device->reserved) { fprintf(stderr, "NOT ENOUGH FREE SPACE on filesystem 0x%lx (the filesystem '%s' is on)\n" "available blocks %llu, needed blocks %llu (+%llu safety margin), block size is %llu.\n" diff -Nru reprepro-4.5.0/freespace.h reprepro-4.6.0/freespace.h --- reprepro-4.5.0/freespace.h 2009-07-14 14:34:08.000000000 +0000 +++ reprepro-4.6.0/freespace.h 2011-05-05 14:42:55.000000000 +0000 @@ -8,10 +8,10 @@ struct devices; enum spacecheckmode { scm_NONE, /* scm_ASSUMESINGLEFS, */ scm_FULL }; -retvalue space_prepare(/*@out@*/struct devices **,enum spacecheckmode,off_t reservedfordb,off_t reservedforothers); +retvalue space_prepare(/*@out@*/struct devices **, enum spacecheckmode, off_t /*reservedfordb*/, off_t /*reservedforothers*/); struct checksums; -retvalue space_needed(/*@null@*/struct devices *, const char *filename, const struct checksums *); +retvalue space_needed(/*@null@*/struct devices *, const char * /*filename*/, const struct checksums *); retvalue space_check(/*@null@*/struct devices *); diff -Nru reprepro-4.5.0/globals.h reprepro-4.6.0/globals.h --- reprepro-4.5.0/globals.h 2010-10-24 08:59:10.000000000 +0000 +++ reprepro-4.6.0/globals.h 2011-05-05 14:42:55.000000000 +0000 @@ -6,7 +6,7 @@ # define true (1==1) # define false (0==42) /* avoid problems with __builtin_expect being long instead of boolean */ -# define __builtin_expect(a,b) (a) +# define __builtin_expect(a, b) (a) # define __builtin_constant_p(a) (__builtin_constant_p(a) != 0) #else # if HAVE_STDBOOL_H @@ -27,8 +27,8 @@ #define READONLY true #define READWRITE false -#define ISSET(a,b) ((a&b)!=0) -#define NOTSET(a,b) ((a&b)==0) +#define ISSET(a, b) ((a & b) != 0) +#define NOTSET(a, b) ((a & b) == 0) #ifdef STUPIDCC #define IFSTUPIDCC(a) a @@ -86,4 +86,9 @@ enum compression { c_none, c_gzip, c_bzip2, c_lzma, c_xz, c_lunzip, c_COUNT }; +#define NEW(type) ((type *)malloc(sizeof(type))) +#define nNEW(num, type) ((type *)malloc((num) * sizeof(type))) +#define zNEW(type) ((type *)calloc(1, sizeof(type))) +#define nzNEW(num, type) ((type *)calloc(num, sizeof(type))) + #endif diff -Nru reprepro-4.5.0/globmatch.c reprepro-4.6.0/globmatch.c --- reprepro-4.5.0/globmatch.c 2009-06-05 11:27:41.000000000 +0000 +++ reprepro-4.6.0/globmatch.c 2011-05-05 14:42:55.000000000 +0000 @@ -44,124 +44,124 @@ bool possible[ l + 1 ]; const char *p; - if( strlen(pattern) > (size_t)INT_MAX ) + if (strlen(pattern) > (size_t)INT_MAX) return false; memset(possible, 0, sizeof(bool)*(l+1)); /* the first character must match the first pattern character or the first one after the first star */ possible[smallest_possible] = true; - while( pattern[largest_possible] == '*' ) + while (pattern[largest_possible] == '*') largest_possible++; - Assert( largest_possible <= l ); + Assert (largest_possible <= l); possible[largest_possible] = true; - for( p = string ; *p != '\0' ; p++ ) { - Assert( largest_possible >= smallest_possible ); - for( i = largest_possible ; i >= smallest_possible ; i-- ) { - if( !possible[i] ) + for (p = string ; *p != '\0' ; p++) { + Assert (largest_possible >= smallest_possible); + for (i = largest_possible ; i >= smallest_possible ; i--) { + if (!possible[i]) continue; /* no character matches the end of the pattern: */ - if( pattern[i] == '\0' ) { - Assert( i == l ); + if (pattern[i] == '\0') { + Assert (i == l); possible[i] = false; do { - if( largest_possible <= - smallest_possible ) + if (largest_possible <= + smallest_possible) return false; largest_possible--; - } while( !possible[largest_possible] ); + } while (!possible[largest_possible]); i = largest_possible + 1; continue; } - Assert( i < l ); - if( pattern[i] == '*' ) { + Assert (i < l); + if (pattern[i] == '*') { int j = i + 1; - while( pattern[j] == '*' ) + while (pattern[j] == '*') j++; /* all the '*' match one character: */ - Assert( j <= l ); + Assert (j <= l); possible[j] = true; - if( j > largest_possible ) + if (j > largest_possible) largest_possible = j; /* or more than one */ continue; } - if( pattern[i] == '[' ) { + if (pattern[i] == '[') { int j = i+1; bool matches = false, negate = false; - if( pattern[j] == '!' || pattern[j] == '^' ) { + if (pattern[j] == '!' || pattern[j] == '^') { j++; negate = true; } - if( pattern[j] == '\0' ) + if (pattern[j] == '\0') return false; do { - if( pattern[j+1] == '-' && + if (pattern[j+1] == '-' && pattern[j+2] != ']' && - pattern[j+2] != '\0' ) { - if( *p >= pattern[j] && - *p <= pattern[j+2] ) + pattern[j+2] != '\0') { + if (*p >= pattern[j] && + *p <= pattern[j+2]) matches = true; j += 3; } else { - if( *p == pattern[j] ) + if (*p == pattern[j]) matches = true; j++; } - if( pattern[j] == '\0' ) { + if (pattern[j] == '\0') { /* stray [ matches nothing */ return false; } - } while( pattern[j] != ']' ); + } while (pattern[j] != ']'); j++; - Assert( j <= l ); - if( negate ) + Assert (j <= l); + if (negate) matches = !matches; - if( matches ) { + if (matches) { possible[j] = true; /* if the next character is a star, that might also match 0 characters */ - while( pattern[j] == '*' ) + while (pattern[j] == '*') j++; - Assert( j <= l ); + Assert (j <= l); possible[j] = true; - if( j > largest_possible ) + if (j > largest_possible) largest_possible = j; } - } else if( pattern[i] == '?' || pattern[i] == *p ) { + } else if (pattern[i] == '?' || pattern[i] == *p) { int j = i + 1; possible[j] = true; /* if the next character is a star, that might also match 0 characters */ - while( pattern[j] == '*' ) + while (pattern[j] == '*') j++; - Assert( j <= l ); + Assert (j <= l); possible[j] = true; - if( j > largest_possible ) + if (j > largest_possible) largest_possible = j; } possible[i] = false; - if( i == smallest_possible ) { + if (i == smallest_possible) { smallest_possible++; - while( !possible[smallest_possible] ) { - if( smallest_possible >= - largest_possible ) + while (!possible[smallest_possible]) { + if (smallest_possible >= + largest_possible) return false; smallest_possible++; } - Assert( smallest_possible <= l ); + Assert (smallest_possible <= l); } - if( i == largest_possible ) { + if (i == largest_possible) { do { - if( largest_possible <= - smallest_possible ) + if (largest_possible <= + smallest_possible) return false; largest_possible--; - } while( !possible[largest_possible] ); - Assert( largest_possible >= 0 ); + } while (!possible[largest_possible]); + Assert (largest_possible >= 0); } } } @@ -172,11 +172,11 @@ #ifdef TEST_GLOBMATCH int main(int argc, const char *argv[]) { - if( argc != 3 ) { + if (argc != 3) { fputs("Wrong number of arguments!\n", stderr); exit(EXIT_FAILURE); } - if( globmatch(argv[2], argv[1]) ) { + if (globmatch(argv[2], argv[1])) { puts("true"); return 0; } else { diff -Nru reprepro-4.5.0/guesscomponent.c reprepro-4.6.0/guesscomponent.c --- reprepro-4.5.0/guesscomponent.c 2008-10-12 17:28:23.000000000 +0000 +++ reprepro-4.6.0/guesscomponent.c 2011-05-05 14:42:55.000000000 +0000 @@ -36,8 +36,8 @@ int i; size_t section_len; - if( atom_defined(givencomponent) ) { - if( !atomlist_in(components, givencomponent) ) { + if (atom_defined(givencomponent)) { + if (!atomlist_in(components, givencomponent)) { (void)fprintf(stderr, "Could not find '%s' in components of '%s': ", atoms_components[givencomponent], @@ -50,50 +50,54 @@ *guess = givencomponent; return RET_OK; } - if( section == NULL ) { - fprintf(stderr,"Found no section for '%s', so I cannot guess the component to put it in!\n",package); + if (section == NULL) { + fprintf(stderr, +"Found no section for '%s', so I cannot guess the component to put it in!\n", + package); return RET_ERROR; } - if( components->count <= 0 ) { - fprintf(stderr,"I do not find any components in '%s', so there is no chance I cannot even take one by guessing!\n",codename); + if (components->count <= 0) { + fprintf(stderr, +"I do not find any components in '%s', so there is no chance I cannot even take one by guessing!\n", + codename); return RET_ERROR; } section_len = strlen(section); - for( i = 0 ; i < components->count ; i++ ) { + for (i = 0 ; i < components->count ; i++) { const char *component = atoms_components[components->atoms[i]]; - if( strcmp(section, component) == 0 ) { + if (strcmp(section, component) == 0) { *guess = components->atoms[i]; return RET_OK; } } - for( i = 0 ; i < components->count ; i++ ) { + for (i = 0 ; i < components->count ; i++) { const char *component = atoms_components[components->atoms[i]]; size_t len = strlen(component); - if( lenatoms[i]; return RET_OK; } } - for( i = 0 ; i < components->count ; i++ ) { + for (i = 0 ; i < components->count ; i++) { const char *component = atoms_components[components->atoms[i]]; size_t len = strlen(component); - if( lenatoms[i]; return RET_OK; } } - for( i = 0 ; i < components->count ; i++ ) { + for (i = 0 ; i < components->count ; i++) { const char *component = atoms_components[components->atoms[i]]; - if( strncmp(section, component, section_len) == 0 && - component[section_len] == '/' ) { + if (strncmp(section, component, section_len) == 0 && + component[section_len] == '/') { *guess = components->atoms[i]; return RET_OK; } diff -Nru reprepro-4.5.0/guesscomponent.h reprepro-4.6.0/guesscomponent.h --- reprepro-4.5.0/guesscomponent.h 2008-10-05 09:58:05.000000000 +0000 +++ reprepro-4.6.0/guesscomponent.h 2011-05-05 14:42:55.000000000 +0000 @@ -9,6 +9,6 @@ #include "atoms.h" #endif -retvalue guess_component(const char *codename, const struct atomlist *components, const char *package, const char *section, component_t, /*@out@*/component_t *); +retvalue guess_component(const char * /*codename*/, const struct atomlist * /*components*/, const char * /*package*/, const char * /*section*/, component_t, /*@out@*/component_t *); #endif diff -Nru reprepro-4.5.0/ignore.c reprepro-4.6.0/ignore.c --- reprepro-4.5.0/ignore.c 2008-06-10 14:54:47.000000000 +0000 +++ reprepro-4.6.0/ignore.c 2011-05-05 14:42:55.000000000 +0000 @@ -27,37 +27,43 @@ bool ignore[IGN_COUNT]; enum config_option_owner owner_ignore[IGN_COUNT]; -void init_ignores(void) { - int i; - for( i = 0 ; i < IGN_COUNT ; i++ ) { - ignored[i] = 0; - ignore[i] = false; - owner_ignore[i] = CONFIG_OWNER_DEFAULT; - } +static const char * const ignores[] = { +#define IGN(what) #what , + VALID_IGNORES +#undef IGN +}; + +bool print_ignore_type_message(bool i, enum ignore what) { + ignored[what]++; + if (ignore[what]) + fprintf(stderr, "%s as --ignore=%s given.\n", + i ? "Ignoring" : "Not rejecting", + ignores[what]); + else + fprintf(stderr, "To ignore use --ignore=%s.\n", + ignores[what]); + return ignore[what]; } static retvalue set(const char *given, size_t len, bool newvalue, enum config_option_owner newowner) { int i; - static const char * const ignores[] = { -#define IGN(what) #what , - VALID_IGNORES -#undef IGN - }; //TODO: allow multiple values sperated by some sign here... - for( i = 0 ; i < IGN_COUNT ; i++) { - if( strncmp(given,ignores[i],len) == 0 && ignores[i][len] == '\0' ) { - if( owner_ignore[i] <= newowner ) { + for (i = 0 ; i < IGN_COUNT ; i++) { + if (strncmp(given, ignores[i], len) == 0 && + ignores[i][len] == '\0') { + if (owner_ignore[i] <= newowner) { ignore[i] = newvalue; owner_ignore[i] = newowner; } break; } } - if( i == IGN_COUNT ) { - char *str = strndup(given,len); - if( IGNORING("Ignoring","To Ignore",ignore,"Unknown --ignore value: '%s'!\n",(str!=NULL)?str:given)) { + if (i == IGN_COUNT) { + char *str = strndup(given, len); + if (IGNORING(ignore, +"Unknown --ignore value: '%s'!\n", (str!=NULL)?str:given)) { free(str); return RET_NOTHING; } else { @@ -69,25 +75,27 @@ } retvalue set_ignore(const char *given, bool newvalue, enum config_option_owner newowner) { - const char *g,*p; + const char *g, *p; retvalue r; - assert( given != NULL); + assert (given != NULL); g = given; - while( true ) { + while (true) { p = g; - while( *p != '\0' && *p !=',' ) + while (*p != '\0' && *p != ',') p++; - if( p == g ) { - fprintf(stderr,"Empty ignore option in --ignore='%s'!\n",given); + if (p == g) { + fprintf(stderr, +"Empty ignore option in --ignore='%s'!\n", + given); return RET_ERROR_MISSING; } - r = set(g,p-g,newvalue,newowner); - if( RET_WAS_ERROR(r) ) + r = set(g, p - g, newvalue, newowner); + if (RET_WAS_ERROR(r)) return r; - if( *p == '\0' ) + if (*p == '\0') return RET_OK; g = p+1; } diff -Nru reprepro-4.5.0/ignore.h reprepro-4.6.0/ignore.h --- reprepro-4.5.0/ignore.h 2010-07-11 10:16:01.000000000 +0000 +++ reprepro-4.6.0/ignore.h 2011-05-05 14:42:55.000000000 +0000 @@ -48,25 +48,17 @@ extern int ignored[IGN_COUNT]; extern bool ignore[IGN_COUNT]; -#define IGNORING(ignoring,toignore,what,...) \ - ({ fprintf(stderr, ## __VA_ARGS__); \ - ignored[IGN_ ## what] ++; \ - if( ignore[IGN_ ## what] ) { \ - fputs(ignoring " as --ignore=" #what " given.\n",stderr); \ - } else { \ - fputs(toignore " use --ignore=" #what ".\n",stderr); \ - } \ - ignore[IGN_ ## what]; \ - }) -#define IGNORING_(what,...) IGNORING("Ignoring","To ignore",what, __VA_ARGS__ ) -#define IGNORABLE(what) ignore[IGN_ ## what] - -#define RETURN_IF_ERROR_UNLESS_IGNORED(r,what,msg_fmt, ...) \ - if( RET_WAS_ERROR(r) && !ISIGNORED(what,msg_fmt, ## __VA_ARGS__) ) \ - return r; +/* Having that as function avoids those strings to be duplacated everywhere */ +bool print_ignore_type_message(bool, enum ignore); -void init_ignores(void); +#define IGNORING__(ignoring, what, ...) ({ \ + fprintf(stderr, ## __VA_ARGS__); \ + print_ignore_type_message(ignoring, IGN_ ## what ); \ +}) +#define IGNORING(what, ...) IGNORING__(true, what, __VA_ARGS__) +#define IGNORING_(what, ...) IGNORING__(false, what, __VA_ARGS__) +#define IGNORABLE(what) ignore[IGN_ ## what] -retvalue set_ignore(const char *given, bool newvalue, enum config_option_owner newowner); +retvalue set_ignore(const char *, bool, enum config_option_owner); #endif diff -Nru reprepro-4.5.0/incoming.c reprepro-4.6.0/incoming.c --- reprepro-4.5.0/incoming.c 2011-02-09 14:20:22.000000000 +0000 +++ reprepro-4.6.0/incoming.c 2011-05-05 14:42:55.000000000 +0000 @@ -28,6 +28,7 @@ #include #include #include +#include #include "error.h" #include "ignore.h" #include "mprintf.h" @@ -103,12 +104,12 @@ /* only to ease parsing: */ size_t lineno; }; -#define BASENAME(i,ofs) (i)->files.values[ofs] +#define BASENAME(i, ofs) (i)->files.values[ofs] /* the changes file is always the first one listed */ #define changesfile(c) (c->files) static void incoming_free(/*@only@*/ struct incoming *i) { - if( i == NULL ) + if (i == NULL) return; free(i->name); free(i->morguedir); @@ -131,39 +132,41 @@ /* TODO: decide whether to clean this directory first ... */ r = dirs_make_recursive(i->tempdir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; dir = opendir(i->directory); - if( dir == NULL ) { + if (dir == NULL) { int e = errno; - fprintf(stderr, "Cannot scan '%s': %s\n", i->directory, strerror(e)); + fprintf(stderr, "Cannot scan '%s': %s\n", + i->directory, strerror(e)); return RET_ERRNO(e); } - while( (ent = readdir(dir)) != NULL ) { - if( ent->d_name[0] == '.' ) + while ((ent = readdir(dir)) != NULL) { + if (ent->d_name[0] == '.') continue; /* this should be impossible to hit. * but given utf-8 encoding filesystems and * overlong slashes, better check than be sorry */ - if( strchr(ent->d_name, '/') != NULL ) + if (strchr(ent->d_name, '/') != NULL) continue; r = strlist_add_dup(&i->files, ent->d_name) ; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)closedir(dir); return r; } } ret = closedir(dir); - if( ret != 0 ) { + if (ret != 0) { int e = errno; - fprintf(stderr, "Error scanning '%s': %s\n", i->directory, strerror(e)); + fprintf(stderr, "Error scanning '%s': %s\n", + i->directory, strerror(e)); return RET_ERRNO(e); } - i->processed = calloc(i->files.count, sizeof(bool)); - if( i->processed == NULL ) + i->processed = nzNEW(i->files.count, bool); + if (FAILEDTOALLOC(i->processed)) return RET_ERROR_OOM; - i->delete = calloc(i->files.count, sizeof(bool)); - if( i->delete == NULL ) + i->delete = nzNEW(i->files.count, bool); + if (FAILEDTOALLOC(i->delete)) return RET_ERROR_OOM; return RET_OK; } @@ -178,12 +181,12 @@ struct distribution **d; int j; - d = calloc(names->count,sizeof(struct distribution*)); - if( d == NULL ) + d = nzNEW(names->count, struct distribution *); + if (FAILEDTOALLOC(d)) return RET_ERROR_OOM; - for( j = 0 ; j < names->count ; j++ ) { + for (j = 0 ; j < names->count ; j++) { d[j] = distribution_find(distributions, names->values[j]); - if( d[j] == NULL ) { + if (d[j] == NULL) { free(d); return RET_ERROR; } @@ -193,25 +196,26 @@ } CFstartparse(incoming) { - CFstartparseVAR(incoming,result_p); + CFstartparseVAR(incoming, result_p); struct incoming *i; - i = calloc(1,sizeof(struct incoming)); - if( i == NULL ) + i = zNEW(struct incoming); + if (FAILEDTOALLOC(i)) return RET_ERROR_OOM; *result_p = i; return RET_OK; } CFfinishparse(incoming) { - CFfinishparseVARS(incoming,i,last,d); + CFfinishparseVARS(incoming, i, last, d); - if( !complete || strcmp(i->name, d->name) != 0) { + if (!complete || strcmp(i->name, d->name) != 0) { incoming_free(i); return RET_NOTHING; } - if( d->i != NULL ) { - fprintf(stderr, "Multiple definitions of '%s' within '%s': first started at line %u, second at line %u!\n", + if (d->i != NULL) { + fprintf(stderr, +"Multiple definitions of '%s' within '%s': first started at line %u, second at line %u!\n", d->name, config_filename(iter), (unsigned int)d->i->lineno, @@ -221,43 +225,43 @@ d->i = NULL; return RET_ERROR; } - if( i->logdir != NULL && i->logdir[0] != '/' ) { + if (i->logdir != NULL && i->logdir[0] != '/') { char *n = calc_dirconcat(global.basedir, i->logdir); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { incoming_free(i); return RET_ERROR_OOM; } free(i->logdir); i->logdir = n; } - if( i->morguedir != NULL && i->morguedir[0] != '/' ) { + if (i->morguedir != NULL && i->morguedir[0] != '/') { char *n = calc_dirconcat(global.basedir, i->morguedir); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { incoming_free(i); return RET_ERROR_OOM; } free(i->morguedir); i->morguedir = n; } - if( i->tempdir[0] != '/' ) { + if (i->tempdir[0] != '/') { char *n = calc_dirconcat(global.basedir, i->tempdir); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { incoming_free(i); return RET_ERROR_OOM; } free(i->tempdir); i->tempdir = n; } - if( i->directory[0] != '/' ) { + if (i->directory[0] != '/') { char *n = calc_dirconcat(global.basedir, i->directory); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { incoming_free(i); return RET_ERROR_OOM; } free(i->directory); i->directory = n; } - if( i->default_into == NULL && i->allow.count == 0 ) { + if (i->default_into == NULL && i->allow.count == 0) { fprintf(stderr, "There is neither an 'Allow' nor a 'Default' definition in rule '%s'\n" "(starting at line %u, ending at line %u of %s)!\n" @@ -268,9 +272,9 @@ incoming_free(i); return RET_ERROR; } - if( i->morguedir != NULL && !i->cleanup[cuf_on_deny] + if (i->morguedir != NULL && !i->cleanup[cuf_on_deny] && !i->cleanup[cuf_on_error] - && !i->cleanup[cuf_unused_files] ) { + && !i->cleanup[cuf_unused_files]) { fprintf(stderr, "Warning: There is a 'MorgueDir' but no 'Cleanup' to act on in rule '%s'\n" "(starting at line %u, ending at line %u of %s)!\n", @@ -286,39 +290,39 @@ return RET_OK; } -CFSETPROC(incoming,default) { - CFSETPROCVARS(incoming,i,d); +CFSETPROC(incoming, default) { + CFSETPROCVARS(incoming, i, d); char *default_into; retvalue r; r = config_getonlyword(iter, headername, NULL, &default_into); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; i->default_into = distribution_find(d->distributions, default_into); free(default_into); - return ( i->default_into == NULL )?RET_ERROR:RET_OK; + return (i->default_into == NULL)?RET_ERROR:RET_OK; } -CFSETPROC(incoming,allow) { - CFSETPROCVARS(incoming,i,d); +CFSETPROC(incoming, allow) { + CFSETPROCVARS(incoming, i, d); struct strlist allow_into; retvalue r; r = config_getsplitwords(iter, headername, &i->allow, &allow_into); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - assert( i->allow.count == allow_into.count ); + assert (i->allow.count == allow_into.count); r = translate(d->distributions, &allow_into, &i->allow_into); strlist_done(&allow_into); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } -CFSETPROC(incoming,permit) { - CFSETPROCVARS(incoming,i,d); +CFSETPROC(incoming, permit) { + CFSETPROCVARS(incoming, i, d); static const struct constant const permitconstants[] = { { "unused_files", pmf_unused_files}, { "older_version", pmf_oldpackagenewer}, @@ -328,14 +332,14 @@ { NULL, -1} }; - if( IGNORABLE(unknownfield) ) + if (IGNORABLE(unknownfield)) return config_getflags(iter, headername, permitconstants, i->permit, true, ""); - else if( i->name == NULL ) + else if (i->name == NULL) return config_getflags(iter, headername, permitconstants, i->permit, false, "\n(try put Name: before Permit: to ignore if it is from the wrong rule"); - else if( strcmp(i->name, d->name) != 0 ) + else if (strcmp(i->name, d->name) != 0) return config_getflags(iter, headername, permitconstants, i->permit, true, " (but not within the rule we are intrested in.)"); @@ -346,8 +350,8 @@ } -CFSETPROC(incoming,cleanup) { - CFSETPROCVARS(incoming,i,d); +CFSETPROC(incoming, cleanup) { + CFSETPROCVARS(incoming, i, d); static const struct constant const cleanupconstants[] = { { "unused_files", cuf_unused_files}, { "on_deny", cuf_on_deny}, @@ -358,14 +362,14 @@ { NULL, -1} }; - if( IGNORABLE(unknownfield) ) + if (IGNORABLE(unknownfield)) return config_getflags(iter, headername, cleanupconstants, i->cleanup, true, ""); - else if( i->name == NULL ) + else if (i->name == NULL) return config_getflags(iter, headername, cleanupconstants, i->cleanup, false, "\n(try put Name: before Cleanup: to ignore if it is from the wrong rule"); - else if( strcmp(i->name, d->name) != 0 ) + else if (strcmp(i->name, d->name) != 0) return config_getflags(iter, headername, cleanupconstants, i->cleanup, true, " (but not within the rule we are intrested in.)"); @@ -375,22 +379,22 @@ " (use --ignore=unknownfield to ignore this)\n"); } -CFSETPROC(incoming,options) { - CFSETPROCVARS(incoming,i,d); +CFSETPROC(incoming, options) { + CFSETPROCVARS(incoming, i, d); static const struct constant const optionsconstants[] = { { "limit_arch_all", iof_limit_arch_all}, { "multiple_distributions", iof_multiple_distributions}, { NULL, -1} }; - if( IGNORABLE(unknownfield) ) + if (IGNORABLE(unknownfield)) return config_getflags(iter, headername, optionsconstants, i->options, true, ""); - else if( i->name == NULL ) + else if (i->name == NULL) return config_getflags(iter, headername, optionsconstants, i->options, false, "\n(try put Name: before Options: to ignore if it is from the wrong rule"); - else if( strcmp(i->name, d->name) != 0 ) + else if (strcmp(i->name, d->name) != 0) return config_getflags(iter, headername, optionsconstants, i->options, true, " (but not within the rule we are intrested in.)"); @@ -433,16 +437,17 @@ startparseincoming, finishparseincoming, incomingconfigfields, ARRAYCOUNT(incomingconfigfields), &imports); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( imports.i == NULL ) { - fprintf(stderr, "No definition for '%s' found in '%s/incoming'!\n", + if (imports.i == NULL) { + fprintf(stderr, +"No definition for '%s' found in '%s/incoming'!\n", name, global.confdir); return RET_ERROR_MISSING; } r = incoming_prepare(imports.i); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { incoming_free(imports.i); return r; } @@ -470,7 +475,7 @@ * otherwise the data from the .changes for this file: */ char *section; char *priority; - architecture_t architecture_atom; + architecture_t architecture; char *name; /* like above, but updated once files are copied */ struct checksums *checksums; @@ -495,7 +500,7 @@ * to be included */ struct candidate_package *next; const struct candidate_file *master; - component_t component_atom; + component_t component; packagetype_t packagetype; struct strlist filekeys; /* a list of pointers to the files belonging to those @@ -514,7 +519,8 @@ const struct byhandhook *hook; } *byhandhookstocall; } *perdistribution; - /* the logsubdir, and the list of files to put there, otherwise both NULL */ + /* the logsubdir, and the list of files to put there, + * otherwise both NULL */ char *logsubdir; int logcount; const struct candidate_file **logfiles; @@ -525,11 +531,11 @@ free(f->section); free(f->priority); free(f->name); - if( FE_BINARY(f->type) ) + if (FE_BINARY(f->type)) binaries_debdone(&f->deb); - if( f->type == fe_DSC ) + if (f->type == fe_DSC) sources_done(&f->dsc); - if( f->tempfilename != NULL ) { + if (f->tempfilename != NULL) { (void)unlink(f->tempfilename); free(f->tempfilename); f->tempfilename = NULL; @@ -546,7 +552,7 @@ } static void candidate_free(/*@only@*/struct candidate *c) { - if( c == NULL ) + if (c == NULL) return; free(c->control); signatures_free(c->signatures); @@ -556,23 +562,23 @@ strlist_done(&c->distributions); strlist_done(&c->architectures); strlist_done(&c->binaries); - while( c->perdistribution != NULL ) { + while (c->perdistribution != NULL) { struct candidate_perdistribution *d = c->perdistribution; c->perdistribution = d->next; - while( d->packages != NULL ) { + while (d->packages != NULL) { struct candidate_package *p = d->packages; d->packages = p->next; candidate_package_free(p); } - while( d->byhandhookstocall != NULL ) { + while (d->byhandhookstocall != NULL) { struct byhandfile *h = d->byhandhookstocall; d->byhandhookstocall = h->next; free(h); } free(d); } - while( c->files != NULL ) { + while (c->files != NULL) { struct candidate_file *f = c->files; c->files = f->next; candidate_file_free(f); @@ -583,15 +589,15 @@ } static retvalue candidate_newdistribution(struct candidate *c, struct distribution *distribution) { - struct candidate_perdistribution *n,**pp = &c->perdistribution; + struct candidate_perdistribution *n, **pp = &c->perdistribution; - while( *pp != NULL ) { - if( (*pp)->into == distribution ) + while (*pp != NULL) { + if ((*pp)->into == distribution) return RET_NOTHING; pp = &(*pp)->next; } - n = calloc(1, sizeof(struct candidate_perdistribution)); - if( n == NULL ) + n = zNEW(struct candidate_perdistribution); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->into = distribution; *pp = n; @@ -599,48 +605,49 @@ } static struct candidate_package *candidate_newpackage(struct candidate_perdistribution *fordistribution, const struct candidate_file *master) { - struct candidate_package *n,**pp = &fordistribution->packages; + struct candidate_package *n, **pp = &fordistribution->packages; - while( *pp != NULL ) + while (*pp != NULL) pp = &(*pp)->next; - n = calloc(1, sizeof(struct candidate_package)); - if( n != NULL ) { - n->component_atom = atom_unknown; - n->packagetype = atom_unknown; - n->master = master; - *pp = n; - } + n = zNEW(struct candidate_package); + if (FAILEDTOALLOC(n)) + return NULL; + n->component = atom_unknown; + n->packagetype = atom_unknown; + n->master = master; + *pp = n; return n; } -static retvalue candidate_usefile(const struct incoming *i,const struct candidate *c,struct candidate_file *file); +static retvalue candidate_usefile(const struct incoming *i, const struct candidate *c, struct candidate_file *file); static retvalue candidate_read(struct incoming *i, int ofs, struct candidate **result, bool *broken) { struct candidate *n; retvalue r; - n = calloc(1,sizeof(struct candidate)); - if( n == NULL ) + n = zNEW(struct candidate); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->ofs = ofs; /* first file of any .changes file is the file itself */ - n->files = calloc(1,sizeof(struct candidate_file)); - if( n->files == NULL ) { + n->files = zNEW(struct candidate_file); + if (FAILEDTOALLOC(n->files)) { free(n); return RET_ERROR_OOM; } n->files->ofs = n->ofs; n->files->type = fe_CHANGES; r = candidate_usefile(i, n, n->files); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { candidate_free(n); return r; } - assert( n->files->tempfilename != NULL ); - r = signature_readsignedchunk(n->files->tempfilename, BASENAME(i,ofs), &n->control, &n->signatures, broken); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (n->files->tempfilename != NULL); + r = signature_readsignedchunk(n->files->tempfilename, BASENAME(i, ofs), + &n->control, &n->signatures, broken); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { candidate_free(n); return r; } @@ -653,19 +660,20 @@ char *basefilename; retvalue r; - n = calloc(1,sizeof(struct candidate_file)); - if( n == NULL ) + n = zNEW(struct candidate_file); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; r = changes_parsefileline(fileline, &n->type, &basefilename, &n->h.hashes[cs_md5sum], &n->h.hashes[cs_length], - &n->section, &n->priority, &n->architecture_atom, &n->name); - if( RET_WAS_ERROR(r) ) { + &n->section, &n->priority, &n->architecture, + &n->name); + if (RET_WAS_ERROR(r)) { free(n); return r; } n->ofs = strlist_ofs(&i->files, basefilename); - if( n->ofs < 0 ) { + if (n->ofs < 0) { fprintf(stderr, "In '%s': file '%s' not found in the incoming dir!\n", i->files.values[c->ofs], basefilename); @@ -676,7 +684,7 @@ free(basefilename); p = &c->files; - while( *p != NULL ) + while (*p != NULL) p = &(*p)->next; *p = n; return RET_OK; @@ -685,7 +693,7 @@ static retvalue candidate_addhashes(struct incoming *i, struct candidate *c, enum checksumtype cs, const struct strlist *lines) { int j; - for( j = 0 ; j < lines->count ; j++ ) { + for (j = 0 ; j < lines->count ; j++) { const char *fileline = lines->values[j]; struct candidate_file *f; const char *basefilename; @@ -694,12 +702,12 @@ r = hashline_parse(BASENAME(i, c->ofs), fileline, cs, &basefilename, &hash, &size); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; f = c->files; - while( f != NULL && strcmp(BASENAME(i, f->ofs), basefilename) != 0 ) + while (f != NULL && strcmp(BASENAME(i, f->ofs), basefilename) != 0) f = f->next; - if( f == NULL ) { + if (f == NULL) { fprintf(stderr, "Warning: Ignoring file '%s' listed in '%s' but not in '%s' of '%s'!\n", basefilename, changes_checksum_names[cs], @@ -707,9 +715,9 @@ BASENAME(i, c->ofs)); continue; } - if( f->h.hashes[cs_length].len != size.len || + if (f->h.hashes[cs_length].len != size.len || memcmp(f->h.hashes[cs_length].start, - size.start, size.len) != 0 ) { + size.start, size.len) != 0) { fprintf(stderr, "Error: Different size of '%s' listed in '%s' and '%s' of '%s'!\n", basefilename, changes_checksum_names[cs], @@ -728,9 +736,9 @@ /* store collected hashes as checksums structs, * starting after .changes file: */ - for( f = c->files->next ; f != NULL ; f = f->next ) { + for (f = c->files->next ; f != NULL ; f = f->next) { r = checksums_initialize(&f->checksums, f->h.hashes); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -741,34 +749,36 @@ struct strlist filelines[cs_hashCOUNT]; enum checksumtype cs; int j; -#define R if( RET_WAS_ERROR(r) ) return r; -#define E(err,...) { \ - if( r == RET_NOTHING ) { \ - fprintf(stderr, "In '%s': " err "\n",BASENAME(i,c->ofs), ## __VA_ARGS__ ); \ +#define R if (RET_WAS_ERROR(r)) return r; +#define E(err, ...) { \ + if (r == RET_NOTHING) { \ + fprintf(stderr, "In '%s': " err "\n", \ + BASENAME(i, c->ofs), ## __VA_ARGS__); \ r = RET_ERROR; \ - } \ - if( RET_WAS_ERROR(r) ) return r; \ + } \ + if (RET_WAS_ERROR(r)) return r; \ } - r = chunk_getnameandversion(c->control, "Source", &c->source, &c->sourceversion); + r = chunk_getnameandversion(c->control, "Source", &c->source, + &c->sourceversion); E("Missing 'Source' field!"); r = propersourcename(c->source); E("Malforce Source name!"); - if( c->sourceversion != NULL ) { + if (c->sourceversion != NULL) { r = properversion(c->sourceversion); E("Malforce Source Version number!"); } - r = chunk_getwordlist(c->control,"Binary",&c->binaries); + r = chunk_getwordlist(c->control, "Binary", &c->binaries); E("Missing 'Binary' field!"); - r = chunk_getwordlist(c->control,"Architecture",&c->architectures); + r = chunk_getwordlist(c->control, "Architecture", &c->architectures); E("Missing 'Architecture' field!"); - r = chunk_getvalue(c->control,"Version",&c->changesversion); + r = chunk_getvalue(c->control, "Version", &c->changesversion); E("Missing 'Version' field!"); r = properversion(c->changesversion); E("Malforce Version number!"); // TODO: logic to detect binNMUs to warn against sources? - if( c->sourceversion == NULL ) { + if (c->sourceversion == NULL) { c->sourceversion = strdup(c->changesversion); - if( c->sourceversion == NULL ) + if (FAILEDTOALLOC(c->sourceversion)) return RET_ERROR_OOM; c->isbinNMU = false; } else { @@ -778,41 +788,41 @@ R; c->isbinNMU = cmp != 0; } - r = chunk_getwordlist(c->control,"Distribution",&c->distributions); + r = chunk_getwordlist(c->control, "Distribution", &c->distributions); E("Missing 'Distribution' field!"); r = chunk_getextralinelist(c->control, changes_checksum_names[cs_md5sum], &filelines[cs_md5sum]); E("Missing '%s' field!", changes_checksum_names[cs_md5sum]); - for( j = 0 ; j < filelines[cs_md5sum].count ; j++ ) { + for (j = 0 ; j < filelines[cs_md5sum].count ; j++) { r = candidate_addfileline(i, c, filelines[cs_md5sum].values[j]); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filelines[cs_md5sum]); return r; } } - for( cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++) { r = chunk_getextralinelist(c->control, changes_checksum_names[cs], &filelines[cs]); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = candidate_addhashes(i, c, cs, &filelines[cs]); else strlist_init(&filelines[cs]); - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) strlist_done(&filelines[cs]); return r; } } r = candidate_finalizechecksums(c); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) strlist_done(&filelines[cs]); R; - if( c->files == NULL || c->files->next == NULL ) { - fprintf(stderr,"In '%s': Empty 'Files' section!\n", - BASENAME(i,c->ofs)); + if (c->files == NULL || c->files->next == NULL) { + fprintf(stderr, "In '%s': Empty 'Files' section!\n", + BASENAME(i, c->ofs)); return RET_ERROR; } return RET_OK; @@ -825,50 +835,51 @@ // TODO: allow being more permissive, // that will need some more checks later, though r = propersourcename(c->source); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = properversion(c->sourceversion); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->type != fe_CHANGES && file->type != fe_BYHAND && + for (file = c->files ; file != NULL ; file = file->next) { + if (file->type != fe_CHANGES && file->type != fe_BYHAND && file->type != fe_LOG && - !atom_defined(file->architecture_atom) ) { + !atom_defined(file->architecture)) { fprintf(stderr, "'%s' contains '%s' not matching an valid architecture in any distribution known!\n", BASENAME(i, c->ofs), BASENAME(i, file->ofs)); return RET_ERROR; } - if( !FE_PACKAGE(file->type) ) + if (!FE_PACKAGE(file->type)) continue; - assert( atom_defined(file->architecture_atom) ); - if( strlist_in(&c->architectures, - atoms_architectures[file->architecture_atom]) ) + assert (atom_defined(file->architecture)); + if (strlist_in(&c->architectures, + atoms_architectures[file->architecture])) continue; - fprintf(stderr, "'%s' is not listed in the Architecture header of '%s' but file '%s' looks like it!\n", - atoms_architectures[file->architecture_atom], - BASENAME(i,c->ofs), BASENAME(i,file->ofs)); + fprintf(stderr, +"'%s' is not listed in the Architecture header of '%s' but file '%s' looks like it!\n", + atoms_architectures[file->architecture], + BASENAME(i, c->ofs), BASENAME(i, file->ofs)); return RET_ERROR; } return RET_OK; } /* Is used before any other candidate fields are set */ -static retvalue candidate_usefile(const struct incoming *i,const struct candidate *c,struct candidate_file *file) { +static retvalue candidate_usefile(const struct incoming *i, const struct candidate *c, struct candidate_file *file) { const char *basefilename; - char *origfile,*tempfilename; + char *origfile, *tempfilename; struct checksums *readchecksums; retvalue r; bool improves; const char *p; - if( file->used && file->tempfilename != NULL ) + if (file->used && file->tempfilename != NULL) return RET_OK; assert(file->tempfilename == NULL); basefilename = BASENAME(i, file->ofs); - for( p = basefilename; *p != '\0' ; p++ ) { - if( (0x80 & *(const unsigned char *)p) != 0 ) { + for (p = basefilename; *p != '\0' ; p++) { + if ((0x80 & *(const unsigned char *)p) != 0) { fprintf(stderr, "Invalid filename '%s' listed in '%s': contains 8-bit characters\n", basefilename, BASENAME(i, c->ofs)); @@ -876,26 +887,26 @@ } } tempfilename = calc_dirconcat(i->tempdir, basefilename); - if( tempfilename == NULL ) + if (FAILEDTOALLOC(tempfilename)) return RET_ERROR_OOM; origfile = calc_dirconcat(i->directory, basefilename); - if( origfile == NULL ) { + if (FAILEDTOALLOC(origfile)) { free(tempfilename); return RET_ERROR_OOM; } r = checksums_copyfile(tempfilename, origfile, true, &readchecksums); free(origfile); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(tempfilename); return r; } - if( file->checksums == NULL ) { + if (file->checksums == NULL) { file->checksums = readchecksums; file->tempfilename = tempfilename; file->used = true; return RET_OK; } - if( !checksums_check(file->checksums, readchecksums, &improves) ) { + if (!checksums_check(file->checksums, readchecksums, &improves)) { fprintf(stderr, "ERROR: File '%s' does not match expectations:\n", basefilename); @@ -906,9 +917,9 @@ free(tempfilename); return RET_ERROR_WRONG_MD5; } - if( improves ) { + if (improves) { r = checksums_combine(&file->checksums, readchecksums, NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(readchecksums); deletefile(tempfilename); free(tempfilename); @@ -927,32 +938,32 @@ component_t fc; section = override_get(oinfo, SECTION_FIELDNAME); - if( section == NULL ) { + if (section == NULL) { // TODO: warn about disparities here? section = file->section; } - if( section == NULL || strcmp(section,"-") == 0 ) { + if (section == NULL || strcmp(section, "-") == 0) { fprintf(stderr, "No section found for '%s' ('%s' in '%s')!\n", name, - BASENAME(i,file->ofs), BASENAME(i,c->ofs)); + BASENAME(i, file->ofs), BASENAME(i, c->ofs)); return RET_ERROR; } priority = override_get(oinfo, PRIORITY_FIELDNAME); - if( priority == NULL ) { + if (priority == NULL) { // TODO: warn about disparities here? priority = file->priority; } - if( priority == NULL || strcmp(priority,"-") == 0 ) { + if (priority == NULL || strcmp(priority, "-") == 0) { fprintf(stderr, "No priority found for '%s' ('%s' in '%s')!\n", name, - BASENAME(i,file->ofs), BASENAME(i,c->ofs)); + BASENAME(i, file->ofs), BASENAME(i, c->ofs)); return RET_ERROR; } forcecomponent = override_get(oinfo, "$Component"); - if( forcecomponent != NULL ) { + if (forcecomponent != NULL) { fc = component_find(forcecomponent); - if( !atom_defined(fc)) { + if (!atom_defined(fc)) { fprintf(stderr, "Unknown component '%s' (in $Component in override file for '%s'\n", forcecomponent, name); @@ -963,9 +974,9 @@ } else fc = atom_unknown; r = guess_component(into->codename, &into->components, - BASENAME(i,file->ofs), section, + BASENAME(i, file->ofs), section, fc, component); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } *section_p = section; @@ -973,57 +984,62 @@ return RET_OK; } -static retvalue candidate_read_deb(struct incoming *i,struct candidate *c,struct candidate_file *file) { +static retvalue candidate_read_deb(struct incoming *i, struct candidate *c, struct candidate_file *file) { retvalue r; r = binaries_readdeb(&file->deb, file->tempfilename, true); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( strcmp(file->name, file->deb.name) != 0 ) { + if (strcmp(file->name, file->deb.name) != 0) { // TODO: add permissive thing to ignore this - fprintf(stderr, "Name part of filename ('%s') and name within the file ('%s') do not match for '%s' in '%s'!\n", + fprintf(stderr, +"Name part of filename ('%s') and name within the file ('%s') do not match for '%s' in '%s'!\n", file->name, file->deb.name, - BASENAME(i,file->ofs), BASENAME(i,c->ofs)); + BASENAME(i, file->ofs), BASENAME(i, c->ofs)); return RET_ERROR; } - if( file->architecture_atom != file->deb.architecture_atom ) { + if (file->architecture != file->deb.architecture) { // TODO: add permissive thing to ignore this in some cases // but do not forget to look into into->architectures then - fprintf(stderr, "Architecture '%s' of '%s' does not match '%s' specified in '%s'!\n", - atoms_architectures[file->deb.architecture_atom], - BASENAME(i,file->ofs), - atoms_architectures[file->architecture_atom], - BASENAME(i,c->ofs)); + fprintf(stderr, +"Architecture '%s' of '%s' does not match '%s' specified in '%s'!\n", + atoms_architectures[file->deb.architecture], + BASENAME(i, file->ofs), + atoms_architectures[file->architecture], + BASENAME(i, c->ofs)); return RET_ERROR; } - if( strcmp(c->source, file->deb.source) != 0 ) { + if (strcmp(c->source, file->deb.source) != 0) { // TODO: add permissive thing to ignore this // (beware if tracking is active) - fprintf(stderr, "Source header '%s' of '%s' and source name '%s' within the file '%s' do not match!\n", - c->source, BASENAME(i,c->ofs), - file->deb.source, BASENAME(i,file->ofs)); + fprintf(stderr, +"Source header '%s' of '%s' and source name '%s' within the file '%s' do not match!\n", + c->source, BASENAME(i, c->ofs), + file->deb.source, BASENAME(i, file->ofs)); return RET_ERROR; } - if( strcmp(c->sourceversion, file->deb.sourceversion) != 0 ) { + if (strcmp(c->sourceversion, file->deb.sourceversion) != 0) { // TODO: add permissive thing to ignore this // (beware if tracking is active) - fprintf(stderr, "Source version '%s' of '%s' and source version '%s' within the file '%s' do not match!\n", - c->sourceversion, BASENAME(i,c->ofs), - file->deb.sourceversion, BASENAME(i,file->ofs)); + fprintf(stderr, +"Source version '%s' of '%s' and source version '%s' within the file '%s' do not match!\n", + c->sourceversion, BASENAME(i, c->ofs), + file->deb.sourceversion, BASENAME(i, file->ofs)); return RET_ERROR; } - if( ! strlist_in(&c->binaries, file->deb.name) ) { - fprintf(stderr, "Name '%s' of binary '%s' is not listed in Binaries header of '%s'!\n", - file->deb.name, BASENAME(i,file->ofs), - BASENAME(i,c->ofs)); + if (! strlist_in(&c->binaries, file->deb.name)) { + fprintf(stderr, +"Name '%s' of binary '%s' is not listed in Binaries header of '%s'!\n", + file->deb.name, BASENAME(i, file->ofs), + BASENAME(i, c->ofs)); return RET_ERROR; } r = properpackagename(file->deb.name); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = propersourcename(file->deb.source); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properversion(file->deb.version); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } @@ -1035,14 +1051,14 @@ r = sources_readdsc(&file->dsc, file->tempfilename, BASENAME(i, file->ofs), &broken); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; p = calc_source_basename(file->dsc.name, file->dsc.version); - if( p == NULL ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; r = checksumsarray_include(&file->dsc.files, p, file->checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } // TODO: take a look at "broken"... @@ -1053,97 +1069,99 @@ struct candidate_file *file; retvalue r; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; file = file->next) { - if( !FE_PACKAGE(file->type) ) + if (!FE_PACKAGE(file->type)) continue; r = candidate_usefile(i, c, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; assert(file->tempfilename != NULL); - if( FE_BINARY(file->type) ) + if (FE_BINARY(file->type)) r = candidate_read_deb(i, c, file); - else if( file->type == fe_DSC ) + else if (file->type == fe_DSC) r = candidate_read_dsc(i, file); else { r = RET_ERROR; - assert( FE_BINARY(file->type) || file->type == fe_DSC ); + assert (FE_BINARY(file->type) || file->type == fe_DSC); } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; } -static retvalue candidate_preparechangesfile(struct database *database,const struct candidate *c,struct candidate_perdistribution *per) { +static retvalue candidate_preparechangesfile(const struct candidate *c, struct candidate_perdistribution *per) { retvalue r; char *basefilename, *filekey; struct candidate_package *package; struct candidate_file *file; component_t component = component_strange; - assert( c->files != NULL && c->files->ofs == c->ofs ); + assert (c->files != NULL && c->files->ofs == c->ofs); /* search for a component to use */ - for( package = per->packages ; package != NULL ; package = package->next ) { - if( atom_defined(package->component_atom) ) { - component = package->component_atom; + for (package = per->packages ; package != NULL ; + package = package->next) { + if (atom_defined(package->component)) { + component = package->component; break; } } file = changesfile(c); /* make sure the file is already copied */ - assert( file->used ); - assert( file->checksums != NULL ); + assert (file->used); + assert (file->checksums != NULL); /* pseudo package containing the .changes file */ package = candidate_newpackage(per, c->files); - if( package == NULL ) + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; basefilename = calc_changes_basename(c->source, c->changesversion, &c->architectures); - if( basefilename == NULL ) + if (FAILEDTOALLOC(basefilename)) return RET_ERROR_OOM; filekey = calc_filekey(component, c->source, basefilename); free(basefilename); - if( filekey == NULL ) + if (FAILEDTOALLOC(filekey)) return RET_ERROR_OOM; r = strlist_init_singleton(filekey, &package->filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( package->filekeys.count == 1 ); + assert (package->filekeys.count == 1); filekey = package->filekeys.values[0]; - package->files = calloc(1, sizeof(struct candidate_file *)); - if( package->files == NULL ) + package->files = zNEW(const struct candidate_file *); + if (FAILEDTOALLOC(package->files)) return RET_ERROR_OOM; - r = files_canadd(database, filekey, file->checksums); - if( RET_WAS_ERROR(r) ) + r = files_canadd(filekey, file->checksums); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) package->files[0] = file; return RET_OK; } -static retvalue prepare_deb(struct database *database,const struct incoming *i,const struct candidate *c,struct candidate_perdistribution *per,const struct candidate_file *file) { - const char *section IFSTUPIDCC(=NULL), *priority IFSTUPIDCC(=NULL), *filekey; +static retvalue prepare_deb(const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per, const struct candidate_file *file) { + const char *section IFSTUPIDCC(=NULL), *priority IFSTUPIDCC(=NULL); + const char *filekey; const struct overridedata *oinfo; struct candidate_package *package; const struct distribution *into = per->into; retvalue r; - assert( FE_BINARY(file->type) ); - assert( file->tempfilename != NULL ); - assert( file->deb.name != NULL ); + assert (FE_BINARY(file->type)); + assert (file->tempfilename != NULL); + assert (file->deb.name != NULL); package = candidate_newpackage(per, file); - if( package == NULL ) + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; - assert( file == package->master ); - if( file->type == fe_DEB ) + assert (file == package->master); + if (file->type == fe_DEB) package->packagetype = pt_deb; else package->packagetype = pt_udeb; @@ -1152,69 +1170,71 @@ into->overrides.deb, file->name); - r = getsectionprioritycomponent(i,c,into,file, + r = getsectionprioritycomponent(i, c, into, file, file->name, oinfo, - §ion, &priority, &package->component_atom); - if( RET_WAS_ERROR(r) ) + §ion, &priority, &package->component); + if (RET_WAS_ERROR(r)) return r; - if( file->type == fe_UDEB && - !atomlist_in(&into->udebcomponents, package->component_atom)) { + if (file->type == fe_UDEB && + !atomlist_in(&into->udebcomponents, package->component)) { fprintf(stderr, "Cannot put file '%s' of '%s' into component '%s',\n" "as it is not listed in UDebComponents of '%s'!\n", - BASENAME(i,file->ofs), BASENAME(i,c->ofs), - atoms_components[package->component_atom], into->codename); + BASENAME(i, file->ofs), BASENAME(i, c->ofs), + atoms_components[package->component], + into->codename); return RET_ERROR; } - r = binaries_calcfilekeys(package->component_atom, &file->deb, + r = binaries_calcfilekeys(package->component, &file->deb, package->packagetype, &package->filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( package->filekeys.count == 1 ); + assert (package->filekeys.count == 1); filekey = package->filekeys.values[0]; - package->files = calloc(1, sizeof(struct candidate_file *)); - if( package->files == NULL ) + package->files = zNEW(const struct candidate_file *); + if (FAILEDTOALLOC(package->files)) return RET_ERROR_OOM; - r = files_canadd(database, filekey, file->checksums); - if( RET_WAS_ERROR(r) ) + r = files_canadd(filekey, file->checksums); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) package->files[0] = file; r = binaries_complete(&file->deb, filekey, file->checksums, oinfo, section, priority, &package->control); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } -static retvalue prepare_source_file(struct database *database, const struct incoming *i, const struct candidate *c, const char *filekey, const char *basefilename, struct checksums **checksums_p, int package_ofs, /*@out@*/const struct candidate_file **foundfile_p){ +static retvalue prepare_source_file(const struct incoming *i, const struct candidate *c, const char *filekey, const char *basefilename, struct checksums **checksums_p, int package_ofs, /*@out@*/const struct candidate_file **foundfile_p){ struct candidate_file *f; const struct checksums * const checksums = *checksums_p; retvalue r; bool improves; f = c->files; - while( f != NULL && (f->checksums == NULL || - strcmp(BASENAME(i, f->ofs), basefilename) != 0) ) + while (f != NULL && (f->checksums == NULL || + strcmp(BASENAME(i, f->ofs), basefilename) != 0)) f = f->next; - if( f == NULL ) { - r = files_canadd(database, filekey, checksums); - if( !RET_IS_OK(r) ) + if (f == NULL) { + r = files_canadd(filekey, checksums); + if (!RET_IS_OK(r)) return r; /* no file by this name and also no file with these * characteristics in the pool, look for differently-named * file with the same characteristics: */ f = c->files; - while( f != NULL && ( f->checksums == NULL || + while (f != NULL && (f->checksums == NULL || !checksums_check(f->checksums, checksums, NULL))) f = f->next; - if( f == NULL ) { - fprintf(stderr, "file '%s' is needed for '%s', not yet registered in the pool and not found in '%s'\n", + if (f == NULL) { + fprintf(stderr, +"file '%s' is needed for '%s', not yet registered in the pool and not found in '%s'\n", basefilename, BASENAME(i, package_ofs), BASENAME(i, c->ofs)); return RET_ERROR; @@ -1222,46 +1242,47 @@ /* otherwise proceed with the found file: */ } - if( !checksums_check(f->checksums, checksums, &improves) ) { - fprintf(stderr, "file '%s' has conflicting checksums listed in '%s' and '%s'!\n", + if (!checksums_check(f->checksums, checksums, &improves)) { + fprintf(stderr, +"file '%s' has conflicting checksums listed in '%s' and '%s'!\n", basefilename, BASENAME(i, c->ofs), BASENAME(i, package_ofs)); return RET_ERROR; } - if( improves ) { + if (improves) { /* put additional checksums from the .dsc to the information * found in .changes, so that a file matching those in .changes * but not in .dsc is detected */ r = checksums_combine(&f->checksums, checksums, NULL); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; } - r = files_canadd(database, filekey, f->checksums); - if( r == RET_NOTHING ) { + r = files_canadd(filekey, f->checksums); + if (r == RET_NOTHING) { /* already in the pool, mark as used (in the sense * of "only not needed because it is already there") */ f->used = true; - } else if( RET_IS_OK(r) ) { + } else if (RET_IS_OK(r)) { /* don't have this file in the pool, make sure it is ready * here */ r = candidate_usefile(i, c, f); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // TODO: update checksums to now received checksums? *foundfile_p = f; } - if( !RET_WAS_ERROR(r) && !checksums_iscomplete(checksums) ) { + if (!RET_WAS_ERROR(r) && !checksums_iscomplete(checksums)) { /* update checksums so the source index can show them */ r = checksums_combine(checksums_p, f->checksums, NULL); } return r; } -static retvalue prepare_dsc(struct database *database,const struct incoming *i,const struct candidate *c,struct candidate_perdistribution *per,const struct candidate_file *file) { +static retvalue prepare_dsc(const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per, const struct candidate_file *file) { const char *section IFSTUPIDCC(=NULL), *priority IFSTUPIDCC(=NULL); const struct overridedata *oinfo; struct candidate_package *package; @@ -1269,92 +1290,101 @@ retvalue r; int j; - assert( file->type == fe_DSC ); - assert( file->tempfilename != NULL ); - assert( file->dsc.name != NULL ); + assert (file->type == fe_DSC); + assert (file->tempfilename != NULL); + assert (file->dsc.name != NULL); package = candidate_newpackage(per, file); - if( package == NULL ) + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; - assert( file == package->master ); + assert (file == package->master); package->packagetype = pt_dsc; - if( c->isbinNMU ) { + if (c->isbinNMU) { // TODO: add permissive thing to ignore this - fprintf(stderr, "Source package ('%s') in '%s', which look like a binNMU (as '%s' and '%s' differ)!\n", - BASENAME(i,file->ofs), BASENAME(i,c->ofs), + fprintf(stderr, +"Source package ('%s') in '%s', which look like a binNMU (as '%s' and '%s' differ)!\n", + BASENAME(i, file->ofs), BASENAME(i, c->ofs), c->sourceversion, c->changesversion); return RET_ERROR; } - if( strcmp(file->name, file->dsc.name) != 0 ) { + if (strcmp(file->name, file->dsc.name) != 0) { // TODO: add permissive thing to ignore this - fprintf(stderr, "Name part of filename ('%s') and name within the file ('%s') do not match for '%s' in '%s'!\n", + fprintf(stderr, +"Name part of filename ('%s') and name within the file ('%s') do not match for '%s' in '%s'!\n", file->name, file->dsc.name, - BASENAME(i,file->ofs), BASENAME(i,c->ofs)); + BASENAME(i, file->ofs), BASENAME(i, c->ofs)); return RET_ERROR; } - if( strcmp(c->source, file->dsc.name) != 0 ) { + if (strcmp(c->source, file->dsc.name) != 0) { // TODO: add permissive thing to ignore this // (beware if tracking is active) - fprintf(stderr, "Source header '%s' of '%s' and name '%s' within the file '%s' do not match!\n", - c->source, BASENAME(i,c->ofs), - file->dsc.name, BASENAME(i,file->ofs)); + fprintf(stderr, +"Source header '%s' of '%s' and name '%s' within the file '%s' do not match!\n", + c->source, BASENAME(i, c->ofs), + file->dsc.name, BASENAME(i, file->ofs)); return RET_ERROR; } - if( strcmp(c->sourceversion, file->dsc.version) != 0 ) { + if (strcmp(c->sourceversion, file->dsc.version) != 0) { // TODO: add permissive thing to ignore this // (beware if tracking is active) - fprintf(stderr, "Source version '%s' of '%s' and version '%s' within the file '%s' do not match!\n", - c->sourceversion, BASENAME(i,c->ofs), - file->dsc.version, BASENAME(i,file->ofs)); + fprintf(stderr, +"Source version '%s' of '%s' and version '%s' within the file '%s' do not match!\n", + c->sourceversion, BASENAME(i, c->ofs), + file->dsc.version, BASENAME(i, file->ofs)); return RET_ERROR; } r = propersourcename(file->dsc.name); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properversion(file->dsc.version); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = properfilenames(&file->dsc.files.names); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; oinfo = override_search(into->overrides.dsc, file->dsc.name); r = getsectionprioritycomponent(i, c, into, file, file->dsc.name, oinfo, - §ion, &priority, &package->component_atom); - if( RET_WAS_ERROR(r) ) + §ion, &priority, &package->component); + if (RET_WAS_ERROR(r)) return r; - package->directory = calc_sourcedir(package->component_atom, file->dsc.name); - if( package->directory == NULL ) - return RET_ERROR_OOM; - r = calc_dirconcats(package->directory, &file->dsc.files.names, &package->filekeys); - if( RET_WAS_ERROR(r) ) - return r; - package->files = calloc(package->filekeys.count,sizeof(struct candidate *)); - if( package->files == NULL ) - return RET_ERROR_OOM; - r = files_canadd(database, package->filekeys.values[0], file->checksums); - if( RET_IS_OK(r) ) + package->directory = calc_sourcedir(package->component, + file->dsc.name); + if (FAILEDTOALLOC(package->directory)) + return RET_ERROR_OOM; + r = calc_dirconcats(package->directory, &file->dsc.files.names, + &package->filekeys); + if (RET_WAS_ERROR(r)) + return r; + package->files = nzNEW(package->filekeys.count, + const struct candidate_file *); + if (FAILEDTOALLOC(package->files)) + return RET_ERROR_OOM; + r = files_canadd(package->filekeys.values[0], + file->checksums); + if (RET_IS_OK(r)) package->files[0] = file; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( j = 1 ; j < package->filekeys.count ; j++ ) { - r = prepare_source_file(database, i, c, + for (j = 1 ; j < package->filekeys.count ; j++) { + r = prepare_source_file(i, c, package->filekeys.values[j], file->dsc.files.names.values[j], &file->dsc.files.checksums[j], file->ofs, &package->files[j]); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - r = sources_complete(&file->dsc, package->directory, oinfo, section, priority, &package->control); - if( RET_WAS_ERROR(r) ) + r = sources_complete(&file->dsc, package->directory, oinfo, + section, priority, &package->control); + if (RET_WAS_ERROR(r)) return r; return RET_OK; } -static retvalue candidate_preparetrackbyhands(struct database *database, const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per) { +static retvalue candidate_preparetrackbyhands(const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per) { retvalue r; char *byhanddir; struct candidate_package *package; @@ -1362,133 +1392,135 @@ component_t component = component_strange; int count = 0; - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->type == fe_BYHAND ) { + for (file = c->files ; file != NULL ; file = file->next) { + if (file->type == fe_BYHAND) { count++; - if( firstbyhand == NULL ) + if (firstbyhand == NULL) firstbyhand = file; } } - if( count == 0 ) + if (count == 0) return RET_NOTHING; /* search for a component to use */ - for( package = per->packages ; package != NULL ; package = package->next ) { - if( atom_defined(package->component_atom) ) { - component = package->component_atom; + for (package = per->packages ; package != NULL ; + package = package->next) { + if (atom_defined(package->component)) { + component = package->component; break; } } /* pseudo package containing byhand files */ package = candidate_newpackage(per, firstbyhand); - if( FAILEDTOALLOC(package) ) + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; r = strlist_init_n(count, &package->filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - package->files = calloc(count, sizeof(struct candidate_file *)); - if( FAILEDTOALLOC(package->files) ) + package->files = nzNEW(count, const struct candidate_file *); + if (FAILEDTOALLOC(package->files)) return RET_ERROR_OOM; byhanddir = calc_byhanddir(component, c->source, c->changesversion); - if( FAILEDTOALLOC(byhanddir) ) + if (FAILEDTOALLOC(byhanddir)) return RET_ERROR_OOM; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; file = file->next) { char *filekey; - if( file->type != fe_BYHAND ) + if (file->type != fe_BYHAND) continue; r = candidate_usefile(i, c, file); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(byhanddir); return r; } - filekey = calc_dirconcat(byhanddir, BASENAME(i,file->ofs)); - if( FAILEDTOALLOC(filekey) ) { + filekey = calc_dirconcat(byhanddir, BASENAME(i, file->ofs)); + if (FAILEDTOALLOC(filekey)) { free(byhanddir); return RET_ERROR_OOM; } - r = files_canadd(database, filekey, file->checksums); - if( RET_WAS_ERROR(r) ) { + r = files_canadd(filekey, file->checksums); + if (RET_WAS_ERROR(r)) { free(byhanddir); return r; } - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) package->files[package->filekeys.count] = file; r = strlist_add(&package->filekeys, filekey); - assert( r == RET_OK ); + assert (r == RET_OK); } free(byhanddir); - assert( package->filekeys.count == count ); + assert (package->filekeys.count == count); return RET_OK; } -static retvalue candidate_preparelogs(struct database *database, const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per) { +static retvalue candidate_preparelogs(const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *per) { retvalue r; struct candidate_package *package; struct candidate_file *firstlog = NULL, *file; component_t component = component_strange; int count = 0; - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->type == fe_LOG ) { + for (file = c->files ; file != NULL ; file = file->next) { + if (file->type == fe_LOG) { count++; - if( firstlog == NULL ) + if (firstlog == NULL) firstlog = file; } } - if( count == 0 ) + if (count == 0) return RET_NOTHING; /* search for a component to use */ - for( package = per->packages ; package != NULL ; package = package->next ) { - if( atom_defined(package->component_atom) ) { - component = package->component_atom; + for (package = per->packages ; package != NULL ; + package = package->next) { + if (atom_defined(package->component)) { + component = package->component; break; } } /* pseudo package containing log files */ package = candidate_newpackage(per, firstlog); - if( FAILEDTOALLOC(package) ) + if (FAILEDTOALLOC(package)) return RET_ERROR_OOM; r = strlist_init_n(count, &package->filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - package->files = calloc(count, sizeof(struct candidate_file *)); - if( FAILEDTOALLOC(package->files) ) + package->files = nzNEW(count, const struct candidate_file *); + if (FAILEDTOALLOC(package->files)) return RET_ERROR_OOM; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; file = file->next) { char *filekey; - if( file->type != fe_LOG ) + if (file->type != fe_LOG) continue; r = candidate_usefile(i, c, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; // TODO: add same checks on the basename contents? - filekey = calc_filekey(component, c->source, BASENAME(i,file->ofs)); - if( FAILEDTOALLOC(filekey) ) + filekey = calc_filekey(component, c->source, BASENAME(i, file->ofs)); + if (FAILEDTOALLOC(filekey)) return RET_ERROR_OOM; - r = files_canadd(database, filekey, file->checksums); - if( RET_WAS_ERROR(r) ) + r = files_canadd(filekey, file->checksums); + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) package->files[package->filekeys.count] = file; r = strlist_add(&package->filekeys, filekey); - assert( r == RET_OK ); + assert (r == RET_OK); } - assert( package->filekeys.count == count ); + assert (package->filekeys.count == count); return RET_OK; } @@ -1500,17 +1532,17 @@ retvalue r; b_p = &per->byhandhookstocall; - while( *b_p != NULL ) + while (*b_p != NULL) b_p = &(*b_p)->next; - while( byhandhooks_matched(d->byhandhooks, &h, + while (byhandhooks_matched(d->byhandhooks, &h, file->section, file->priority, - BASENAME(i, file->ofs)) ) { + BASENAME(i, file->ofs))) { r = candidate_usefile(i, c, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - b = calloc(1, sizeof(struct byhandfile)); - if( FAILEDTOALLOC(b) ) + b = zNEW(struct byhandfile); + if (FAILEDTOALLOC(b)) return RET_ERROR_OOM; b->file = file; b->hook = h; @@ -1521,20 +1553,20 @@ return result; } -static retvalue prepare_for_distribution(struct database *database,const struct incoming *i,const struct candidate *c,struct candidate_perdistribution *d) { +static retvalue prepare_for_distribution(const struct incoming *i, const struct candidate *c, struct candidate_perdistribution *d) { struct candidate_file *file; retvalue r; d->into->lookedat = true; - for( file = c->files ; file != NULL ; file = file->next ) { - switch( file->type ) { + for (file = c->files ; file != NULL ; file = file->next) { + switch (file->type) { case fe_UDEB: case fe_DEB: - r = prepare_deb(database, i, c, d, file); + r = prepare_deb(i, c, d, file); break; case fe_DSC: - r = prepare_dsc(database, i, c, d, file); + r = prepare_dsc(i, c, d, file); break; case fe_BYHAND: r = prepare_hookedbyhand(i, c, d, file); @@ -1543,24 +1575,24 @@ r = RET_NOTHING; break; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } } - if( d->into->tracking != dt_NONE ) { - if( d->into->trackingoptions.includebyhand ) { - r = candidate_preparetrackbyhands(database, i, c, d); - if( RET_WAS_ERROR(r) ) + if (d->into->tracking != dt_NONE) { + if (d->into->trackingoptions.includebyhand) { + r = candidate_preparetrackbyhands(i, c, d); + if (RET_WAS_ERROR(r)) return r; } - if( d->into->trackingoptions.includelogs ) { - r = candidate_preparelogs(database, i, c, d); - if( RET_WAS_ERROR(r) ) + if (d->into->trackingoptions.includelogs) { + r = candidate_preparelogs(i, c, d); + if (RET_WAS_ERROR(r)) return r; } - if( d->into->trackingoptions.includechanges ) { - r = candidate_preparechangesfile(database, c, d); - if( RET_WAS_ERROR(r) ) + if (d->into->trackingoptions.includechanges) { + r = candidate_preparechangesfile(c, d); + if (RET_WAS_ERROR(r)) return r; } } @@ -1568,26 +1600,25 @@ return RET_OK; } -static retvalue candidate_addfiles(struct database *database,struct candidate *c) { +static retvalue candidate_addfiles(struct candidate *c) { int j; struct candidate_perdistribution *d; struct candidate_package *p; retvalue r; - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - for( p = d->packages ; p != NULL ; p = p->next ) { - if( p->skip ) + for (d = c->perdistribution ; d != NULL ; d = d->next) { + for (p = d->packages ; p != NULL ; p = p->next) { + if (p->skip) continue; - for( j = 0 ; j < p->filekeys.count ; j++ ) { + for (j = 0 ; j < p->filekeys.count ; j++) { const struct candidate_file *f = p->files[j]; - if( f == NULL ) + if (f == NULL) continue; assert(f->tempfilename != NULL); - r = files_hardlinkandadd(database, - f->tempfilename, + r = files_hardlinkandadd(f->tempfilename, p->filekeys.values[j], f->checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } @@ -1595,21 +1626,21 @@ return RET_OK; } -static retvalue add_dsc(struct database *database, struct distribution *into, struct trackingdata *trackingdata, struct candidate_package *p) { +static retvalue add_dsc(struct distribution *into, struct trackingdata *trackingdata, struct candidate_package *p) { retvalue r; struct target *t = distribution_getpart(into, - p->component_atom, architecture_source, pt_dsc); + p->component, architecture_source, pt_dsc); - assert( logger_isprepared(into->logger) ); + assert (logger_isprepared(into->logger)); /* finally put it into the source distribution */ - r = target_initpackagesdb(t, database, READWRITE); - if( !RET_WAS_ERROR(r) ) { + r = target_initpackagesdb(t, READWRITE); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else - r = target_addpackage(t, into->logger, database, + r = target_addpackage(t, into->logger, p->master->dsc.name, p->master->dsc.version, p->control, @@ -1618,38 +1649,39 @@ architecture_source, NULL, NULL); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } RET_UPDATE(into->status, r); return r; } -static retvalue checkadd_dsc(struct database *database, +static retvalue checkadd_dsc( struct distribution *into, const struct incoming *i, bool tracking, struct candidate_package *p) { retvalue r; struct target *t = distribution_getpart(into, - p->component_atom, architecture_source, pt_dsc); + p->component, architecture_source, pt_dsc); /* check for possible errors putting it into the source distribution */ - r = target_initpackagesdb(t, database, READONLY); - if( !RET_WAS_ERROR(r) ) { + r = target_initpackagesdb(t, READONLY); + if (!RET_WAS_ERROR(r)) { retvalue r2; - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_checkaddpackage(t, p->master->dsc.name, p->master->dsc.version, - tracking, i->permit[pmf_oldpackagenewer]); + tracking, + i->permit[pmf_oldpackagenewer]); r2 = target_closepackagesdb(t); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } return r; } -static retvalue candidate_add_into(struct database *database, const struct incoming *i, const struct candidate *c, const struct candidate_perdistribution *d, const char **changesfilekey_p) { +static retvalue candidate_add_into(const struct incoming *i, const struct candidate *c, const struct candidate_perdistribution *d, const char **changesfilekey_p) { retvalue r; struct candidate_package *p; struct trackingdata trackingdata; @@ -1657,147 +1689,144 @@ trackingdb tracks; struct atomlist binary_architectures; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; into->lookedat = true; - if( into->logger != NULL ) { + if (into->logger != NULL) { r = logger_prepare(d->into->logger); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } tracks = NULL; - if( into->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, into, false); - if( RET_WAS_ERROR(r) ) + if (into->tracking != dt_NONE) { + r = tracking_initialize(&tracks, into, false); + if (RET_WAS_ERROR(r)) return r; } - if( tracks != NULL ) { + if (tracks != NULL) { r = trackingdata_summon(tracks, c->source, c->sourceversion, &trackingdata); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)tracking_done(tracks); return r; } - if( into->trackingoptions.needsources ) { + if (into->trackingoptions.needsources) { // TODO, but better before we start adding... } } atomlist_init(&binary_architectures); - for( p = d->packages ; p != NULL ; p = p->next ) { - if( FE_BINARY(p->master->type) ) { - architecture_t a = p->master->architecture_atom; + for (p = d->packages ; p != NULL ; p = p->next) { + if (FE_BINARY(p->master->type)) { + architecture_t a = p->master->architecture; - if( a != architecture_all ) + if (a != architecture_all) atomlist_add_uniq(&binary_architectures, a); } } r = RET_OK; - for( p = d->packages ; p != NULL ; p = p->next ) { - if( p->skip ) { - if( verbose >= 0 ) + for (p = d->packages ; p != NULL ; p = p->next) { + if (p->skip) { + if (verbose >= 0) printf( "Not putting '%s' in '%s' as already in there with equal or newer version.\n", - BASENAME(i,p->master->ofs), + BASENAME(i, p->master->ofs), into->codename); continue; } - if( p->master->type == fe_DSC ) { - r = add_dsc(database, into, - (tracks==NULL)?NULL:&trackingdata, + if (p->master->type == fe_DSC) { + r = add_dsc(into, (tracks==NULL)?NULL:&trackingdata, p); - } else if( FE_BINARY(p->master->type) ) { - architecture_t a = p->master->architecture_atom; + } else if (FE_BINARY(p->master->type)) { + architecture_t a = p->master->architecture; const struct atomlist *as, architectures = {&a, 1, 1}; - if( i->options[iof_limit_arch_all] && + if (i->options[iof_limit_arch_all] && a == architecture_all && - binary_architectures.count > 0 ) + binary_architectures.count > 0) as = &binary_architectures; else as = &architectures; - r = binaries_adddeb(&p->master->deb, database, + r = binaries_adddeb(&p->master->deb, as, p->packagetype, into, (tracks==NULL)?NULL:&trackingdata, - p->component_atom, &p->filekeys, + p->component, &p->filekeys, p->control); - } else if( p->master->type == fe_CHANGES ) { + } else if (p->master->type == fe_CHANGES) { /* finally add the .changes to tracking, if requested */ - assert( p->master->name == NULL ); - assert( tracks != NULL ); + assert (p->master->name == NULL); + assert (tracks != NULL); r = trackedpackage_adddupfilekeys(trackingdata.tracks, trackingdata.pkg, - ft_CHANGES, &p->filekeys, false, database); - if( p->filekeys.count > 0 ) + ft_CHANGES, &p->filekeys, false); + if (p->filekeys.count > 0) *changesfilekey_p = p->filekeys.values[0]; - } else if( p->master->type == fe_BYHAND ) { - assert( tracks != NULL ); + } else if (p->master->type == fe_BYHAND) { + assert (tracks != NULL); r = trackedpackage_adddupfilekeys(trackingdata.tracks, trackingdata.pkg, - ft_XTRA_DATA, &p->filekeys, false, - database); - } else if( p->master->type == fe_LOG ) { - assert( tracks != NULL ); + ft_XTRA_DATA, &p->filekeys, false); + } else if (p->master->type == fe_LOG) { + assert (tracks != NULL); r = trackedpackage_adddupfilekeys(trackingdata.tracks, trackingdata.pkg, - ft_LOG, &p->filekeys, false, database); + ft_LOG, &p->filekeys, false); } else r = RET_ERROR_INTERNAL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } atomlist_done(&binary_architectures); - if( tracks != NULL ) { + if (tracks != NULL) { retvalue r2; - r2 = trackingdata_finish(tracks, &trackingdata, database); - RET_UPDATE(r,r2); + r2 = trackingdata_finish(tracks, &trackingdata); + RET_UPDATE(r, r2); r2 = tracking_done(tracks); - RET_ENDUPDATE(r,r2); + RET_ENDUPDATE(r, r2); } return r; } -static inline retvalue candidate_checkadd_into(struct database *database,const struct incoming *i,const struct candidate_perdistribution *d) { +static inline retvalue candidate_checkadd_into(const struct incoming *i, const struct candidate_perdistribution *d) { retvalue r; struct candidate_package *p; struct distribution *into = d->into; bool somethingtodo = false; - for( p = d->packages ; p != NULL ; p = p->next ) { - if( p->master->type == fe_DSC ) { - r = checkadd_dsc(database, into, - i, into->tracking != dt_NONE, + for (p = d->packages ; p != NULL ; p = p->next) { + if (p->master->type == fe_DSC) { + r = checkadd_dsc(into, i, into->tracking != dt_NONE, p); - } else if( FE_BINARY(p->master->type) ) { - r = binaries_checkadddeb(&p->master->deb, database, - p->master->architecture_atom, + } else if (FE_BINARY(p->master->type)) { + r = binaries_checkadddeb(&p->master->deb, + p->master->architecture, p->packagetype, into, into->tracking != dt_NONE, - p->component_atom, + p->component, i->permit[pmf_oldpackagenewer]); - } else if( p->master->type == fe_CHANGES + } else if (p->master->type == fe_CHANGES || p->master->type == fe_BYHAND - || p->master->type == fe_LOG ) { + || p->master->type == fe_LOG) { continue; } else r = RET_ERROR_INTERNAL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) p->skip = true; else somethingtodo = true; } - if( somethingtodo ) + if (somethingtodo) return RET_OK; else return RET_NOTHING; @@ -1806,7 +1835,7 @@ static inline bool isallowed(UNUSED(struct incoming *i), struct candidate *c, struct distribution *into, struct upload_conditions *conditions) { const struct candidate_file *file; - do switch( uploaders_nextcondition(conditions) ) { + do switch (uploaders_nextcondition(conditions)) { case uc_ACCEPTED: return true; case uc_REJECTED: @@ -1815,51 +1844,51 @@ (void)uploaders_verifystring(conditions, into->codename); break; case uc_SOURCENAME: - assert( c->source != NULL ); + assert (c->source != NULL); (void)uploaders_verifystring(conditions, c->source); break; case uc_SECTIONS: - for( file = c->files ; file != NULL ; - file = file->next ) { - if( !FE_PACKAGE(file->type) ) + for (file = c->files ; file != NULL ; + file = file->next) { + if (!FE_PACKAGE(file->type)) continue; - if( !uploaders_verifystring(conditions, + if (!uploaders_verifystring(conditions, (file->section == NULL) - ?"-":file->section) ) + ?"-":file->section)) break; } break; case uc_BINARIES: - for( file = c->files ; file != NULL ; - file = file->next ) { - if( !FE_BINARY(file->type) ) + for (file = c->files ; file != NULL ; + file = file->next) { + if (!FE_BINARY(file->type)) continue; - if( !uploaders_verifystring(conditions, - file->name) ) + if (!uploaders_verifystring(conditions, + file->name)) break; } break; case uc_ARCHITECTURES: - for( file = c->files ; file != NULL ; - file = file->next ) { - if( !FE_PACKAGE(file->type) ) + for (file = c->files ; file != NULL ; + file = file->next) { + if (!FE_PACKAGE(file->type)) continue; - if( !uploaders_verifyatom(conditions, - file->architecture_atom) ) + if (!uploaders_verifyatom(conditions, + file->architecture)) break; } break; case uc_BYHAND: - for( file = c->files ; file != NULL ; - file = file->next ) { - if( file->type != fe_BYHAND ) + for (file = c->files ; file != NULL ; + file = file->next) { + if (file->type != fe_BYHAND) continue; - if( !uploaders_verifystring(conditions, - file->section) ) + if (!uploaders_verifystring(conditions, + file->section)) break; } break; - } while( true ); + } while (true); } static retvalue candidate_checkpermissions(struct incoming *i, struct candidate *c, struct distribution *into) { @@ -1868,21 +1897,22 @@ bool allowed; /* no rules means allowed */ - if( into->uploaders == NULL ) + if (into->uploaders == NULL) return RET_OK; r = distribution_loaduploaders(into); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; assert(into->uploaderslist != NULL); - r = uploaders_permissions(into->uploaderslist, c->signatures, &conditions); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + r = uploaders_permissions(into->uploaderslist, c->signatures, + &conditions); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; allowed = isallowed(i, c, into, conditions); free(conditions); - if( allowed ) + if (allowed) return RET_OK; else /* reject */ @@ -1900,31 +1930,34 @@ // forget to check later to only put files in when the distribution can // cope with that. - for( j = 0 ; j < c->architectures.count ; j++ ) { + for (j = 0 ; j < c->architectures.count ; j++) { const char *architecture = c->architectures.values[j]; - if( strcmp(architecture, "all") == 0 ) { + if (strcmp(architecture, "all") == 0) { check_all_availability = true; continue; } - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - if( atomlist_in(&d->into->architectures, architecture_find(architecture)) ) + for (d = c->perdistribution ; d != NULL ; d = d->next) { + if (atomlist_in(&d->into->architectures, architecture_find(architecture))) continue; - fprintf(stderr, "'%s' lists architecture '%s' not found in distribution '%s'!\n", - BASENAME(i,c->ofs), architecture, d->into->codename); + fprintf(stderr, +"'%s' lists architecture '%s' not found in distribution '%s'!\n", + BASENAME(i, c->ofs), architecture, + d->into->codename); return RET_ERROR; } - if( strcmp(architecture, "source") != 0 ) + if (strcmp(architecture, "source") != 0) have_all_available = true; } - if( check_all_availability && ! have_all_available ) { - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - if( d->into->architectures.count > 1 ) + if (check_all_availability && ! have_all_available) { + for (d = c->perdistribution ; d != NULL ; d = d->next) { + if (d->into->architectures.count > 1) continue; - if( d->into->architectures.count > 0 && + if (d->into->architectures.count > 0 && d->into->architectures.atoms[0] != architecture_source) continue; - fprintf(stderr, "'%s' lists architecture 'all' but no binary architecture found in distribution '%s'!\n", - BASENAME(i,c->ofs), d->into->codename); + fprintf(stderr, +"'%s' lists architecture 'all' but no binary architecture found in distribution '%s'!\n", + BASENAME(i, c->ofs), d->into->codename); return RET_ERROR; } } @@ -1937,27 +1970,27 @@ retvalue r; r = dirs_make_recursive(logdir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; p = calc_changes_basename(name, version, architectures); - if( FAILEDTOALLOC(p) ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; dir = calc_dirconcat(logdir, p); free(p); - if( FAILEDTOALLOC(dir) ) + if (FAILEDTOALLOC(dir)) return RET_ERROR_OOM; l = strlen(dir); - assert( l > 8 && strcmp(dir + l - 8 , ".changes") == 0 ); + assert (l > 8 && strcmp(dir + l - 8 , ".changes") == 0); memset(dir + l - 7, '0', 7); r = dirs_create(dir); - while( r == RET_NOTHING ) { + while (r == RET_NOTHING) { p = dir + l - 1; - while( *p == '9' ) { + while (*p == '9') { *p = '0'; p--; } - if( *p < '0' || *p > '8' ) { + if (*p < '0' || *p > '8') { fprintf(stderr, "Failed to create a new directory of the form '%s'\n" "it looks like all 10000000 such directories are already there...\n", @@ -1981,44 +2014,44 @@ c->source, c->changesversion, &c->architectures, &c->logsubdir); - assert( RET_IS_OK(r) ); - if( RET_WAS_ERROR(r) ) + assert (RET_IS_OK(r)); + if (RET_WAS_ERROR(r)) return RET_ERROR_OOM; count = 0; - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->ofs == c->ofs || file->type == fe_LOG - || (file->type == fe_BYHAND && !file->used) ) + for (file = c->files ; file != NULL ; file = file->next) { + if (file->ofs == c->ofs || file->type == fe_LOG + || (file->type == fe_BYHAND && !file->used)) count++; } c->logcount = count; - c->logfiles = calloc(count, sizeof(struct canidate_file*)); - if( FAILEDTOALLOC(c->logfiles) ) + c->logfiles = nzNEW(count, const struct candidate_file *); + if (FAILEDTOALLOC(c->logfiles)) return RET_ERROR_OOM; j = 0; - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->ofs == c->ofs || file->type == fe_LOG - || (file->type == fe_BYHAND && !file->used) ) { + for (file = c->files ; file != NULL ; file = file->next) { + if (file->ofs == c->ofs || file->type == fe_LOG + || (file->type == fe_BYHAND && !file->used)) { r = candidate_usefile(i, c, file); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; c->logfiles[j++] = file; } } - assert( count == j ); + assert (count == j); return RET_OK; } static retvalue candidate_finish_logdir(struct incoming *i, struct candidate *c) { int j; - for( j = 0 ; j < c->logcount ; j++ ) { + for (j = 0 ; j < c->logcount ; j++) { retvalue r; const struct candidate_file *f = c->logfiles[j]; r = checksums_hardlink(c->logsubdir, BASENAME(i, f->ofs), f->tempfilename, f->checksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -2028,13 +2061,13 @@ struct byhandfile *b; retvalue r; - for( b = d->byhandhookstocall ; b != NULL ; b = b->next ){ + for (b = d->byhandhookstocall ; b != NULL ; b = b->next){ const struct candidate_file *f = b->file; r = byhandhook_call(b->hook, d->into->codename, f->section, f->priority, BASENAME(i, f->ofs), f->tempfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -2042,34 +2075,34 @@ /* the actual adding of packages, * everything that can be tested earlier should be already tested now */ -static retvalue candidate_really_add(struct database *database, struct incoming *i, struct candidate *c) { +static retvalue candidate_really_add(struct incoming *i, struct candidate *c) { struct candidate_perdistribution *d; retvalue r; - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - if( d->byhandhookstocall == NULL ) + for (d = c->perdistribution ; d != NULL ; d = d->next) { + if (d->byhandhookstocall == NULL) continue; r = candidate_add_byhands(i, c, d); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } /* make hardlinks/copies of the files */ - r = candidate_addfiles(database, c); - if( RET_WAS_ERROR(r) ) + r = candidate_addfiles(c); + if (RET_WAS_ERROR(r)) return r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - if( i->logdir != NULL ) { + if (i->logdir != NULL) { r = candidate_finish_logdir(i, c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; r = RET_OK; - for( d = c->perdistribution ; d != NULL ; d = d->next ) { + for (d = c->perdistribution ; d != NULL ; d = d->next) { struct distribution *into = d->into; const char *changesfilekey = NULL; @@ -2077,12 +2110,12 @@ * add them and call the log. * If all packages were skipped but a byhandhook run, * still advertise the .changes file to loggers */ - if( !d->skip ) { - r = candidate_add_into(database, i, c, d, + if (!d->skip) { + r = candidate_add_into(i, c, d, &changesfilekey); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - } else if( d->byhandhookstocall == NULL ) + } else if (d->byhandhookstocall == NULL) continue; logger_logchanges(into->logger, into->codename, c->source, c->changesversion, c->control, @@ -2091,58 +2124,58 @@ return RET_OK; } -static retvalue candidate_add(struct database *database, struct incoming *i, struct candidate *c) { +static retvalue candidate_add(struct incoming *i, struct candidate *c) { struct candidate_perdistribution *d; struct candidate_file *file; retvalue r; bool somethingtodo; char *origfilename; - assert( c->perdistribution != NULL ); + assert (c->perdistribution != NULL); /* check if every distribution this is to be added to supports * all architectures we have files for */ r = check_architecture_availability(i, c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( d = c->perdistribution ; d != NULL ; d = d->next ) { + for (d = c->perdistribution ; d != NULL ; d = d->next) { r = distribution_loadalloverrides(d->into); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - // TODO: once uploaderlist allows to look for package names or existing override - // entries or such things, check package names here enable checking for content - // name with outer name + // TODO: once uploaderlist allows to look for package names or existing + // override entries or such things, check package names here enable + // checking for content name with outer name /* when we get here, the package is allowed in, now we have to * read the parts and check all stuff we only know now */ r = candidate_read_files(i, c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* now the distribution specific part starts: */ - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - r = prepare_for_distribution(database, i, c, d); - if( RET_WAS_ERROR(r) ) + for (d = c->perdistribution ; d != NULL ; d = d->next) { + r = prepare_for_distribution(i, c, d); + if (RET_WAS_ERROR(r)) return r; } - if( i->logdir != NULL ) { + if (i->logdir != NULL) { r = candidate_prepare_logdir(i, c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - for( file = c->files ; file != NULL ; file = file->next ) { - if( !file->used && !i->permit[pmf_unused_files] ) { + for (file = c->files ; file != NULL ; file = file->next) { + if (!file->used && !i->permit[pmf_unused_files]) { // TODO: find some way to mail such errors... fprintf(stderr, "Error: '%s' contains unused file '%s'!\n" "(Do Permit: unused_files to conf/incoming to ignore and\n" " additionally Cleanup: unused_files to delete them)\n", - BASENAME(i,c->ofs), BASENAME(i,file->ofs)); - if( file->type == fe_LOG || file->type == fe_BYHAND ) + BASENAME(i, c->ofs), BASENAME(i, file->ofs)); + if (file->type == fe_LOG || file->type == fe_BYHAND) fprintf(stderr, "Alternatively, you can also add a LogDir: for '%s' into conf/incoming\n" "then files like that will be stored there.\n", @@ -2154,25 +2187,25 @@ /* additional test run to see if anything could go wrong, * or if there are already newer versions */ somethingtodo = false; - for( d = c->perdistribution ; d != NULL ; d = d->next ) { - r = candidate_checkadd_into(database, - i, d); - if( RET_WAS_ERROR(r) ) + for (d = c->perdistribution ; d != NULL ; d = d->next) { + r = candidate_checkadd_into(i, d); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { d->skip = true; - if( d->byhandhookstocall != NULL ) + if (d->byhandhookstocall != NULL) somethingtodo = true; } else somethingtodo = true; } - if( ! somethingtodo ) { - if( verbose >= 0 ) { - printf("Skipping %s because all packages are skipped!\n", - BASENAME(i,c->ofs)); + if (! somethingtodo) { + if (verbose >= 0) { + printf( +"Skipping %s because all packages are skipped!\n", + BASENAME(i, c->ofs)); } - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->used || i->cleanup[cuf_unused_files] ) + for (file = c->files ; file != NULL ; file = file->next) { + if (file->used || i->cleanup[cuf_unused_files]) i->delete[file->ofs] = true; } return RET_NOTHING; @@ -2188,106 +2221,108 @@ BASENAME(i, changesfile(c)->ofs)); causingfile = origfilename; - r = candidate_really_add(database, i, c); + r = candidate_really_add(i, c); causingfile = NULL; free(origfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* mark files as done */ - for( file = c->files ; file != NULL ; file = file->next ) { - if( file->used ) + for (file = c->files ; file != NULL ; file = file->next) { + if (file->used) i->processed[file->ofs] = true; - if( file->used || i->cleanup[cuf_unused_files] ) { + if (file->used || i->cleanup[cuf_unused_files]) { i->delete[file->ofs] = true; } } return r; } -static retvalue process_changes(struct database *database, struct incoming *i, int ofs) { +static retvalue process_changes(struct incoming *i, int ofs) { struct candidate *c IFSTUPIDCC(=NULL); retvalue r; - int j,k; + int j, k; bool broken = false, tried = false; r = candidate_read(i, ofs, &c, &broken); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); r = candidate_parse(i, c); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { candidate_free(c); return r; } r = candidate_earlychecks(i, c); - if( RET_WAS_ERROR(r) ) { - if( i->cleanup[cuf_on_error] ) { + if (RET_WAS_ERROR(r)) { + if (i->cleanup[cuf_on_error]) { struct candidate_file *file; i->delete[c->ofs] = true; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; + file = file->next) { i->delete[file->ofs] = true; } } candidate_free(c); return r; } - for( k = 0 ; k < c->distributions.count ; k++ ) { + for (k = 0 ; k < c->distributions.count ; k++) { const char *name = c->distributions.values[k]; - for( j = 0 ; j < i->allow.count ; j++ ) { + for (j = 0 ; j < i->allow.count ; j++) { // TODO: implement "*" - if( strcmp(name, i->allow.values[j]) == 0 ) { + if (strcmp(name, i->allow.values[j]) == 0) { tried = true; r = candidate_checkpermissions(i, c, i->allow_into[j]); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) r = candidate_newdistribution(c, i->allow_into[j]); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { candidate_free(c); return r; } else break; } } - if( c->perdistribution != NULL && - !i->options[iof_multiple_distributions] ) + if (c->perdistribution != NULL && + !i->options[iof_multiple_distributions]) break; } - if( c->perdistribution == NULL && i->default_into != NULL ) { + if (c->perdistribution == NULL && i->default_into != NULL) { tried = true; r = candidate_checkpermissions(i, c, i->default_into); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { candidate_free(c); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = candidate_newdistribution(c, i->default_into); } } - if( c->perdistribution == NULL ) { + if (c->perdistribution == NULL) { fprintf(stderr, tried?"No distribution accepting '%s'!\n": "No distribution found for '%s'!\n", i->files.values[ofs]); - if( i->cleanup[cuf_on_deny] ) { + if (i->cleanup[cuf_on_deny]) { struct candidate_file *file; i->delete[c->ofs] = true; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; + file = file->next) { // TODO: implement same-owner check - if( !i->cleanup[cuf_on_deny_check_owner] ) + if (!i->cleanup[cuf_on_deny_check_owner]) i->delete[file->ofs] = true; } } r = RET_ERROR_INCOMING_DENY; } else { - if( broken ) { + if (broken) { fprintf(stderr, "'%s' is signed with only invalid signatures.\n" "If this was not corruption but willfull modification,\n" @@ -2295,12 +2330,13 @@ i->files.values[ofs]); r = RET_ERROR; } else - r = candidate_add(database, i, c); - if( RET_WAS_ERROR(r) && i->cleanup[cuf_on_error] ) { + r = candidate_add(i, c); + if (RET_WAS_ERROR(r) && i->cleanup[cuf_on_error]) { struct candidate_file *file; i->delete[c->ofs] = true; - for( file = c->files ; file != NULL ; file = file->next ) { + for (file = c->files ; file != NULL ; + file = file->next) { i->delete[file->ofs] = true; } } @@ -2319,25 +2355,26 @@ int e; r = dirs_make_recursive(basedir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return NULL; - if( time(&curtime) == (time_t)-1 ) + if (time(&curtime) == (time_t)-1) tm = NULL; else tm = gmtime(&curtime); - if( tm == NULL || strftime(date, 16, "%Y-%m-%d", tm) != 10 ) + if (tm == NULL || strftime(date, 16, "%Y-%m-%d", tm) != 10) strcpy(date, "timeerror"); - for( number = 0 ; number < 10000 ; number ++ ) { + for (number = 0 ; number < 10000 ; number ++) { dir = mprintf("%s/%s-%lu", basedir, date, number); - if( FAILEDTOALLOC(dir) ) + if (FAILEDTOALLOC(dir)) return NULL; - if( mkdir(dir, 0777) == 0 ) + if (mkdir(dir, 0777) == 0) return dir; e = errno; - if( e != EEXIST ) { - fprintf(stderr, "Error %d creating directory '%s': %s\n", + if (e != EEXIST) { + fprintf(stderr, +"Error %d creating directory '%s': %s\n", e, dir, strerror(e)); free(dir); return NULL; @@ -2349,78 +2386,78 @@ } /* tempdir should ideally be on the same partition like the pooldir */ -retvalue process_incoming(struct database *database, struct distribution *distributions, const char *name, const char *changesfilename) { +retvalue process_incoming(struct distribution *distributions, const char *name, const char *changesfilename) { struct incoming *i; - retvalue result,r; + retvalue result, r; int j; char *morguedir; result = RET_NOTHING; r = incoming_init(distributions, name, &i); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( j = 0 ; j < i->files.count ; j ++ ) { + for (j = 0 ; j < i->files.count ; j ++) { const char *basefilename = i->files.values[j]; size_t l = strlen(basefilename); #define C_SUFFIX ".changes" #define C_LEN strlen(C_SUFFIX) - if( l <= C_LEN || - strcmp(basefilename + (l - C_LEN ), C_SUFFIX) != 0 ) + if (l <= C_LEN || + strcmp(basefilename + (l - C_LEN), C_SUFFIX) != 0) continue; - if( changesfilename != NULL && strcmp(basefilename, changesfilename) != 0 ) + if (changesfilename != NULL && strcmp(basefilename, changesfilename) != 0) continue; /* a .changes file, check it */ - r = process_changes(database, i, j); + r = process_changes(i, j); RET_UPDATE(result, r); } logger_wait(); - if( i->morguedir == NULL ) + if (i->morguedir == NULL) morguedir = NULL; else { morguedir = create_uniq_subdir(i->morguedir); } - for( j = 0 ; j < i->files.count ; j ++ ) { + for (j = 0 ; j < i->files.count ; j ++) { char *fullfilename; - if( !i->delete[j] ) + if (!i->delete[j]) continue; fullfilename = calc_dirconcat(i->directory, i->files.values[j]); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { result = RET_ERROR_OOM; continue; } - if( morguedir != NULL && !i->processed[j] ) { + if (morguedir != NULL && !i->processed[j]) { char *newname = calc_dirconcat(morguedir, i->files.values[j]); - if( newname != NULL && - rename(fullfilename, newname) == 0 ) { + if (newname != NULL && + rename(fullfilename, newname) == 0) { free(newname); free(fullfilename); continue; - } else if( newname == NULL ) { + } else if (FAILEDTOALLOC(newname)) { result = RET_ERROR_OOM; } else { int e = errno; fprintf(stderr, -"Error %d moving '%s' to '%s': %s\n", e, - i->files.values[j], +"Error %d moving '%s' to '%s': %s\n", + e, i->files.values[j], morguedir, strerror(e)); RET_UPDATE(result, RET_ERRNO(e)); /* no continue, instead * delete the file as normal: */ } } - if( verbose >= 3 ) + if (verbose >= 3) printf("deleting '%s'...\n", fullfilename); deletefile(fullfilename); free(fullfilename); } - if( morguedir != NULL ) { + if (morguedir != NULL) { /* in the case it is empty, remove again */ (void)rmdir(morguedir); free(morguedir); diff -Nru reprepro-4.5.0/incoming.h reprepro-4.6.0/incoming.h --- reprepro-4.5.0/incoming.h 2008-10-13 09:55:29.000000000 +0000 +++ reprepro-4.6.0/incoming.h 2011-05-05 14:42:55.000000000 +0000 @@ -6,5 +6,5 @@ #warning "What's hapening here?" #endif -retvalue process_incoming(struct database *, struct distribution *distributions, const char *name, /*@null@*/const char *onlychangesfilename); +retvalue process_incoming(struct distribution *distributions, const char *name, /*@null@*/const char *onlychangesfilename); #endif diff -Nru reprepro-4.5.0/indexfile.c reprepro-4.6.0/indexfile.c --- reprepro-4.5.0/indexfile.c 2010-07-11 10:16:01.000000000 +0000 +++ reprepro-4.6.0/indexfile.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,19 +43,19 @@ }; retvalue indexfile_open(struct indexfile **file_p, const char *filename, enum compression compression) { - struct indexfile *f = calloc(1, sizeof(struct indexfile)); + struct indexfile *f = zNEW(struct indexfile); retvalue r; - if( FAILEDTOALLOC(f) ) + if (FAILEDTOALLOC(f)) return RET_ERROR_OOM; f->filename = strdup(filename); - if( FAILEDTOALLOC(f->filename) ) { + if (FAILEDTOALLOC(f->filename)) { free(f); return RET_ERROR_OOM; } r = uncompress_open(&f->f, filename, compression); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(f->filename); free(f); return RET_ERRNO(errno); @@ -68,7 +68,7 @@ f->content = 0; /* +1 for *d = '\0' in eof case */ f->buffer = malloc(f->size + 1); - if( FAILEDTOALLOC(f->buffer) ) { + if (FAILEDTOALLOC(f->buffer)) { uncompress_abort(f->f); free(f->filename); free(f); @@ -96,7 +96,7 @@ bool afternewline, nothingyet; int bytes_read; - if( f->failed ) + if (f->failed) return RET_ERROR; d = f->buffer; @@ -111,23 +111,23 @@ // input, this could be kept in-situ and only chunk_edit // beautifying this chunk... - while( p < e ) { + while (p < e) { /* just ignore '\r', even if not line-end... */ - if( *p == '\r' ) { + if (*p == '\r') { p++; continue; } - if( *p == '\n' ) { + if (*p == '\n') { f->linenumber++; - if( afternewline ) { + if (afternewline) { p++; f->content -= (p - start); f->ofs += (p - start); - assert( f->ofs == (p - f->buffer)); - if( nothingyet ) + assert (f->ofs == (p - f->buffer)); + if (nothingyet) /* restart */ return indexfile_get(f); - if( d > f->buffer && *(d-1) == '\n' ) + if (d > f->buffer && *(d-1) == '\n') d--; *d = '\0'; return RET_OK; @@ -136,7 +136,7 @@ nothingyet = false; } else afternewline = false; - if( unlikely(*p == '\0') ) { + if (unlikely(*p == '\0')) { *(d++) = ' '; p++; } else @@ -148,7 +148,7 @@ f->ofs = (d - f->buffer); f->content = 0; - if( f->size - f->ofs <= 2048 ) { + if (f->size - f->ofs <= 2048) { /* Adding code to enlarge the buffer in this case * is risky as hard to test properly. * @@ -166,20 +166,20 @@ } bytes_read = uncompress_read(f->f, d, f->size - f->ofs); - if( bytes_read < 0 ) + if (bytes_read < 0) return RET_ERROR; - else if( bytes_read == 0 ) + else if (bytes_read == 0) break; f->content = bytes_read; - } while( true ); + } while (true); - if( d == f->buffer ) + if (d == f->buffer) return RET_NOTHING; /* end of file reached, return what we got so far */ - assert( f->content == 0 ); - assert( d-f->buffer <= f->size ); - if( d > f->buffer && *(d-1) == '\n' ) + assert (f->content == 0); + assert (d-f->buffer <= f->size); + if (d > f->buffer && *(d-1) == '\n') d--; *d = '\0'; return RET_OK; @@ -198,76 +198,76 @@ free(version); version = NULL; f->startlinenumber = f->linenumber + 1; r = indexfile_get(f); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) break; control = f->buffer; r = chunk_getvalue(control, "Package", &packagename); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error parsing %s line %d to %d: Chunk without 'Package:' field!\n", f->filename, f->startlinenumber, f->linenumber); - if( !ignorecruft ) + if (!ignorecruft) r = RET_ERROR_MISSING; else continue; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; r = chunk_getvalue(control, "Version", &version); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error parsing %s line %d to %d: Chunk without 'Version:' field!\n", f->filename, f->startlinenumber, f->linenumber); - if( !ignorecruft ) + if (!ignorecruft) r = RET_ERROR_MISSING; else continue; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; r = chunk_getvalue(control, "Architecture", &architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) architecture = NULL; - if( target->packagetype_atom == pt_dsc ) { + if (target->packagetype == pt_dsc) { free(architecture); atom = architecture_source; } else { /* check if architecture fits for target and error out if not ignorewrongarchitecture */ - if( architecture == NULL ) { + if (architecture == NULL) { fprintf(stderr, "Error parsing %s line %d to %d: Chunk without 'Architecture:' field!\n", f->filename, f->startlinenumber, f->linenumber); - if( !ignorecruft ) { + if (!ignorecruft) { r = RET_ERROR_MISSING; break; } else continue; - } else if( strcmp(architecture, "all") == 0 ) { + } else if (strcmp(architecture, "all") == 0) { atom = architecture_all; - } else if( strcmp(architecture, + } else if (strcmp(architecture, atoms_architectures[ - target->architecture_atom + target->architecture ]) == 0) { - atom = target->architecture_atom; - } else if( !allowwrongarchitecture - && !ignore[IGN_wrongarchitecture] ) { + atom = target->architecture; + } else if (!allowwrongarchitecture + && !ignore[IGN_wrongarchitecture]) { fprintf(stderr, "Warning: ignoring package because of wrong 'Architecture:' field '%s'" " (expected 'all' or '%s') in %s lines %d to %d!\n", architecture, atoms_architectures[ - target->architecture_atom], + target->architecture], f->filename, f->startlinenumber, f->linenumber); - if( ignored[IGN_wrongarchitecture] == 0 ) { + if (ignored[IGN_wrongarchitecture] == 0) { fprintf(stderr, "This either mean the repository you get packages from is of an extremly\n" "low quality, or something went wrong. Trying to ignore it now, though.\n" @@ -284,14 +284,14 @@ } free(architecture); } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; *control_p = control; *name_p = packagename; *version_p = version; *architecture_p = atom; return true; - } while( true ); + } while (true); free(packagename); free(version); RET_UPDATE(f->status, r); diff -Nru reprepro-4.5.0/INSTALL reprepro-4.6.0/INSTALL --- reprepro-4.5.0/INSTALL 2009-09-23 11:45:26.000000000 +0000 +++ reprepro-4.6.0/INSTALL 2011-05-05 14:42:55.000000000 +0000 @@ -1,8 +1,11 @@ Build-Dependencies: - libgpgme >= 0.4.1 (In Debian libgpgme11-dev, NOT libgpgme-dev) - libdb3 + libdb3, libdb4.x or libdb5.x libz -When Building from cvs: +Optional Dependencies: + libgpgme >= 0.4.1 (In Debian libgpgme11-dev, NOT libgpgme-dev) + libbz2 + libarchive +When Building from git: autoconf2.50 (autoconf 2.13 will not work) Basic Installation diff -Nru reprepro-4.5.0/log.c reprepro-4.6.0/log.c --- reprepro-4.5.0/log.c 2010-07-11 10:16:02.000000000 +0000 +++ reprepro-4.6.0/log.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,7 +43,7 @@ #include "filecntl.h" const char *causingfile = NULL; -command_t causingcommand_atom = atom_unknown; +command_t causingcommand = atom_unknown; /*@null@*/ static /*@refcounted@*/ struct logfile { /*@null@*/struct logfile *next; @@ -55,28 +55,28 @@ static retvalue logfile_reference(/*@only@*/char *filename, /*@out@*/struct logfile **logfile) { struct logfile *l; - assert( global.logdir != NULL && filename != NULL ); + assert (global.logdir != NULL && filename != NULL); - for( l = logfile_root ; l != NULL ; l = l->next ) { - if( strcmp(l->filename, filename) == 0 ) { + for (l = logfile_root ; l != NULL ; l = l->next) { + if (strcmp(l->filename, filename) == 0) { l->refcount++; *logfile = l; free(filename); return RET_OK; } } - l = malloc(sizeof(struct logfile)); - if( l == NULL ) { + l = NEW(struct logfile); + if (FAILEDTOALLOC(l)) { free(filename); return RET_ERROR_OOM; } - if( filename[0] == '/' ) + if (filename[0] == '/') l->filename = filename; else { l->filename = calc_dirconcat(global.logdir, filename); free(filename); } - if( l->filename == NULL ) { + if (FAILEDTOALLOC(l->filename)) { free(l); return RET_ERROR_OOM; } @@ -89,26 +89,26 @@ } static void logfile_dereference(struct logfile *logfile) { - assert( logfile != NULL ); - assert( logfile->refcount > 0 ); - if( --logfile->refcount == 0 ) { + assert (logfile != NULL); + assert (logfile->refcount > 0); + if (--logfile->refcount == 0) { - if( logfile_root == logfile ) + if (logfile_root == logfile) logfile_root = logfile->next; else { struct logfile *previous = logfile_root; - while( previous != NULL && previous->next != logfile ) + while (previous != NULL && previous->next != logfile) previous = previous->next; - assert( previous != NULL ); - assert( previous->next == logfile ); + assert (previous != NULL); + assert (previous->next == logfile); previous->next = logfile->next; } - if( logfile->fd >= 0 ) { - int ret,e; + if (logfile->fd >= 0) { + int ret, e; ret = close(logfile->fd); logfile->fd = -1; - if( ret < 0 ) { + if (ret < 0) { e = errno; fprintf(stderr, "Error received when closing log file '%s': %d=%s\n", @@ -121,14 +121,14 @@ } static retvalue logfile_open(struct logfile *logfile) { - assert( logfile != NULL ); - assert( logfile->fd < 0 ); + assert (logfile != NULL); + assert (logfile->fd < 0); (void)dirs_make_parent(logfile->filename); logfile->fd = open(logfile->filename, O_CREAT|O_APPEND|O_LARGEFILE|O_NOCTTY|O_WRONLY, 0666); - if( logfile->fd < 0 ) { + if (logfile->fd < 0) { int e = errno; fprintf(stderr, "Cannot open/create logfile '%s': %d=%s\n", logfile->filename, e, strerror(e)); @@ -137,60 +137,60 @@ return RET_OK; } -static retvalue logfile_write(struct logfile *logfile,struct target *target,const char *name,/*@null@*/const char *version,/*@null@*/const char *oldversion) { +static retvalue logfile_write(struct logfile *logfile, struct target *target, const char *name, /*@null@*/const char *version, /*@null@*/const char *oldversion) { int ret; time_t currenttime; struct tm t; - assert( logfile->fd >= 0 ); + assert (logfile->fd >= 0); currenttime = time(NULL); - if( localtime_r(¤ttime, &t) == NULL ) { - if( version != NULL && oldversion != NULL ) + if (localtime_r(¤ttime, &t) == NULL) { + if (version != NULL && oldversion != NULL) ret = dprintf(logfile->fd, "EEEE-EE-EE EE:EE:EE replace %s %s %s %s %s %s %s\n", target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, version, oldversion); - else if( version != NULL ) + else if (version != NULL) ret = dprintf(logfile->fd, "EEEE-EE-EE EE:EE:EE add %s %s %s %s %s %s\n", target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, version); else ret = dprintf(logfile->fd, "EEEE-EE-EE EE:EE:EE remove %s %s %s %s %s %s\n", target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, oldversion); - } else if( version != NULL && oldversion != NULL ) + } else if (version != NULL && oldversion != NULL) ret = dprintf(logfile->fd, "%04d-%02d-%02d %02u:%02u:%02u replace %s %s %s %s %s %s %s\n", 1900+t.tm_year, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, version, oldversion); - else if( version != NULL ) + else if (version != NULL) ret = dprintf(logfile->fd, "%04d-%02d-%02d %02u:%02u:%02u add %s %s %s %s %s %s\n", 1900+t.tm_year, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, version); else ret = dprintf(logfile->fd, @@ -199,11 +199,11 @@ t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, target->distribution->codename, - atoms_packagetypes[target->packagetype_atom], - atoms_components[target->component_atom], - atoms_architectures[target->architecture_atom], + atoms_packagetypes[target->packagetype], + atoms_components[target->component], + atoms_architectures[target->architecture], name, oldversion); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error writing to log file '%s': %d=%s", logfile->filename, e, strerror(e)); @@ -215,14 +215,14 @@ struct notificator { char *scriptname; /* if defined, only call if it matches the package: */ - packagetype_t packagetype_atom; - component_t component_atom; - architecture_t architecture_atom; - command_t command_atom; + packagetype_t packagetype; + component_t component; + architecture_t architecture; + command_t command; bool withcontrol, changesacceptrule; }; -static void notificator_done(/*@special@*/struct notificator *n) /*@releases n->scriptname,n->packagename,n->component,n->architecture@*/{ +static void notificator_done(/*@special@*/struct notificator *n) /*@releases n->scriptname, n->packagename, n->component, n->architecture@*/{ free(n->scriptname); } @@ -231,12 +231,12 @@ int c; memset(n, 0, sizeof(struct notificator)); - n->architecture_atom = atom_unknown; - n->component_atom = atom_unknown; - n->packagetype_atom = atom_unknown; - n->command_atom = atom_unknown; - while( (c = config_nextnonspaceinline(iter)) != EOF ) { - if( c == '-' ) { + n->architecture = atom_unknown; + n->component = atom_unknown; + n->packagetype = atom_unknown; + n->command = atom_unknown; + while ((c = config_nextnonspaceinline(iter)) != EOF) { + if (c == '-') { char *word, *s, *detachedargument = NULL; const char *argument; atom_t *value_p = NULL; @@ -244,68 +244,68 @@ bool error = false; r = config_completeword(iter, c, &word); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; s = word + 1; - while( *s != '\0' && *s != '=' ) + while (*s != '\0' && *s != '=') s++; - if( *s == '=' ) { + if (*s == '=') { argument = s+1; s[0] = '\0'; } else argument = NULL; - switch( s-word ) { + switch (s-word) { case 2: - if( word[1] == 'A' ) { - value_p = &n->architecture_atom; + if (word[1] == 'A') { + value_p = &n->architecture; value_type = at_architecture; - } else if( word[1] == 'C' ) { - value_p = &n->component_atom; + } else if (word[1] == 'C') { + value_p = &n->component; value_type = at_component; - } else if( word[1] == 'T' ) { - value_p = &n->packagetype_atom; + } else if (word[1] == 'T') { + value_p = &n->packagetype; value_type = at_packagetype; } else error = true; break; case 5: - if( strcmp(word, "--via") == 0 ) { - value_p = &n->command_atom; + if (strcmp(word, "--via") == 0) { + value_p = &n->command; value_type = at_command; } else error = true; break; case 6: - if( strcmp(word, "--type") == 0 ) { - value_p = &n->packagetype_atom; + if (strcmp(word, "--type") == 0) { + value_p = &n->packagetype; value_type = at_packagetype; } else error = true; break; case 9: - if( strcmp(word, "--changes") == 0 ) + if (strcmp(word, "--changes") == 0) n->changesacceptrule = true; else error = true; break; case 11: - if( strcmp(word, "--component") == 0 ) { - value_p = &n->component_atom; + if (strcmp(word, "--component") == 0) { + value_p = &n->component; value_type = at_component; } else error = true; break; case 13: - if( strcmp(word, "--withcontrol") == 0 ) + if (strcmp(word, "--withcontrol") == 0) n->withcontrol = true; else error = true; break; case 14: - if( strcmp(word, "--architecture") == 0 ) { - value_p = &n->architecture_atom; + if (strcmp(word, "--architecture") == 0) { + value_p = &n->architecture; value_type = at_architecture; } else error = true; @@ -314,7 +314,7 @@ error = true; break; } - if( error ) { + if (error) { fprintf(stderr, "Unknown Log notifier option in %s, line %u, column %u: '%s'\n", config_filename(iter), @@ -323,8 +323,8 @@ free(word); return RET_ERROR; } - if( value_p == NULL ) { - if( argument != NULL ) { + if (value_p == NULL) { + if (argument != NULL) { fprintf(stderr, "Log notifier option has = but may not, in %s, line %u, column %u: '%s'\n", config_filename(iter), @@ -338,20 +338,21 @@ continue; } /* option expecting string value: */ - if( atom_defined(*value_p) ) { + if (atom_defined(*value_p)) { fprintf(stderr, "Repeated notifier option %s in %s, line %u, column %u!\n", word, config_filename(iter), - config_markerline(iter), config_markercolumn(iter)); + config_markerline(iter), + config_markercolumn(iter)); free(word); return RET_ERROR; } detachedargument = NULL; - if( argument == NULL ) { + if (argument == NULL) { r = config_getwordinline(iter, &detachedargument); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Log notifier option %s misses an argument in %s, line %u, column %u\n", word, config_filename(iter), @@ -363,7 +364,7 @@ argument = detachedargument; } *value_p = atom_find(value_type, argument); - if( !atom_defined(*value_p) ) { + if (!atom_defined(*value_p)) { fprintf(stderr, "Warning: unknown %s '%s', ignoring notificator line line %u in %s\n", atomtypes[value_type], @@ -379,19 +380,19 @@ } else { char *script; - if( n->changesacceptrule && atom_defined(n->architecture_atom) ) { + if (n->changesacceptrule && atom_defined(n->architecture)) { fprintf(stderr, "Error: --changes and --architecture cannot be combined! (line %u in '%s')\n", config_markerline(iter), config_filename(iter)); return RET_ERROR; } - if( n->changesacceptrule && atom_defined(n->component_atom) ) { + if (n->changesacceptrule && atom_defined(n->component)) { fprintf(stderr, "Error: --changes and --component cannot be combined! (line %u in %s)\n", config_markerline(iter), config_filename(iter)); return RET_ERROR; } - if( n->changesacceptrule && atom_defined(n->packagetype_atom) ) { + if (n->changesacceptrule && atom_defined(n->packagetype)) { fprintf(stderr, "Error: --changes and --type cannot be combined! (line %u in %s)\n", config_markerline(iter), config_filename(iter)); @@ -399,12 +400,12 @@ } r = config_completeword(iter, c, &script); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; c = config_nextnonspaceinline(iter); - if( c != EOF ) { + if (c != EOF) { fprintf(stderr, "Error parsing config file %s, line %u, column %u:\n" "Unexpected data at end of notifier after script name '%s'\n", @@ -414,13 +415,13 @@ free(script); return RET_ERROR; } - if( script[0] == '/' ) + if (script[0] == '/') n->scriptname = script; else { n->scriptname = calc_conffile(script); free(script); } - if( n->scriptname == NULL ) + if (FAILEDTOALLOC(n->scriptname)) return RET_ERROR_OOM; return RET_OK; } @@ -438,7 +439,7 @@ /*@null@*/char *causingfile; /*@null@*/char *causingrule; /*@null@*/char *suitefrom; - command_t causingcommand_atom; + command_t causingcommand; /* data to send to the process */ size_t datalen, datasent; /*@null@*/char *data; @@ -450,9 +451,9 @@ static void notification_process_free(/*@only@*/struct notification_process *p) { char **a; - if( p->fd >= 0 ) + if (p->fd >= 0) (void)close(p->fd); - for( a = p->arguments ; *a != NULL ; a++ ) + for (a = p->arguments ; *a != NULL ; a++) free(*a); free(p->causingfile); free(p->causingrule); @@ -472,38 +473,38 @@ * check for our children. (As not many run, that * is no large overhead. */ pp = &processes; - while( (p=*pp) != NULL ) { - if( p->child <= 0 ) { + while ((p=*pp) != NULL) { + if (p->child <= 0) { pp = &p->next; continue; } child = waitpid(p->child, &status, WNOHANG); - if( child == 0 ) { + if (child == 0) { pp = &p->next; continue; } - if( child < 0 ) { + if (child < 0) { int e = errno; fprintf(stderr, "Error calling waitpid on notification child: %d=%s\n", e, strerror(e)); /* but still handle the failed child: */ - } else if( WIFSIGNALED(status) ) { + } else if (WIFSIGNALED(status)) { fprintf(stderr, "Notification process '%s' killed with signal %d!\n", p->arguments[0], WTERMSIG(status)); - } else if( !WIFEXITED(status) ) { + } else if (!WIFEXITED(status)) { fprintf(stderr, "Notification process '%s' failed!\n", p->arguments[0]); - } else if( WIFEXITED(status) && WEXITSTATUS(status) != 0 ) { + } else if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { fprintf(stderr, "Notification process '%s' returned with exit code %d!\n", p->arguments[0], (int)(WEXITSTATUS(status))); } - if( p->fd >= 0 ) { + if (p->fd >= 0) { (void)close(p->fd); p->fd = -1; } @@ -520,32 +521,32 @@ fd_set w; int ret; int number = 0; - struct timeval tv = {0,0}; + struct timeval tv = {0, 0}; FD_ZERO(&w); - for( p = processes; p!= NULL ; p = p->next ) { - if( p->child > 0 && p->fd >= 0 && p->datasent < p->datalen ) { + for (p = processes; p!= NULL ; p = p->next) { + if (p->child > 0 && p->fd >= 0 && p->datasent < p->datalen) { FD_SET(p->fd, &w); - if( p->fd >= number ) + if (p->fd >= number) number = p->fd + 1; } } - if( number == 0 ) + if (number == 0) return; ret = select(number, NULL, &w, NULL, dowait?NULL:&tv); - if( ret < 0 ) { + if (ret < 0) { // TODO... return; } - for( p = processes; p != NULL ; p = p->next ) { - if( p->child > 0 && p->fd >= 0 && FD_ISSET(p->fd, &w) ) { + for (p = processes; p != NULL ; p = p->next) { + if (p->child > 0 && p->fd >= 0 && FD_ISSET(p->fd, &w)) { size_t tosent = p->datalen - p->datasent; ssize_t sent; - if( tosent > (size_t)512 ) + if (tosent > (size_t)512) tosent = 512; sent = write(p->fd, p->data+p->datasent, 512); - if( sent < 0 ) { + if (sent < 0) { int e = errno; fprintf(stderr, "Error '%s' while sending data to '%s', sending SIGABRT to it!\n", @@ -554,7 +555,7 @@ (void)kill(p->child, SIGABRT); } p->datasent += sent; - if( p->datasent >= p->datalen ) { + if (p->datasent >= p->datalen) { free(p->data); p->data = NULL; } @@ -567,7 +568,7 @@ size_t running = 0; p = processes; - while( p != NULL && p->child != 0 ) { + while (p != NULL && p->child != 0) { running ++; p = p->next; } @@ -581,15 +582,16 @@ int ret; p = processes; - while( p != NULL && p->child != 0 ) + while (p != NULL && p->child != 0) p = p->next; - if( p == NULL ) + if (p == NULL) return RET_NOTHING; - if( p->datalen > 0 ) { + if (p->datalen > 0) { ret = pipe(filedes); - if( ret < 0 ) { + if (ret < 0) { int e = errno; - fprintf(stderr, "Error creating pipe: %d=%s!\n", e, strerror(e)); + fprintf(stderr, "Error creating pipe: %d=%s!\n", + e, strerror(e)); return RET_ERRNO(e); } p->fd = filedes[1]; @@ -597,30 +599,30 @@ p->fd = -1; } child = fork(); - if( child == 0 ) { - if( p->datalen > 0 ) { + if (child == 0) { + if (p->datalen > 0) { dup2(filedes[0], 0); - if( filedes[0] != 0) + if (filedes[0] != 0) (void)close(filedes[0]); (void)close(filedes[1]); } /* Try to close all open fd but 0,1,2 */ closefrom(3); - if( p->causingfile != NULL ) + if (p->causingfile != NULL) setenv("REPREPRO_CAUSING_FILE", p->causingfile, true); else unsetenv("REPREPRO_CAUSING_FILE"); - if( p->causingrule != NULL ) + if (p->causingrule != NULL) setenv("REPREPRO_CAUSING_RULE", p->causingrule, true); else unsetenv("REPREPRO_CAUSING_RULE"); - if( p->suitefrom != NULL ) + if (p->suitefrom != NULL) setenv("REPREPRO_FROM", p->suitefrom, true); else unsetenv("REPREPRO_FROM"); - if( atom_defined(p->causingcommand_atom) ) + if (atom_defined(p->causingcommand)) setenv("REPREPRO_CAUSING_COMMAND", - atoms_commands[p->causingcommand_atom], + atoms_commands[p->causingcommand], true); else unsetenv("REPREPRO_CAUSING_COMMAND"); @@ -634,44 +636,44 @@ strerror(errno)); _exit(255); } - if( p->datalen > 0 ) { + if (p->datalen > 0) { (void)close(filedes[0]); markcloseonexec(p->fd); } - if( child < 0 ) { + if (child < 0) { int e = errno; fprintf(stderr, "Error forking: %d=%s!\n", e, strerror(e)); - if( p->fd >= 0 ) { + if (p->fd >= 0) { (void)close(p->fd); p->fd = -1; } return RET_ERRNO(e); } p->child = child; - if( p->datalen > 0 ) { + if (p->datalen > 0) { struct pollfd polldata; ssize_t written; polldata.fd = p->fd; polldata.events = POLLOUT; - while( poll(&polldata, 1, 0) > 0 ) { - if( (polldata.revents & POLLNVAL) != 0 ) { + while (poll(&polldata, 1, 0) > 0) { + if ((polldata.revents & POLLNVAL) != 0) { p->fd = -1; return RET_ERROR; } - if( (polldata.revents & POLLHUP) != 0 ) { + if ((polldata.revents & POLLHUP) != 0) { (void)close(p->fd); p->fd = -1; return RET_OK; } - if( (polldata.revents & POLLOUT) != 0 ) { + if ((polldata.revents & POLLOUT) != 0) { size_t towrite = p->datalen - p->datasent; - if( towrite > (size_t)512 ) + if (towrite > (size_t)512) towrite = 512; written = write(p->fd, p->data + p->datasent, towrite); - if( written < 0 ) { + if (written < 0) { int e = errno; fprintf(stderr, "Error '%s' while sending data to '%s', sending SIGABRT to it!\n", @@ -681,12 +683,12 @@ return RET_ERRNO(e); } p->datasent += written; - if( p->datasent >= p->datalen ) { + if (p->datasent >= p->datalen) { free(p->data); p->data = NULL; ret = close(p->fd); p->fd = -1; - if( ret != 0 ) + if (ret != 0) return RET_ERRNO(errno); else return RET_OK; @@ -701,23 +703,23 @@ return RET_OK; } -static retvalue notificator_enqueuechanges(struct notificator *n,const char *codename,const char *name,const char *version,const char *changeschunk,const char *safefilename,/*@null@*/const char *filekey) { - size_t count,i,j; +static retvalue notificator_enqueuechanges(struct notificator *n, const char *codename, const char *name, const char *version, const char *changeschunk, const char *safefilename, /*@null@*/const char *filekey) { + size_t count, i, j; char **arguments; struct notification_process *p; catchchildren(); feedchildren(false); - if( !n->changesacceptrule ) + if (!n->changesacceptrule) return RET_NOTHING; - if( limitation_missed(n->command_atom, causingcommand_atom) ) { + if (limitation_missed(n->command, causingcommand)) { return RET_NOTHING; } count = 6; /* script "accepted" codename name version safename */ - if( filekey != NULL ) + if (filekey != NULL) count++; - arguments = calloc(count+1, sizeof(char*)); - if( arguments == NULL ) + arguments = nzNEW(count + 1, char*); + if (FAILEDTOALLOC(arguments)) return RET_ERROR_OOM; i = 0; arguments[i++] = strdup(n->scriptname); @@ -726,38 +728,38 @@ arguments[i++] = strdup(name); arguments[i++] = strdup(version); arguments[i++] = strdup(safefilename); - if( filekey != NULL ) + if (filekey != NULL) arguments[i++] = strdup(filekey); - assert( i == count ); + assert (i == count); arguments[i] = NULL; - for( i = 0 ; i < count ; i++ ) - if( arguments[i] == NULL ) { - for( j = 0 ; j < count ; j++ ) + for (i = 0 ; i < count ; i++) + if (FAILEDTOALLOC(arguments[i])) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); return RET_ERROR_OOM; } - if( processes == NULL ) { - p = malloc(sizeof(struct notification_process)); + if (processes == NULL) { + p = NEW(struct notification_process); processes = p; } else { p = processes; - while( p->next != NULL ) + while (p->next != NULL) p = p->next; - p->next = malloc(sizeof(struct notification_process)); + p->next = NEW(struct notification_process); p = p->next; } - if( FAILEDTOALLOC(p) ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(p)) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); return RET_ERROR_OOM; } - p->causingcommand_atom = causingcommand_atom; - if( causingfile != NULL ) { + p->causingcommand = causingcommand; + if (causingfile != NULL) { p->causingfile = strdup(causingfile); - if( FAILEDTOALLOC(p->causingfile) ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(p->causingfile)) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); free(p); @@ -778,7 +780,7 @@ // until that changeschunk is not yet needed: changeschunk = changeschunk; - if( runningchildren() < 1 ) + if (runningchildren() < 1) startchild(); return RET_OK; } @@ -791,114 +793,114 @@ catchchildren(); feedchildren(false); - if( n->changesacceptrule ) + if (n->changesacceptrule) return RET_NOTHING; // some day, some atom handling for those would be nice - if( limitation_missed(n->architecture_atom, target->architecture_atom) ) { - if( runningchildren() < 1 ) + if (limitation_missed(n->architecture, target->architecture)) { + if (runningchildren() < 1) startchild(); return RET_NOTHING; } - if( limitation_missed(n->component_atom, target->component_atom) ) { - if( runningchildren() < 1 ) + if (limitation_missed(n->component, target->component)) { + if (runningchildren() < 1) startchild(); return RET_NOTHING; } - if( limitation_missed(n->packagetype_atom, target->packagetype_atom) ) { - if( runningchildren() < 1 ) + if (limitation_missed(n->packagetype, target->packagetype)) { + if (runningchildren() < 1) startchild(); return RET_NOTHING; } - if( limitation_missed(n->command_atom, causingcommand_atom) ) { - if( runningchildren() < 1 ) + if (limitation_missed(n->command, causingcommand)) { + if (runningchildren() < 1) startchild(); return RET_NOTHING; } count = 7; /* script action codename type component architecture */ - if( version != NULL ) { + if (version != NULL) { action = "add"; count += 2; /* version and filekeylist marker */ - if( filekeys != NULL ) + if (filekeys != NULL) count += filekeys->count; } - if( oldversion != NULL ) { - assert( !renotification ); + if (oldversion != NULL) { + assert (!renotification); - if( action == NULL ) + if (action == NULL) action = "remove"; else action = "replace"; count += 2; /* version and filekeylist marker */ - if( oldfilekeys != NULL ) + if (oldfilekeys != NULL) count += oldfilekeys->count; } - assert( action != NULL ); - if( renotification ) + assert (action != NULL); + if (renotification) action = "info"; - arguments = calloc(count+1, sizeof(char*)); - if( arguments == NULL ) + arguments = nzNEW(count + 1, char*); + if (FAILEDTOALLOC(arguments)) return RET_ERROR_OOM; i = 0; arguments[i++] = strdup(n->scriptname); arguments[i++] = strdup(action); arguments[i++] = strdup(target->distribution->codename); - arguments[i++] = strdup(atoms_packagetypes[target->packagetype_atom]); - arguments[i++] = strdup(atoms_components[target->component_atom]); - arguments[i++] = strdup(atoms_architectures[target->architecture_atom]); + arguments[i++] = strdup(atoms_packagetypes[target->packagetype]); + arguments[i++] = strdup(atoms_components[target->component]); + arguments[i++] = strdup(atoms_architectures[target->architecture]); arguments[i++] = strdup(name); - if( version != NULL ) + if (version != NULL) arguments[i++] = strdup(version); - if( oldversion != NULL ) + if (oldversion != NULL) arguments[i++] = strdup(oldversion); - if( version != NULL ) { + if (version != NULL) { int j; arguments[i++] = strdup("--"); - if( filekeys != NULL ) - for( j = 0 ; j < filekeys->count ; j++ ) + if (filekeys != NULL) + for (j = 0 ; j < filekeys->count ; j++) arguments[i++] = strdup(filekeys->values[j]); } - if( oldversion != NULL ) { + if (oldversion != NULL) { int j; arguments[i++] = strdup("--"); - if( oldfilekeys != NULL ) - for( j = 0 ; j < oldfilekeys->count ; j++ ) + if (oldfilekeys != NULL) + for (j = 0 ; j < oldfilekeys->count ; j++) arguments[i++] = strdup(oldfilekeys->values[j]); } - assert( i == count ); + assert (i == count); arguments[i] = NULL; - for( i = 0 ; i < count ; i++ ) { + for (i = 0 ; i < count ; i++) { size_t j; - if( arguments[i] == NULL ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(arguments[i])) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); return RET_ERROR_OOM; } } - if( processes == NULL ) { - p = malloc(sizeof(struct notification_process)); + if (processes == NULL) { + p = NEW(struct notification_process); processes = p; } else { p = processes; - while( p->next != NULL ) + while (p->next != NULL) p = p->next; - p->next = malloc(sizeof(struct notification_process)); + p->next = NEW(struct notification_process); p = p->next; } - if( FAILEDTOALLOC(p) ) { + if (FAILEDTOALLOC(p)) { size_t j; - for( j = 0 ; j < count ; j++ ) + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); return RET_ERROR_OOM; } - p->causingcommand_atom = causingcommand_atom; - if( causingfile != NULL ) { + p->causingcommand = causingcommand; + if (causingfile != NULL) { size_t j; p->causingfile = strdup(causingfile); - if( FAILEDTOALLOC(p->causingfile) ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(p->causingfile)) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); free(p); @@ -906,11 +908,11 @@ } } else p->causingfile = NULL; - if( causingrule != NULL ) { + if (causingrule != NULL) { size_t j; p->causingrule = strdup(causingrule); - if( FAILEDTOALLOC(p->causingrule) ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(p->causingrule)) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); free(p->causingfile); @@ -919,11 +921,11 @@ } } else p->causingrule = NULL; - if( suitefrom != NULL ) { + if (suitefrom != NULL) { size_t j; p->suitefrom = strdup(suitefrom); - if( FAILEDTOALLOC(p->suitefrom) ) { - for( j = 0 ; j < count ; j++ ) + if (FAILEDTOALLOC(p->suitefrom)) { + for (j = 0 ; j < count ; j++) free(arguments[j]); free(arguments); free(p->causingfile); @@ -943,19 +945,19 @@ // TODO: implement --withcontrol // until that control is not yet needed: control = control; oldcontrol = oldcontrol; - if( runningchildren() < 1 ) + if (runningchildren() < 1) startchild(); return RET_OK; } void logger_wait(void) { - while( processes != NULL ) { + while (processes != NULL) { catchchildren(); - if( interrupted() ) + if (interrupted()) break; feedchildren(true); // TODO: add option to start multiple at the same time - if( runningchildren() < 1 ) + if (runningchildren() < 1) startchild(); else { struct timeval tv = { 0, 100 }; @@ -967,23 +969,23 @@ void logger_warn_waiting(void) { struct notification_process *p; - if( processes != NULL ) { + if (processes != NULL) { (void)fputs( "WARNING: some notificator hooks were not run!\n" "(most likely due to receiving an interruption request)\n" "You will either have to run them by hand or run rerunnotifiers if\n" "you want the information they get to not be out of sync.\n" "Missed calls are:\n", stderr); - for( p = processes ; p != NULL ; p = p->next ) { + for (p = processes ; p != NULL ; p = p->next) { char **c = p->arguments; - if( c == NULL ) + if (c == NULL) continue; - while( *c != NULL ) { + while (*c != NULL) { (void)fputc('"', stderr); (void)fputs(*c, stderr); (void)fputc('"', stderr); c++; - if( *c != NULL ) + if (*c != NULL) (void)fputc(' ', stderr); } (void)fputc('\n', stderr); @@ -998,15 +1000,15 @@ }; void logger_free(struct logger *logger) { - if( logger == NULL ) + if (logger == NULL) return; - if( logger->logfile != NULL ) + if (logger->logfile != NULL) logfile_dereference(logger->logfile); - if( logger->notificators != NULL ) { + if (logger->notificators != NULL) { size_t i; - for( i = 0 ; i < logger->notificator_count ; i++ ) + for (i = 0 ; i < logger->notificator_count ; i++) notificator_done(&logger->notificators[i]); free(logger->notificators); } @@ -1021,11 +1023,11 @@ bool havenotificators; r = config_getfileinline(iter, &logfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) logfilename = NULL; - if( config_nextnonspaceinline(iter) != EOF ) { + if (config_nextnonspaceinline(iter) != EOF) { fprintf(stderr, "Error parsing %s, line %u, column %u:\n" "Unexpected second filename for logfile.\n", config_filename(iter), config_line(iter), @@ -1035,20 +1037,20 @@ } config_overline(iter); havenotificators = config_nextline(iter); - if( !havenotificators && logfilename == NULL ) { + if (!havenotificators && logfilename == NULL) { *logger_p = NULL; return RET_NOTHING; } - n = malloc(sizeof(struct logger)); - if( n == NULL ) { + n = NEW(struct logger); + if (FAILEDTOALLOC(n)) { free(logfilename); return RET_ERROR_OOM; } - if( logfilename != NULL ) { - assert( *logfilename != '\0'); + if (logfilename != NULL) { + assert (*logfilename != '\0'); r = logfile_reference(logfilename, &n->logfile); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(n); return r; } @@ -1058,23 +1060,24 @@ n->notificators = NULL; n->notificator_count = 0; - while( havenotificators ) { + while (havenotificators) { struct notificator *newnot; newnot = realloc(n->notificators, - (n->notificator_count+1)* sizeof(struct notificator)); - if( newnot == NULL ) { + (n->notificator_count+1) + * sizeof(struct notificator)); + if (FAILEDTOALLOC(newnot)) { logger_free(n); return RET_ERROR_OOM; } n->notificators = newnot; r = notificator_parse(&n->notificators[n->notificator_count++], iter); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { /* a bit ugly: also free the just failed item here */ logger_free(n); return r; } - if( r == RET_NOTHING ) + if (r == RET_NOTHING) n->notificator_count--; // TODO assert eol here... havenotificators = config_nextline(iter); @@ -1086,39 +1089,39 @@ retvalue logger_prepare(struct logger *logger) { retvalue r; - if( logger->logfile == NULL ) + if (logger->logfile == NULL) return RET_NOTHING; - if( logger->logfile != NULL && logger->logfile->fd < 0 ) { + if (logger->logfile != NULL && logger->logfile->fd < 0) { r = logfile_open(logger->logfile); } else r = RET_OK; return r; } bool logger_isprepared(/*@null@*/const struct logger *logger) { - if( logger == NULL ) + if (logger == NULL) return true; - if( logger->logfile != NULL && logger->logfile->fd < 0 ) + if (logger->logfile != NULL && logger->logfile->fd < 0) return false; return true; } -void logger_log(struct logger *log,struct target *target,const char *name,const char *version,const char *oldversion,const char *control,const char *oldcontrol,const struct strlist *filekeys, const struct strlist *oldfilekeys, const char *causingrule, const char *suitefrom) { +void logger_log(struct logger *log, struct target *target, const char *name, const char *version, const char *oldversion, const char *control, const char *oldcontrol, const struct strlist *filekeys, const struct strlist *oldfilekeys, const char *causingrule, const char *suitefrom) { size_t i; - assert( name != NULL ); - assert( control != NULL || oldcontrol != NULL ); + assert (name != NULL); + assert (control != NULL || oldcontrol != NULL); - assert( version != NULL || control == NULL ); + assert (version != NULL || control == NULL); /* so that a replacement can be detected by existance of oldversion */ - if( oldcontrol != NULL && oldversion == NULL ) + if (oldcontrol != NULL && oldversion == NULL) oldversion = "#unparseable#"; - assert( version != NULL || oldversion != NULL ); + assert (version != NULL || oldversion != NULL); - if( log->logfile != NULL ) + if (log->logfile != NULL) logfile_write(log->logfile, target, name, version, oldversion); - for( i = 0 ; i < log->notificator_count ; i++ ) { + for (i = 0 ; i < log->notificator_count ; i++) { notificator_enqueue(&log->notificators[i], target, name, version, oldversion, control, oldcontrol, @@ -1127,18 +1130,19 @@ } } -void logger_logchanges(struct logger *log,const char *codename,const char *name,const char *version,const char *data,const char *safefilename,const char *changesfilekey) { +void logger_logchanges(struct logger *log, const char *codename, const char *name, const char *version, const char *data, const char *safefilename, const char *changesfilekey) { size_t i; - assert( name != NULL ); - assert( version != NULL ); + assert (name != NULL); + assert (version != NULL); - if( log == NULL ) + if (log == NULL) return; - for( i = 0 ; i < log->notificator_count ; i++ ) { + for (i = 0 ; i < log->notificator_count ; i++) { notificator_enqueuechanges(&log->notificators[i], codename, - name, version, data, safefilename, changesfilekey); + name, version, data, safefilename, + changesfilekey); } } @@ -1146,37 +1150,37 @@ size_t i; struct notificator *n; - for( i = 0 ; i < logger->notificator_count ; i++ ) { + for (i = 0 ; i < logger->notificator_count ; i++) { n = &logger->notificators[i]; - if( limitation_missed(n->architecture_atom, target->architecture_atom) ) + if (limitation_missed(n->architecture, target->architecture)) continue; - if( limitation_missed(n->component_atom, target->component_atom) ) + if (limitation_missed(n->component, target->component)) continue; - if( limitation_missed(n->packagetype_atom, target->packagetype_atom) ) + if (limitation_missed(n->packagetype, target->packagetype)) continue; return true; } return false; } -retvalue logger_reruninfo(struct logger *logger,struct target *target,const char *name,const char *version,const char *control,/*@null@*/const struct strlist *filekeys) { - retvalue result,r; +retvalue logger_reruninfo(struct logger *logger, struct target *target, const char *name, const char *version, const char *control, /*@null@*/const struct strlist *filekeys) { + retvalue result, r; size_t i; - assert( name != NULL ); - assert( version != NULL ); - assert( control != NULL ); + assert (name != NULL); + assert (version != NULL); + assert (control != NULL); result = RET_NOTHING; - for( i = 0 ; i < logger->notificator_count ; i++ ) { + for (i = 0 ; i < logger->notificator_count ; i++) { r = notificator_enqueue(&logger->notificators[i], target, name, version, NULL, control, NULL, filekeys, NULL, true, NULL, NULL); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } return result; } diff -Nru reprepro-4.5.0/log.h reprepro-4.6.0/log.h --- reprepro-4.5.0/log.h 2010-02-16 15:29:02.000000000 +0000 +++ reprepro-4.6.0/log.h 2011-05-05 14:42:55.000000000 +0000 @@ -14,7 +14,7 @@ /* file causing the current logger_log* run */ extern /*@null@*/ const char *causingfile; /* command causing the current logger_log* run */ -extern command_t causingcommand_atom; +extern command_t causingcommand; retvalue logger_init(struct configiterator *, /*@out@*/struct logger **); void logger_free(/*@only@*/struct logger *); @@ -22,15 +22,13 @@ retvalue logger_prepare(struct logger *logger); bool logger_isprepared(/*@null@*/const struct logger *logger); -void logger_logchanges(struct logger *,const char *codename,const char *name,const char *version,const char *data,const char *safefilename,/*@null@*/const char *changesfilekey); +void logger_logchanges(struct logger *, const char * /*codename*/, const char * /*name*/, const char * /*version*/, const char * /*data*/, const char * /*safefilename*/, /*@null@*/const char * /*changesfilekey*/); -void logger_log(struct logger *,struct target *,const char *name,/*@null@*/const char *version,/*@null@*/const char *oldversion,/*@null@*/const char *control,/*@null@*/const char *oldcontrol,/*@null@*/const struct strlist *filekeys,/*@null@*/const struct strlist *oldfilekeys, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom); +void logger_log(struct logger *, struct target *, const char * /*name*/, /*@null@*/const char * /*version*/, /*@null@*/const char */*oldversion*/, /*@null@*/const char * /*control*/, /*@null@*/const char * /*oldcontrol*/, /*@null@*/const struct strlist * /*filekeys*/, /*@null@*/const struct strlist * /*oldfilekeys*/, /*@null@*/const char * /*causingrule*/, /*@null@*/const char * /*suitefrom*/); bool logger_rerun_needs_target(const struct logger *, const struct target *); -retvalue logger_reruninfo(struct logger *,struct target *,const char *name,const char *version,const char *control,/*@null@*/const struct strlist *filekeys); +retvalue logger_reruninfo(struct logger *, struct target *, const char * /*name*/, const char * /*version*/, const char * /*control*/, /*@null@*/const struct strlist * /*filekeys*/); -/* do work that is left */ -retvalue logger_continue(struct logger *); /* wait for all jobs to finish */ void logger_wait(void); void logger_warn_waiting(void); diff -Nru reprepro-4.5.0/main.c reprepro-4.6.0/main.c --- reprepro-4.5.0/main.c 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/main.c 2011-05-05 14:42:55.000000000 +0000 @@ -39,7 +39,6 @@ #include "filecntl.h" #include "files.h" #include "filelist.h" -#include "database_p.h" #include "target.h" #include "reference.h" #include "binaries.h" @@ -73,6 +72,7 @@ #include "sourcecheck.h" #include "uploaderslist.h" #include "sizes.h" +#include "filterlist.h" #ifndef STD_BASE_DIR #define STD_BASE_DIR "." @@ -141,120 +141,112 @@ O(fast), O(x_morguedir), O(x_outdir), O(x_basedir), O(x_distdir), O(x_dbdir), O(x_listdir), O(x_confdir), O(x_logdir), O(x_methoddir), O(x_section), O(x_priority), O(x_component), O(x_architecture), O(x_packagetype), O(nothingiserror), O(nolistsdownload), O(keepunusednew), O(keepunreferenced), O(keeptemporaries), O(keepdirectories), O(askforpassphrase), O(skipold), O(export), O(waitforlock), O(spacecheckmode), O(reserveddbspace), O(reservedotherspace), O(guessgpgtty), O(verbosedatabase), O(gunzip), O(bunzip2), O(unlzma), O(unxz), O(lunzip), O(gnupghome), O(listformat), O(listmax), O(listskip), O(onlysmalldeletes); #undef O -#define CONFIGSET(variable,value) if(owner_ ## variable <= config_state) { \ +#define CONFIGSET(variable, value) if (owner_ ## variable <= config_state) { \ owner_ ## variable = config_state; \ variable = value; } -#define CONFIGGSET(variable,value) if(owner_ ## variable <= config_state) { \ +#define CONFIGGSET(variable, value) if (owner_ ## variable <= config_state) { \ owner_ ## variable = config_state; \ global.variable = value; } -#define CONFIGDUP(variable,value) if(owner_ ## variable <= config_state) { \ +#define CONFIGDUP(variable, value) if (owner_ ## variable <= config_state) { \ owner_ ## variable = config_state; \ free(variable); \ variable = strdup(value); \ - if( variable == NULL ) { \ - (void)fputs("Out of Memory!",stderr); \ + if (FAILEDTOALLOC(variable)) { \ + (void)fputs("Out of Memory!", \ + stderr); \ exit(EXIT_FAILURE); \ } } -#define y(type,name) type name -#define n(type,name) UNUSED(type dummy_ ## name) +#define y(type, name) type name +#define n(type, name) UNUSED(type dummy_ ## name) -#define ACTION_N(act,sp,args,name) static retvalue action_n_ ## act ## _ ## sp ## _ ## name ( \ - UNUSED(struct distribution *dummy2), \ - UNUSED(struct database *dummy), \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ - int argc, args(const char *,argv[])) - -#define ACTION_C(act,sp,name) static retvalue action_c_ ## act ## _ ## sp ## _ ## name ( \ - struct distribution *alldistributions, \ - UNUSED(struct database *dummy), \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ - int argc,const char *argv[]) - -#define ACTION_B(act,sp,u,name) static retvalue action_b_ ## act ## _ ## sp ## _ ## name ( \ - u(struct distribution *,alldistributions), \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ +#define ACTION_N(act, sp, args, name) static retvalue action_n_ ## act ## _ ## sp ## _ ## name ( \ + UNUSED(struct distribution *dummy2), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ + int argc, args(const char *, argv[])) + +#define ACTION_C(act, sp, name) static retvalue action_c_ ## act ## _ ## sp ## _ ## name ( \ + struct distribution *alldistributions, \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ int argc, const char *argv[]) -#define ACTION_L(act,sp,u,args,name) static retvalue action_l_ ## act ## _ ## sp ## _ ## name ( \ - struct distribution *alldistributions, \ - u(struct database *,database), \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ - int argc, args(const char *,argv[])) - -#define ACTION_R(act,sp,d,a,name) static retvalue action_r_ ## act ## _ ## sp ## _ ## name ( \ - d(struct distribution *, alldistributions), \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ +#define ACTION_B(act, sp, u, name) static retvalue action_b_ ## act ## _ ## sp ## _ ## name ( \ + u(struct distribution *, alldistributions), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ + int argc, const char *argv[]) + +#define ACTION_L(act, sp, u, args, name) static retvalue action_l_ ## act ## _ ## sp ## _ ## name ( \ + struct distribution *alldistributions, \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ + int argc, args(const char *, argv[])) + +#define ACTION_R(act, sp, d, a, name) static retvalue action_r_ ## act ## _ ## sp ## _ ## name ( \ + d(struct distribution *, alldistributions), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ a(int, argc), a(const char *, argv[])) -#define ACTION_T(act,sp,name) static retvalue action_t_ ## act ## _ ## sp ## _ ## name ( \ - UNUSED(struct distribution *ddummy), \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ +#define ACTION_T(act, sp, name) static retvalue action_t_ ## act ## _ ## sp ## _ ## name ( \ + UNUSED(struct distribution *ddummy), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ UNUSED(int argc), UNUSED(const char *dummy4[])) -#define ACTION_F(act,sp,d,a,name) static retvalue action_f_ ## act ## _ ## sp ## _ ## name ( \ - d(struct distribution *,alldistributions), \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ +#define ACTION_F(act, sp, d, a, name) static retvalue action_f_ ## act ## _ ## sp ## _ ## name ( \ + d(struct distribution *, alldistributions), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ a(int, argc), a(const char *, argv[])) -#define ACTION_RF(act,sp,u,name) static retvalue action_rf_ ## act ## _ ## sp ## _ ## name ( \ - u(struct distribution *, alldistributions), \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ +#define ACTION_RF(act, sp, u, name) static retvalue action_rf_ ## act ## _ ## sp ## _ ## name ( \ + u(struct distribution *, alldistributions), \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ u(int, argc), u(const char *, argv[])) -#define ACTION_D(act,sp,u,name) static retvalue action_d_ ## act ## _ ## sp ## _ ## name ( \ - struct distribution *alldistributions, \ - struct database *database, \ - sp(const char *, section), \ - sp(const char *, priority), \ - act(const struct atomlist *, architectures), \ - act(const struct atomlist *, components), \ - act(const struct atomlist *, packagetypes), \ - u(int,argc), u(const char *,argv[])) +#define ACTION_D(act, sp, u, name) static retvalue action_d_ ## act ## _ ## sp ## _ ## name ( \ + struct distribution *alldistributions, \ + sp(const char *, section), \ + sp(const char *, priority), \ + act(const struct atomlist *, architectures), \ + act(const struct atomlist *, components), \ + act(const struct atomlist *, packagetypes), \ + u(int, argc), u(const char *, argv[])) ACTION_N(n, n, y, printargs) { int i; - fprintf(stderr,"argc: %d\n",argc); - for( i=0 ; i < argc ; i++ ) { - fprintf(stderr,"%s\n",argv[i]); + fprintf(stderr, "argc: %d\n", argc); + for (i=0 ; i < argc ; i++) { + fprintf(stderr, "%s\n", argv[i]); } return RET_OK; } @@ -262,32 +254,36 @@ ACTION_N(n, n, n, dumpuncompressors) { enum compression c; - assert( argc == 1 ); - for( c = 0 ; c < c_COUNT ; c++ ) { - if( c == c_none ) + assert (argc == 1); + for (c = 0 ; c < c_COUNT ; c++) { + if (c == c_none) continue; printf("%s: ", uncompression_suffix[c]); - if( uncompression_builtin(c) ) { - if( extern_uncompressors[c] != NULL ) + if (uncompression_builtin(c)) { + if (extern_uncompressors[c] != NULL) printf("built-in + '%s'\n", extern_uncompressors[c]); else printf("built-in\n"); - } else if( extern_uncompressors[c] != NULL ) + } else if (extern_uncompressors[c] != NULL) printf("'%s'\n", extern_uncompressors[c]); - else switch( c ) { + else switch (c) { case c_bzip2: - printf("not supported (install bzip2 or use --bunzip2 to tell where bunzip2 is).\n"); + printf( +"not supported (install bzip2 or use --bunzip2 to tell where bunzip2 is).\n"); break; case c_lzma: - printf("not supported (install lzma or use --unlzma to tell where unlzma is).\n"); + printf( +"not supported (install lzma or use --unlzma to tell where unlzma is).\n"); break; case c_xz: - printf("not supported (install xz-utils or use --unxz to tell where unxz is).\n"); + printf( +"not supported (install xz-utils or use --unxz to tell where unxz is).\n"); break; case c_lunzip: - printf("not supported (install lzip or use --lunzip to tell where lunzip is).\n"); + printf( +"not supported (install lzip or use --lunzip to tell where lunzip is).\n"); break; default: printf("not supported\n"); @@ -298,16 +294,18 @@ ACTION_N(n, n, y, uncompress) { enum compression c; - assert( argc == 4 ); + assert (argc == 4); c = c_none + 1; - while( c < c_COUNT && strcmp(argv[1], uncompression_suffix[c]) != 0 ) + while (c < c_COUNT && strcmp(argv[1], uncompression_suffix[c]) != 0) c++; - if( c >= c_COUNT ) { + if (c >= c_COUNT) { fprintf(stderr, "Unknown compression format '%s'\n", argv[1]); return RET_ERROR; } - if( !uncompression_supported(c) ) { - fprintf(stderr, "Cannot uncompress format '%s'\nCheck __dumpuncompressors for more details.\n", argv[1]); + if (!uncompression_supported(c)) { + fprintf(stderr, +"Cannot uncompress format '%s'\nCheck __dumpuncompressors for more details.\n", + argv[1]); return RET_ERROR; } return uncompress_file(argv[2], argv[3], c); @@ -317,11 +315,11 @@ retvalue result; char *control; - assert( argc == 2 ); + assert (argc == 2); - result = extractcontrol(&control,argv[1]); + result = extractcontrol(&control, argv[1]); - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { puts(control); free(control); } @@ -336,21 +334,21 @@ const unsigned char *dirs[256]; int depth = 0, i, j; - assert( argc == 2 ); + assert (argc == 2); result = getfilelist(&filelist, &fls, argv[1]); - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { const unsigned char *p = (unsigned char*)filelist; - while( *p != '\0' ) { + while (*p != '\0') { unsigned char c = *(p++); - if( c > 2 ) { - if( depth >= c ) + if (c > 2) { + if (depth >= c) depth -= c; else depth = 0; - } else if( c == 2 ) { + } else if (c == 2) { len = 0; - while( *p == 255 ) { + while (*p == 255) { len +=255; p++; } @@ -360,20 +358,20 @@ p += len; } else { len = 0; - while( *p == 255 ) { + while (*p == 255) { len +=255; p++; } len += *(p++); (void)putchar('/'); - for( i = 0 ; i < depth ; i++ ) { + for (i = 0 ; i < depth ; i++) { const unsigned char *n = dirs[i]; j = lengths[i]; - while( j-- > 0 ) + while (j-- > 0) (void)putchar(*(n++)); (void)putchar('/'); } - while( len-- > 0 ) + while (len-- > 0) (void)putchar(*(p++)); (void)putchar('\n'); } @@ -391,56 +389,56 @@ bool broken; int i; - assert( argc == 2 ); + assert (argc == 2); r = sources_readdsc(&dsc, argv[1], argv[1], &broken); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - if( broken && !IGNORING_(brokensignatures, + if (broken && !IGNORING(brokensignatures, "'%s' contains only broken signatures.\n" "This most likely means the file was damaged or edited improperly\n", - argv[1]) ) + argv[1])) return RET_ERROR; r = dirs_getdirectory(argv[1], &directory); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { sources_done(&dsc); return r; } - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); extraction = sourceextraction_init(§ion, &priority); - if( FAILEDTOALLOC(extraction) ) { + if (FAILEDTOALLOC(extraction)) { sources_done(&dsc); return RET_ERROR_OOM; } - for( i = 0 ; i < dsc.files.names.count ; i ++ ) + for (i = 0 ; i < dsc.files.names.count ; i ++) sourceextraction_setpart(extraction, i, dsc.files.names.values[i]); result = RET_OK; - while( sourceextraction_needs(extraction, &i) ) { + while (sourceextraction_needs(extraction, &i)) { filename = calc_dirconcat(directory, dsc.files.names.values[i]); - if( FAILEDTOALLOC(filename) ) { + if (FAILEDTOALLOC(filename)) { result = RET_ERROR_OOM; break; } r = sourceextraction_analyse(extraction, filename); free(filename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } } free(directory); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { sourceextraction_abort(extraction); } else { r = sourceextraction_finish(extraction); RET_UPDATE(result, r); } - if( RET_IS_OK(result) ) { - if( section != NULL ) + if (RET_IS_OK(result)) { + if (section != NULL) printf("Section: %s\n", section); - if( priority != NULL ) + if (priority != NULL) printf("Priority: %s\n", priority); } sources_done(&dsc); @@ -450,31 +448,31 @@ } ACTION_F(n, n, n, y, fakeemptyfilelist) { - assert( argc == 2 ); - return fakefilelist(database, argv[1]); + assert (argc == 2); + return fakefilelist(argv[1]); } ACTION_F(n, n, n, y, generatefilelists) { - assert( argc == 2 || argc == 3 ); + assert (argc == 2 || argc == 3); - if( argc == 2 ) - return files_regenerate_filelist(database, false); - if( strcmp(argv[1], "reread") == 0 ) - return files_regenerate_filelist(database, true); + if (argc == 2) + return files_regenerate_filelist(false); + if (strcmp(argv[1], "reread") == 0) + return files_regenerate_filelist(true); - fprintf(stderr,"Error: Unrecognized second argument '%s'\n" + fprintf(stderr, "Error: Unrecognized second argument '%s'\n" "Syntax: reprepro generatefilelists [reread]\n", argv[1]); return RET_ERROR; } ACTION_T(n, n, translatefilelists) { - return database_translate_filelists(database); + return database_translate_filelists(); } ACTION_N(n, n, n, translatelegacychecksums) { - assert( argc == 1); + assert (argc == 1); return database_translate_legacy_checksums( verbosedatabase || verbose > 10); @@ -482,35 +480,35 @@ ACTION_F(n, n, n, n, addmd5sums) { - char buffer[2000],*c,*m; - retvalue result,r; + char buffer[2000], *c, *m; + retvalue result, r; result = RET_NOTHING; - while( fgets(buffer,1999,stdin) != NULL ) { + while (fgets(buffer, 1999, stdin) != NULL) { struct checksums *checksums; - c = strchr(buffer,'\n'); - if( c == NULL ) { - fprintf(stderr,"Line too long\n"); + c = strchr(buffer, '\n'); + if (c == NULL) { + fprintf(stderr, "Line too long\n"); return RET_ERROR; } *c = '\0'; - m = strchr(buffer,' '); - if( m == NULL ) { - fprintf(stderr,"Malformed line\n"); + m = strchr(buffer, ' '); + if (m == NULL) { + fprintf(stderr, "Malformed line\n"); return RET_ERROR; } *m = '\0'; m++; - if( *m == '\0' ) { - fprintf(stderr,"Malformed line\n"); + if (*m == '\0') { + fprintf(stderr, "Malformed line\n"); return RET_ERROR; } r = checksums_setall(&checksums, m, strlen(m)); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - r = files_add_checksums(database, buffer, checksums); - RET_UPDATE(result,r); + r = files_add_checksums(buffer, checksums); + RET_UPDATE(result, r); checksums_free(checksums); } @@ -519,49 +517,23 @@ ACTION_R(n, n, n, y, removereferences) { - assert( argc == 2 ); - return references_remove(database, argv[1]); + assert (argc == 2); + return references_remove(argv[1]); } ACTION_R(n, n, n, n, dumpreferences) { - struct cursor *cursor; - retvalue result, r; - const char *found_to, *found_by; - - r = table_newglobalcursor(database->references, &cursor); - if( !RET_IS_OK(r) ) - return r; - - result = RET_OK; - while( cursor_nexttemp(database->references, cursor, - &found_to, &found_by) ) { - if( fputs(found_by, stdout) == EOF || - putchar(' ') == EOF || - puts(found_to) == EOF ) { - result = RET_ERROR; - break; - } - result = RET_OK; - if( interrupted() ) { - result = RET_ERROR_INTERRUPTED; - break; - } - } - r = cursor_close(database->references, cursor); - RET_ENDUPDATE(result, r); - return result; + return references_dump(); } -static retvalue checkifreferenced(void *data, const char *filekey) { - struct database *database = data; +static retvalue checkifreferenced(UNUSED(void *data), const char *filekey) { retvalue r; - r = references_isused(database, filekey); - if( r == RET_NOTHING ) { - printf("%s\n",filekey); + r = references_isused(filekey); + if (r == RET_NOTHING) { + printf("%s\n", filekey); return RET_OK; - } else if( RET_IS_OK(r) ) { + } else if (RET_IS_OK(r)) { return RET_NOTHING; } else return r; @@ -570,19 +542,18 @@ ACTION_RF(n, n, n, dumpunreferenced) { retvalue result; - result = files_foreach(database, checkifreferenced, database); + result = files_foreach(checkifreferenced, NULL); return result; } -static retvalue deleteifunreferenced(void *data, const char *filekey) { - struct database *database = data; +static retvalue deleteifunreferenced(UNUSED(void *data), const char *filekey) { retvalue r; - r = references_isused(database,filekey); - if( r == RET_NOTHING ) { - r = pool_delete(database, filekey); + r = references_isused(filekey); + if (r == RET_NOTHING) { + r = pool_delete(filekey); return r; - } else if( RET_IS_OK(r) ) { + } else if (RET_IS_OK(r)) { return RET_NOTHING; } else return r; @@ -591,9 +562,10 @@ ACTION_RF(n, n, n, deleteunreferenced) { retvalue result; - if( keepunreferenced ) { - if( owner_keepunreferenced == CONFIG_OWNER_CMDLINE ) - fprintf(stderr,"Calling deleteunreferenced with --keepunreferencedfiles does not really make sense, does it?\n"); + if (keepunreferenced) { + if (owner_keepunreferenced == CONFIG_OWNER_CMDLINE) + fprintf(stderr, +"Calling deleteunreferenced with --keepunreferencedfiles does not really make sense, does it?\n"); else fprintf(stderr, "Error: deleteunreferenced called with option\n" @@ -602,36 +574,36 @@ "if you are sure you want to delete those files.\n"); return RET_ERROR; } - result = files_foreach(database, deleteifunreferenced, database); + result = files_foreach(deleteifunreferenced, NULL); return result; } ACTION_R(n, n, n, y, addreference) { - assert( argc == 2 || argc == 3 ); - return references_increment(database, argv[1], argv[2]); + assert (argc == 2 || argc == 3); + return references_increment(argv[1], argv[2]); } -static retvalue remove_from_target(struct database *db, struct distribution *distribution, struct trackingdata *trackingdata, struct target *target, int count, const char * const *names, int *todo, bool *gotremoved) { - retvalue result,r; +static retvalue remove_from_target(struct distribution *distribution, struct trackingdata *trackingdata, struct target *target, int count, const char * const *names, int *todo, bool *gotremoved) { + retvalue result, r; int i; result = RET_NOTHING; - for( i = 0 ; i < count ; i++ ){ - r = target_removepackage(target, distribution->logger, db, + for (i = 0 ; i < count ; i++){ + r = target_removepackage(target, distribution->logger, names[i], trackingdata); RET_UPDATE(distribution->status, r); - if( RET_IS_OK(r) ) { - if( !gotremoved[i] ) + if (RET_IS_OK(r)) { + if (!gotremoved[i]) (*todo)--; gotremoved[i] = true; } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } return result; } ACTION_D(y, n, y, remove) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; struct target *t; bool *gotremoved; @@ -641,81 +613,83 @@ struct trackingdata trackingdata; r = distribution_get(alldistributions, argv[1], true, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( distribution->readonly ) { - fprintf(stderr, "Cannot remove packages from read-only distribution '%s'\n", + if (distribution->readonly) { + fprintf(stderr, +"Cannot remove packages from read-only distribution '%s'\n", distribution->codename); return RET_ERROR; } r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( distribution->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(r) ) { + if (distribution->tracking != dt_NONE) { + r = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(r)) { return r; } - r = trackingdata_new(tracks,&trackingdata); - if( RET_WAS_ERROR(r) ) { + r = trackingdata_new(tracks, &trackingdata); + if (RET_WAS_ERROR(r)) { (void)tracking_done(tracks); return r; } } todo = argc-2; - gotremoved = calloc(argc-2, sizeof(*gotremoved)); + gotremoved = nzNEW(argc - 2, bool); result = RET_NOTHING; - if( FAILEDTOALLOC(gotremoved) ) + if (FAILEDTOALLOC(gotremoved)) result = RET_ERROR_OOM; - else for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, components, architectures, packagetypes) ) + else for (t = distribution->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, components, architectures, packagetypes)) continue; - r = target_initpackagesdb(t, database, READWRITE); + r = target_initpackagesdb(t, READWRITE); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; - r = remove_from_target(database, - distribution, - (distribution->tracking != dt_NONE)?&trackingdata:NULL, + r = remove_from_target(distribution, + (distribution->tracking != dt_NONE) + ? &trackingdata + : NULL, t, argc-2, argv+2, &todo, gotremoved); RET_UPDATE(result, r); r = target_closepackagesdb(t); RET_UPDATE(distribution->status, r); RET_UPDATE(result, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } logger_wait(); - r = distribution_export(export, distribution, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, distribution); + RET_ENDUPDATE(result, r); - if( distribution->tracking != dt_NONE ) { - if( RET_WAS_ERROR(result) ) + if (distribution->tracking != dt_NONE) { + if (RET_WAS_ERROR(result)) trackingdata_done(&trackingdata); else - trackingdata_finish(tracks, &trackingdata, database); + trackingdata_finish(tracks, &trackingdata); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); } - if( verbose >= 0 && !RET_WAS_ERROR(result) && todo > 0 ) { + if (verbose >= 0 && !RET_WAS_ERROR(result) && todo > 0) { int i = argc - 2; (void)fputs("Not removed as not found: ", stderr); - while( i > 0 ) { + while (i > 0) { i--; assert(gotremoved != NULL); - if( !gotremoved[i] ) { + if (!gotremoved[i]) { (void)fputs(argv[2 + i], stderr); todo--; - if( todo > 0 ) + if (todo > 0) (void)fputs(", ", stderr); } } @@ -731,26 +705,26 @@ bool found; }; -static retvalue package_source_fits(UNUSED(struct database *da), UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { +static retvalue package_source_fits(UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { struct removesrcdata *d = data; char *sourcename, *sourceversion; retvalue r; r = target->getsourceandversion(control, packagename, &sourcename, &sourceversion); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - for( ; d->sourcename != NULL ; d++ ) { - if( strcmp(sourcename, d->sourcename) != 0 ) + for (; d->sourcename != NULL ; d++) { + if (strcmp(sourcename, d->sourcename) != 0) continue; - if( d->sourceversion == NULL ) + if (d->sourceversion == NULL) break; - if( strcmp(sourceversion, d->sourceversion) == 0 ) + if (strcmp(sourceversion, d->sourceversion) == 0) break; } free(sourcename); free(sourceversion); - if( d->sourcename == NULL ) + if (d->sourcename == NULL) return RET_NOTHING; else { d->found = true; @@ -758,35 +732,34 @@ } } -static retvalue remove_packages(struct database *database, struct distribution *distribution, struct removesrcdata *toremove) { +static retvalue remove_packages(struct distribution *distribution, struct removesrcdata *toremove) { trackingdb tracks; retvalue result, r; r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( distribution->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(r) ) { + if (distribution->tracking != dt_NONE) { + r = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(r)) { return r; } - if( r == RET_NOTHING ) + if (r == RET_NOTHING) tracks = NULL; } else tracks = NULL; result = RET_NOTHING; - if( tracks != NULL ) { + if (tracks != NULL) { result = RET_NOTHING; - for( ; toremove->sourcename != NULL ; toremove++ ) { - r = tracking_removepackages(tracks, database, - distribution, + for (; toremove->sourcename != NULL ; toremove++) { + r = tracking_removepackages(tracks, distribution, toremove->sourcename, toremove->sourceversion); RET_UPDATE(result, r); - if( r == RET_NOTHING ) { - if( verbose >= -2 ) { - if( toremove->sourceversion == NULL ) + if (r == RET_NOTHING) { + if (verbose >= -2) { + if (toremove->sourceversion == NULL) fprintf(stderr, "Nothing about source package '%s' found in the tracking data of '%s'!\n" "This either means nothing from this source in this version is there,\n" @@ -804,20 +777,20 @@ } } } - if( RET_IS_OK(result) ) { - r = distribution_export(export, distribution, database); + if (RET_IS_OK(result)) { + r = distribution_export(export, distribution); RET_ENDUPDATE(result, r); } r = tracking_done(tracks); RET_ENDUPDATE(result, r); return result; } - result = distribution_remove_packages(distribution, database, + result = distribution_remove_packages(distribution, // TODO: why not arch comp pt here? atom_unknown, atom_unknown, atom_unknown, package_source_fits, NULL, toremove); - r = distribution_export(export, distribution, database); + r = distribution_export(export, distribution); RET_ENDUPDATE(result, r); return result; } @@ -828,28 +801,32 @@ struct removesrcdata data[2]; r = distribution_get(alldistributions, argv[1], true, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( distribution->readonly ) { - fprintf(stderr, "Error: Cannot remove packages from read-only distribution '%s'\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: Cannot remove packages from read-only distribution '%s'\n", distribution->codename); return RET_ERROR; } data[0].found = false; data[0].sourcename = argv[2]; - if( argc <= 3 ) + if (argc <= 3) data[0].sourceversion = NULL; else data[0].sourceversion = argv[3]; - if( index(data[0].sourcename, '=') != NULL && verbose >= 0 ) { - fputs("Warning: removesrc treats '=' as normal character. Did you want to use removesrcs?\n", stderr); + if (index(data[0].sourcename, '=') != NULL && verbose >= 0) { + fputs( +"Warning: removesrc treats '=' as normal character.\n" +"Did you want to use removesrcs?\n", + stderr); } data[1].sourcename = NULL; data[1].sourceversion = NULL; - return remove_packages(database, distribution, data); + return remove_packages(distribution, data); } ACTION_D(n, n, y, removesrcs) { @@ -859,32 +836,36 @@ int i; r = distribution_get(alldistributions, argv[1], true, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( distribution->readonly ) { - fprintf(stderr, "Error: Cannot remove packages from read-only distribution '%s'\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: Cannot remove packages from read-only distribution '%s'\n", distribution->codename); return RET_ERROR; } - for( i = 0 ; i < argc-2 ; i++ ) { + for (i = 0 ; i < argc-2 ; i++) { data[i].found = false; data[i].sourcename = argv[2 + i]; data[i].sourceversion = index(data[i].sourcename, '='); - if( data[i].sourceversion != NULL ) { - if( index(data[i].sourceversion+1, '=') != NULL ) { - fprintf(stderr, "Cannot parse '%s': more than one '='\n", + if (data[i].sourceversion != NULL) { + if (index(data[i].sourceversion+1, '=') != NULL) { + fprintf(stderr, +"Cannot parse '%s': more than one '='\n", data[i].sourcename); data[i].sourcename = NULL; r = RET_ERROR; - } else if( data[i].sourceversion[1] == '\0' ) { - fprintf(stderr, "Cannot parse '%s': no version after '='\n", + } else if (data[i].sourceversion[1] == '\0') { + fprintf(stderr, +"Cannot parse '%s': no version after '='\n", data[i].sourcename); data[i].sourcename = NULL; r = RET_ERROR; - } else if( data[i].sourceversion == data[i].sourcename ) { - fprintf(stderr, "Cannot parse '%s': no source name found before the '='\n", + } else if (data[i].sourceversion == data[i].sourcename) { + fprintf(stderr, +"Cannot parse '%s': no source name found before the '='\n", data[i].sourcename); data[i].sourcename = NULL; r = RET_ERROR; @@ -892,14 +873,14 @@ data[i].sourcename = strndup(data[i].sourcename, data[i].sourceversion - data[i].sourcename); - if( data[i].sourcename == NULL ) + if (FAILEDTOALLOC(data[i].sourcename)) r = RET_ERROR_OOM; else r = RET_OK; } - if( RET_WAS_ERROR(r) ) { - for( i-- ; i >= 0 ; i-- ) { - if( data[i].sourceversion != NULL ) + if (RET_WAS_ERROR(r)) { + for (i-- ; i >= 0 ; i--) { + if (data[i].sourceversion != NULL) free((char*)data[i].sourcename); } return r; @@ -909,24 +890,26 @@ } data[i].sourcename = NULL; data[i].sourceversion= NULL; - r = remove_packages(database, distribution, data); - for( i = 0 ; i < argc-2 ; i++ ) { - if( verbose >= 0 && !data[i].found ) { - if( data[i].sourceversion != NULL ) - fprintf(stderr, "No package from source '%s', version '%s' found.\n", + r = remove_packages(distribution, data); + for (i = 0 ; i < argc-2 ; i++) { + if (verbose >= 0 && !data[i].found) { + if (data[i].sourceversion != NULL) + fprintf(stderr, +"No package from source '%s', version '%s' found.\n", data[i].sourcename, data[i].sourceversion); else - fprintf(stderr, "No package from source '%s' (any version) found.\n", + fprintf(stderr, +"No package from source '%s' (any version) found.\n", data[i].sourcename); } - if( data[i].sourceversion != NULL ) + if (data[i].sourceversion != NULL) free((char*)data[i].sourcename); } return r; } -static retvalue package_matches_condition(UNUSED(struct database *da), UNUSED(struct distribution *di), struct target *target, UNUSED(const char *pa), const char *control, void *data) { +static retvalue package_matches_condition(UNUSED(struct distribution *di), struct target *target, UNUSED(const char *pa), const char *control, void *data) { term *condition = data; return term_decidechunktarget(condition, control, target); @@ -939,40 +922,41 @@ struct trackingdata trackingdata; term *condition; - assert( argc == 3 ); + assert (argc == 3); r = distribution_get(alldistributions, argv[1], true, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( distribution->readonly ) { - fprintf(stderr, "Error: Cannot remove packages from read-only distribution '%s'\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: Cannot remove packages from read-only distribution '%s'\n", distribution->codename); return RET_ERROR; } result = term_compilefortargetdecision(&condition, argv[2]); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { term_free(condition); return r; } - if( distribution->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(r) ) { + if (distribution->tracking != dt_NONE) { + r = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(r)) { term_free(condition); return r; } - if( r == RET_NOTHING ) + if (r == RET_NOTHING) tracks = NULL; else { r = trackingdata_new(tracks, &trackingdata); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)tracking_done(tracks); term_free(condition); return r; @@ -981,24 +965,24 @@ } else tracks = NULL; - result = distribution_remove_packages(distribution, database, + result = distribution_remove_packages(distribution, components, architectures, packagetypes, package_matches_condition, (tracks != NULL)?&trackingdata:NULL, condition); - r = distribution_export(export, distribution, database); + r = distribution_export(export, distribution); RET_ENDUPDATE(result, r); - if( tracks != NULL ) { - trackingdata_finish(tracks, &trackingdata, database); + if (tracks != NULL) { + trackingdata_finish(tracks, &trackingdata); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); } term_free(condition); return result; } -static retvalue package_matches_glob(UNUSED(struct database *da), UNUSED(struct distribution *di), UNUSED(struct target *ta), const char *packagename, UNUSED(const char *control), void *data) { - if( globmatch(packagename, data) ) +static retvalue package_matches_glob(UNUSED(struct distribution *di), UNUSED(struct target *ta), const char *packagename, UNUSED(const char *control), void *data) { + if (globmatch(packagename, data)) return RET_OK; else return RET_NOTHING; @@ -1010,32 +994,33 @@ trackingdb tracks; struct trackingdata trackingdata; - assert( argc == 3 ); + assert (argc == 3); r = distribution_get(alldistributions, argv[1], true, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( distribution->readonly ) { - fprintf(stderr, "Error: Cannot remove packages from read-only distribution '%s'\n", + if (distribution->readonly) { + fprintf(stderr, +"Error: Cannot remove packages from read-only distribution '%s'\n", distribution->codename); return RET_ERROR; } r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( distribution->tracking != dt_NONE ) { - r = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(r) ) + if (distribution->tracking != dt_NONE) { + r = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) tracks = NULL; else { r = trackingdata_new(tracks, &trackingdata); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)tracking_done(tracks); return r; } @@ -1043,17 +1028,17 @@ } else tracks = NULL; - result = distribution_remove_packages(distribution, database, + result = distribution_remove_packages(distribution, components, architectures, packagetypes, package_matches_glob, (tracks != NULL)?&trackingdata:NULL, (void*)argv[2]); - r = distribution_export(export, distribution, database); + r = distribution_export(export, distribution); RET_ENDUPDATE(result, r); - if( tracks != NULL ) { - trackingdata_finish(tracks, &trackingdata, database); + if (tracks != NULL) { + trackingdata_finish(tracks, &trackingdata); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); } return result; } @@ -1064,43 +1049,45 @@ const char *glob; architecture_t arch; - if( architectures != NULL ) { - fprintf(stderr, "Error: build-needing cannot be used with --architecture!\n"); + if (architectures != NULL) { + fprintf(stderr, +"Error: build-needing cannot be used with --architecture!\n"); return RET_ERROR; } - if( packagetypes != NULL ) { - fprintf(stderr, "Error: build-needing cannot be used with --packagetype!\n"); + if (packagetypes != NULL) { + fprintf(stderr, +"Error: build-needing cannot be used with --packagetype!\n"); return RET_ERROR; } - if( argc == 4 ) + if (argc == 4) glob = argv[3]; else glob = NULL; arch = architecture_find(argv[2]); - if( !atom_defined(arch) ) { + if (!atom_defined(arch)) { fprintf(stderr, "Error: Architecture '%s' is not known!\n", argv[2]); return RET_ERROR; } - if( arch == architecture_source || arch == architecture_all ) { + if (arch == architecture_source || arch == architecture_all) { fprintf(stderr, "Error: Architecture '%s' makes no sense for build-needing!\n", argv[2]); return RET_ERROR; } r = distribution_get(alldistributions, argv[1], false, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( !atomlist_in(&distribution->architectures, architecture_source) ) { + if (!atomlist_in(&distribution->architectures, architecture_source)) { fprintf(stderr, "Error: Architecture '%s' does not contain sources. build-needing cannot be used!\n", distribution->codename); return RET_ERROR; } - if( !atomlist_in(&distribution->architectures, arch) ) { + if (!atomlist_in(&distribution->architectures, arch)) { fprintf(stderr, "Error: Architecture '%s' not found in distribution '%s'!\n", argv[2], distribution->codename); @@ -1108,28 +1095,27 @@ } - return find_needs_build(database, distribution, arch, components, - glob); + return find_needs_build(distribution, arch, components, glob); } -static retvalue list_in_target(struct database *database, struct target *target, const char *packagename) { - retvalue r,result; +static retvalue list_in_target(struct target *target, const char *packagename) { + retvalue r, result; char *control; - if( listmax == 0 ) + if (listmax == 0) return RET_NOTHING; - r = target_initpackagesdb(target, database, READONLY); - if( !RET_IS_OK(r) ) + r = target_initpackagesdb(target, READONLY); + if (!RET_IS_OK(r)) return r; result = table_getrecord(target->packages, packagename, &control); - if( RET_IS_OK(result) ) { - if( listskip <= 0 ) { + if (RET_IS_OK(result)) { + if (listskip <= 0) { r = listformat_print(listformat, target, packagename, control); RET_UPDATE(result, r); - if( listmax > 0 ) + if (listmax > 0) listmax--; } else listskip--; @@ -1140,12 +1126,12 @@ return result; } -static retvalue list_package(UNUSED(struct database *dummy1), UNUSED(struct distribution *dummy2), struct target *target, const char *package, const char *control, UNUSED(void *dummy3)) { - if( listmax == 0 ) +static retvalue list_package(UNUSED(struct distribution *dummy2), struct target *target, const char *package, const char *control, UNUSED(void *dummy3)) { + if (listmax == 0) return RET_NOTHING; - if( listskip <= 0 ) { - if( listmax > 0 ) + if (listskip <= 0) { + if (listmax > 0) listmax--; return listformat_print(listformat, target, package, control); } else { @@ -1159,22 +1145,22 @@ struct distribution *distribution; struct target *t; - assert( argc >= 2 ); + assert (argc >= 2); r = distribution_get(alldistributions, argv[1], false, &distribution); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( argc == 2 ) - return distribution_foreach_package(distribution, database, + if (argc == 2) + return distribution_foreach_package(distribution, components, architectures, packagetypes, list_package, NULL, NULL); - else for( t = distribution->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, components, architectures, packagetypes) ) + else for (t = distribution->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, components, architectures, packagetypes)) continue; - r = list_in_target(database, t, argv[2]); - if( RET_WAS_ERROR(r) ) + r = list_in_target(t, argv[2]); + if (RET_WAS_ERROR(r)) return r; RET_UPDATE(result, r); } @@ -1190,33 +1176,34 @@ static retvalue newlsversion(struct lsversion **versions_p, /*@only@*/char *version, architecture_t architecture) { struct lsversion *v, **v_p; - for( v_p = versions_p ; (v = *v_p) != NULL ; v_p = &v->next ) { - if( strcmp(v->version, version) != 0 ) + for (v_p = versions_p ; (v = *v_p) != NULL ; v_p = &v->next) { + if (strcmp(v->version, version) != 0) continue; free(version); return atomlist_add_uniq(&v->architectures, architecture); } - v = calloc(1, sizeof(struct lsversion)); - if( FAILEDTOALLOC(v) ) + v = zNEW(struct lsversion); + if (FAILEDTOALLOC(v)) return RET_ERROR_OOM; *v_p = v; v->version = version; return atomlist_add(&v->architectures, architecture); } -static retvalue ls_in_target(struct database *database, struct target *target, const char *packagename, struct lsversion **versions_p) { - retvalue r,result; - char *control,*version; +static retvalue ls_in_target(struct target *target, const char *packagename, struct lsversion **versions_p) { + retvalue r, result; + char *control, *version; - r = target_initpackagesdb(target, database, READONLY); - if( !RET_IS_OK(r) ) + r = target_initpackagesdb(target, READONLY); + if (!RET_IS_OK(r)) return r; result = table_getrecord(target->packages, packagename, &control); - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { r = target->getversion(control, &version); - if( RET_IS_OK(r) ) - r = newlsversion(versions_p, version, target->architecture_atom); + if (RET_IS_OK(r)) + r = newlsversion(versions_p, version, + target->architecture); free(control); RET_UPDATE(result, r); } @@ -1231,35 +1218,36 @@ struct target *t; size_t maxcodenamelen; - assert( argc == 2 ); + assert (argc == 2); maxcodenamelen = 1; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { size_t l = strlen(d->codename); - if( l > maxcodenamelen ) + if (l > maxcodenamelen) maxcodenamelen = l; } - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { struct lsversion *versions = NULL, *v; size_t maxversionlen; int i; - for( t = d->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, components, architectures, packagetypes) ) + for (t = d->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, components, architectures, + packagetypes)) continue; - r = ls_in_target(database, t, argv[1], &versions); - if( RET_WAS_ERROR(r) ) + r = ls_in_target(t, argv[1], &versions); + if (RET_WAS_ERROR(r)) return r; } maxversionlen = 1; - for( v = versions ; v != NULL ; v = v->next ) { + for (v = versions ; v != NULL ; v = v->next) { size_t l = strlen(v->version); - if( l > maxversionlen ) + if (l > maxversionlen) maxversionlen = l; } - while( versions != NULL ) { + while (versions != NULL) { architecture_t a; v = versions; @@ -1271,7 +1259,7 @@ v->version, (int)maxcodenamelen, d->codename); - for( i = 0 ; i + 1 < v->architectures.count ; i++ ) { + for (i = 0 ; i + 1 < v->architectures.count ; i++) { a = v->architectures.atoms[i]; printf("%s, ", atoms_architectures[a]); } @@ -1287,17 +1275,17 @@ } -static retvalue listfilterprint(UNUSED(struct database *da), UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { +static retvalue listfilterprint(UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { term *condition = data; retvalue r; - if( listmax == 0 ) + if (listmax == 0) return RET_NOTHING; r = term_decidechunktarget(condition, control, target); - if( RET_IS_OK(r) ) { - if( listskip <= 0 ) { - if( listmax > 0 ) + if (RET_IS_OK(r)) { + if (listskip <= 0) { + if (listmax > 0) listmax--; r = listformat_print(listformat, target, packagename, control); @@ -1310,38 +1298,38 @@ } ACTION_B(y, n, y, listfilter) { - retvalue r,result; + retvalue r, result; struct distribution *distribution; term *condition; - assert( argc == 3 ); + assert (argc == 3); r = distribution_get(alldistributions, argv[1], false, &distribution); - assert( r != RET_NOTHING); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { return r; } result = term_compilefortargetdecision(&condition, argv[2]); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - result = distribution_foreach_package(distribution, database, + result = distribution_foreach_package(distribution, components, architectures, packagetypes, listfilterprint, NULL, condition); term_free(condition); return result; } -static retvalue listmatchprint(UNUSED(struct database *da), UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { +static retvalue listmatchprint(UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *control, void *data) { const char *glob = data; - if( listmax == 0 ) + if (listmax == 0) return RET_NOTHING; - if( globmatch(packagename, glob) ) { - if( listskip <= 0 ) { - if( listmax > 0 ) + if (globmatch(packagename, glob)) { + if (listskip <= 0) { + if (listmax > 0) listmax--; return listformat_print(listformat, target, packagename, control); @@ -1354,134 +1342,135 @@ } ACTION_B(y, n, y, listmatched) { - retvalue r,result; + retvalue r, result; struct distribution *distribution; - assert( argc == 3 ); + assert (argc == 3); r = distribution_get(alldistributions, argv[1], false, &distribution); - assert( r != RET_NOTHING); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { return r; } - result = distribution_foreach_package(distribution, database, + result = distribution_foreach_package(distribution, components, architectures, packagetypes, listmatchprint, NULL, (void*)argv[2]); return result; } ACTION_F(n, n, n, y, detect) { - char buffer[5000],*nl; + char buffer[5000], *nl; int i; - retvalue r,ret; + retvalue r, ret; ret = RET_NOTHING; - if( argc > 1 ) { - for( i = 1 ; i < argc ; i++ ) { - r = files_detect(database,argv[i]); - RET_UPDATE(ret,r); + if (argc > 1) { + for (i = 1 ; i < argc ; i++) { + r = files_detect(argv[i]); + RET_UPDATE(ret, r); } } else - while( fgets(buffer,4999,stdin) != NULL ) { - nl = strchr(buffer,'\n'); - if( nl == NULL ) { + while (fgets(buffer, 4999, stdin) != NULL) { + nl = strchr(buffer, '\n'); + if (nl == NULL) { return RET_ERROR; } *nl = '\0'; - r = files_detect(database,buffer); - RET_UPDATE(ret,r); + r = files_detect(buffer); + RET_UPDATE(ret, r); } return ret; } ACTION_F(n, n, n, y, forget) { - char buffer[5000],*nl; + char buffer[5000], *nl; int i; - retvalue r,ret; + retvalue r, ret; ret = RET_NOTHING; - if( argc > 1 ) { - for( i = 1 ; i < argc ; i++ ) { - r = files_remove(database, argv[i]); - RET_UPDATE(ret,r); + if (argc > 1) { + for (i = 1 ; i < argc ; i++) { + r = files_remove(argv[i]); + RET_UPDATE(ret, r); } } else - while( fgets(buffer,4999,stdin) != NULL ) { - nl = strchr(buffer,'\n'); - if( nl == NULL ) { + while (fgets(buffer, 4999, stdin) != NULL) { + nl = strchr(buffer, '\n'); + if (nl == NULL) { return RET_ERROR; } *nl = '\0'; - r = files_remove(database, buffer); - RET_UPDATE(ret,r); + r = files_remove(buffer); + RET_UPDATE(ret, r); } return ret; } ACTION_F(n, n, n, n, listmd5sums) { - return files_printmd5sums(database); + return files_printmd5sums(); } ACTION_F(n, n, n, n, listchecksums) { - return files_printchecksums(database); + return files_printchecksums(); } ACTION_B(n, n, n, dumpcontents) { - retvalue result,r; + retvalue result, r; struct table *packages; const char *package, *chunk; struct cursor *cursor; - assert( argc == 2 ); + assert (argc == 2); - result = database_openpackages(database, argv[1], true, &packages); - if( RET_WAS_ERROR(result) ) + result = database_openpackages(argv[1], true, &packages); + if (RET_WAS_ERROR(result)) return result; r = table_newglobalcursor(packages, &cursor); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { (void)table_close(packages); return r; } result = RET_NOTHING; - while( cursor_nexttemp(packages, cursor, &package, &chunk) ) { + while (cursor_nexttemp(packages, cursor, &package, &chunk)) { printf("'%s' -> '%s'\n", package, chunk); result = RET_OK; } r = cursor_close(packages, cursor); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); r = table_close(packages); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } ACTION_F(n, n, y, y, export) { - retvalue result,r; + retvalue result, r; struct distribution *d; - if( export == EXPORT_NEVER ) { - fprintf(stderr, "Error: reprepro export incompatible with --export=never\n"); + if (export == EXPORT_NEVER || export == EXPORT_SILENT_NEVER) { + fprintf(stderr, +"Error: reprepro export incompatible with --export=never\n"); return RET_ERROR; } result = distribution_match(alldistributions, argc-1, argv+1, true, READWRITE); - assert( result != RET_NOTHING); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( verbose > 0 ) { - printf("Exporting %s...\n",d->codename); + if (verbose > 0) { + printf("Exporting %s...\n", d->codename); } - r = distribution_fullexport(d, database); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) && export != EXPORT_FORCE) { + r = distribution_fullexport(d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r) && export != EXPORT_FORCE) { return r; } } @@ -1491,93 +1480,101 @@ /***********************update********************************/ ACTION_D(n, n, y, update) { - retvalue result,r; + retvalue result, r; struct update_pattern *patterns; struct update_distribution *u_distributions; result = dirs_make_recursive(global.listdir); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = distribution_match(alldistributions, argc-1, argv+1, true, READWRITE); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = updates_getpatterns(&patterns); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); result = updates_calcindices(patterns, alldistributions, &u_distributions); - if( !RET_IS_OK(result) ) { - if( result == RET_NOTHING ) { - if( argc == 1 ) - fputs("Nothing to do, because no distribution has an Update: field.\n", stderr); + if (!RET_IS_OK(result)) { + if (result == RET_NOTHING) { + if (argc == 1) + fputs( +"Nothing to do, because no distribution has an Update: field.\n", stderr); else - fputs("Nothing to do, because none of the selected distributions has an Update: field.\n", stderr); + fputs( +"Nothing to do, because none of the selected distributions has an Update: field.\n", + stderr); } updates_freepatterns(patterns); return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); - if( !RET_WAS_ERROR(result) ) - result = updates_update(database, u_distributions, + if (!RET_WAS_ERROR(result)) + result = updates_update(u_distributions, nolistsdownload, skipold, - spacecheckmode, reserveddbspace, reservedotherspace); + spacecheckmode, reserveddbspace, + reservedotherspace); updates_freeupdatedistributions(u_distributions); updates_freepatterns(patterns); - r = distribution_exportlist(export, alldistributions, database); - RET_ENDUPDATE(result,r); + r = distribution_exportlist(export, alldistributions); + RET_ENDUPDATE(result, r); return result; } ACTION_D(n, n, y, predelete) { - retvalue result,r; + retvalue result, r; struct update_pattern *patterns; struct update_distribution *u_distributions; result = dirs_make_recursive(global.listdir); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = distribution_match(alldistributions, argc-1, argv+1, true, READWRITE); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = updates_getpatterns(&patterns); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); result = updates_calcindices(patterns, alldistributions, &u_distributions); - if( !RET_IS_OK(result) ) { - if( result == RET_NOTHING ) { - if( argc == 1 ) - fputs("Nothing to do, because no distribution has an Update: field.\n", stderr); + if (!RET_IS_OK(result)) { + if (result == RET_NOTHING) { + if (argc == 1) + fputs( +"Nothing to do, because no distribution has an Update: field.\n", stderr); else - fputs("Nothing to do, because none of the selected distributions has an Update: field.\n", stderr); + fputs( +"Nothing to do, because none of the selected distributions has an Update: field.\n", + stderr); } updates_freepatterns(patterns); return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); - if( !RET_WAS_ERROR(result) ) - result = updates_predelete(database, u_distributions, nolistsdownload, skipold); + if (!RET_WAS_ERROR(result)) + result = updates_predelete(u_distributions, + nolistsdownload, skipold); updates_freeupdatedistributions(u_distributions); updates_freepatterns(patterns); - r = distribution_exportlist(export, alldistributions, database); + r = distribution_exportlist(export, alldistributions); RET_ENDUPDATE(result, r); return result; @@ -1589,34 +1586,37 @@ struct update_distribution *u_distributions; result = dirs_make_recursive(global.listdir); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = updates_getpatterns(&patterns); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = updates_calcindices(patterns, alldistributions, &u_distributions); - if( !RET_IS_OK(result) ) { - if( result == RET_NOTHING ) { - if( argc == 1 ) - fputs("Nothing to do, because no distribution has an Updates: field.\n", stderr); + if (!RET_IS_OK(result)) { + if (result == RET_NOTHING) { + if (argc == 1) + fputs( +"Nothing to do, because no distribution has an Updates: field.\n", stderr); else - fputs("Nothing to do, because none of the selected distributions has an Update: field.\n", stderr); + fputs( +"Nothing to do, because none of the selected distributions has an Update: field.\n", + stderr); } updates_freepatterns(patterns); return result; } - result = updates_checkupdate(database, u_distributions, + result = updates_checkupdate(u_distributions, nolistsdownload, skipold); updates_freeupdatedistributions(u_distributions); @@ -1631,34 +1631,37 @@ struct update_distribution *u_distributions; result = dirs_make_recursive(global.listdir); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = updates_getpatterns(&patterns); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = updates_calcindices(patterns, alldistributions, &u_distributions); - if( !RET_IS_OK(result) ) { - if( result == RET_NOTHING ) { - if( argc == 1 ) - fputs("Nothing to do, because no distribution has an Updates: field.\n", stderr); + if (!RET_IS_OK(result)) { + if (result == RET_NOTHING) { + if (argc == 1) + fputs( +"Nothing to do, because no distribution has an Updates: field.\n", stderr); else - fputs("Nothing to do, because none of the selected distributions has an Update: field.\n", stderr); + fputs( +"Nothing to do, because none of the selected distributions has an Update: field.\n", + stderr); } updates_freepatterns(patterns); return result; } - result = updates_dumpupdate(database, u_distributions, + result = updates_dumpupdate(u_distributions, nolistsdownload, skipold); updates_freeupdatedistributions(u_distributions); @@ -1671,13 +1674,13 @@ retvalue result; struct update_pattern *patterns; - assert( argc == 1 ); + assert (argc == 1); - if( !isdirectory(global.listdir) ) + if (!isdirectory(global.listdir)) return RET_NOTHING; result = updates_getpatterns(&patterns); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; result = updates_cleanlists(alldistributions, patterns); @@ -1688,34 +1691,34 @@ /***********************migrate*******************************/ ACTION_D(n, n, y, pull) { - retvalue result,r; + retvalue result, r; struct pull_rule *rules; struct pull_distribution *p; result = distribution_match(alldistributions, argc-1, argv+1, true, READWRITE); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = pull_getrules(&rules); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); result = pull_prepare(alldistributions, rules, fast, &p); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { pull_freerules(rules); return result; } - result = pull_update(database, p); + result = pull_update(p); pull_freerules(rules); pull_freedistributions(p); - r = distribution_exportlist(export, alldistributions, database); - RET_ENDUPDATE(result,r); + r = distribution_exportlist(export, alldistributions); + RET_ENDUPDATE(result, r); return result; } @@ -1727,22 +1730,22 @@ result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = pull_getrules(&rules); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); result = pull_prepare(alldistributions, rules, fast, &p); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { pull_freerules(rules); return result; } - result = pull_checkupdate(database, p); + result = pull_checkupdate(p); pull_freerules(rules); pull_freedistributions(p); @@ -1757,22 +1760,22 @@ result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = pull_getrules(&rules); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - assert( RET_IS_OK(result) ); + assert (RET_IS_OK(result)); result = pull_prepare(alldistributions, rules, fast, &p); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { pull_freerules(rules); return result; } - result = pull_dumpupdate(database, p); + result = pull_dumpupdate(p); pull_freerules(rules); pull_freedistributions(p); @@ -1785,31 +1788,32 @@ retvalue result, r; result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = distribution_get(alldistributions, argv[2], false, &source); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = copy_by_name(database, destination, source, argc-3, argv+3, + r = copy_by_name(destination, source, argc-3, argv+3, components, architectures, packagetypes); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; @@ -1820,30 +1824,31 @@ retvalue result, r; result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = distribution_get(alldistributions, argv[2], false, &source); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = copy_by_source(database, destination, source, argc-3, argv+3, + r = copy_by_source(destination, source, argc-3, argv+3, components, architectures, packagetypes); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -1852,33 +1857,34 @@ struct distribution *destination, *source; retvalue result, r; - assert( argc == 4 ); + assert (argc == 4); result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = distribution_get(alldistributions, argv[2], false, &source); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = copy_by_formula(database, destination, source, argv[3], + r = copy_by_formula(destination, source, argv[3], components, architectures, packagetypes); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -1887,33 +1893,34 @@ struct distribution *destination, *source; retvalue result, r; - assert( argc == 4 ); + assert (argc == 4); result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = distribution_get(alldistributions, argv[2], false, &source); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = copy_by_glob(database, destination, source, argv[3], + r = copy_by_glob(destination, source, argv[3], components, architectures, packagetypes); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -1923,27 +1930,28 @@ retvalue result, r; result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = restore_by_name(database, destination, + r = restore_by_name(destination, components, architectures, packagetypes, argv[2], argc-3, argv+3); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; @@ -1954,27 +1962,28 @@ retvalue result, r; result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = restore_by_source(database, destination, + r = restore_by_source(destination, components, architectures, packagetypes, argv[2], argc-3, argv+3); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -1983,30 +1992,31 @@ struct distribution *destination; retvalue result, r; - assert( argc == 4 ); + assert (argc == 4); result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = restore_by_glob(database, destination, + r = restore_by_glob(destination, components, architectures, packagetypes, argv[2], argv[3]); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -2015,30 +2025,31 @@ struct distribution *destination; retvalue result, r; - assert( argc == 4 ); + assert (argc == 4); result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot copy packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot copy packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - r = restore_by_formula(database, destination, + r = restore_by_formula(destination, components, architectures, packagetypes, argv[2], argv[3]); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -2050,62 +2061,66 @@ component_t component = atom_unknown; packagetype_t packagetype = atom_unknown; - if( packagetypes != NULL ) { - if( packagetypes->count > 1 ) { - fprintf(stderr, "_addpackage can only cope with one packagetype at a time!\n"); + if (packagetypes != NULL) { + if (packagetypes->count > 1) { + fprintf(stderr, +"_addpackage can only cope with one packagetype at a time!\n"); return RET_ERROR; } packagetype = packagetypes->atoms[0]; } - if( architectures != NULL ) { - if( architectures->count > 1 ) { - fprintf(stderr, "_addpackage can only cope with one architecture at a time!\n"); + if (architectures != NULL) { + if (architectures->count > 1) { + fprintf(stderr, +"_addpackage can only cope with one architecture at a time!\n"); return RET_ERROR; } architecture = architectures->atoms[0]; } - if( components != NULL ) { - if( components->count > 1 ) { - fprintf(stderr, "_addpackage can only cope with one component at a time!\n"); + if (components != NULL) { + if (components->count > 1) { + fprintf(stderr, +"_addpackage can only cope with one component at a time!\n"); return RET_ERROR; } component = components->atoms[0]; } - if( !atom_defined(packagetype) && atom_defined(architecture) && - architecture == architecture_source ) + if (!atom_defined(packagetype) && atom_defined(architecture) && + architecture == architecture_source) packagetype = pt_dsc; - if( atom_defined(packagetype) && !atom_defined(architecture) && - packagetype == pt_dsc ) + if (atom_defined(packagetype) && !atom_defined(architecture) && + packagetype == pt_dsc) architecture = architecture_source; // TODO: some more guesses based on components and udebcomponents - if( !atom_defined(architecture) || !atom_defined(component) || - !atom_defined(packagetype) ) { + if (!atom_defined(architecture) || !atom_defined(component) || + !atom_defined(packagetype)) { fprintf(stderr, "_addpackage needs -C and -A and -T set!\n"); return RET_ERROR; } result = distribution_get(alldistributions, argv[1], true, &destination); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( destination->readonly ) { - fprintf(stderr, "Cannot add packages to read-only distribution '%s'.\n", + if (destination->readonly) { + fprintf(stderr, +"Cannot add packages to read-only distribution '%s'.\n", destination->codename); return RET_ERROR; } result = distribution_prepareforwriting(destination); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - result = copy_from_file(database, destination, + result = copy_from_file(destination, component, architecture, packagetype, argv[2], argc-3, argv+3); logger_wait(); - r = distribution_export(export, destination, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, destination); + RET_ENDUPDATE(result, r); return result; } @@ -2117,25 +2132,25 @@ struct target *t; result = distribution_match(alldistributions, argc-1, argv+1, true, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( verbose > 0 ) { - printf("Referencing %s...\n",d->codename); + if (verbose > 0) { + printf("Referencing %s...\n", d->codename); } - for( t = d->targets ; t != NULL ; t = t->next ) { - r = target_rereference(t, database); + for (t = d->targets ; t != NULL ; t = t->next) { + r = target_rereference(t); RET_UPDATE(result, r); } - r = tracking_rereference(database, d); + r = tracking_rereference(d); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } @@ -2143,53 +2158,55 @@ } /***************************retrack****************************/ ACTION_D(n, n, y, retrack) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, true, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( d->tracking == dt_NONE ) { - if( argc > 1 ) { - fprintf(stderr, "Cannot retrack %s: Tracking not activated for this distribution!\n", d->codename); + if (d->tracking == dt_NONE) { + if (argc > 1) { + fprintf(stderr, +"Cannot retrack %s: Tracking not activated for this distribution!\n", + d->codename); RET_UPDATE(result, RET_ERROR); } continue; } - r = tracking_retrack(database, d, true); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(result) ) + r = tracking_retrack(d, true); + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(result)) break; } return result; } ACTION_D(n, n, y, removetrack) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; trackingdb tracks; - assert( argc == 4 ); + assert (argc == 4); result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - r = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(r) ) { + r = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(r)) { return r; } - result = tracking_remove(tracks, argv[2], argv[3], database); + result = tracking_remove(tracks, argv[2], argv[3]); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } @@ -2199,14 +2216,14 @@ const char *codename; int i; - if( delete <= 0 ) - for( i = 1 ; i < argc ; i ++ ) { + if (delete <= 0) + for (i = 1 ; i < argc ; i ++) { codename = argv[i]; d = alldistributions; - while( d != NULL && strcmp(codename, d->codename) != 0 ) + while (d != NULL && strcmp(codename, d->codename) != 0) d = d->next; - if( d != NULL && d->tracking != dt_NONE ) { + if (d != NULL && d->tracking != dt_NONE) { fprintf(stderr, "Error: Requested removing of all tracks of distribution '%s',\n" "which still has tracking enabled. Use --delete to delete anyway.\n", @@ -2215,22 +2232,22 @@ } } result = RET_NOTHING; - for( i = 1 ; i < argc ; i ++ ) { + for (i = 1 ; i < argc ; i ++) { codename = argv[i]; - if( verbose >= 0 ) { + if (verbose >= 0) { printf("Deleting all tracks for %s...\n", codename); } - r = tracking_drop(database, codename); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) + r = tracking_drop(codename); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) break; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { d = alldistributions; - while( d != NULL && strcmp(codename, d->codename) != 0 ) + while (d != NULL && strcmp(codename, d->codename) != 0) d = d->next; - if( d == NULL ) { + if (d == NULL) { fprintf(stderr, "Warning: There was no tracking information to delete for '%s',\n" "which is also not found in conf/distributions. Either this was already\n" @@ -2242,81 +2259,82 @@ } ACTION_D(n, n, y, tidytracks) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, true, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { trackingdb tracks; - if( !d->selected ) + if (!d->selected) continue; - if( d->tracking == dt_NONE ) { - r = tracking_drop(database, d->codename); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + if (d->tracking == dt_NONE) { + r = tracking_drop(d->codename); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; continue; } - if( verbose >= 0 ) { - printf("Looking for old tracks in %s...\n",d->codename); + if (verbose >= 0) { + printf("Looking for old tracks in %s...\n", + d->codename); } - r = tracking_initialize(&tracks, database, d, false); - if( RET_WAS_ERROR(r) ) { - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = tracking_initialize(&tracks, d, false); + if (RET_WAS_ERROR(r)) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; continue; } - r = tracking_tidyall(tracks, database); - RET_UPDATE(result,r); + r = tracking_tidyall(tracks); + RET_UPDATE(result, r); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(result) ) + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(result)) break; } return result; } ACTION_B(n, n, y, dumptracks) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { trackingdb tracks; - if( !d->selected ) + if (!d->selected) continue; - r = tracking_initialize(&tracks, database, d, true); - if( RET_WAS_ERROR(r) ) { - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = tracking_initialize(&tracks, d, true); + if (RET_WAS_ERROR(r)) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; continue; } - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; r = tracking_printall(tracks); - RET_UPDATE(result,r); + RET_UPDATE(result, r); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); - if( RET_WAS_ERROR(result) ) + RET_ENDUPDATE(result, r); + if (RET_WAS_ERROR(result)) break; } return result; @@ -2325,29 +2343,29 @@ /***********************checking*************************/ ACTION_RF(y, n, y, check) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( verbose > 0 ) { - printf("Checking %s...\n",d->codename); + if (verbose > 0) { + printf("Checking %s...\n", d->codename); } - r = distribution_foreach_package(d, database, + r = distribution_foreach_package(d, components, architectures, packagetypes, package_check, NULL, NULL); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } return result; @@ -2355,69 +2373,72 @@ ACTION_F(n, n, n, y, checkpool) { - if( argc == 2 && strcmp(argv[1],"fast") != 0 ) { - fprintf(stderr,"Error: Unrecognized second argument '%s'\n" + if (argc == 2 && strcmp(argv[1], "fast") != 0) { + fprintf(stderr, "Error: Unrecognized second argument '%s'\n" "Syntax: reprepro checkpool [fast]\n", argv[1]); return RET_ERROR; } - return files_checkpool(database, argc == 2); + return files_checkpool(argc == 2); } /* Update checksums of existing files */ ACTION_F(n, n, n, n, collectnewchecksums) { - return files_collectnewchecksums(database); + return files_collectnewchecksums(); } /*****************reapplying override info***************/ ACTION_F(y, n, y, y, reoverride) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, true, READWRITE); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { - if( !d->selected ) + if (!d->selected) continue; - if( verbose > 0 ) { - fprintf(stderr,"Reapplying override to %s...\n",d->codename); + if (verbose > 0) { + fprintf(stderr, "Reapplying override to %s...\n", + d->codename); } r = distribution_loadalloverrides(d); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { struct target *t; - for( t = d->targets ; t != NULL ; t = t->next ) { - if( !target_matches(t, - components, architectures, packagetypes) ) + for (t = d->targets ; t != NULL ; t = t->next) { + if (!target_matches(t, + components, architectures, packagetypes)) continue; - r = target_reoverride(t, d, database); + r = target_reoverride(t, d); RET_UPDATE(result, r); // TODO: how to seperate this in those affecting d // and those that do not? RET_UPDATE(d->status, r); } distribution_unloadoverrides(d); - } else if( r == RET_NOTHING ) { - fprintf(stderr,"No override files, thus nothing to do for %s.\n",d->codename); + } else if (r == RET_NOTHING) { + fprintf(stderr, +"No override files, thus nothing to do for %s.\n", + d->codename); } else { RET_UPDATE(result, r); } - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } - r = distribution_exportlist(export, alldistributions, database); - RET_ENDUPDATE(result,r); + r = distribution_exportlist(export, alldistributions); + RET_ENDUPDATE(result, r); return result; } @@ -2429,97 +2450,101 @@ result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } - return sizes_distributions(database, alldistributions, argc > 1); + return sizes_distributions(alldistributions, argc > 1); } /***********************include******************************************/ ACTION_D(y, y, y, includedeb) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; bool isudeb; trackingdb tracks; int i = 0; component_t component = atom_unknown; - if( components != NULL ) { - if( components->count > 1 ) { - fprintf(stderr, "Error: Only one component is allowed with %s!\n",argv[0]); + if (components != NULL) { + if (components->count > 1) { + fprintf(stderr, +"Error: Only one component is allowed with %s!\n", + argv[0]); return RET_ERROR; } - assert(components->count > 0 ); + assert(components->count > 0); component = components->atoms[0]; } - if( architectures != NULL ) - if( !atomlist_hasexcept(architectures, architecture_source) ) { + if (architectures != NULL) + if (!atomlist_hasexcept(architectures, architecture_source)) { fprintf(stderr, "Error: -A source is not possible with includedeb!\n"); return RET_ERROR; } - if( strcmp(argv[0],"includeudeb") == 0 ) { + if (strcmp(argv[0], "includeudeb") == 0) { isudeb = true; - if( limitations_missed(packagetypes, pt_udeb) ) { - fprintf(stderr, "Calling includeudeb with a -T not containing udeb makes no sense!\n"); + if (limitations_missed(packagetypes, pt_udeb)) { + fprintf(stderr, +"Calling includeudeb with a -T not containing udeb makes no sense!\n"); return RET_ERROR; } - } else if( strcmp(argv[0],"includedeb") == 0 ) { + } else if (strcmp(argv[0], "includedeb") == 0) { isudeb = false; - if( limitations_missed(packagetypes, pt_deb) ) { - fprintf(stderr, "Calling includedeb with a -T not containing deb makes no sense!\n"); + if (limitations_missed(packagetypes, pt_deb)) { + fprintf(stderr, +"Calling includedeb with a -T not containing deb makes no sense!\n"); return RET_ERROR; } } else { - fprintf(stderr,"Internal error while parding command!\n"); + fprintf(stderr, "Internal error while parding command!\n"); return RET_ERROR; } - for( i = 2 ; i < argc ; i++ ) { + for (i = 2 ; i < argc ; i++) { const char *filename = argv[i]; - if( isudeb ) { - if( !endswith(filename,".udeb") && !IGNORING_(extension, -"includeudeb called with file '%s' not ending with '.udeb'\n", filename) ) + if (isudeb) { + if (!endswith(filename, ".udeb") && !IGNORING(extension, +"includeudeb called with file '%s' not ending with '.udeb'\n", filename)) return RET_ERROR; } else { - if( !endswith(filename,".deb") && !IGNORING_(extension, -"includedeb called with file '%s' not ending with '.deb'\n", filename) ) + if (!endswith(filename, ".deb") && !IGNORING(extension, +"includedeb called with file '%s' not ending with '.deb'\n", filename)) return RET_ERROR; } } result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } - if( distribution->readonly ) { + if (distribution->readonly) { fprintf(stderr, "Cannot add packages to read-only distribution '%s'.\n", distribution->codename); return RET_ERROR; } - if( isudeb ) - result = override_read( distribution->udeb_override, + if (isudeb) + result = override_read(distribution->udeb_override, &distribution->overrides.udeb, false); else - result = override_read( distribution->deb_override, + result = override_read(distribution->deb_override, &distribution->overrides.deb, false); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } // TODO: same for component? (depending on type?) - if( architectures != NULL ) { + if (architectures != NULL) { architecture_t missing = atom_unknown; - if( !atomlist_subset(&distribution->architectures, - architectures, &missing) ){ + if (!atomlist_subset(&distribution->architectures, + architectures, &missing)){ fprintf(stderr, "Cannot force into the architecture '%s' not available in '%s'!\n", atoms_architectures[missing], @@ -2529,23 +2554,23 @@ } r = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return RET_ERROR; } - if( distribution->tracking != dt_NONE ) { - result = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(result) ) { + if (distribution->tracking != dt_NONE) { + result = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(result)) { return result; } } else { tracks = NULL; } result = RET_NOTHING; - for( i = 2 ; i < argc ; i++ ) { + for (i = 2 ; i < argc ; i++) { const char *filename = argv[i]; - r = deb_add(database, component, architectures, + r = deb_add(component, architectures, section, priority, isudeb?pt_udeb:pt_deb, distribution, filename, delete, tracks); @@ -2555,153 +2580,159 @@ distribution_unloadoverrides(distribution); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); logger_wait(); - r = distribution_export(export, distribution, database); - RET_ENDUPDATE(result,r); + r = distribution_export(export, distribution); + RET_ENDUPDATE(result, r); return result; } ACTION_D(y, y, y, includedsc) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; trackingdb tracks; component_t component = atom_unknown; - if( components != NULL ) { - if( components->count > 1 ) { - fprintf(stderr, "Error: Only one component is allowed with %s!\n",argv[0]); + if (components != NULL) { + if (components->count > 1) { + fprintf(stderr, +"Error: Only one component is allowed with %s!\n", + argv[0]); return RET_ERROR; } - assert(components->count > 0 ); + assert(components->count > 0); component = components->atoms[0]; } - assert( argc == 3 ); + assert (argc == 3); - if( limitations_missed(architectures, architecture_source) ) { - fprintf(stderr, "Cannot put a source package anywhere else than in architecture 'source'!\n"); + if (limitations_missed(architectures, architecture_source)) { + fprintf(stderr, +"Cannot put a source package anywhere else than in architecture 'source'!\n"); return RET_ERROR; } - if( limitations_missed(packagetypes, pt_dsc) ) { - fprintf(stderr, "Cannot put a source package anywhere else than in type 'dsc'!\n"); + if (limitations_missed(packagetypes, pt_dsc)) { + fprintf(stderr, +"Cannot put a source package anywhere else than in type 'dsc'!\n"); return RET_ERROR; } - if( !endswith(argv[2],".dsc") && !IGNORING_(extension, - "includedsc called with a file not ending with '.dsc'\n") ) + if (!endswith(argv[2], ".dsc") && !IGNORING(extension, +"includedsc called with a file not ending with '.dsc'\n")) return RET_ERROR; result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( distribution->readonly ) { - fprintf(stderr, "Cannot add packages to read-only distribution '%s'.\n", + if (distribution->readonly) { + fprintf(stderr, +"Cannot add packages to read-only distribution '%s'.\n", distribution->codename); return RET_ERROR; } result = override_read(distribution->dsc_override, &distribution->overrides.dsc, true); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } result = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - if( distribution->tracking != dt_NONE ) { - result = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(result) ) { + if (distribution->tracking != dt_NONE) { + result = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(result)) { return result; } } else { tracks = NULL; } - result = dsc_add(database, component, section, priority, + result = dsc_add(component, section, priority, distribution, argv[2], delete, tracks); logger_wait(); distribution_unloadoverrides(distribution); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); - r = distribution_export(export, distribution, database); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); + r = distribution_export(export, distribution); + RET_ENDUPDATE(result, r); return result; } ACTION_D(y, y, y, include) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; trackingdb tracks; component_t component = atom_unknown; - if( components != NULL ) { - if( components->count > 1 ) { - fprintf(stderr, "Error: Only one component is allowed with %s!\n", + if (components != NULL) { + if (components->count > 1) { + fprintf(stderr, +"Error: Only one component is allowed with %s!\n", argv[0]); return RET_ERROR; } - assert(components->count > 0 ); + assert(components->count > 0); component = components->atoms[0]; } - assert( argc == 3 ); + assert (argc == 3); - if( !endswith(argv[2],".changes") && !IGNORING_(extension, - "include called with a file not ending with '.changes'\n" - "(Did you mean includedeb or includedsc?)\n") ) + if (!endswith(argv[2], ".changes") && !IGNORING(extension, +"include called with a file not ending with '.changes'\n" +"(Did you mean includedeb or includedsc?)\n")) return RET_ERROR; result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( distribution->readonly ) { - fprintf(stderr, "Cannot add packages to read-only distribution '%s'.\n", + if (distribution->readonly) { + fprintf(stderr, +"Cannot add packages to read-only distribution '%s'.\n", distribution->codename); return RET_ERROR; } result = distribution_loadalloverrides(distribution); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - if( distribution->tracking != dt_NONE ) { - result = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(result) ) { + if (distribution->tracking != dt_NONE) { + result = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(result)) { return result; } } else { tracks = NULL; } result = distribution_loaduploaders(distribution); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { r = tracking_done(tracks); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } - result = changes_add(database, tracks, - packagetypes, component, architectures, + result = changes_add(tracks, packagetypes, component, architectures, section, priority, distribution, argv[2], delete); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) RET_UPDATE(distribution->status, result); distribution_unloadoverrides(distribution); distribution_unloaduploaders(distribution); r = tracking_done(tracks); - RET_ENDUPDATE(result,r); - r = distribution_export(export, distribution, database); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); + r = distribution_export(export, distribution); + RET_ENDUPDATE(result, r); return result; } @@ -2715,13 +2746,13 @@ * cause this link to exist. No tests whether this really will * cause it to be created (or already existing). */ - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( d->suite == NULL ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (d->suite == NULL) continue; - if( strcmp(d->suite, part) == 0 && + if (strcmp(d->suite, part) == 0 && strcmp(d->codename, cnpart) == 0) return true; - if( strcmp(d->codename, part) == 0 && + if (strcmp(d->codename, part) == 0 && strcmp(d->suite, cnpart) == 0) return true; } @@ -2729,55 +2760,56 @@ } ACTION_C(n, n, createsymlinks) { - retvalue result,r; - struct distribution *d,*d2; + retvalue result, r; + struct distribution *d, *d2; bool warned_slash = false; r = dirs_make_recursive(global.distdir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) { + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) { return result; } result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - char *linkname,*buffer; + for (d = alldistributions ; d != NULL ; d = d->next) { + char *linkname, *buffer; size_t bufsize; int ret; const char *separator_in_suite; - if( !d->selected ) + if (!d->selected) continue; - if( d->suite == NULL || strcmp(d->suite, d->codename) == 0 ) + if (d->suite == NULL || strcmp(d->suite, d->codename) == 0) continue; r = RET_NOTHING; - for( d2 = alldistributions ; d2 != NULL ; d2 = d2->next ) { - if( !d2->selected ) + for (d2 = alldistributions ; d2 != NULL ; d2 = d2->next) { + if (!d2->selected) continue; - if( d!=d2 && d2->suite!=NULL &&strcmp(d->suite,d2->suite)==0) { + if (d!=d2 && d2->suite!=NULL && + strcmp(d->suite, d2->suite)==0) { fprintf(stderr, "Not linking %s->%s due to conflict with %s->%s\n", - d->suite,d->codename, - d2->suite,d2->codename); + d->suite, d->codename, + d2->suite, d2->codename); r = RET_ERROR; - } else if( strcmp(d->suite,d2->codename)==0) { + } else if (strcmp(d->suite, d2->codename)==0) { fprintf(stderr, "Not linking %s->%s due to conflict with %s\n", - d->suite,d->codename,d2->codename); + d->suite, d->codename, d2->codename); r = RET_ERROR; } } - if( RET_WAS_ERROR(r) ) { - RET_UPDATE(result,r); + if (RET_WAS_ERROR(r)) { + RET_UPDATE(result, r); continue; } separator_in_suite = strchr(d->suite, '/'); - if( separator_in_suite != NULL ) { + if (separator_in_suite != NULL) { /* things with / in it are tricky: * relative symbolic links are hard, * perhaps something else already moved @@ -2786,24 +2818,24 @@ size_t ofs_in_suite = separator_in_suite - d->suite; char *part = strndup(d->suite, ofs_in_suite); - if( FAILEDTOALLOC(part) ) + if (FAILEDTOALLOC(part)) return RET_ERROR_OOM; /* check if this is some case we do not want to warn about: */ separator_in_codename = strchr(d->codename, '/'); - if( separator_in_codename != NULL && + if (separator_in_codename != NULL && strcmp(separator_in_codename, - separator_in_suite) == 0 ) { + separator_in_suite) == 0) { /* all but the first is common: */ size_t cnofs = separator_in_codename - d->codename; char *cnpart = strndup(d->codename, cnofs); - if( FAILEDTOALLOC(cnpart) ) { + if (FAILEDTOALLOC(cnpart)) { free(part); return RET_ERROR_OOM; } - if( mayaliasas(alldistributions, part, cnpart) ) { - if( verbose > 1 ) + if (mayaliasas(alldistributions, part, cnpart)) { + if (verbose > 1) fprintf(stderr, "Not creating '%s' -> '%s' because of the '/' in it.\n" "Hopefully something else will link '%s' -> '%s' then this is not needed.\n", @@ -2816,12 +2848,12 @@ free(cnpart); } free(part); - if( verbose >= 0 && !warned_slash ) { + if (verbose >= 0 && !warned_slash) { fprintf(stderr, "Creating symlinks with '/' in them is not yet supported:\n"); warned_slash = true; } - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "Not creating '%s' -> '%s' because of '/'.\n", d->suite, d->codename); continue; @@ -2829,59 +2861,65 @@ linkname = calc_dirconcat(global.distdir, d->suite); bufsize = strlen(d->codename)+10; - buffer = calloc(1,bufsize); - if( linkname == NULL || buffer == NULL ) { - free(linkname);free(buffer); - (void)fputs("Out of Memory!\n",stderr); + buffer = calloc(1, bufsize); + if (FAILEDTOALLOC(linkname) || FAILEDTOALLOC(buffer)) { + free(linkname); free(buffer); + (void)fputs("Out of Memory!\n", stderr); return RET_ERROR_OOM; } - ret = readlink(linkname,buffer,bufsize-4); - if( ret < 0 && errno == ENOENT ) { - ret = symlink(d->codename,linkname); - if( ret != 0 ) { + ret = readlink(linkname, buffer, bufsize - 4); + if (ret < 0 && errno == ENOENT) { + ret = symlink(d->codename, linkname); + if (ret != 0) { int e = errno; r = RET_ERRNO(e); fprintf(stderr, "Error %d creating symlink %s->%s: %s\n", e, linkname, d->codename, strerror(e)); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } else { - if( verbose > 0 ) { - printf("Created %s->%s\n",linkname,d->codename); + if (verbose > 0) { + printf("Created %s->%s\n", linkname, + d->codename); } - RET_UPDATE(result,RET_OK); + RET_UPDATE(result, RET_OK); } - } else if( ret >= 0 ) { + } else if (ret >= 0) { buffer[ret] = '\0'; - if( ret >= ((int)bufsize)-4 ) { + if (ret >= ((int)bufsize) - 4) { buffer[bufsize-4]='.'; buffer[bufsize-3]='.'; buffer[bufsize-2]='.'; buffer[bufsize-1]='\0'; } - if( strcmp(buffer,d->codename) == 0 ) { - if( verbose > 2 ) { - printf("Already ok: %s->%s\n",linkname,d->codename); + if (strcmp(buffer, d->codename) == 0) { + if (verbose > 2) { + printf("Already ok: %s->%s\n", + linkname, d->codename); } - RET_UPDATE(result,RET_OK); + RET_UPDATE(result, RET_OK); } else { - if( delete <= 0 ) { - fprintf(stderr,"Cannot create %s as already pointing to %s instead of %s,\n use --delete to delete the old link before creating an new one.\n",linkname,buffer,d->codename); - RET_UPDATE(result,RET_ERROR); + if (delete <= 0) { + fprintf(stderr, +"Cannot create %s as already pointing to %s instead of %s,\n" +" use --delete to delete the old link before creating an new one.\n", + linkname, buffer, d->codename); + RET_UPDATE(result, RET_ERROR); } else { unlink(linkname); - ret = symlink(d->codename,linkname); - if( ret != 0 ) { + ret = symlink(d->codename, linkname); + if (ret != 0) { int e = errno; r = RET_ERRNO(e); fprintf(stderr, "Error %d creating symlink %s->%s: %s\n", e, linkname, d->codename, strerror(e)); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } else { - if( verbose > 0 ) { - printf("Replaced %s->%s\n",linkname,d->codename); + if (verbose > 0) { + printf( +"Replaced %s->%s\n", linkname, d->codename); } - RET_UPDATE(result,RET_OK); + RET_UPDATE(result, RET_OK); } } @@ -2891,11 +2929,11 @@ r = RET_ERRNO(e); fprintf(stderr, "Error %d checking %s, perhaps not a symlink?: %s\n", e, linkname, strerror(e)); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - free(linkname);free(buffer); + free(linkname); free(buffer); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } return result; } @@ -2912,39 +2950,42 @@ struct signature *sig; architecture_t architecture; - if( isatty(0) ) { - puts("Please input the simulated package data to test.\n" - "Format: (source|section|binary|byhand|architecture|signature) \n" - "some keys may be given multiple times"); + if (isatty(0)) { + puts( +"Please input the simulated package data to test.\n" +"Format: (source|section|binary|byhand|architecture|signature) \n" +"some keys may be given multiple times"); } - while( (got = getline(buffer_p, bufferlen_p, stdin)) >= 0 ) { + while ((got = getline(buffer_p, bufferlen_p, stdin)) >= 0) { buffer = *buffer_p; - if( got == 0 || buffer[got - 1] != '\n' ) { + if (got == 0 || buffer[got - 1] != '\n') { fputs("stdin is not text\n", stderr); return RET_ERROR; } buffer[--got] = '\0'; - if( strncmp(buffer, "source ", 7) == 0 ) { - if( *sourcename != NULL ) { - fprintf(stderr, "Source name only allowed once!\n"); + if (strncmp(buffer, "source ", 7) == 0) { + if (*sourcename != NULL) { + fprintf(stderr, +"Source name only allowed once!\n"); return RET_ERROR; } *sourcename = strdup(buffer + 7); - if( FAILEDTOALLOC(*sourcename) ) + if (FAILEDTOALLOC(*sourcename)) return RET_ERROR_OOM; continue; - } else if( strncmp(buffer, "signature ", 10) == 0 ) { + } else if (strncmp(buffer, "signature ", 10) == 0) { v = buffer + 10; - if( *signatures == NULL ) { + if (*signatures == NULL) { s = calloc(1, sizeof(struct signatures) +sizeof(struct signature)); - if( FAILEDTOALLOC(s) ) + if (FAILEDTOALLOC(s)) return RET_ERROR_OOM; } else { - s = realloc(*signatures, sizeof(struct signatures) - +(s->count+1)* - sizeof(struct signature)); - if( FAILEDTOALLOC(s) ) + s = realloc(*signatures, + sizeof(struct signatures) + + (s->count+1) + * sizeof(struct signature)); + if (FAILEDTOALLOC(s)) return RET_ERROR_OOM; } *signatures = s; @@ -2955,7 +2996,7 @@ sig->expired_signature = false; sig->revoced_key = false; sig->state = sist_valid; - switch( *v ) { + switch (*v) { case 'b': sig->state = sist_bad; s->validcount--; @@ -2974,65 +3015,70 @@ break; } p = v; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) p++; sig->keyid = strndup(v, p-v); sig->primary_keyid = NULL; - if( FAILEDTOALLOC(sig->keyid) ) + if (FAILEDTOALLOC(sig->keyid)) return RET_ERROR_OOM; - if( *p == ':' ) { + if (*p == ':') { p++; v = p; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) + while ((*p >= '0' && *p <= '9') + || (*p >= 'a' && *p <= 'f')) p++; - if( *p != '\0' ) { - fprintf(stderr, "Invalid character in key id: '%c'!\n", *p); + if (*p != '\0') { + fprintf(stderr, +"Invalid character in key id: '%c'!\n", + *p); return RET_ERROR; } sig->primary_keyid = strdup(v); - } else if( *p != '\0' ) { - fprintf(stderr, "Invalid character in key id: '%c'!\n", *p); + } else if (*p != '\0') { + fprintf(stderr, +"Invalid character in key id: '%c'!\n", + *p); return RET_ERROR; } else sig->primary_keyid = strdup(sig->keyid); - if( FAILEDTOALLOC(sig->primary_keyid) ) + if (FAILEDTOALLOC(sig->primary_keyid)) return RET_ERROR_OOM; continue; - } else if( strncmp(buffer, "section ", 8) == 0 ) { + } else if (strncmp(buffer, "section ", 8) == 0) { v = buffer + 8; l = sections; - } else if( strncmp(buffer, "binary ", 7) == 0 ) { + } else if (strncmp(buffer, "binary ", 7) == 0) { v = buffer + 7; l = binaries; - } else if( strncmp(buffer, "byhand ", 7) == 0 ) { + } else if (strncmp(buffer, "byhand ", 7) == 0) { v = buffer + 7; l = byhands; - } else if( strncmp(buffer, "architecture ", 13) == 0 ) { + } else if (strncmp(buffer, "architecture ", 13) == 0) { v = buffer + 13; r = architecture_intern(v, &architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = atomlist_add(architectures, architecture); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; continue; - } else if( strcmp(buffer, "finished") == 0 ) { + } else if (strcmp(buffer, "finished") == 0) { break; } else { fprintf(stderr, "Unparseable line '%s'\n", buffer); return RET_ERROR; } r = strlist_add_dup(l, v); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( ferror(stdin) ) { + if (ferror(stdin)) { int e = errno; fprintf(stderr, "Error %d reading data from stdin: %s\n", e, strerror(e)); return RET_ERRNO(e); } - if( *sourcename == NULL ) { + if (*sourcename == NULL) { fprintf(stderr, "No source name specified!\n"); return RET_ERROR; } @@ -3041,15 +3087,15 @@ static inline void verifystrlist(struct upload_conditions *conditions, const struct strlist *list) { int i; - for( i = 0 ; i < list->count ; i++ ) { - if( !uploaders_verifystring(conditions, list->values[i]) ) + for (i = 0 ; i < list->count ; i++) { + if (!uploaders_verifystring(conditions, list->values[i])) break; } } static inline void verifyatomlist(struct upload_conditions *conditions, const struct atomlist *list) { int i; - for( i = 0 ; i < list->count ; i++ ) { - if( !uploaders_verifyatom(conditions, list->atoms[i]) ) + for (i = 0 ; i < list->count ; i++) { + if (!uploaders_verifyatom(conditions, list->atoms[i])) break; } } @@ -3069,15 +3115,15 @@ int i; r = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { return r; } - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; r = distribution_loaduploaders(d); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } @@ -3086,9 +3132,11 @@ strlist_init(&byhands); atomlist_init(&architectures); - r = read_package_description(&sourcename, §ions, &binaries, &byhands, &architectures, &signatures, &buffer, &bufferlen); + r = read_package_description(&sourcename, §ions, &binaries, + &byhands, &architectures, &signatures, + &buffer, &bufferlen); free(buffer); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(sourcename); strlist_done(§ions); strlist_done(&byhands); @@ -3099,29 +3147,32 @@ result = RET_NOTHING; accepted = false; - for( i = 1 ; !accepted && i < argc ; i++ ) { + for (i = 1 ; !accepted && i < argc ; i++) { r = distribution_get(alldistributions, argv[i], false, &d); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } r = distribution_loaduploaders(d); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - if( d->uploaderslist == NULL ) { - printf("'%s' would have been accepted by '%s' (as it has no uploader restrictions)\n", sourcename, d->codename); + if (d->uploaderslist == NULL) { + printf( +"'%s' would have been accepted by '%s' (as it has no uploader restrictions)\n", + sourcename, d->codename); accepted = true; break; } - r = uploaders_permissions(d->uploaderslist, signatures, &conditions); - if( RET_WAS_ERROR(r) ) { + r = uploaders_permissions(d->uploaderslist, signatures, + &conditions); + if (RET_WAS_ERROR(r)) { result = r; break; } rejected = false; - do switch( uploaders_nextcondition(conditions) ) { + do switch (uploaders_nextcondition(conditions)) { case uc_ACCEPTED: accepted = true; break; @@ -3146,24 +3197,27 @@ case uc_BINARIES: verifystrlist(conditions, &byhands); break; - } while( !accepted && !rejected ); + } while (!accepted && !rejected); free(conditions); - if( accepted ) { - printf("'%s' would have been accepted by '%s'\n", sourcename, d->codename); + if (accepted) { + printf("'%s' would have been accepted by '%s'\n", + sourcename, d->codename); break; } } - if( !accepted ) - printf("'%s' would NOT have been accepted by any of the distributions selected.\n", sourcename); + if (!accepted) + printf( +"'%s' would NOT have been accepted by any of the distributions selected.\n", + sourcename); free(sourcename); strlist_done(§ions); strlist_done(&byhands); atomlist_done(&architectures); signatures_free(signatures); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; - else if( accepted ) + else if (accepted) return RET_OK; else return RET_NOTHING; @@ -3172,52 +3226,50 @@ /***********************clearvanished***********************************/ ACTION_D(n, n, n, clearvanished) { - retvalue result,r; + retvalue result, r; struct distribution *d; struct strlist identifiers, codenames; bool *inuse; int i; - result = database_listpackages(database, &identifiers); - if( !RET_IS_OK(result) ) { + result = database_listpackages(&identifiers); + if (!RET_IS_OK(result)) { return result; } - inuse = calloc(identifiers.count, sizeof(bool)); - if( inuse == NULL ) { + inuse = nzNEW(identifiers.count, bool); + if (FAILEDTOALLOC(inuse)) { strlist_done(&identifiers); return RET_ERROR_OOM; } - for( d = alldistributions; d != NULL ; d = d->next ) { + for (d = alldistributions; d != NULL ; d = d->next) { struct target *t; - for( t = d->targets; t != NULL ; t = t->next ) { + for (t = d->targets; t != NULL ; t = t->next) { int ofs = strlist_ofs(&identifiers, t->identifier); - if( ofs >= 0 ) { + if (ofs >= 0) { inuse[ofs] = true; - if( verbose > 6 ) + if (verbose > 6) printf( "Marking '%s' as used.\n", t->identifier); - } else if( verbose > 3 && database->capabilities.createnewtables){ + } else if (verbose > 3 && database_allcreated()){ fprintf(stderr, "Strange, '%s' does not appear in packages.db yet.\n", t->identifier); - } } } - for( i = 0 ; i < identifiers.count ; i ++ ) { + for (i = 0 ; i < identifiers.count ; i ++) { const char *identifier = identifiers.values[i]; const char *p, *q; - if( inuse[i] ) + if (inuse[i]) continue; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - if( delete <= 0 ) { + if (delete <= 0) { struct table *packages; - r = database_openpackages(database, identifier, true, - &packages); - if( RET_IS_OK(r) ) { - if( !table_isempty(packages) ) { + r = database_openpackages(identifier, true, &packages); + if (RET_IS_OK(r)) { + if (!table_isempty(packages)) { fprintf(stderr, "There are still packages in '%s', not removing (give --delete to do so)!\n", identifier); (void)table_close(packages); @@ -3226,7 +3278,7 @@ r = table_close(packages); } } - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; // TODO: if delete, check what is removed, so that tracking // information can be updated. @@ -3235,56 +3287,57 @@ /* intern component and architectures, so parsing * has no problems (actually only need component now) */ p = identifier; - if( strncmp(p, "u|", 2) == 0 ) + if (strncmp(p, "u|", 2) == 0) p += 2; p = strchr(p, '|'); - if( p != NULL ) { + if (p != NULL) { p++; q = strchr(p, '|'); - if( q != NULL ) { + if (q != NULL) { atom_t dummy; char *component = strndup(p, q-p); q++; char *architecture = strdup(q); - if( FAILEDTOALLOC(component) || - FAILEDTOALLOC(architecture) ) { + if (FAILEDTOALLOC(component) || + FAILEDTOALLOC(architecture)) { free(component); free(architecture); return RET_ERROR_OOM; } r = architecture_intern(architecture, &dummy); free(architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(component); return r; } r = component_intern(component, &dummy); free(component); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } /* derference anything left */ - references_remove(database, identifier); + references_remove(identifier); /* remove the database */ - database_droppackages(database, identifier); + database_droppackages(identifier); } free(inuse); strlist_done(&identifiers); - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - r = tracking_listdistributions(database, &codenames); + r = tracking_listdistributions(&codenames); RET_UPDATE(result, r); - if( RET_IS_OK(r) ) { - for( d = alldistributions; d != NULL ; d = d->next ) { + if (RET_IS_OK(r)) { + for (d = alldistributions; d != NULL ; d = d->next) { strlist_remove(&codenames, d->codename); } - for( i = 0 ; i < codenames.count ; i ++ ) { - printf("Deleting tracking data for vanished distribution '%s'.\n", + for (i = 0 ; i < codenames.count ; i ++) { + printf( +"Deleting tracking data for vanished distribution '%s'.\n", codenames.values[i]); - r = tracking_drop(database, codenames.values[i]); + r = tracking_drop(codenames.values[i]); RET_UPDATE(result, r); } strlist_done(&codenames); @@ -3299,35 +3352,35 @@ const struct distribution *d; int i; - result = database_listpackages(database, &identifiers); - if( !RET_IS_OK(result) ) { + result = database_listpackages(&identifiers); + if (!RET_IS_OK(result)) { return result; } result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( i = 0 ; i < identifiers.count ; i++ ) { + for (i = 0 ; i < identifiers.count ; i++) { const char *p, *q, *identifier = identifiers.values[i]; - if( argc <= 1 ) { + if (argc <= 1) { puts(identifier); result = RET_OK; continue; } p = identifier; - if( strncmp(p, "u|", 2) == 0 ) + if (strncmp(p, "u|", 2) == 0) p += 2; q = strchr(p, '|'); - if( q == NULL ) + if (q == NULL) q = strchr(p, '\0'); - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( strncmp(p, d->codename, q-p) == 0 - && d->codename[q-p] == '\0' ) { + if (strncmp(p, d->codename, q - p) == 0 + && d->codename[q-p] == '\0') { puts(identifier); result = RET_OK; break; @@ -3344,15 +3397,15 @@ retvalue result; result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - for( t = d->targets; t != NULL ; t = t->next ) { + for (t = d->targets; t != NULL ; t = t->next) { puts(t->identifier); result = RET_OK; } @@ -3364,20 +3417,20 @@ retvalue r; int i; - assert( argc == 3 ); + assert (argc == 3); r = properversion(argv[1]); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) fprintf(stderr, "'%s' is not a proper version!\n", argv[1]); r = properversion(argv[2]); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) fprintf(stderr, "'%s' is not a proper version!\n", argv[2]); - r = dpkgversions_cmp(argv[1],argv[2],&i); - if( RET_IS_OK(r) ) { - if( i < 0 ) { + r = dpkgversions_cmp(argv[1], argv[2], &i); + if (RET_IS_OK(r)) { + if (i < 0) { printf("'%s' is smaller than '%s'.\n", argv[1], argv[2]); - } else if( i > 0 ) { + } else if (i > 0) { printf("'%s' is larger than '%s'.\n", argv[1], argv[2]); } else @@ -3388,18 +3441,19 @@ } /***********************processincoming********************************/ ACTION_D(n, n, y, processincoming) { - retvalue result,r; + retvalue result, r; struct distribution *d; - for( d = alldistributions ; d != NULL ; d = d->next ) + for (d = alldistributions ; d != NULL ; d = d->next) d->selected = true; - result = process_incoming(database, alldistributions, argv[1], (argc==3)?argv[2]:NULL); + result = process_incoming(alldistributions, argv[1], + (argc==3) ? argv[2] : NULL); logger_wait(); - r = distribution_exportlist(export, alldistributions, database); - RET_ENDUPDATE(result,r); + r = distribution_exportlist(export, alldistributions); + RET_ENDUPDATE(result, r); return result; } @@ -3408,57 +3462,57 @@ retvalue result; struct distribution *distribution; - assert( argc == 3 ); + assert (argc == 3); result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - return distribution_snapshot(distribution, database, argv[2]); + return distribution_snapshot(distribution, argv[2]); } /***********************rerunnotifiers********************************/ -static retvalue rerunnotifiersintarget(UNUSED(struct database *da), struct distribution *d, struct target *target, UNUSED(void *dummy)) { - if( !logger_rerun_needs_target(d->logger, target) ) +static retvalue rerunnotifiersintarget(struct distribution *d, struct target *target, UNUSED(void *dummy)) { + if (!logger_rerun_needs_target(d->logger, target)) return RET_NOTHING; return RET_OK; } ACTION_B(y, n, y, rerunnotifiers) { - retvalue result,r; + retvalue result, r; struct distribution *d; result = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( result != RET_NOTHING); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( d->logger == NULL ) + if (d->logger == NULL) continue; - if( verbose > 0 ) { - printf("Processing %s...\n",d->codename); + if (verbose > 0) { + printf("Processing %s...\n", d->codename); } r = logger_prepare(d->logger); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - r = distribution_foreach_package(d, database, + r = distribution_foreach_package(d, components, architectures, packagetypes, package_rerunnotifiers, rerunnotifiersintarget, NULL); logger_wait(); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } return result; @@ -3467,34 +3521,35 @@ /*********************** flood ****************************/ ACTION_D(y, n, y, flood) { - retvalue result,r; + retvalue result, r; struct distribution *distribution; trackingdb tracks; component_t architecture = atom_unknown; result = distribution_get(alldistributions, argv[1], true, &distribution); - assert( result != RET_NOTHING ); - if( RET_WAS_ERROR(result) ) + assert (result != RET_NOTHING); + if (RET_WAS_ERROR(result)) return result; - if( distribution->readonly ) { - fprintf(stderr, "Cannot add packages to read-only distribution '%s'.\n", + if (distribution->readonly) { + fprintf(stderr, +"Cannot add packages to read-only distribution '%s'.\n", distribution->codename); return RET_ERROR; } - if( argc == 3 ) { + if (argc == 3) { architecture = architecture_find(argv[2]); - if( !atom_defined(architecture) ) { + if (!atom_defined(architecture)) { fprintf(stderr, "Error: Unknown architecture '%s'!\n", argv[2]); return RET_ERROR; } - if( architecture == architecture_source ) { + if (architecture == architecture_source) { fprintf(stderr, "Error: Architecture 'source' does not make sense with 'flood'!\n"); return RET_ERROR; } - if( !atomlist_in(&distribution->architectures, architecture) ) { + if (!atomlist_in(&distribution->architectures, architecture)) { fprintf(stderr, "Error: Architecture '%s' not part of '%s'!\n", argv[2], distribution->codename); @@ -3503,30 +3558,30 @@ } result = distribution_prepareforwriting(distribution); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { return result; } - if( distribution->tracking != dt_NONE ) { - result = tracking_initialize(&tracks, database, distribution, false); - if( RET_WAS_ERROR(result) ) { + if (distribution->tracking != dt_NONE) { + result = tracking_initialize(&tracks, distribution, false); + if (RET_WAS_ERROR(result)) { return result; } } else tracks = NULL; result = flood(distribution, components, architectures, packagetypes, - architecture, database, tracks); + architecture, tracks); logger_wait(); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) RET_UPDATE(distribution->status, result); - if( tracks != NULL ) { + if (tracks != NULL) { r = tracking_done(tracks); RET_ENDUPDATE(result, r); } - r = distribution_export(export, distribution, database); + r = distribution_export(export, distribution); RET_ENDUPDATE(result, r); return result; @@ -3538,10 +3593,10 @@ r = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - return unusedsources(database, alldistributions); + return unusedsources(alldistributions); } /*********************** missingsource ****************************/ @@ -3550,10 +3605,10 @@ r = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - return sourcemissing(database, alldistributions); + return sourcemissing(alldistributions); } /*********************** reportcruft ****************************/ ACTION_B(n, n, y, reportcruft) { @@ -3561,10 +3616,10 @@ r = distribution_match(alldistributions, argc-1, argv+1, false, READONLY); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - return reportcruft(database, alldistributions); + return reportcruft(alldistributions); } /*********************/ @@ -3584,6 +3639,7 @@ #define NEED_ACT 256 #define NEED_SP 512 #define NEED_DELNEW 1024 +#define NEED_RESTRICT 2048 #define A_N(w) action_n_n_n_ ## w, 0 #define A_C(w) action_c_n_n_ ## w, NEED_CONFIG #define A_ROB(w) action_b_n_n_ ## w, NEED_DATABASE|IS_RO @@ -3608,13 +3664,12 @@ const char *name; retvalue (*start)( /*@null@*/struct distribution *, - /*@null@*/struct database*, /*@null@*/const char *priority, /*@null@*/const char *section, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, /*@null@*/const struct atomlist *, - int argc,const char *argv[]); + int argc, const char *argv[]); int needs; int minargs, maxargs; const char *wrongargmessage; @@ -3707,15 +3762,15 @@ 0, -1, "tidytracks []"}, {"removetrack", A_D(removetrack), 3, 3, "removetrack "}, - {"update", A_D(update), + {"update", A_D(update)|NEED_RESTRICT, 0, -1, "update []"}, - {"checkupdate", A_B(checkupdate), + {"checkupdate", A_B(checkupdate)|NEED_RESTRICT, 0, -1, "checkupdate []"}, - {"dumpupdate", A_B(dumpupdate), + {"dumpupdate", A_B(dumpupdate)|NEED_RESTRICT, 0, -1, "dumpupdate []"}, {"predelete", A_D(predelete), 0, -1, "predelete []"}, - {"pull", A_D(pull), + {"pull", A_D(pull)|NEED_RESTRICT, 0, -1, "pull []"}, {"copy", A_Dact(copy), 3, -1, "[-C ] [-A ] [-T ] copy "}, @@ -3733,9 +3788,9 @@ 3, 3, "[-C ] [-A ] [-T ] restorematched "}, {"restorefilter", A_Dact(restorefilter), 3, 3, "[-C ] [-A ] [-T ] restorefilter "}, - {"dumppull", A_B(dumppull), + {"dumppull", A_B(dumppull)|NEED_RESTRICT, 0, -1, "dumppull []"}, - {"checkpull", A_B(checkpull), + {"checkpull", A_B(checkpull)|NEED_RESTRICT, 0, -1, "checkpull []"}, {"includedeb", A_Dactsp(includedeb)|NEED_DELNEW, 2, -1, "[--delete] includedeb <.deb-file>"}, @@ -3775,7 +3830,7 @@ 0, -1, "sourcemissing []"}, {"reportcruft", A_B(reportcruft), 0, -1, "reportcruft []"}, - {NULL,NULL,0,0,0,NULL} + {NULL, NULL , 0, 0, 0, NULL} }; #undef A_N #undef A_B @@ -3789,203 +3844,207 @@ static retvalue callaction(command_t command, const struct action *action, int argc, const char *argv[]) { retvalue result, r; - struct database *database; struct distribution *alldistributions = NULL; bool deletederef, deletenew; int needs; - struct atomlist as, *architectures; - struct atomlist cs, *components; - struct atomlist ps, *packagetypes; + struct atomlist as, *architectures = NULL; + struct atomlist cs, *components = NULL; + struct atomlist ps, *packagetypes = NULL; assert(action != NULL); - causingcommand_atom = command; + causingcommand = command; - if( action->minargs >= 0 && argc < 1 + action->minargs ) { - fprintf(stderr, "Error: Too few arguments for command '%s'!\nSyntax: reprepro %s\n", + if (action->minargs >= 0 && argc < 1 + action->minargs) { + fprintf(stderr, +"Error: Too few arguments for command '%s'!\nSyntax: reprepro %s\n", argv[0], action->wrongargmessage); return RET_ERROR; } - if( action->maxargs >= 0 && argc > 1 + action->maxargs ) { - fprintf(stderr, "Error: Too many arguments for command '%s'!\nSyntax: reprepro %s\n", + if (action->maxargs >= 0 && argc > 1 + action->maxargs) { + fprintf(stderr, +"Error: Too many arguments for command '%s'!\nSyntax: reprepro %s\n", argv[0], action->wrongargmessage); return RET_ERROR; } needs = action->needs; - if( !ISSET(needs, NEED_ACT) && ( x_architecture != NULL ) ) { - if( !IGNORING_(unusedoption, + if (!ISSET(needs, NEED_ACT) && (x_architecture != NULL)) { + if (!IGNORING(unusedoption, "Action '%s' cannot be restricted to an architecture!\n" "neither --archiecture nor -A make sense here.\n", - action->name) ) + action->name)) return RET_ERROR; } - if( !ISSET(needs, NEED_ACT) && ( x_component != NULL ) ) { - if( !IGNORING_(unusedoption, + if (!ISSET(needs, NEED_ACT) && (x_component != NULL)) { + if (!IGNORING(unusedoption, "Action '%s' cannot be restricted to a component!\n" "neither --component nor -C make sense here.\n", - action->name) ) + action->name)) return RET_ERROR; } - if( !ISSET(needs, NEED_ACT) && ( x_packagetype != NULL ) ) { - if( !IGNORING_(unusedoption, + if (!ISSET(needs, NEED_ACT) && (x_packagetype != NULL)) { + if (!IGNORING(unusedoption, "Action '%s' cannot be restricted to a packagetype!\n" "neither --packagetype nor -T make sense here.\n", - action->name) ) + action->name)) return RET_ERROR; } - if( !ISSET(needs, NEED_SP) && ( x_section != NULL ) ) { - if( !IGNORING_(unusedoption, + if (!ISSET(needs, NEED_SP) && (x_section != NULL)) { + if (!IGNORING(unusedoption, "Action '%s' cannot take a section option!\n" "neither --section nor -S make sense here.\n", - action->name) ) + action->name)) return RET_ERROR; } - if( !ISSET(needs, NEED_SP) && ( x_priority != NULL ) ) { - if( !IGNORING_(unusedoption, + if (!ISSET(needs, NEED_SP) && (x_priority != NULL)) { + if (!IGNORING(unusedoption, "Action '%s' cannot take a priority option!\n" "neither --priority nor -P make sense here.\n", - action->name) ) + action->name)) + return RET_ERROR; + } + if (!ISSET(needs, NEED_RESTRICT) && (cmdline_bin_filter.set + || cmdline_src_filter.set)) { + if (!IGNORING(unusedoption, +"Action '%s' cannot take a --restrict-* option!\n", + action->name)) return RET_ERROR; } - if( ISSET(needs, NEED_DATABASE)) + if (ISSET(needs, NEED_DATABASE)) needs |= NEED_CONFIG; - if( ISSET(needs, NEED_CONFIG) ) { + if (ISSET(needs, NEED_CONFIG)) { r = distribution_readall(&alldistributions); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( !ISSET(needs, NEED_DATABASE) ) { - assert( (needs & ~NEED_CONFIG) == 0); + if (!ISSET(needs, NEED_DATABASE)) { + assert ((needs & ~NEED_CONFIG) == 0); - result = action->start(alldistributions, NULL, + result = action->start(alldistributions, x_section, x_priority, atom_unknown, atom_unknown, atom_unknown, argc, argv); r = distribution_freelist(alldistributions); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } - if( ISSET(needs, NEED_ACT) ) { + if (ISSET(needs, NEED_ACT)) { const char *unknownitem; - if( x_architecture != NULL ) { + if (x_architecture != NULL) { r = atomlist_filllist(at_architecture, &as, x_architecture, &unknownitem); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error: Architecture '%s' as given to --architecture is not know.\n" "(it does not appear as architecture in %s/distributions (did you mistype?))\n", unknownitem, global.confdir); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_freelist(alldistributions); return r; } architectures = &as; } else { atomlist_init(&as); - architectures = NULL; } - if( x_component != NULL ) { + if (x_component != NULL) { r = atomlist_filllist(at_component, &cs, x_component, &unknownitem); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error: Component '%s' as given to --component is not know.\n" "(it does not appear as component in %s/distributions (did you mistype?))\n", unknownitem, global.confdir); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_freelist(alldistributions); return r; } components = &cs; } else { atomlist_init(&cs); - components = NULL; } - if( x_packagetype != NULL ) { + if (x_packagetype != NULL) { r = atomlist_filllist(at_packagetype, &ps, x_packagetype, &unknownitem); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error: Packagetype '%s' as given to --packagetype is not know.\n" "(only dsc, deb, udeb and combinations of those are allowed)\n", unknownitem); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)distribution_freelist(alldistributions); return r; } packagetypes = &ps; } else { atomlist_init(&ps); - packagetypes = NULL; } - if( ps.count == 1 && ps.atoms[0] == pt_dsc && + if (ps.count == 1 && ps.atoms[0] == pt_dsc && limitations_missed(architectures, - architecture_source) ) { + architecture_source)) { fprintf(stderr, "Error: -T dsc is not possible with -A not including source!\n"); return RET_ERROR; } - if( as.count == 1 && as.atoms[0] == architecture_source && - limitations_missed(packagetypes, pt_dsc) ) { + if (as.count == 1 && as.atoms[0] == architecture_source && + limitations_missed(packagetypes, pt_dsc)) { fprintf(stderr, "Error: -A source is not possible with -T not including dsc!\n"); return RET_ERROR; } } - deletederef = ISSET(needs,NEED_DEREF) && !keepunreferenced; - deletenew = ISSET(needs,NEED_DELNEW) && !keepunusednew; + deletederef = ISSET(needs, NEED_DEREF) && !keepunreferenced; + deletenew = ISSET(needs, NEED_DELNEW) && !keepunusednew; - result = database_create(&database, alldistributions, + result = database_create(alldistributions, fast, ISSET(needs, NEED_NO_PACKAGES), ISSET(needs, MAY_UNUSED), ISSET(needs, IS_RO), waitforlock, verbosedatabase || (verbose >= 30)); - if( !RET_IS_OK(result) ) { + if (!RET_IS_OK(result)) { (void)distribution_freelist(alldistributions); return result; } /* adding files may check references to see if they were added */ - if( ISSET(needs,NEED_FILESDB) ) + if (ISSET(needs, NEED_FILESDB)) needs |= NEED_REFERENCES; - if( ISSET(needs,NEED_REFERENCES) ) - result = database_openreferences(database); + if (ISSET(needs, NEED_REFERENCES)) + result = database_openreferences(); - assert( result != RET_NOTHING ); - if( RET_IS_OK(result) ) { + assert (result != RET_NOTHING); + if (RET_IS_OK(result)) { - if( ISSET(needs,NEED_FILESDB) ) - result = database_openfiles(database); + if (ISSET(needs, NEED_FILESDB)) + result = database_openfiles(); - assert( result != RET_NOTHING ); - if( RET_IS_OK(result) ) { + assert (result != RET_NOTHING); + if (RET_IS_OK(result)) { - if( deletederef ) { - assert( ISSET(needs,NEED_REFERENCES) ); + if (deletederef) { + assert (ISSET(needs, NEED_REFERENCES)); } - if( !interrupted() ) { + if (!interrupted()) { result = action->start(alldistributions, - database, x_section, x_priority, architectures, components, packagetypes, argc, argv); /* wait for package specific loggers */ logger_wait(); /* remove files added but not used */ - pool_tidyadded(database, deletenew); + pool_tidyadded(deletenew); // TODO: tell hook script the added files // TODO: tell hook scripts the modified distributions @@ -3997,36 +4056,35 @@ // was not exported lost files // (and in a far future do not remove references // before the index is written) - if( deletederef && RET_WAS_ERROR(result) ) { + if (deletederef && RET_WAS_ERROR(result)) { deletederef = false; - if( pool_havedereferenced ) { + if (pool_havedereferenced) { fprintf(stderr, "Not deleting possibly left over files due to previous errors.\n" "(To keep the files in the still existing index files from vanishing)\n" "Use dumpunreferenced/deleteunreferenced to show/delete files without references.\n"); } } - r = pool_removeunreferenced(database, deletederef); + r = pool_removeunreferenced(deletederef); RET_ENDUPDATE(result, r); // TODO: tell hook scripts the deleted files } } } - if( !interrupted() ) { + if (!interrupted()) { logger_wait(); } - if( ISSET(needs, NEED_ACT) ) { + if (ISSET(needs, NEED_ACT)) { atomlist_done(&as); atomlist_done(&cs); atomlist_done(&ps); } logger_warn_waiting(); - r = database_close(database); + r = database_close(); RET_ENDUPDATE(result, r); r = distribution_freelist(alldistributions); - RET_ENDUPDATE(result,r); - database = NULL; + RET_ENDUPDATE(result, r); return result; } @@ -4083,28 +4141,36 @@ LO_LISTMAX, LO_MORGUEDIR, LO_SHOWPERCENT, +LO_RESTRICT_BIN, +LO_RESTRICT_SRC, +LO_RESTRICT_FILE_BIN, +LO_RESTRICT_FILE_SRC, LO_UNIGNORE}; static int longoption = 0; const char *programname; static void setexport(const char *argument) { - if( strcasecmp(argument, "never") == 0 ) { + if (strcasecmp(argument, "silent-never") == 0) { + CONFIGSET(export, EXPORT_SILENT_NEVER); + return; + } + if (strcasecmp(argument, "never") == 0) { CONFIGSET(export, EXPORT_NEVER); return; } - if( strcasecmp(argument, "changed") == 0 ) { + if (strcasecmp(argument, "changed") == 0) { CONFIGSET(export, EXPORT_CHANGED); return; } - if( strcasecmp(argument, "normal") == 0 ) { + if (strcasecmp(argument, "normal") == 0) { CONFIGSET(export, EXPORT_NORMAL); return; } - if( strcasecmp(argument, "lookedat") == 0 ) { + if (strcasecmp(argument, "lookedat") == 0) { CONFIGSET(export, EXPORT_NORMAL); return; } - if( strcasecmp(argument, "force") == 0 ) { + if (strcasecmp(argument, "force") == 0) { CONFIGSET(export, EXPORT_FORCE); return; } @@ -4119,11 +4185,11 @@ char *p; l = strtoll(argument, &p, 10); - if( p==NULL || *p != '\0' || l < 0 ) { + if (p==NULL || *p != '\0' || l < 0) { fprintf(stderr, "Invalid argument to %s: '%s'\n", name, argument); exit(EXIT_FAILURE); } - if( l == LLONG_MAX || l > max ) { + if (l == LLONG_MAX || l > max) { fprintf(stderr, "Too large argument for to %s: '%s'\n", name, argument); exit(EXIT_FAILURE); } @@ -4134,7 +4200,7 @@ retvalue r; int i; - switch( c ) { + switch (c) { case 'h': printf( "reprepro - Produce and Manage a Debian package repository\n\n" @@ -4187,10 +4253,10 @@ "\n"); exit(EXIT_SUCCESS); case '\0': - switch( longoption ) { + switch (longoption) { case LO_UNIGNORE: r = set_ignore(argument, false, config_state); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { exit(EXIT_FAILURE); } break; @@ -4312,7 +4378,9 @@ CONFIGDUP(x_morguedir, argument); break; case LO_VERSION: - fprintf(stderr,"%s: This is " PACKAGE " version " VERSION "\n",programname); + fprintf(stderr, +"%s: This is " PACKAGE " version " VERSION "\n", + programname); exit(EXIT_SUCCESS); case LO_WAITFORLOCK: CONFIGSET(waitforlock, parse_number( @@ -4320,9 +4388,9 @@ argument, LONG_MAX)); break; case LO_SPACECHECK: - if( strcasecmp(argument, "none") == 0 ) { + if (strcasecmp(argument, "none") == 0) { CONFIGSET(spacecheckmode, scm_NONE); - } else if( strcasecmp(argument, "full") == 0 ) { + } else if (strcasecmp(argument, "full") == 0) { CONFIGSET(spacecheckmode, scm_FULL); } else { fprintf(stderr, @@ -4361,7 +4429,7 @@ case LO_LISTMAX: i = parse_number("--list-max", argument, INT_MAX); - if( i == 0 ) + if (i == 0) i = -1; CONFIGSET(listmax, i); break; @@ -4371,13 +4439,38 @@ CONFIGSET(listskip, i); break; case LO_LISTFORMAT: - if( strcmp(argument, "NONE") == 0 ) { + if (strcmp(argument, "NONE") == 0) { CONFIGSET(listformat, NULL); } else CONFIGDUP(listformat, argument); break; + case LO_RESTRICT_BIN: + r = filterlist_cmdline_add_pkg(false, + argument); + if (RET_WAS_ERROR(r)) + exit(EXIT_FAILURE); + break; + case LO_RESTRICT_SRC: + r = filterlist_cmdline_add_pkg(true, + argument); + if (RET_WAS_ERROR(r)) + exit(EXIT_FAILURE); + break; + case LO_RESTRICT_FILE_BIN: + r = filterlist_cmdline_add_file(false, + argument); + if (RET_WAS_ERROR(r)) + exit(EXIT_FAILURE); + break; + case LO_RESTRICT_FILE_SRC: + r = filterlist_cmdline_add_file(true, + argument); + if (RET_WAS_ERROR(r)) + exit(EXIT_FAILURE); + break; default: - fprintf (stderr,"Error parsing arguments!\n"); + fputs( +"Error parsing arguments!\n", stderr); exit(EXIT_FAILURE); } longoption = 0; @@ -4392,53 +4485,59 @@ verbose+=5; break; case 'f': - fprintf(stderr, "Ignoring no longer existing option -f/--force!\n"); + fprintf(stderr, +"Ignoring no longer existing option -f/--force!\n"); break; case 'b': CONFIGDUP(x_basedir, argument); break; case 'i': r = set_ignore(argument, true, config_state); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { exit(EXIT_FAILURE); } break; case 'C': - if( x_component != NULL && + if (x_component != NULL && strcmp(x_component, argument) != 0) { - fprintf(stderr,"Multiple '-C' are not supported!\n"); + fprintf(stderr, +"Multiple '-%c' are not supported!\n", 'C'); exit(EXIT_FAILURE); } CONFIGDUP(x_component, argument); break; case 'A': - if( x_architecture != NULL && + if (x_architecture != NULL && strcmp(x_architecture, argument) != 0) { - fprintf(stderr,"Multiple '-A's are not supported!\n"); + fprintf(stderr, +"Multiple '-%c' are not supported!\n", 'A'); exit(EXIT_FAILURE); } CONFIGDUP(x_architecture, argument); break; case 'T': - if( x_packagetype != NULL && + if (x_packagetype != NULL && strcmp(x_packagetype, argument) != 0) { - fprintf(stderr,"Multiple '-T's are not supported!\n"); + fprintf(stderr, +"Multiple '-%c' are not supported!\n", 'T'); exit(EXIT_FAILURE); } CONFIGDUP(x_packagetype, argument); break; case 'S': - if( x_section != NULL && + if (x_section != NULL && strcmp(x_section, argument) != 0) { - fprintf(stderr,"Multiple '-S' are not supported!\n"); + fprintf(stderr, +"Multiple '-%c' are not supported!\n", 'S'); exit(EXIT_FAILURE); } CONFIGDUP(x_section, argument); break; case 'P': - if( x_priority != NULL && + if (x_priority != NULL && strcmp(x_priority, argument) != 0) { - fprintf(stderr,"Multiple '-P's are mpt supported!\n"); + fprintf(stderr, +"Multiple '-%c' are not supported!\n", 'P'); exit(EXIT_FAILURE); } CONFIGDUP(x_priority, argument); @@ -4447,7 +4546,7 @@ /* getopt_long should have already given an error msg */ exit(EXIT_FAILURE); default: - fprintf (stderr,"Not supported option '-%c'\n", c); + fprintf(stderr, "Not supported option '-%c'\n", c); exit(EXIT_FAILURE); } } @@ -4456,10 +4555,11 @@ static bool interruption_printed = false; bool interrupted(void) { - if( was_interrupted ) { - if( !interruption_printed ) { + if (was_interrupted) { + if (!interruption_printed) { interruption_printed = true; - fprintf(stderr, "\n\nInterruption in progress, interrupt again to force-stop it (and risking database corruption!)\n\n"); + fprintf(stderr, +"\n\nInterruption in progress, interrupt again to force-stop it (and risking database corruption!)\n\n"); } return true; } else @@ -4492,14 +4592,15 @@ } static void disallow_plus_prefix(const char *dir, const char *name, const char *allowed) { - if( dir[0] != '+' ) + if (dir[0] != '+') return; - if( dir[1] == '\0' || dir[2] != '/' ) { - fprintf(stderr, "Error: %s starts with +, but does not continue with '+b/'.\n", + if (dir[1] == '\0' || dir[2] != '/') { + fprintf(stderr, +"Error: %s starts with +, but does not continue with '+b/'.\n", name); myexit(EXIT_FAILURE); } - if( strchr(allowed, dir[1]) != NULL ) + if (strchr(allowed, dir[1]) != NULL) return; fprintf(stderr, "Error: %s is not allowed to start with '+%c/'.\n" "(if your directory is named like that, set it to './+%c/')\n", @@ -4513,9 +4614,9 @@ disallow_plus_prefix(dir, name, allowed); - if( dir[0] == '/' || (dir[0] == '.' && dir[1] == '/') ) + if (dir[0] == '/' || (dir[0] == '.' && dir[1] == '/')) return dir; - if( dir[0] != '+' ) { + if (dir[0] != '+') { fprintf(stderr, "Warning: %s '%s' does not start with '/', './', or '+'.\n" "This currently means it is relative to the current working directory,\n" @@ -4523,33 +4624,33 @@ name, dir); return dir; } - if( dir[1] == 'b' ) { + if (dir[1] == 'b') { fromdir = x_basedir; - } else if( dir[1] == 'o' ) { + } else if (dir[1] == 'o') { fromdir = x_outdir; - } else if( dir[1] == 'c' ) { + } else if (dir[1] == 'c') { fromdir = x_confdir; } else { abort(); return dir; } - if( dir[3] == '\0' ) + if (dir[3] == '\0') newdir = strdup(fromdir); else newdir = calc_dirconcat(fromdir, dir + 3); - if( FAILEDTOALLOC(newdir) ) { - (void)fputs("Out of Memory!\n",stderr); + if (FAILEDTOALLOC(newdir)) { + (void)fputs("Out of Memory!\n", stderr); exit(EXIT_FAILURE); } - if( freedir ) + if (freedir) free(dir); return newdir; } -int main(int argc,char *argv[]) { +int main(int argc, char *argv[]) { static struct option longopts[] = { - {"delete", no_argument, &longoption,LO_DELETE}, - {"nodelete", no_argument, &longoption,LO_NODELETE}, + {"delete", no_argument, &longoption, LO_DELETE}, + {"nodelete", no_argument, &longoption, LO_NODELETE}, {"basedir", required_argument, NULL, 'b'}, {"ignore", required_argument, NULL, 'i'}, {"unignore", required_argument, &longoption, LO_UNIGNORE}, @@ -4619,6 +4720,14 @@ {"list-max", required_argument, &longoption, LO_LISTMAX}, {"morguedir", required_argument, &longoption, LO_MORGUEDIR}, {"show-percent", no_argument, &longoption, LO_SHOWPERCENT}, + {"restrict", required_argument, &longoption, LO_RESTRICT_SRC}, + {"restrict-source", required_argument, &longoption, LO_RESTRICT_SRC}, + {"restrict-src", required_argument, &longoption, LO_RESTRICT_SRC}, + {"restrict-binary", required_argument, &longoption, LO_RESTRICT_BIN}, + {"restrict-file", required_argument, &longoption, LO_RESTRICT_FILE_SRC}, + {"restrict-file-source", required_argument, &longoption, LO_RESTRICT_FILE_SRC}, + {"restrict-file-src", required_argument, &longoption, LO_RESTRICT_FILE_SRC}, + {"restrict-file-binary", required_argument, &longoption, LO_RESTRICT_FILE_BIN}, {NULL, 0, NULL, 0} }; const struct action *a; @@ -4645,8 +4754,6 @@ programname = argv[0]; - init_ignores(); - config_state = CONFIG_OWNER_DEFAULT; CONFIGDUP(x_basedir, STD_BASE_DIR); CONFIGDUP(x_confdir, "+b/conf"); @@ -4658,27 +4765,28 @@ CONFIGDUP(x_listdir, "+b/lists"); config_state = CONFIG_OWNER_CMDLINE; - if( interrupted() ) + if (interrupted()) exit(EXIT_RET(RET_ERROR_INTERRUPTED)); - while( (c = getopt_long(argc,argv,"+fVvshb:P:i:A:C:S:T:",longopts,NULL)) != -1 ) { - handle_option(c,optarg); + while ((c = getopt_long(argc, argv, "+fVvshb:P:i:A:C:S:T:", longopts, NULL)) != -1) { + handle_option(c, optarg); } - if( optind >= argc ) { - fprintf(stderr,"No action given. (see --help for available options and actions)\n"); + if (optind >= argc) { + fputs( +"No action given. (see --help for available options and actions)\n", stderr); exit(EXIT_FAILURE); } - if( interrupted() ) + if (interrupted()) exit(EXIT_RET(RET_ERROR_INTERRUPTED)); /* only for this CONFIG_OWNER_ENVIRONMENT is a bit stupid, * but perhaps it gets more... */ config_state = CONFIG_OWNER_ENVIRONMENT; - if( getenv("REPREPRO_BASE_DIR") != NULL ) { + if (getenv("REPREPRO_BASE_DIR") != NULL) { CONFIGDUP(x_basedir, getenv("REPREPRO_BASE_DIR")); } - if( getenv("REPREPRO_CONFIG_DIR") != NULL ) { - CONFIGDUP(x_confdir,getenv("REPREPRO_CONFIG_DIR")); + if (getenv("REPREPRO_CONFIG_DIR") != NULL) { + CONFIGDUP(x_confdir, getenv("REPREPRO_CONFIG_DIR")); } disallow_plus_prefix(x_basedir, "basedir", ""); @@ -4686,7 +4794,7 @@ config_state = CONFIG_OWNER_FILE; optionsfile_parse(tempconfdir, longopts, handle_option); - if( tempconfdir != x_confdir ) + if (tempconfdir != x_confdir) free(tempconfdir); disallow_plus_prefix(x_basedir, "basedir", ""); @@ -4697,26 +4805,28 @@ x_dbdir = expand_plus_prefix(x_dbdir, "dbdir", "boc", true); x_distdir = expand_plus_prefix(x_distdir, "distdir", "boc", true); x_listdir = expand_plus_prefix(x_listdir, "listdir", "boc", true); - if( x_morguedir != NULL ) + if (x_morguedir != NULL) x_morguedir = expand_plus_prefix(x_morguedir, "morguedir", "boc", true); - if( guessgpgtty && (getenv("GPG_TTY")==NULL) && isatty(0) ) { + if (guessgpgtty && (getenv("GPG_TTY")==NULL) && isatty(0)) { static char terminalname[1024]; ssize_t len; len = readlink("/proc/self/fd/0", terminalname, 1023); - if( len > 0 && len < 1024 ) { + if (len > 0 && len < 1024) { terminalname[len] = '\0'; setenv("GPG_TTY", terminalname, 0); - } else if( verbose > 10 ) { - fprintf(stderr, "Could not readlink /proc/self/fd/0 (error was %s), not setting GPG_TTY.\n", strerror(errno)); + } else if (verbose > 10) { + fprintf(stderr, +"Could not readlink /proc/self/fd/0 (error was %s), not setting GPG_TTY.\n", + strerror(errno)); } } - if( delete < D_COPY ) + if (delete < D_COPY) delete = D_COPY; - if( interrupted() ) + if (interrupted()) exit(EXIT_RET(RET_ERROR_INTERRUPTED)); global.basedir = x_basedir; global.dbdir = x_dbdir; @@ -4728,15 +4838,15 @@ global.listdir = x_listdir; global.morguedir = x_morguedir; - if( gunzip != NULL && gunzip[0] == '+' ) + if (gunzip != NULL && gunzip[0] == '+') gunzip = expand_plus_prefix(gunzip, "gunzip", "boc", true); - if( bunzip2 != NULL && bunzip2[0] == '+' ) + if (bunzip2 != NULL && bunzip2[0] == '+') bunzip2 = expand_plus_prefix(bunzip2, "bunzip2", "boc", true); - if( unlzma != NULL && unlzma[0] == '+' ) + if (unlzma != NULL && unlzma[0] == '+') unlzma = expand_plus_prefix(unlzma, "unlzma", "boc", true); - if( unxz != NULL && unxz[0] == '+' ) + if (unxz != NULL && unxz[0] == '+') unxz = expand_plus_prefix(unxz, "unxz", "boc", true); - if( lunzip != NULL && lunzip[0] == '+' ) + if (lunzip != NULL && lunzip[0] == '+') lunzip = expand_plus_prefix(lunzip, "lunzip", "boc", true); uncompressions_check(gunzip, bunzip2, unlzma, unxz, lunzip); free(gunzip); @@ -4746,33 +4856,34 @@ free(lunzip); a = all_actions; - while( a->name != NULL ) { + while (a->name != NULL) { a++; } r = atoms_init(a - all_actions); - if( r == RET_ERROR_OOM ) - (void)fputs("Out of Memory!\n",stderr); - if( RET_WAS_ERROR(r) ) + if (r == RET_ERROR_OOM) + (void)fputs("Out of Memory!\n", stderr); + if (RET_WAS_ERROR(r)) exit(EXIT_RET(r)); - for( a = all_actions; a->name != NULL ; a++ ) { + for (a = all_actions; a->name != NULL ; a++) { atoms_commands[1 + (a - all_actions)] = a->name; } - if( gnupghome != NULL ) { + if (gnupghome != NULL) { gnupghome = expand_plus_prefix(gnupghome, "gnupghome", "boc", true); - if( setenv("GNUPGHOME", gnupghome, 1) != 0 ) { + if (setenv("GNUPGHOME", gnupghome, 1) != 0) { int e = errno; - fprintf(stderr, "Error %d setting GNUPGHOME to '%s': %s\n", + fprintf(stderr, +"Error %d setting GNUPGHOME to '%s': %s\n", e, gnupghome, strerror(e)); myexit(EXIT_FAILURE); } } a = all_actions; - while( a->name != NULL ) { - if( strcasecmp(a->name,argv[optind]) == 0 ) { + while (a->name != NULL) { + if (strcasecmp(a->name, argv[optind]) == 0) { signature_init(askforpassphrase); r = callaction(1 + (a - all_actions), a, argc-optind, (const char**)argv+optind); @@ -4781,18 +4892,22 @@ * readable */ signatures_done(); free_known_keys(); - if( RET_WAS_ERROR(r) ) { - if( r == RET_ERROR_OOM ) - (void)fputs("Out of Memory!\n",stderr); - else if( verbose >= 0 ) - (void)fputs("There have been errors!\n",stderr); + if (RET_WAS_ERROR(r)) { + if (r == RET_ERROR_OOM) + (void)fputs("Out of Memory!\n", stderr); + else if (verbose >= 0) + (void)fputs( +"There have been errors!\n", + stderr); } myexit(EXIT_RET(r)); } else a++; } - fprintf(stderr,"Unknown action '%s'. (see --help for available options and actions)\n",argv[optind]); + fprintf(stderr, +"Unknown action '%s'. (see --help for available options and actions)\n", + argv[optind]); signatures_done(); myexit(EXIT_FAILURE); } diff -Nru reprepro-4.5.0/mprintf.c reprepro-4.6.0/mprintf.c --- reprepro-4.5.0/mprintf.c 2007-11-20 11:58:47.000000000 +0000 +++ reprepro-4.6.0/mprintf.c 2011-05-05 14:42:55.000000000 +0000 @@ -12,28 +12,28 @@ // TODO: check for asprintf in configure and // write a replacement for such situations. -char * mprintf(const char *fmt,...) { +char * mprintf(const char *fmt, ...) { char *p; int r; va_list va; - va_start(va,fmt); - r = vasprintf(&p,fmt,va); + va_start(va, fmt); + r = vasprintf(&p, fmt, va); va_end(va); /* return NULL both when r is < 0 and when NULL was returned */ - if( r < 0 ) + if (r < 0) return NULL; else return p; } -char * vmprintf(const char *fmt,va_list va) { +char * vmprintf(const char *fmt, va_list va) { char *p; int r; - r = vasprintf(&p,fmt,va); + r = vasprintf(&p, fmt, va); /* return NULL both when r is < 0 and when NULL was returned */ - if( r < 0 ) + if (r < 0) return NULL; else return p; @@ -49,7 +49,7 @@ va_start(va, format); buffer = vmprintf(format, va); va_end(va); - if( buffer == NULL ) + if (buffer == NULL) return -1; ret = write(fd, buffer, strlen(buffer)); free(buffer); @@ -60,11 +60,11 @@ #ifndef HAVE_STRNDUP /* That's not the best possible strndup implementation, but it suffices for what * it is used here */ -char *strndup(const char *str,size_t n) { +char *strndup(const char *str, size_t n) { char *r = malloc(n+1); - if( r == NULL ) + if (r == NULL) return r; - memcpy(r,str,n); + memcpy(r, str, n); r[n] = '\0'; return r; } diff -Nru reprepro-4.5.0/mprintf.h reprepro-4.6.0/mprintf.h --- reprepro-4.5.0/mprintf.h 2006-12-31 12:47:58.000000000 +0000 +++ reprepro-4.6.0/mprintf.h 2011-05-05 14:42:55.000000000 +0000 @@ -6,7 +6,7 @@ /* This is just a asprintf-wrapper to be more easily used * and alwasy returns NULL on error */ -/*@null@*/char * mprintf(const char *fmt,...) __attribute__ ((format (printf, 1, 2))); -/*@null@*/char * vmprintf(const char *fmt,va_list va); +/*@null@*/char * mprintf(const char *, ...) __attribute__ ((format (printf, 1, 2))); +/*@null@*/char * vmprintf(const char *, va_list); #endif diff -Nru reprepro-4.5.0/names.c reprepro-4.6.0/names.c --- reprepro-4.5.0/names.c 2008-10-12 17:28:23.000000000 +0000 +++ reprepro-4.6.0/names.c 2011-05-05 14:42:55.000000000 +0000 @@ -28,16 +28,16 @@ #include "strlist.h" #include "names.h" -char *calc_addsuffix(const char *str1,const char *str2) { - return mprintf("%s.%s",str1,str2); +char *calc_addsuffix(const char *str1, const char *str2) { + return mprintf("%s.%s", str1, str2); } -char *calc_dirconcat(const char *str1,const char *str2) { - return mprintf("%s/%s",str1,str2); +char *calc_dirconcat(const char *str1, const char *str2) { + return mprintf("%s/%s", str1, str2); } -char *calc_dirconcat3(const char *str1,const char *str2,const char *str3) { - return mprintf("%s/%s/%s",str1,str2,str3); +char *calc_dirconcat3(const char *str1, const char *str2, const char *str3) { + return mprintf("%s/%s/%s", str1, str2, str3); } /* Create a strlist consisting out of calc_dirconcat'ed entries of the old */ @@ -46,23 +46,23 @@ retvalue r; int i; - assert(directory != NULL && basefilenames != NULL && files != NULL ); + assert (directory != NULL && basefilenames != NULL && files != NULL); - r = strlist_init_n(basefilenames->count,files); - if( RET_WAS_ERROR(r) ) + r = strlist_init_n(basefilenames->count, files); + if (RET_WAS_ERROR(r)) return r; r = RET_NOTHING; - for( i = 0 ; i < basefilenames->count ; i++ ) { + for (i = 0 ; i < basefilenames->count ; i++) { char *file; file = calc_dirconcat(directory, basefilenames->values[i]); - if( file == NULL ) { + if (FAILEDTOALLOC(file)) { strlist_done(files); return RET_ERROR_OOM; } - r = strlist_add(files,file); - if( RET_WAS_ERROR(r) ) { + r = strlist_add(files, file); + if (RET_WAS_ERROR(r)) { strlist_done(files); return r; } @@ -74,12 +74,12 @@ retvalue calc_inplacedirconcats(const char *directory, struct strlist *files) { int i; - assert(directory != NULL && files != NULL ); - for( i = 0 ; i < files->count ; i++ ) { + assert (directory != NULL && files != NULL ); + for (i = 0 ; i < files->count ; i++) { char *file; file = calc_dirconcat(directory, files->values[i]); - if( file == NULL ) + if (FAILEDTOALLOC(file)) return RET_ERROR_OOM; free(files->values[i]); files->values[i] = file; @@ -91,61 +91,61 @@ const char *n = *version; bool hadepoch = epochsuppressed; - if( *n < '0' || *n > '9' ) { - if( (*n < 'a' || *n > 'z') && (*n < 'A' || *n > 'Z') ) + if (*n < '0' || *n > '9') { + if ((*n < 'a' || *n > 'z') && (*n < 'A' || *n > 'Z')) return; } else n++; - while( *n >= '0' && *n <= '9' ) + while (*n >= '0' && *n <= '9') n++; - if( *n == ':' ) { + if (*n == ':') { hadepoch = true; n++; } - while( ( *n >= '0' && *n <= '9' ) || ( *n >= 'a' && *n <= 'z') - || ( *n >= 'A' && *n <= 'Z' ) || *n == '.' || *n == '~' - || *n == '-' || *n == '+' || (hadepoch && *n == ':') ) + while ((*n >= '0' && *n <= '9') || (*n >= 'a' && *n <= 'z') + || (*n >= 'A' && *n <= 'Z') || *n == '.' || *n == '~' + || *n == '-' || *n == '+' || (hadepoch && *n == ':')) n++; *version = n; } -char *calc_trackreferee(const char *codename,const char *sourcename,const char *sourceversion) { - return mprintf("%s %s %s",codename,sourcename,sourceversion); +char *calc_trackreferee(const char *codename, const char *sourcename, const char *sourceversion) { + return mprintf("%s %s %s", codename, sourcename, sourceversion); } -char *calc_changes_basename(const char *name,const char *version,const struct strlist *architectures) { +char *calc_changes_basename(const char *name, const char *version, const struct strlist *architectures) { size_t name_l, version_l, l; int i; - char *n,*p; + char *n, *p; name_l = strlen(name); version_l = strlen(version); l = name_l + version_l + sizeof("__.changes"); - for( i = 0 ; i < architectures->count ; i++ ) { + for (i = 0 ; i < architectures->count ; i++) { l += strlen(architectures->values[i]); - if( i != 0 ) + if (i != 0) l++; } n = malloc(l); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return n; p = n; memcpy(p, name, name_l); p+=name_l; *(p++) = '_'; memcpy(p, version, version_l); p+=version_l; *(p++) = '_'; - for( i = 0 ; i < architectures->count ; i++ ) { + for (i = 0 ; i < architectures->count ; i++) { size_t a_l = strlen(architectures->values[i]); - if( i != 0 ) + if (i != 0) *(p++) = '+'; - assert( (size_t)((p+a_l)-n) < l ); + assert ((size_t)((p+a_l)-n) < l); memcpy(p, architectures->values[i], a_l); p += a_l; } - assert( (size_t)(p-n) < l-8 ); - memcpy(p, ".changes", 9 ); p += 9; - assert( *(p-1) == '\0' ); - assert( (size_t)(p-n) == l ); + assert ((size_t)(p-n) < l-8); + memcpy(p, ".changes", 9); p += 9; + assert (*(p-1) == '\0'); + assert ((size_t)(p-n) == l); return n; } diff -Nru reprepro-4.5.0/names.h reprepro-4.6.0/names.h --- reprepro-4.5.0/names.h 2008-10-05 09:58:06.000000000 +0000 +++ reprepro-4.6.0/names.h 2011-05-05 14:42:55.000000000 +0000 @@ -5,36 +5,35 @@ #include "strlist.h" #endif -char *calc_addsuffix(const char *str1,const char *str2); -char *calc_dirconcat(const char *str1,const char *str2); -char *calc_dirconcat3(const char *str1,const char *str2,const char *str3); +char *calc_addsuffix(const char *, const char *); +char *calc_dirconcat(const char *, const char *); +char *calc_dirconcat3(const char *, const char *, const char *); #define calc_conffile(name) calc_dirconcat(global.confdir, name) -char *calc_changes_basename(const char *name,const char *version,const struct strlist *architectures); -char *calc_trackreferee(const char *codename,const char *sourcename,const char *sourceversion); +char *calc_changes_basename(const char *, const char *, const struct strlist *); +char *calc_trackreferee(const char *, const char *, const char *); #define calc_snapshotbasedir(codename, name) mprintf("%s/%s/snapshots/%s", global.distdir, codename, name) /* Create a strlist consisting out of calc_dirconcat'ed entries of the old */ -retvalue calc_dirconcats(const char *directory, const struct strlist *basefilenames,/*@out@*/struct strlist *files); -retvalue calc_inplacedirconcats(const char *directory, struct strlist *); +retvalue calc_dirconcats(const char *, const struct strlist *, /*@out@*/struct strlist *); +retvalue calc_inplacedirconcats(const char *, struct strlist *); -/* move over a version number, if epochsuppresed is true, colons may happen even without epoch there */ -void names_overversion(const char **version, bool epochsuppressed); +/* move over a version number, + * if epochsuppresed is true, colons may happen even without epoch there */ +void names_overversion(const char **, bool /*epochsuppressed*/); /* check for forbidden characters */ -retvalue propersourcename(const char *string); -retvalue properfilenamepart(const char *string); -retvalue properfilename(const char *string); -retvalue properfilenames(const struct strlist *names); -retvalue properpackagename(const char *string); -retvalue properversion(const char *string); +retvalue propersourcename(const char *); +retvalue properfilenamepart(const char *); +retvalue properfilename(const char *); +retvalue properfilenames(const struct strlist *); +retvalue properpackagename(const char *); +retvalue properversion(const char *); static inline bool endswith(const char *name, const char *suffix) { - size_t ln,ls; - ln = strlen(name); - ls = strlen(suffix); - return ln > ls && strcmp(name+(ln-ls),suffix) == 0; + size_t ln = strlen(name), ls = strlen(suffix); + return ln > ls && strcmp(name + (ln - ls), suffix) == 0; } #endif diff -Nru reprepro-4.5.0/needbuild.c reprepro-4.6.0/needbuild.c --- reprepro-4.5.0/needbuild.c 2009-08-24 13:35:08.000000000 +0000 +++ reprepro-4.6.0/needbuild.c 2011-05-05 14:42:55.000000000 +0000 @@ -38,7 +38,7 @@ For each source package check: - if tracking is enabled and there is a .log or .changes file for the given arch -> SKIP - - if there is a binary package for the given architecture -> SKIP + - if there is a binary package for the given architecture -> SKIP - if the package's Architecture field excludes this arch -> SKIP - if the package's Binary field only lists existing ones (i.e. architecture all) -> SKIP @@ -51,53 +51,53 @@ int i; memset(found_binary, 0, sizeof(bool)*binary->count); - for( i = 0 ; i < tp->filekeys.count ; i++ ) { + for (i = 0 ; i < tp->filekeys.count ; i++) { enum filetype ft = tp->filetypes[i]; const char *fk = tp->filekeys.values[i]; - if( ft == ft_XTRA_DATA ) + if (ft == ft_XTRA_DATA) continue; - if( ft == ft_ALL_BINARY ) { + if (ft == ft_ALL_BINARY) { int j; /* determine which binary files are arch all packages: */ - for( j = 0 ; j < binary->count ; j++ ) { + for (j = 0 ; j < binary->count ; j++) { const char *b = binary->values[j]; size_t l = strlen(b); - if( strncmp(fk, b, l) == 0 && - fk[l] == '_' ) + if (strncmp(fk, b, l) == 0 && + fk[l] == '_') found_binary[j] = true; } continue; } - if( ft == ft_ARCH_BINARY ) { + if (ft == ft_ARCH_BINARY) { const char *a = strrchr(fk, '_'); - if( a == NULL ) + if (a == NULL) continue; a++; - if( strncmp(a, archstring, archstringlen) != 0 || - a[archstringlen] != '.' ) + if (strncmp(a, archstring, archstringlen) != 0 || + a[archstringlen] != '.') continue; /* found an .deb with this architecture, so nothing is to be done */ return RET_NOTHING; } - if( ft == ft_LOG || ft == ft_CHANGES ) { + if (ft == ft_LOG || ft == ft_CHANGES) { const char *a = strrchr(fk, '_'); const char *e; - if( a == NULL ) + if (a == NULL) continue; a++; - while( (e = strchr(a, '+')) != NULL ) { - if( (size_t)(e-a) != archstringlen ) { + while ((e = strchr(a, '+')) != NULL) { + if ((size_t)(e-a) != archstringlen) { a = e+1; continue; } - if( memcmp(a, archstring, archstringlen) != 0 ){ + if (memcmp(a, archstring, archstringlen) != 0){ a = e+1; continue; } @@ -105,13 +105,13 @@ return RET_NOTHING; } e = strchr(a, '.'); - if( e == NULL ) + if (e == NULL) continue; - if( (size_t)(e-a) != archstringlen ) { + if ((size_t)(e-a) != archstringlen) { a = e+1; continue; } - if( memcmp(a, archstring, archstringlen) != 0 ){ + if (memcmp(a, archstring, archstringlen) != 0){ a = e+1; continue; } @@ -121,8 +121,8 @@ } /* nothing for this architecture was found, check if is has any binary packages that are lacking: */ - for( i = 0 ; i < binary->count ; i++ ) { - if( !found_binary[i] ) { + for (i = 0 ; i < binary->count ; i++) { + if (!found_binary[i]) { printf("%s %s %s\n", sourcename, sourceversion, dscfilename); @@ -138,7 +138,7 @@ /*@null@*/ const char *glob; }; -static retvalue check_source_needs_build(UNUSED(struct database *database), struct distribution *distribution, struct target *target, const char *sourcename, const char *control, void *data) { +static retvalue check_source_needs_build(struct distribution *distribution, struct target *target, const char *sourcename, const char *control, void *data) { struct needbuild_data *d = data; char *sourceversion; struct strlist binary, architectures, filekeys; @@ -146,52 +146,52 @@ int i; retvalue r; - if( d->glob != NULL && !globmatch(sourcename, d->glob) ) + if (d->glob != NULL && !globmatch(sourcename, d->glob)) return RET_NOTHING; r = target->getversion(control, &sourceversion); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; r = chunk_getwordlist(control, "Architecture", &architectures); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { bool skip = true; - for( i = 0 ; i < architectures.count ; i++ ) { + for (i = 0 ; i < architectures.count ; i++) { const char *a = architectures.values[i]; - if( strcmp(a, "any") == 0 ) { + if (strcmp(a, "any") == 0) { skip = false; break; } - if( strcmp(a, atoms_architectures[ - d->architecture]) == 0 ) { + if (strcmp(a, atoms_architectures[ + d->architecture]) == 0) { skip = false; break; } } strlist_done(&architectures); - if( skip ) { + if (skip) { free(sourceversion); return RET_NOTHING; } } r = chunk_getwordlist(control, "Binary", &binary); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(sourceversion); return r; } r = target->getfilekeys(control, &filekeys); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { strlist_done(&binary); free(sourceversion); return r; } - for( i = 0 ; i < filekeys.count ; i++ ) { - if( endswith(filekeys.values[i], ".dsc") ) { + for (i = 0 ; i < filekeys.count ; i++) { + if (endswith(filekeys.values[i], ".dsc")) { dscfilename = filekeys.values[i]; break; } } - if( dscfilename == NULL ) { + if (dscfilename == NULL) { fprintf(stderr, "Warning: source package '%s' in '%s' without dsc file!\n", sourcename, target->identifier); @@ -201,17 +201,17 @@ return RET_NOTHING; } - if( d->tracks != NULL ) { + if (d->tracks != NULL) { struct trackedpackage *tp; r = tracking_get(d->tracks, sourcename, sourceversion, &tp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(sourceversion); strlist_done(&binary); strlist_done(&filekeys); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = tracked_source_needs_build( d->architecture, sourcename, sourceversion, dscfilename, @@ -222,7 +222,10 @@ strlist_done(&filekeys); return r; } - fprintf(stderr, "Warning: %s's tracking data of %s (%s) is out of date. Run retrack to repair!\n", distribution->codename, sourcename, sourceversion); + fprintf(stderr, +"Warning: %s's tracking data of %s (%s) is out of date. Run retrack to repair!\n", + distribution->codename, + sourcename, sourceversion); } // TODO: implement without tracking free(sourceversion); @@ -232,14 +235,14 @@ } -retvalue find_needs_build(struct database *database, struct distribution *distribution, architecture_t architecture, const struct atomlist *onlycomponents, const char *glob) { +retvalue find_needs_build(struct distribution *distribution, architecture_t architecture, const struct atomlist *onlycomponents, const char *glob) { retvalue result, r; struct needbuild_data d; d.architecture = architecture; d.glob = glob; - if( distribution->tracking == dt_NONE ) { + if (distribution->tracking == dt_NONE) { fprintf(stderr, "ERROR: '%s' has no source package Tracking enabled and\n" "build-needing is currently only implemented for distributions where\n" @@ -250,16 +253,16 @@ return RET_ERROR; } - if( distribution->tracking != dt_NONE ) { - r = tracking_initialize(&d.tracks, database, distribution, true); - if( RET_WAS_ERROR(r) ) + if (distribution->tracking != dt_NONE) { + r = tracking_initialize(&d.tracks, distribution, true); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) d.tracks = NULL; } else d.tracks = NULL; - result = distribution_foreach_package_c(distribution, database, + result = distribution_foreach_package_c(distribution, onlycomponents, architecture_source, pt_dsc, check_source_needs_build, &d); diff -Nru reprepro-4.5.0/needbuild.h reprepro-4.6.0/needbuild.h --- reprepro-4.5.0/needbuild.h 2009-08-24 13:35:08.000000000 +0000 +++ reprepro-4.6.0/needbuild.h 2011-05-05 14:42:55.000000000 +0000 @@ -11,6 +11,6 @@ #include "distribution.h" #endif -retvalue find_needs_build(struct database *, struct distribution *, architecture_t, const struct atomlist *, /*@null@*/const char *glob); +retvalue find_needs_build(struct distribution *, architecture_t, const struct atomlist *, /*@null@*/const char *glob); #endif diff -Nru reprepro-4.5.0/NEWS reprepro-4.6.0/NEWS --- reprepro-4.5.0/NEWS 2011-02-21 15:34:27.000000000 +0000 +++ reprepro-4.6.0/NEWS 2011-05-05 14:42:55.000000000 +0000 @@ -1,3 +1,13 @@ +Updates between 4.5.1 and 4.6.0: +- add 'FilterSrcList' for update and pull +- ignore leading comments in control files + +Updates between 4.5.0 and 4.5.1: +- 'check' also checks if architectures match +- buffix in 'sourcemissing', 'unusedsources' and 'reportcruft' without tracking +- fix 'pull' copying packages with wrong architecture +- compile with libdb5 + Updates between 4.4.0 and 4.5.0: - support reading of Release files without MD5Sum - add all missing Checksums-* when importing from remote repositories diff -Nru reprepro-4.5.0/optionsfile.c reprepro-4.6.0/optionsfile.c --- reprepro-4.5.0/optionsfile.c 2009-08-24 13:35:08.000000000 +0000 +++ reprepro-4.6.0/optionsfile.c 2011-05-05 14:42:55.000000000 +0000 @@ -26,7 +26,7 @@ #include "names.h" #include "optionsfile.h" -void optionsfile_parse(const char *directory, const struct option *longopts, void handle_option(int,const char *)) { +void optionsfile_parse(const char *directory, const struct option *longopts, void handle_option(int, const char *)) { FILE *f; char *filename; char buffer[1000]; @@ -34,89 +34,93 @@ const struct option *option; filename = calc_dirconcat(directory, "options"); - if( FAILEDTOALLOC(filename) ) { + if (FAILEDTOALLOC(filename)) { (void)fputs("Out of memory!\n", stderr); exit(EXIT_FAILURE); } - f = fopen(filename,"r"); - if( f == NULL ) { + f = fopen(filename, "r"); + if (f == NULL) { free(filename); return; } - while( fgets(buffer,999,f) != NULL ) { + while (fgets(buffer, 999, f) != NULL) { size_t l; - char *optionname,*argument; + char *optionname, *argument; linenr++; l = strlen(buffer); - if( l == 0 || buffer[l-1] != '\n' ) { - fprintf(stderr,"%s:%d: Ignoring too long (or incomplete) line.\n",filename,linenr); + if (l == 0 || buffer[l-1] != '\n') { + fprintf(stderr, +"%s:%d: Ignoring too long (or incomplete) line.\n", + filename, linenr); do { - if( fgets(buffer,999,f) == NULL ) + if (fgets(buffer, 999, f) == NULL) break; l = strlen(buffer); - } while( l > 0 && buffer[l-1] != '\n' ); + } while (l > 0 && buffer[l-1] != '\n'); continue; } do{ buffer[l-1] = '\0'; l--; - } while( l > 0 && xisspace(buffer[l-1])); + } while (l > 0 && xisspace(buffer[l-1])); - if( l == 0 ) + if (l == 0) continue; optionname = buffer; - while( *optionname != '\0' && xisspace(*optionname) ) + while (*optionname != '\0' && xisspace(*optionname)) optionname++; - assert( *optionname != '\0' ); - if( *optionname == '#' || *optionname == ';' ) + assert (*optionname != '\0'); + if (*optionname == '#' || *optionname == ';') continue; argument = optionname; - while( *argument != '\0' && !xisspace(*argument) ) + while (*argument != '\0' && !xisspace(*argument)) argument++; - while( *argument != '\0' && xisspace(*argument) ) { + while (*argument != '\0' && xisspace(*argument)) { *argument = '\0'; argument++; } - if( *argument == '\0' ) + if (*argument == '\0') argument = NULL; option = longopts; - while( option->name != NULL && strcmp(option->name,optionname) != 0 ) + while (option->name != NULL && strcmp(option->name, optionname) != 0) option++; - if( option->name == NULL ) { - fprintf(stderr,"%s:%d: unknown option '%s'!\n", - filename,linenr,optionname); + if (option->name == NULL) { + fprintf(stderr, "%s:%d: unknown option '%s'!\n", + filename, linenr, optionname); exit(EXIT_FAILURE); } - if( option->has_arg==no_argument && argument != NULL ) { - fprintf(stderr,"%s:%d: option '%s' has an unexpected argument '%s'!\n", - filename,linenr,optionname,argument); + if (option->has_arg==no_argument && argument != NULL) { + fprintf(stderr, +"%s:%d: option '%s' has an unexpected argument '%s'!\n", + filename, linenr, optionname, argument); exit(EXIT_FAILURE); } - if( option->has_arg==required_argument && argument == NULL ) { - fprintf(stderr,"%s:%d: option '%s' is missing an argument!\n", - filename,linenr,optionname); + if (option->has_arg==required_argument && argument == NULL) { + fprintf(stderr, +"%s:%d: option '%s' is missing an argument!\n", + filename, linenr, optionname); exit(EXIT_FAILURE); } - if( option->flag == NULL ) - handle_option(option->val,argument); + if (option->flag == NULL) + handle_option(option->val, argument); else { *option->flag = option->val; - handle_option(0,argument); + handle_option(0, argument); } } - if( ferror(f) != 0 ) { + if (ferror(f) != 0) { int e = ferror(f); - fprintf(stderr,"%s: error while reading config file: %d=%s\n", + fprintf(stderr, "%s: error while reading config file: %d=%s\n", filename, e, strerror(e)); exit(EXIT_FAILURE); } - if( fclose(f) != 0 ) { + if (fclose(f) != 0) { int e = errno; - fprintf(stderr,"%s: error while reading config file: %d=%s\n", + fprintf(stderr, "%s: error while reading config file: %d=%s\n", filename, e, strerror(e)); exit(EXIT_FAILURE); } diff -Nru reprepro-4.5.0/optionsfile.h reprepro-4.6.0/optionsfile.h --- reprepro-4.5.0/optionsfile.h 2009-08-24 13:35:08.000000000 +0000 +++ reprepro-4.6.0/optionsfile.h 2011-05-05 14:42:55.000000000 +0000 @@ -8,6 +8,6 @@ #warning "What's hapening here?" #endif -void optionsfile_parse(const char *directory, const struct option *longopts, void handle_option(int,const char *)); +void optionsfile_parse(const char * /*directory*/, const struct option *, void handle_option(int, const char *)); #endif /*REPREPRO_OPTIONSFILE_H*/ diff -Nru reprepro-4.5.0/override.c reprepro-4.6.0/override.c --- reprepro-4.5.0/override.c 2010-10-24 08:59:10.000000000 +0000 +++ reprepro-4.6.0/override.c 2011-05-05 14:42:55.000000000 +0000 @@ -66,12 +66,12 @@ void override_free(struct overridefile *info) { struct overridepattern *i; - if( info == NULL ) + if (info == NULL) return; tdestroy(info->packages, freeoverridepackage); - while( (i = info->patterns) != NULL ) { - if( i == NULL ) + while ((i = info->patterns) != NULL) { + if (i == NULL) return; strlist_done(&i->data.fields); free(i->pattern); @@ -82,30 +82,30 @@ } static bool forbidden_field_name(bool source, const char *field) { - if( strcasecmp(field, "Package") == 0 ) + if (strcasecmp(field, "Package") == 0) return true; - if( strcasecmp(field, "Version") == 0 ) + if (strcasecmp(field, "Version") == 0) return true; - if( source ) { - if( strcasecmp(field, "Files") == 0 ) + if (source) { + if (strcasecmp(field, "Files") == 0) return true; - if( strcasecmp(field, "Directory") == 0 ) + if (strcasecmp(field, "Directory") == 0) return true; - if( strcasecmp(field, "Checksums-Sha256") == 0 ) + if (strcasecmp(field, "Checksums-Sha256") == 0) return true; - if( strcasecmp(field, "Checksums-Sha1") == 0 ) + if (strcasecmp(field, "Checksums-Sha1") == 0) return true; return false; } else { - if( strcasecmp(field, "Filename") == 0 ) + if (strcasecmp(field, "Filename") == 0) return true; - if( strcasecmp(field, "MD5sum") == 0 ) + if (strcasecmp(field, "MD5sum") == 0) return true; - if( strcasecmp(field, "SHA1") == 0 ) + if (strcasecmp(field, "SHA1") == 0) return true; - if( strcasecmp(field, "SHA256") == 0 ) + if (strcasecmp(field, "SHA256") == 0) return true; - if( strcasecmp(field, "Size") == 0 ) + if (strcasecmp(field, "Size") == 0) return true; return false; } @@ -115,34 +115,34 @@ retvalue r; char *p; - if( forbidden_field_name(source, secondpart) ) { + if (forbidden_field_name(source, secondpart)) { fprintf(stderr, "Error: field '%s' not allowed in override files.\n", secondpart); return RET_ERROR; } - if( secondpart[0] == '$' ) { - if( strcasecmp(secondpart, "$Delete") == 0 ) { - if( forbidden_field_name(source, thirdpart) ) { + if (secondpart[0] == '$') { + if (strcasecmp(secondpart, "$Delete") == 0) { + if (forbidden_field_name(source, thirdpart)) { fprintf(stderr, "Error: field '%s' not allowed in override files (not even as to be deleted).\n", thirdpart); return RET_ERROR; } - } else if( strcasecmp(secondpart, "$Component") != 0 ) { + } else if (strcasecmp(secondpart, "$Component") != 0) { fprintf(stderr, "Warning: special override field '%s' unknown and will be ignored\n", secondpart); } } p = strdup(secondpart); - if( FAILEDTOALLOC(p) ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; r = strlist_add(&data->fields, p); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; p = strdup(thirdpart); - if( FAILEDTOALLOC(p) ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; r = strlist_add(&data->fields, p); return r; @@ -151,11 +151,11 @@ static struct overridepackage *new_package(const char *name) { struct overridepackage *p; - p = calloc(1, sizeof(struct overridepackage)); - if( FAILEDTOALLOC(p) ) + p = zNEW(struct overridepackage); + if (FAILEDTOALLOC(p)) return NULL; p->packagename = strdup(name); - if( FAILEDTOALLOC(p->packagename) ) { + if (FAILEDTOALLOC(p->packagename)) { free(p); return NULL; } @@ -175,29 +175,29 @@ struct overridepattern *p, **l; c = firstpart; - while (*c != '\0' && *c != '*' && *c != '[' && *c != '?' ) + while (*c != '\0' && *c != '*' && *c != '[' && *c != '?') c++; - if( *c != '\0' ) { + if (*c != '\0') { /* This is a pattern, put into the pattern list */ l = &i->patterns; - while( (p = *l) != NULL - && strcmp(p->pattern, firstpart) != 0 ) { + while ((p = *l) != NULL + && strcmp(p->pattern, firstpart) != 0) { l = &p->next; } - if( p == NULL ) { - p = calloc(1, sizeof(struct overridepattern)); - if( FAILEDTOALLOC(p) ) + if (p == NULL) { + p = zNEW(struct overridepattern); + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->pattern = strdup(firstpart); - if( FAILEDTOALLOC(p->pattern) ) { + if (FAILEDTOALLOC(p->pattern)) { free(p); return RET_ERROR_OOM; } } r = add_override_field(&p->data, secondpart, thirdpart, source); - if( RET_WAS_ERROR(r) ) { - if( *l != p ) { + if (RET_WAS_ERROR(r)) { + if (*l != p) { free(p->pattern); free(p); } @@ -208,14 +208,14 @@ } pkg = new_package(firstpart); - if( FAILEDTOALLOC(pkg) ) + if (FAILEDTOALLOC(pkg)) return RET_ERROR_OOM; node = tsearch(pkg, &i->packages, opackage_compare); - if( FAILEDTOALLOC(node) ) + if (FAILEDTOALLOC(node)) return RET_ERROR_OOM; - if( *node == pkg ) { + if (*node == pkg) { r = strlist_init_n(6, &pkg->data.fields); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } else { free(pkg->packagename); @@ -228,45 +228,45 @@ retvalue override_read(const char *filename, struct overridefile **info, bool source) { struct overridefile *i; - struct overridepattern **next_pattern; FILE *file; char buffer[1001]; - if( filename == NULL ) { + if (filename == NULL) { *info = NULL; return RET_OK; } - if( filename[0] != '/' ) { + if (filename[0] != '/') { char *fn = calc_conffile(filename); - if( fn == NULL ) + if (FAILEDTOALLOC(fn)) return RET_ERROR_OOM; file = fopen(fn, "r"); free(fn); } else - file = fopen(filename,"r"); + file = fopen(filename, "r"); - if( file == NULL ) { + if (file == NULL) { int e = errno; fprintf(stderr, "Error %d opening override file '%s': %s\n", e, filename, strerror(e)); return RET_ERRNO(e); } - i = calloc(1, sizeof(struct overridefile)); - if( FAILEDTOALLOC(i) ) { + i = zNEW(struct overridefile); + if (FAILEDTOALLOC(i)) { (void)fclose(file); return RET_ERROR_OOM; } - next_pattern = &i->patterns; - while( fgets(buffer,1000,file) != NULL ){ + while (fgets(buffer, 1000, file) != NULL){ retvalue r; const char *firstpart, *secondpart, *thirdpart; char *p; size_t l = strlen(buffer); - if( buffer[l-1] != '\n' ) { - if( l >= 999 ) { - fprintf(stderr,"Too long line in '%s'!\n",filename); + if (buffer[l-1] != '\n') { + if (l >= 999) { + fprintf(stderr, +"Too long line in '%s'!\n", + filename); override_free(i); (void)fclose(file); return RET_ERROR; @@ -277,35 +277,35 @@ l--; buffer[l] = '\0'; } - while( l>0 && xisspace(buffer[l])) { + while (l>0 && xisspace(buffer[l])) { buffer[l] = '\0'; l--; } - if( l== 0 ) + if (l== 0) continue; p = buffer; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) *(p++)='\0'; firstpart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) *(p++)='\0'; secondpart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) *(p++)='\0'; thirdpart = p; r = add_override(i, firstpart, secondpart, thirdpart, source); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { override_free(i); (void)fclose(file); return r; } } (void)fclose(file); - if( i->packages != NULL || i->patterns != NULL ) { + if (i->packages != NULL || i->patterns != NULL) { *info = i; return RET_OK; } else { @@ -319,15 +319,15 @@ struct overridepackage pkg, **node; struct overridepattern *p; - if( overrides == NULL ) + if (overrides == NULL) return NULL; pkg.packagename = (char*)package; node = tfind(&pkg, &overrides->packages, opackage_compare); - if( node != NULL && *node != NULL ) + if (node != NULL && *node != NULL) return &(*node)->data; - for( p = overrides->patterns ; p != NULL ; p = p->next ) { - if( globmatch(package, p->pattern) ) + for (p = overrides->patterns ; p != NULL ; p = p->next) { + if (globmatch(package, p->pattern)) return &p->data; } return NULL; @@ -336,12 +336,12 @@ const char *override_get(const struct overridedata *override, const char *field) { int i; - if( override == NULL ) + if (override == NULL) return NULL; - for( i = 0 ; i+1 < override->fields.count ; i+=2 ) { + for (i = 0 ; i+1 < override->fields.count ; i+=2) { // TODO curently case-sensitiv. warn if otherwise? - if( strcmp(override->fields.values[i], field) == 0 ) + if (strcmp(override->fields.values[i], field) == 0) return override->fields.values[i+1]; } return NULL; @@ -353,26 +353,26 @@ struct fieldtoadd *override_addreplacefields(const struct overridedata *override, struct fieldtoadd *otherreplaces) { int i; - if( override == NULL ) + if (override == NULL) return otherreplaces; - for( i = 0 ; i+1 < override->fields.count ; i+=2 ) { - if( strcmp(override->fields.values[i], + for (i = 0 ; i+1 < override->fields.count ; i+=2) { + if (strcmp(override->fields.values[i], SECTION_FIELDNAME) != 0 && strcmp(override->fields.values[i], PRIORITY_FIELDNAME) != 0 && - override->fields.values[i][0] != '$' ) { + override->fields.values[i][0] != '$') { otherreplaces = addfield_new( override->fields.values[i], override->fields.values[i+1], otherreplaces); - if( otherreplaces == NULL ) + if (otherreplaces == NULL) return NULL; - } else if( strcasecmp(override->fields.values[i], - "$delete") == 0 ) { + } else if (strcasecmp(override->fields.values[i], + "$delete") == 0) { otherreplaces = deletefield_new( override->fields.values[i+1], otherreplaces); - if( otherreplaces == NULL ) + if (otherreplaces == NULL) return NULL; } } @@ -384,25 +384,25 @@ int i; struct fieldtoadd *fields = NULL; - assert( override != NULL ); + assert (override != NULL); - for( i = 0 ; i+1 < override->fields.count ; i+=2 ) { - if( override->fields.values[i][0] != '$' ) { + for (i = 0 ; i+1 < override->fields.count ; i+=2) { + if (override->fields.values[i][0] != '$') { fields = addfield_new( override->fields.values[i], override->fields.values[i+1], fields); - if( fields == NULL ) + if (FAILEDTOALLOC(fields)) return RET_ERROR_OOM; - } else if( strcasecmp(override->fields.values[i], - "$delete") == 0 ) { + } else if (strcasecmp(override->fields.values[i], + "$delete") == 0) { fields = deletefield_new( override->fields.values[i+1], fields); - if( fields == NULL ) + if (FAILEDTOALLOC(fields)) return RET_ERROR_OOM; } } - if( fields == NULL ) + if (fields == NULL) return RET_NOTHING; *fields_p = fields; return RET_OK; diff -Nru reprepro-4.5.0/pool.c reprepro-4.6.0/pool.c --- reprepro-4.5.0/pool.c 2009-07-26 11:39:30.000000000 +0000 +++ reprepro-4.6.0/pool.c 2011-05-05 14:42:55.000000000 +0000 @@ -73,32 +73,32 @@ struct source_node *node; component_t c; - if( unlikely(memcmp(filekey, "pool/", 5) != 0) ) + if (unlikely(memcmp(filekey, "pool/", 5) != 0)) return RET_NOTHING; filekey += 5; p = strchr(filekey, '/'); - if( unlikely(p == NULL) ) + if (unlikely(p == NULL)) return RET_NOTHING; c = component_find_l(filekey, (size_t)(p - filekey)); - if( unlikely(!atom_defined(c)) ) + if (unlikely(!atom_defined(c))) return RET_NOTHING; p++; - if( p[0] != '\0' && p[1] == '/' && p[0] != '/' && p[2] == p[0] ) { + if (p[0] != '\0' && p[1] == '/' && p[0] != '/' && p[2] == p[0]) { p += 2; - if( unlikely(p[0] == 'l' && p[1] == 'i' && p[2] == 'b') ) + if (unlikely(p[0] == 'l' && p[1] == 'i' && p[2] == 'b')) return RET_NOTHING; - } else if( p[0] == 'l' && p[1] == 'i' && p[2] == 'b' && p[3] != '\0' && - p[4] == '/' && p[5] == 'l' && p[6] == 'i' && p[7] == 'b' && - p[3] != '/' && p[8] == p[3] ) { + } else if (p[0] == 'l' && p[1] == 'i' && p[2] == 'b' && p[3] != '\0' + && p[4] == '/' && p[5] == 'l' && p[6] == 'i' + && p[7] == 'b' && p[3] != '/' && p[8] == p[3]) { p += 5; } else return RET_NOTHING; source = p; p = strchr(source, '/'); - if( unlikely(p == NULL) ) + if (unlikely(p == NULL)) return RET_NOTHING; node = malloc(sizeof(struct source_node) + (p - source) + 1); - if( FAILEDTOALLOC(node) ) + if (FAILEDTOALLOC(node)) return RET_ERROR_OOM; node->file_changes = NULL; memcpy(node->sourcename, source, p - source); @@ -116,12 +116,12 @@ char **p; p = tsearch(name - 1, root_p, legacy_compare); - if( p == NULL ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; - if( *p == name - 1 ) { + if (*p == name - 1) { size_t l = strlen(name); *p = malloc(l + 2); - if (*p == NULL) + if (FAILEDTOALLOC(*p)) return RET_ERROR_OOM; **p = mode; memcpy((*p) + 1, name, l + 1); @@ -139,30 +139,30 @@ const char *basefilename IFSTUPIDCC(= NULL); r = split_filekey(filekey, &c, &node, &basefilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_OK ) { - assert( atom_defined(c) ); - if( c > reserved_components ) { + if (r == RET_OK) { + assert (atom_defined(c)); + if (c > reserved_components) { void ** h; - assert( c <= components_count() ); + assert (c <= components_count()); h = realloc(file_changes_per_component, sizeof(struct source_node*) * (c + 1)); - if( FAILEDTOALLOC(h) ) + if (FAILEDTOALLOC(h)) return RET_ERROR_OOM; file_changes_per_component = h; - while( reserved_components < c ) { + while (reserved_components < c) { h[++reserved_components] = NULL; } } - assert( file_changes_per_component != NULL ); + assert (file_changes_per_component != NULL); found = tsearch(node, &file_changes_per_component[c], source_node_compare); - if( FAILEDTOALLOC(found) ) + if (FAILEDTOALLOC(found)) return RET_ERROR_OOM; - if( *found != node ) { + if (*found != node) { free(node); node = *found; } @@ -192,44 +192,45 @@ size_t bufsize = 1024*1024; buffer = malloc(bufsize); - if( FAILEDTOALLOC(buffer) ) { + if (FAILEDTOALLOC(buffer)) { (void)close(outfd); (void)unlink(destination); bufsize = 16*1024; buffer = malloc(bufsize); - if( FAILEDTOALLOC(buffer) ) { + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; - } } infd = open(source, O_RDONLY|O_NOCTTY); - if( infd < 0 ) { + if (infd < 0) { int en = errno; - fprintf(stderr, "error %d opening file %s to be copied into the morgue: %s\n", + fprintf(stderr, +"error %d opening file %s to be copied into the morgue: %s\n", en, source, strerror(en)); free(buffer); (void)close(outfd); (void)unlink(destination); return RET_ERRNO(en); } - while( (readbytes = read(infd, buffer, bufsize)) > 0 ) { + while ((readbytes = read(infd, buffer, bufsize)) > 0) { const char *start = buffer; - if( (off_t)readbytes > length ) { - fprintf(stderr, "Mismatch of sizes of '%s': files is larger than expected!\n", + if ((off_t)readbytes > length) { + fprintf(stderr, +"Mismatch of sizes of '%s': files is larger than expected!\n", destination); break; } - while( readbytes > 0 ) { + while (readbytes > 0) { ssize_t written; written = write(outfd, start, readbytes); - if( written > 0 ) { - assert( written <= readbytes ); + if (written > 0) { + assert (written <= readbytes); readbytes -= written; start += written; - } else if( written < 0 ) { + } else if (written < 0) { int en = errno; (void)close(infd); @@ -237,33 +238,35 @@ (void)unlink(destination); free(buffer); - fprintf(stderr, "error %d writing to morgue file %s: %s\n", + fprintf(stderr, +"error %d writing to morgue file %s: %s\n", en, destination, strerror(en)); return RET_ERRNO(en); } } } free(buffer); - if( readbytes == 0 ) { + if (readbytes == 0) { err = close(infd); - if( err != 0 ) + if (err != 0) readbytes = -1; infd = -1; } - if( readbytes < 0 ) { + if (readbytes < 0) { int en = errno; - fprintf(stderr, "error %d reading file %s to be copied into the morgue: %s\n", + fprintf(stderr, +"error %d reading file %s to be copied into the morgue: %s\n", en, source, strerror(en)); - if( infd >= 0 ) + if (infd >= 0) (void)close(infd); (void)close(outfd); (void)unlink(destination); return RET_ERRNO(en); } - if( infd >= 0 ) + if (infd >= 0) (void)close(infd); err = close(outfd); - if( err != 0 ) { + if (err != 0) { int en = errno; fprintf(stderr, "error %d writing to morgue file %s: %s\n", @@ -280,50 +283,50 @@ int fd, en, number; retvalue r; - if( FAILEDTOALLOC(firsttry) ) + if (FAILEDTOALLOC(firsttry)) return RET_ERROR_OOM; fd = open(firsttry, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( fd >= 0 ) { - assert( fd > 2 ); + if (fd >= 0) { + assert (fd > 2); *name_p = firsttry; *fd_p = fd; return RET_OK; } en = errno; - if( en == ENOENT ) { + if (en == ENOENT) { r = dirs_make_recursive(global.morguedir); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(firsttry); return r; } /* try again */ fd = open(firsttry, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( fd >= 0 ) { - assert( fd > 2 ); + if (fd >= 0) { + assert (fd > 2); *name_p = firsttry; *fd_p = fd; return RET_OK; } en = errno; } - if( en != EEXIST ) { + if (en != EEXIST) { fprintf(stderr, "error %d creating morgue-file %s: %s\n", en, firsttry, strerror(en)); free(firsttry); return RET_ERRNO(en); } /* file exists, try names with -number appended: */ - for( number = 1 ; number < 1000 ; number++ ) { + for (number = 1 ; number < 1000 ; number++) { char *try = mprintf("%s-%d", firsttry, number); - if( FAILEDTOALLOC(try) ) { + if (FAILEDTOALLOC(try)) { free(firsttry); return RET_ERROR_OOM; } fd = open(try, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( fd >= 0 ) { - assert( fd > 2 ); + if (fd >= 0) { + assert (fd > 2); free(firsttry); *name_p = try; *fd_p = fd; @@ -343,51 +346,54 @@ int err; retvalue r; - if( !new && global.morguedir != NULL ) { + if (!new && global.morguedir != NULL) { int morguefd = -1; struct stat s; - r = morgue_name(filekey, &morguefilename, &morguefd); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + r = morgue_name(filekey, &morguefilename, &morguefd); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; err = lstat(filename, &s); - if( err != 0 ) { + if (err != 0) { int en = errno; - if( errno == ENOENT ) { + if (errno == ENOENT) { (void)close(morguefd); (void)unlink(morguefilename); free(morguefilename); return RET_NOTHING; } - fprintf(stderr, "error %d looking at file %s to be moved into the morgue: %s\n", + fprintf(stderr, +"error %d looking at file %s to be moved into the morgue: %s\n", en, filename, strerror(en)); (void)close(morguefd); (void)unlink(morguefilename); free(morguefilename); return RET_ERRNO(en); } - if( S_ISLNK(s.st_mode) ) { + if (S_ISLNK(s.st_mode)) { /* no need to copy a symbolic link: */ (void)close(morguefd); (void)unlink(morguefilename); free(morguefilename); morguefilename = NULL; - } else if( S_ISREG(s.st_mode) ) { + } else if (S_ISREG(s.st_mode)) { err = rename(filename, morguefilename); - if( err == 0 ) { + if (err == 0) { (void)close(morguefd); free(morguefilename); return RET_OK; } r = copyfile(filename, morguefilename, morguefd, s.st_size); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(morguefilename); return r; } } else { - fprintf(stderr, "Strange (non-regular) file '%s' in the pool.\nPlease delete manually!\n", filename); + fprintf(stderr, +"Strange (non-regular) file '%s' in the pool.\nPlease delete manually!\n", + filename); (void)close(morguefd); (void)unlink(morguefilename); free(morguefilename); @@ -396,13 +402,13 @@ } } err = unlink(filename); - if( err != 0 ) { + if (err != 0) { int en = errno; - if( errno == ENOENT ) + if (errno == ENOENT) return RET_NOTHING; fprintf(stderr, "error %d while unlinking %s: %s\n", en, filename, strerror(en)); - if( morguefilename != NULL ) { + if (morguefilename != NULL) { (void)unlink(morguefilename); free(morguefilename); } @@ -419,43 +425,45 @@ char *filename; retvalue r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; filename = files_calcfullfilename(filekey); - if( filename == NULL ) + if (FAILEDTOALLOC(filename)) return RET_ERROR_OOM; /* move to morgue or simply delete: */ r = movefiletomorgue(filekey, filename, new); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "%s not found, forgetting anyway\n", filename); } - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(filename); return r; } - if( !global.keepdirectories ) { + if (!global.keepdirectories) { /* try to delete parent directories, until one gives * errors (hopefully because it still contains files) */ size_t fixedpartlen = strlen(global.outdir); char *p; int err, en; - while( (p = strrchr(filename,'/')) != NULL ) { + while ((p = strrchr(filename, '/')) != NULL) { /* do not try to remove parts of the mirrordir */ - if( (size_t)(p-filename) <= fixedpartlen+1 ) + if ((size_t)(p-filename) <= fixedpartlen+1) break; *p ='\0'; /* try to rmdir the directory, this will * fail if there are still other files or directories * in it: */ err = rmdir(filename); - if( err == 0 ) { - if( verbose > 1 ) { - printf("removed now empty directory %s\n",filename); + if (err == 0) { + if (verbose > 1) { + printf( +"removed now empty directory %s\n", + filename); } } else { en = errno; - if( en != ENOTEMPTY ) { + if (en != ENOTEMPTY) { //TODO: check here if only some //other error was first and it //is not empty so we do not have @@ -476,17 +484,17 @@ } -retvalue pool_delete(struct database *database, const char *filekey) { +retvalue pool_delete(const char *filekey) { retvalue r; - if( verbose >= 1 ) - printf("deleting and forgetting %s\n",filekey); + if (verbose >= 1) + printf("deleting and forgetting %s\n", filekey); r = deletepoolfile(filekey, false); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - return files_remove(database, filekey); + return files_remove(filekey); } /* called from files_remove: */ @@ -497,7 +505,6 @@ /* libc's twalk misses a callback_data pointer, so we need some temporary * global variables: */ -static struct database *d; static retvalue result; static bool first, onlycount; static long woulddelete_count; @@ -508,39 +515,39 @@ char *node; const char *filekey; retvalue r; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(char **)nodep; filekey = node + 1; - if( (*node & pl_UNREFERENCED) == 0 ) + if ((*node & pl_UNREFERENCED) == 0) return; - r = references_isused(d, filekey); - if( r != RET_NOTHING ) + r = references_isused(filekey); + if (r != RET_NOTHING) return; - if( onlycount ) { + if (onlycount) { woulddelete_count++; return; } - if( verbose >= 0 && first ) { + if (verbose >= 0 && first) { printf("Deleting files no longer referenced...\n"); first = false; } - if( verbose >= 1 ) + if (verbose >= 1) printf("deleting and forgetting %s\n", filekey); r = deletepoolfile(filekey, (*node & pl_ADDED) != 0); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) { - r = files_removesilent(d, filekey); + if (!RET_WAS_ERROR(r)) { + r = files_removesilent(filekey); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) *node &= ~pl_UNREFERENCED; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *node |= pl_DELETED; } } @@ -551,40 +558,40 @@ char *filekey; retvalue r; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(char **)nodep; - if( (*node & pl_UNREFERENCED) == 0 ) + if ((*node & pl_UNREFERENCED) == 0) return; filekey = calc_filekey(current_component, sourcename, node + 1); - r = references_isused(d, filekey); - if( r != RET_NOTHING ) { + r = references_isused(filekey); + if (r != RET_NOTHING) { free(filekey); return; } - if( onlycount ) { + if (onlycount) { woulddelete_count++; free(filekey); return; } - if( verbose >= 0 && first ) { + if (verbose >= 0 && first) { printf("Deleting files no longer referenced...\n"); first = false; } - if( verbose >= 1 ) + if (verbose >= 1) printf("deleting and forgetting %s\n", filekey); r = deletepoolfile(filekey, (*node & pl_ADDED) != 0); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) { - r = files_removesilent(d, filekey); + if (!RET_WAS_ERROR(r)) { + r = files_removesilent(filekey); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) *node &= ~pl_UNREFERENCED; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *node |= pl_DELETED; } RET_UPDATE(result, r); @@ -594,10 +601,10 @@ static void removeunreferenced_from_component(const void *nodep, const VISIT which, UNUSED(const int depth)) { struct source_node *node; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(struct source_node **)nodep; @@ -605,28 +612,26 @@ twalk(node->file_changes, removeifunreferenced2); } -retvalue pool_removeunreferenced(struct database *database, bool delete) { +retvalue pool_removeunreferenced(bool delete) { component_t c; - if( !delete && verbose <= 0 ) + if (!delete && verbose <= 0) return RET_NOTHING; - d = database; result = RET_NOTHING; first = true; onlycount = !delete; woulddelete_count = 0; - for( c = 1 ; c <= reserved_components ; c++ ) { - assert( file_changes_per_component != NULL ); + for (c = 1 ; c <= reserved_components ; c++) { + assert (file_changes_per_component != NULL); current_component = c; twalk(file_changes_per_component[c], removeunreferenced_from_component); } twalk(legacy_file_changes, removeifunreferenced); - d = NULL; - if( interrupted() ) + if (interrupted()) result = RET_ERROR_INTERRUPTED; - if( !delete && woulddelete_count > 0 ) { + if (!delete && woulddelete_count > 0) { printf( "%lu files lost their last reference.\n" "(dumpunreferenced lists such files, use deleteunreferenced to delete them.)\n", @@ -639,42 +644,44 @@ char *node; const char *filekey; retvalue r; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(char **)nodep; filekey = node + 1; /* only look at newly added and not already deleted */ - if( (*node & (pl_ADDED|pl_DELETED)) != pl_ADDED ) + if ((*node & (pl_ADDED|pl_DELETED)) != pl_ADDED) return; - r = references_isused(d, filekey); - if( r != RET_NOTHING ) + r = references_isused(filekey); + if (r != RET_NOTHING) return; - if( onlycount ) { + if (onlycount) { woulddelete_count++; return; } - if( verbose >= 0 && first ) { - printf("Deleting files just added to the pool but not used (to avoid use --keepunusednewfiles next time)\n"); + if (verbose >= 0 && first) { + printf( +"Deleting files just added to the pool but not used.\n" +"(to avoid use --keepunusednewfiles next time)\n"); first = false; } - if( verbose >= 1 ) + if (verbose >= 1) printf("deleting and forgetting %s\n", filekey); r = deletepoolfile(filekey, true); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) { - r = files_removesilent(d, filekey); + if (!RET_WAS_ERROR(r)) { + r = files_removesilent(filekey); RET_UPDATE(result, r); /* don't remove pl_ADDED here, otherwise the hook * script will be told to remove something not added */ - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) *node &= ~pl_UNREFERENCED; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *node |= pl_DELETED; } } @@ -685,43 +692,45 @@ char *filekey; retvalue r; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(char **)nodep; /* only look at newly added and not already deleted */ - if( (*node & (pl_ADDED|pl_DELETED)) != pl_ADDED ) + if ((*node & (pl_ADDED|pl_DELETED)) != pl_ADDED) return; filekey = calc_filekey(current_component, sourcename, node + 1); - r = references_isused(d, filekey); - if( r != RET_NOTHING ) { + r = references_isused(filekey); + if (r != RET_NOTHING) { free(filekey); return; } - if( onlycount ) { + if (onlycount) { woulddelete_count++; free(filekey); return; } - if( verbose >= 0 && first ) { - printf("Deleting files just added to the pool but not used (to avoid use --keepunusednewfiles next time)\n"); + if (verbose >= 0 && first) { + printf( +"Deleting files just added to the pool but not used.\n" +"(to avoid use --keepunusednewfiles next time)\n"); first = false; } - if( verbose >= 1 ) + if (verbose >= 1) printf("deleting and forgetting %s\n", filekey); r = deletepoolfile(filekey, true); RET_UPDATE(result, r); - if( !RET_WAS_ERROR(r) ) { - r = files_removesilent(d, filekey); + if (!RET_WAS_ERROR(r)) { + r = files_removesilent(filekey); RET_UPDATE(result, r); /* don't remove pl_ADDED here, otherwise the hook * script will be told to remove something not added */ - if( !RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r)) *node &= ~pl_UNREFERENCED; - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *node |= pl_DELETED; } RET_UPDATE(result, r); @@ -731,10 +740,10 @@ static void removeunusednew_from_component(const void *nodep, const VISIT which, UNUSED(const int depth)) { struct source_node *node; - if( which != leaf && which != postorder) + if (which != leaf && which != postorder) return; - if( interrupted() ) + if (interrupted()) return; node = *(struct source_node **)nodep; @@ -742,27 +751,25 @@ twalk(node->file_changes, removeunusednew2); } -void pool_tidyadded(struct database *database, bool delete) { +void pool_tidyadded(bool delete) { component_t c; - if( !delete && verbose < 0 ) + if (!delete && verbose < 0) return; - d = database; result = RET_NOTHING; first = true; onlycount = !delete; woulddelete_count = 0; - for( c = 1 ; c <= reserved_components ; c++ ) { - assert( file_changes_per_component != NULL ); + for (c = 1 ; c <= reserved_components ; c++) { + assert (file_changes_per_component != NULL); current_component = c; twalk(file_changes_per_component[c], removeunusednew_from_component); } // this should not really happen at all, but better safe then sorry: twalk(legacy_file_changes, removeunusednew); - d = NULL; - if( !delete && woulddelete_count > 0 ) { + if (!delete && woulddelete_count > 0) { printf( "%lu files were added but not used.\n" "The next deleteunreferenced call will delete them.\n", diff -Nru reprepro-4.5.0/pool.h reprepro-4.6.0/pool.h --- reprepro-4.5.0/pool.h 2008-11-04 10:10:05.000000000 +0000 +++ reprepro-4.6.0/pool.h 2011-05-05 14:42:55.000000000 +0000 @@ -17,12 +17,12 @@ retvalue pool_markdeleted(const char *); /* Remove all files that lost their last reference, or only count them */ -retvalue pool_removeunreferenced(struct database *, bool delete); +retvalue pool_removeunreferenced(bool delete); /* Delete all added files that are not used, or only count them */ -void pool_tidyadded(struct database*, bool deletenew); +void pool_tidyadded(bool deletenew); /* delete and forget a single file */ -retvalue pool_delete(struct database *, const char *); +retvalue pool_delete(const char *); #endif diff -Nru reprepro-4.5.0/printlistformat.c reprepro-4.6.0/printlistformat.c --- reprepro-4.5.0/printlistformat.c 2010-07-11 10:16:03.000000000 +0000 +++ reprepro-4.6.0/printlistformat.c 2011-05-05 14:42:55.000000000 +0000 @@ -36,13 +36,13 @@ retvalue r; const char *p, *q; - if( listformat == NULL ) { + if (listformat == NULL) { char *version; r = target->getversion(control, &version); - if( RET_IS_OK(r) ) { - printf( -"%s: %s %s\n", target->identifier, package, version); + if (RET_IS_OK(r)) { + printf( "%s: %s %s\n", + target->identifier, package, version); free(version); } else { printf("Could not retrieve version from %s in %s\n", @@ -51,16 +51,16 @@ return r; } /* try to produce the same output dpkg-query --show produces: */ - for( p = listformat ; *p != '\0' ; p++ ) { + for (p = listformat ; *p != '\0' ; p++) { long length; char *value; const char *v; - if( *p == '\\' ) { + if (*p == '\\') { p++; - if( *p == '\0' ) + if (*p == '\0') break; - switch( *p ) { + switch (*p) { case 'n': putchar('\n'); break; @@ -80,89 +80,89 @@ } continue; } - if( *p != '$' || p[1] != '{' ) { + if (*p != '$' || p[1] != '{') { putchar(*p); continue; } p++; /* substitute veriable */ q = p; - while( *q != '\0' && *q != '}' && *q != ';' ) + while (*q != '\0' && *q != '}' && *q != ';') q++; - if( *q == '\0' || q == p ) { + if (*q == '\0' || q == p) { putchar('$'); putchar('{'); continue; } - if( q - p == 12 && strncasecmp(p, "{$identifier", 12) == 0 ) { + if (q - p == 12 && strncasecmp(p, "{$identifier", 12) == 0) { value = NULL; v = target->identifier; - } else if( q - p == 6 && strncasecmp(p, "{$type", 6) == 0 ) { + } else if (q - p == 6 && strncasecmp(p, "{$type", 6) == 0) { value = NULL; - v = atoms_packagetypes[target->packagetype_atom]; - } else if( q - p == 10 && - strncasecmp(p, "{$codename", 10) == 0 ) { + v = atoms_packagetypes[target->packagetype]; + } else if (q - p == 10 && + strncasecmp(p, "{$codename", 10) == 0) { value = NULL; v = target->distribution->codename; - } else if( q - p == 14 && - strncasecmp(p, "{$architecture", 14) == 0 ) { + } else if (q - p == 14 && + strncasecmp(p, "{$architecture", 14) == 0) { value = NULL; - v = atoms_architectures[target->architecture_atom]; - } else if( q - p == 11 && - strncasecmp(p, "{$component", 11) == 0 ) { + v = atoms_architectures[target->architecture]; + } else if (q - p == 11 && + strncasecmp(p, "{$component", 11) == 0) { value = NULL; - v = atoms_components[target->component_atom]; - } else if( q - p == 8 && strncasecmp(p, "{$source", 8) == 0 ) { + v = atoms_components[target->component]; + } else if (q - p == 8 && strncasecmp(p, "{$source", 8) == 0) { char *dummy = NULL; r = target->getsourceandversion(control, package, &value, &dummy); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(dummy); v = value; } else { value = NULL; v = ""; } - } else if( q - p == 15 && strncasecmp(p, "{$sourceversion", 15) == 0 ) { + } else if (q - p == 15 && strncasecmp(p, "{$sourceversion", 15) == 0) { char *dummy = NULL; r = target->getsourceandversion(control, package, &dummy, &value); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(dummy); v = value; } else { value = NULL; v = ""; } - } else if( q - p == 8 && strncasecmp(p, "{package", 8) == 0 ) { + } else if (q - p == 8 && strncasecmp(p, "{package", 8) == 0) { value = NULL; v = package; } else { char *variable = strndup(p + 1, q - (p + 1)); - if( FAILEDTOALLOC(variable) ) - return RET_ERROR_OOM; + if (FAILEDTOALLOC(variable)) + return RET_ERROR_OOM; r = chunk_getwholedata(control, variable, &value); free(variable); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { v = value; - while( *v != '\0' && xisspace(*v) ) + while (*v != '\0' && xisspace(*v)) v++; } else { value = NULL; v = ""; } } - if( *q == ';' ) { + if (*q == ';') { /* dpkg-query allows octal an hexadecimal, * so we do, too */ length = strtol(q + 1, (char**)&p, 0); - if( *p != '}' ) { + if (*p != '}') { free(value); putchar('$'); putchar('{'); @@ -173,26 +173,26 @@ length = 0; } /* as in dpkg-query, length 0 means unlimited */ - if( length == 0 ) { + if (length == 0) { fputs(v, stdout); } else { long value_length = strlen(v); - if( length < 0 ) { + if (length < 0) { length = -length; - while( value_length < length ) { + while (value_length < length) { putchar(' '); length--; } } - if( value_length > length ) { + if (value_length > length) { fwrite(v, length, 1, stdout); length = 0; - } else if( value_length > 0 ) { + } else if (value_length > 0) { fwrite(v, value_length, 1, stdout); length -= value_length; } - while( length-- > 0 ) + while (length-- > 0) putchar(' '); } free(value); diff -Nru reprepro-4.5.0/pull.c reprepro-4.6.0/pull.c --- reprepro-4.5.0/pull.c 2011-02-09 14:20:22.000000000 +0000 +++ reprepro-4.6.0/pull.c 2011-05-05 14:42:55.000000000 +0000 @@ -62,13 +62,14 @@ // NULL means no condition /*@null@*/term *includecondition; struct filterlist filterlist; + struct filterlist filtersrclist; /*----only set after _addsourcedistribution----*/ /*@NULL@*/ struct distribution *distribution; bool used; }; static void pull_rule_free(/*@only@*/struct pull_rule *pull) { - if( pull == NULL ) + if (pull == NULL) return; free(pull->name); free(pull->from); @@ -78,11 +79,12 @@ atomlist_done(&pull->udebcomponents); term_free(pull->includecondition); filterlist_release(&pull->filterlist); + filterlist_release(&pull->filtersrclist); free(pull); } void pull_freerules(struct pull_rule *p) { - while( p != NULL ) { + while (p != NULL) { struct pull_rule *rule; rule = p; @@ -97,6 +99,7 @@ CFatomlistSETPROC(pull_rule, components, at_component) CFatomlistSETPROC(pull_rule, udebcomponents, at_component) CFfilterlistSETPROC(pull_rule, filterlist) +CFfilterlistSETPROC(pull_rule, filtersrclist) CFtermSETPROC(pull_rule, includecondition) CFUSETPROC(pull_rule, architectures) { @@ -108,7 +111,7 @@ at_architecture, &this->architectures_from, &this->architectures_into); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Warning parsing %s, line %u: an empty Architectures field\n" "causes the whole rule to do nothing.\n", @@ -125,6 +128,7 @@ CF("Components", pull_rule, components), CF("UDebComponents", pull_rule, udebcomponents), CF("FilterFormula", pull_rule, includecondition), + CF("FilterSrcList", pull_rule, filtersrclist), CF("FilterList", pull_rule, filterlist) }; @@ -135,10 +139,10 @@ r = configfile_parse("pulls", IGNORABLE(unknownfield), configparser_pull_rule_init, linkedlistfinish, pullconfigfields, ARRAYCOUNT(pullconfigfields), &pull); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) *rules = pull; - else if( r == RET_NOTHING ) { - assert( pull == NULL ); + else if (r == RET_NOTHING) { + assert (pull == NULL); *rules = NULL; r = RET_OK; } else { @@ -165,7 +169,7 @@ }; void pull_freedistributions(struct pull_distribution *d) { - while( d != NULL ) { + while (d != NULL) { struct pull_distribution *next; next = d->next; @@ -182,25 +186,25 @@ int i; assert(distribution != NULL); - if( distribution->pulls.count == 0 ) + if (distribution->pulls.count == 0) return RET_NOTHING; p = malloc(sizeof(struct pull_distribution)+ sizeof(struct pull_rules *)*distribution->pulls.count); - if( p == NULL ) + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->next = NULL; p->distribution = distribution; p->targets = NULL; - for( i = 0 ; i < distribution->pulls.count ; i++ ) { + for (i = 0 ; i < distribution->pulls.count ; i++) { const char *name = distribution->pulls.values[i]; - if( strcmp(name,"-") == 0 ) { + if (strcmp(name, "-") == 0) { p->rules[i] = NULL; } else { struct pull_rule *rule = rules; - while( rule && strcmp(rule->name,name) != 0 ) + while (rule && strcmp(rule->name, name) != 0) rule = rule->next; - if( rule == NULL ) { + if (rule == NULL) { fprintf(stderr, "Error: Unknown pull rule '%s' in distribution '%s'!\n", name, distribution->codename); @@ -222,16 +226,16 @@ struct distribution *d; retvalue r; - for( d = distributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = distributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; r = pull_initdistribution(pp, d, rules); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { pull_freedistributions(p); return r; } - if( RET_IS_OK(r) ) { - assert( *pp != NULL ); + if (RET_IS_OK(r)) { + assert (*pp != NULL); pp = &(*pp)->next; } } @@ -248,16 +252,17 @@ struct pull_rule *rule; struct distribution *d; - for( rule = rules ; rule != NULL ; rule = rule->next ) { - if( rule->used && rule->distribution == NULL ) { - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( strcmp(d->codename, rule->from) == 0 ) { + for (rule = rules ; rule != NULL ; rule = rule->next) { + if (rule->used && rule->distribution == NULL) { + for (d = alldistributions ; d != NULL ; d = d->next) { + if (strcmp(d->codename, rule->from) == 0) { rule->distribution = d; break; } } - if( d == NULL ) { - fprintf(stderr, "Error: Unknown distribution '%s' referenced in pull rule '%s'\n", + if (d == NULL) { + fprintf(stderr, +"Error: Unknown distribution '%s' referenced in pull rule '%s'\n", rule->from, rule->name); return RET_ERROR_MISSING; } @@ -285,10 +290,10 @@ }; static void pull_freetargets(struct pull_target *targets) { - while( targets != NULL ) { + while (targets != NULL) { struct pull_target *target = targets; targets = target->next; - while( target->sources != NULL ) { + while (target->sources != NULL) { struct pull_source *source = target->sources; target->sources = source->next; free(source); @@ -304,47 +309,47 @@ const struct atomlist *a_from, *a_into; int ai; - assert( rule != NULL ); - assert( rule->distribution != NULL ); + assert (rule != NULL); + assert (rule->distribution != NULL); - if( rule->architectures_set ) { + if (rule->architectures_set) { a_from = &rule->architectures_from; a_into = &rule->architectures_into; } else { a_from = &rule->distribution->architectures; a_into = &rule->distribution->architectures; } - if( target->packagetype_atom == pt_udeb ) { - if( rule->udebcomponents_set ) + if (target->packagetype == pt_udeb) { + if (rule->udebcomponents_set) c = &rule->udebcomponents; else c = &rule->distribution->udebcomponents; } else { - if( rule->components_set ) + if (rule->components_set) c = &rule->components; else c = &rule->distribution->components; } - if( !atomlist_in(c, target->component_atom) ) + if (!atomlist_in(c, target->component)) return RET_NOTHING; - for( ai = 0 ; ai < a_into->count ; ai++ ) { + for (ai = 0 ; ai < a_into->count ; ai++) { struct pull_source *source; - if( a_into->atoms[ai] != target->architecture_atom ) + if (a_into->atoms[ai] != target->architecture) continue; - source = malloc(sizeof(struct pull_source)); - if( source == NULL ) + source = NEW(struct pull_source); + if (FAILEDTOALLOC(source)) return RET_ERROR_OOM; source->next = NULL; source->rule = rule; source->source = distribution_getpart(rule->distribution, - target->component_atom, + target->component, a_from->atoms[ai], - target->packagetype_atom); + target->packagetype); **s = source; *s = &source->next; } @@ -354,8 +359,8 @@ static retvalue pull_createdelete(struct pull_source ***s) { struct pull_source *source; - source = malloc(sizeof(struct pull_source)); - if( source == NULL ) + source = NEW(struct pull_source); + if (FAILEDTOALLOC(source)) return RET_ERROR_OOM; source->next = NULL; @@ -372,10 +377,9 @@ retvalue r; int i; - pt = malloc(sizeof(struct pull_target)); - if( pt == NULL ) { + pt = NEW(struct pull_target); + if (FAILEDTOALLOC(pt)) return RET_ERROR_OOM; - } pt->target = target; pt->next = pd->targets; pt->upgradelist = NULL; @@ -383,14 +387,14 @@ s = &pt->sources; pd->targets = pt; - for( i = 0 ; i < pd->distribution->pulls.count ; i++ ) { + for (i = 0 ; i < pd->distribution->pulls.count ; i++) { struct pull_rule *rule = pd->rules[i]; - if( rule == NULL) + if (rule == NULL) r = pull_createdelete(&s); else r = pull_createsource(rule, target, &s); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } @@ -400,17 +404,14 @@ static retvalue pull_generatetargets(struct pull_distribution *pull_distributions) { struct pull_distribution *pd; struct target *target; - struct pull_distribution *u_ds; retvalue r; - u_ds = NULL; - - for( pd = pull_distributions ; pd != NULL ; pd = pd->next ) { - for( target = pd->distribution->targets ; target != NULL ; + for (pd = pull_distributions ; pd != NULL ; pd = pd->next) { + for (target = pd->distribution->targets ; target != NULL ; target = target->next) { - r = generatepulltarget(pd,target); - if( RET_WAS_ERROR(r) ) + r = generatepulltarget(pd, target); + if (RET_WAS_ERROR(r)) return r; } } @@ -425,14 +426,14 @@ bool *found; int i, j; - found = calloc(list->count, sizeof(bool)); - if( found == NULL ) + found = nzNEW(list->count, bool); + if (FAILEDTOALLOC(found)) return found; - for( i = 0 ; i < list->count ; i++ ) { - if( found[i] ) + for (i = 0 ; i < list->count ; i++) { + if (found[i]) continue; - for( j = i + 1 ; j < list->count ; j++ ) - if( list->atoms[i] == list->atoms[j] ) + for (j = i + 1 ; j < list->count ; j++) + if (list->atoms[i] == list->atoms[j]) found[j] = true; } return found; @@ -442,12 +443,12 @@ static inline void markasused(const struct strlist *pulls, const char *rulename, const struct atomlist *needed, const struct atomlist *have, bool *found) { int i, j, o; - for( i = 0 ; i < pulls->count ; i++ ) { - if( strcmp(pulls->values[i], rulename) != 0 ) + for (i = 0 ; i < pulls->count ; i++) { + if (strcmp(pulls->values[i], rulename) != 0) continue; - for( j = 0 ; j < have->count ; j++ ) { + for (j = 0 ; j < have->count ; j++) { o = atomlist_ofs(needed, have->atoms[j]); - if( o >= 0 ) + if (o >= 0) found[o] = true; } } @@ -458,19 +459,19 @@ const struct distribution *d; int i; - assert( rule != NULL ); - if( architectures->count == 0 ) + assert (rule != NULL); + if (architectures->count == 0) return; found = preparefoundlist(architectures); - if( found == NULL ) + if (found == NULL) return; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { markasused(&d->pulls, rule->name, architectures, &d->architectures, found); } - for( i = 0 ; i < architectures->count ; i++ ) { - if( found[i] ) + for (i = 0 ; i < architectures->count ; i++) { + if (found[i]) continue; fprintf(stderr, "Warning: pull rule '%s' wants to %s architecture '%s',\n" @@ -488,19 +489,19 @@ const struct distribution *d; int i; - assert( rule != NULL ); - if( components->count == 0 ) + assert (rule != NULL); + if (components->count == 0) return; found = preparefoundlist(components); - if( found == NULL ) + if (found == NULL) return; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { markasused(&d->pulls, rule->name, components, &d->components, found); } - for( i = 0 ; i < components->count ; i++ ) { - if( found[i] ) + for (i = 0 ; i < components->count ; i++) { + if (found[i]) continue; fprintf(stderr, "Warning: pull rule '%s' wants to %s component '%s',\n" @@ -518,19 +519,19 @@ const struct distribution *d; int i; - assert( rule != NULL ); - if( udebcomponents->count == 0 ) + assert (rule != NULL); + if (udebcomponents->count == 0) return; found = preparefoundlist(udebcomponents); - if( found == NULL ) + if (found == NULL) return; - for( d = alldistributions ; d != NULL ; d = d->next ) { + for (d = alldistributions ; d != NULL ; d = d->next) { markasused(&d->pulls, rule->name, udebcomponents, &d->udebcomponents, found); } - for( i = 0 ; i < udebcomponents->count ; i++ ) { - if( found[i] ) + for (i = 0 ; i < udebcomponents->count ; i++) { + if (found[i]) continue; fprintf(stderr, "Warning: pull rule '%s' wants to %s udeb component '%s',\n" @@ -546,17 +547,17 @@ static void checksubset(const struct atomlist *needed, const struct atomlist *have, const char *rulename, const char *from, const char *what, const char **atoms) { int i, j; - for( i = 0 ; i < needed->count ; i++ ) { + for (i = 0 ; i < needed->count ; i++) { atom_t value = needed->atoms[i]; - for( j = 0 ; j < i ; j++ ) { - if( value == needed->atoms[j]) + for (j = 0 ; j < i ; j++) { + if (value == needed->atoms[j]) break; } - if( j < i ) + if (j < i) continue; - if( !atomlist_in(have, value) ) { + if (!atomlist_in(have, value)) { fprintf(stderr, "Warning: pull rule '%s' wants to get something from %s '%s',\n" "but there is no such %s in distribution '%s'.\n" @@ -568,7 +569,7 @@ } static void searchunused(const struct distribution *alldistributions, const struct pull_rule *rule) { - if( rule->distribution != NULL ) { + if (rule->distribution != NULL) { // TODO: move this part of the checks into parsing? checksubset(&rule->architectures_from, &rule->distribution->architectures, @@ -584,8 +585,8 @@ atoms_components); } - if( rule->distribution == NULL ) { - assert( strcmp(rule->from, "*") == 0 ); + if (rule->distribution == NULL) { + assert (strcmp(rule->from, "*") == 0); checkifarchitectureisused(&rule->architectures_from, alldistributions, rule, "get something from"); /* no need to check component and udebcomponent, as those @@ -602,8 +603,8 @@ static void pull_searchunused(const struct distribution *alldistributions, struct pull_rule *pull_rules) { struct pull_rule *rule; - for( rule = pull_rules ; rule != NULL ; rule = rule->next ) { - if( !rule->used ) + for (rule = pull_rules ; rule != NULL ; rule = rule->next) { + if (!rule->used) continue; searchunused(alldistributions, rule); @@ -619,19 +620,19 @@ retvalue r; r = pull_init(&pulls, rules, alldistributions); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = pull_loadsourcedistributions(alldistributions, rules); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { pull_freedistributions(pulls); return r; } - if( !fast ) + if (!fast) pull_searchunused(alldistributions, rules); r = pull_generatetargets(pulls); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { pull_freedistributions(pulls); return r; } @@ -644,12 +645,36 @@ * decide what gets pulled * **************************************************************************/ -static upgrade_decision ud_decide_by_rule(void *privdata, const struct target *target, const char *package, /*@null@*/const char *old_version, UNUSED(const char *new_version), const char *newcontrolchunk) { +static upgrade_decision ud_decide_by_rule(void *privdata, const struct target *target, const char *package, const char *sourcename, /*@null@*/const char *old_version, const char *new_version, const char *sourceversion, const char *newcontrolchunk) { struct pull_rule *rule = privdata; upgrade_decision decision = UD_UPGRADE; retvalue r; + struct filterlist *fl; + const char *n, *v; + bool cmdline_still_undecided; + + if (target->packagetype == pt_dsc) { + assert (strcmp(package, sourcename) == 0); + assert (strcmp(new_version, sourceversion) == 0); + if (rule->filtersrclist.set) + fl = &rule->filtersrclist; + else + fl = &rule->filterlist; + n = package; + v = new_version; + } else { + if (rule->filterlist.set) { + fl = &rule->filterlist; + n = package; + v = new_version; + } else { + fl = &rule->filtersrclist; + n = sourcename; + v = sourceversion; + } + } - switch( filterlist_find(package,&rule->filterlist) ) { + switch (filterlist_find(n, v, fl)) { case flt_deinstall: case flt_purge: return UD_NO; @@ -664,19 +689,93 @@ "Package name marked to be unexpected('error'): '%s'!\n", package); return UD_ERROR; case flt_upgradeonly: - if( old_version == NULL ) + if (old_version == NULL) return UD_NO; break; case flt_install: break; + case flt_unchanged: + case flt_auto_hold: + assert (false); + break; + } + + cmdline_still_undecided = false; + switch (filterlist_find(sourcename, sourceversion, + &cmdline_src_filter)) { + case flt_deinstall: + case flt_purge: + return UD_NO; + case flt_warning: + return UD_LOUDNO; + case flt_auto_hold: + cmdline_still_undecided = true; + decision = UD_HOLD; + break; + case flt_hold: + decision = UD_HOLD; + break; + case flt_error: + /* cannot yet be handled! */ + fprintf(stderr, +"Package name marked to be unexpected('error'): '%s'!\n", package); + return UD_ERROR; + case flt_upgradeonly: + if (old_version == NULL) + return UD_NO; + break; + case flt_install: + decision = UD_UPGRADE; + break; + case flt_unchanged: + cmdline_still_undecided = true; + break; + } + + + if (target->packagetype != pt_dsc) { + switch (filterlist_find(package, new_version, + &cmdline_bin_filter)) { + case flt_deinstall: + case flt_purge: + return UD_NO; + case flt_warning: + return UD_LOUDNO; + case flt_hold: + decision = UD_HOLD; + break; + case flt_error: + /* cannot yet be handled! */ + fprintf(stderr, +"Package name marked to be unexpected('error'): '%s'!\n", package); + return UD_ERROR; + case flt_upgradeonly: + if (old_version == NULL) + return UD_NO; + break; + case flt_install: + decision = UD_UPGRADE; + break; + case flt_unchanged: + break; + case flt_auto_hold: + /* hold only if it was not in the src-filter */ + if (cmdline_still_undecided) + decision = UD_HOLD; + break; + } + } else if (cmdline_bin_filter.defaulttype == flt_auto_hold) { + if (cmdline_still_undecided) + decision = UD_HOLD; } - if( rule->includecondition != NULL ) { + /* formula tested last as it is the most expensive */ + if (rule->includecondition != NULL) { r = term_decidechunktarget(rule->includecondition, newcontrolchunk, target); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return UD_ERROR; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { return UD_NO; } } @@ -684,55 +783,54 @@ return decision; } -static inline retvalue pull_searchformissing(/*@null@*/FILE *out,struct database *database,struct pull_target *p) { +static inline retvalue pull_searchformissing(/*@null@*/FILE *out, struct pull_target *p) { struct pull_source *source; - retvalue result,r; + retvalue result, r; - if( verbose > 2 && out != NULL ) - fprintf(out," pulling into '%s'\n",p->target->identifier); + if (verbose > 2 && out != NULL) + fprintf(out, " pulling into '%s'\n", p->target->identifier); assert(p->upgradelist == NULL); - r = upgradelist_initialize(&p->upgradelist, p->target, database); - if( RET_WAS_ERROR(r) ) + r = upgradelist_initialize(&p->upgradelist, p->target); + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - for( source=p->sources ; source != NULL ; source=source->next ) { + for (source=p->sources ; source != NULL ; source=source->next) { - if( source->rule == NULL ) { - if( verbose > 4 && out != NULL ) - fprintf(out," marking everything to be deleted\n"); + if (source->rule == NULL) { + if (verbose > 4 && out != NULL) + fprintf(out, +" marking everything to be deleted\n"); r = upgradelist_deleteall(p->upgradelist); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) return result; continue; } - if( verbose > 4 && out != NULL ) - fprintf(out," looking what to get from '%s'\n", + if (verbose > 4 && out != NULL) + fprintf(out, " looking what to get from '%s'\n", source->source->identifier); - r = upgradelist_pull(p->upgradelist, - source->source, - ud_decide_by_rule, source->rule, - database, source); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = upgradelist_pull(p->upgradelist, source->source, + ud_decide_by_rule, source->rule, source); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) return result; } return result; } -static retvalue pull_search(/*@null@*/FILE *out,struct database *database,struct pull_distribution *d) { - retvalue result,r; +static retvalue pull_search(/*@null@*/FILE *out, struct pull_distribution *d) { + retvalue result, r; struct pull_target *u; result = RET_NOTHING; - for( u=d->targets ; u != NULL ; u=u->next ) { - r = pull_searchformissing(out, database, u); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (u=d->targets ; u != NULL ; u=u->next) { + r = pull_searchformissing(out, u); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } return result; @@ -741,10 +839,10 @@ static bool pull_isbigdelete(struct pull_distribution *d) { struct pull_target *u, *v; - for( u = d->targets ; u != NULL ; u=u->next ) { - if( upgradelist_isbigdelete(u->upgradelist) ) { + for (u = d->targets ; u != NULL ; u=u->next) { + if (upgradelist_isbigdelete(u->upgradelist)) { d->distribution->omitted = true; - for( v = d->targets ; v != NULL ; v = v->next ) { + for (v = d->targets ; v != NULL ; v = v->next) { upgradelist_free(v->upgradelist); v->upgradelist = NULL; } @@ -762,27 +860,26 @@ *from_p = source->rule->from; } -static retvalue pull_install(struct database *database, struct pull_distribution *distribution) { - retvalue result,r; +static retvalue pull_install(struct pull_distribution *distribution) { + retvalue result, r; struct pull_target *u; struct distribution *d = distribution->distribution; - assert( logger_isprepared(d->logger) ); + assert (logger_isprepared(d->logger)); result = RET_NOTHING; - for( u=distribution->targets ; u != NULL ; u=u->next ) { + for (u=distribution->targets ; u != NULL ; u=u->next) { r = upgradelist_install(u->upgradelist, d->logger, - database, false, - pull_from_callback); + false, pull_from_callback); RET_UPDATE(d->status, r); - RET_UPDATE(result,r); + RET_UPDATE(result, r); upgradelist_free(u->upgradelist); u->upgradelist = NULL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } - if( RET_IS_OK(result) && d->tracking != dt_NONE ) { - r = tracking_retrack(database, d, false); + if (RET_IS_OK(result) && d->tracking != dt_NONE) { + r = tracking_retrack(d, false); RET_ENDUPDATE(result, r); } return result; @@ -791,12 +888,12 @@ static void pull_dumppackage(const char *packagename, /*@null@*/const char *oldversion, /*@null@*/const char *newversion, /*@null@*/const char *bestcandidate, /*@null@*/const struct strlist *newfilekeys, /*@null@*/const char *newcontrol, void *privdata) { struct pull_source *source = privdata; - if( newversion == NULL ) { - if( oldversion != NULL && bestcandidate != NULL ) { + if (newversion == NULL) { + if (oldversion != NULL && bestcandidate != NULL) { printf("'%s': '%s' will be deleted" " (best new: '%s')\n", packagename, oldversion, bestcandidate); - } else if( oldversion != NULL ) { + } else if (oldversion != NULL) { printf("'%s': '%s' will be deleted" " (no longer available)\n", packagename, oldversion); @@ -804,15 +901,15 @@ printf("'%s': will NOT be added as '%s'\n", packagename, bestcandidate); } - } else if( newversion == oldversion ) { - if( bestcandidate != NULL ) { - if( verbose > 1 ) + } else if (newversion == oldversion) { + if (bestcandidate != NULL) { + if (verbose > 1) printf("'%s': '%s' will be kept" " (best new: '%s')\n", packagename, oldversion, bestcandidate); } else { - if( verbose > 0 ) + if (verbose > 0) printf("'%s': '%s' will be kept" " (unavailable for reload)\n", packagename, oldversion); @@ -820,9 +917,9 @@ } else { const char *via = source->rule->name; - assert( newfilekeys != NULL ); - assert( newcontrol != NULL ); - if( oldversion != NULL ) + assert (newfilekeys != NULL); + assert (newcontrol != NULL); + if (oldversion != NULL) (void)printf("'%s': '%s' will be upgraded" " to '%s' (from '%s'):\n files needed: ", packagename, oldversion, @@ -832,7 +929,7 @@ " as '%s' (from '%s'):\n files needed: ", packagename, newversion, via); (void)strlist_fprint(stdout, newfilekeys); - if( verbose > 2) + if (verbose > 2) (void)printf("\n installing as: '%s'\n", newcontrol); else @@ -843,8 +940,8 @@ static void pull_dump(struct pull_distribution *distribution) { struct pull_target *u; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->upgradelist == NULL ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->upgradelist == NULL) continue; printf("Updates needed for '%s':\n", u->target->identifier); upgradelist_dump(u->upgradelist, pull_dumppackage); @@ -856,12 +953,12 @@ static void pull_dumplistpackage(const char *packagename, /*@null@*/const char *oldversion, /*@null@*/const char *newversion, /*@null@*/const char *bestcandidate, /*@null@*/const struct strlist *newfilekeys, /*@null@*/const char *newcontrol, void *privdata) { struct pull_source *source = privdata; - if( newversion == NULL ) { - if( oldversion == NULL ) + if (newversion == NULL) { + if (oldversion == NULL) return; printf("delete '%s' '%s'\n", packagename, oldversion); - } else if( newversion == oldversion ) { - if( bestcandidate != NULL ) + } else if (newversion == oldversion) { + if (bestcandidate != NULL) printf("keep '%s' '%s' '%s'\n", packagename, oldversion, bestcandidate); else @@ -870,9 +967,9 @@ } else { const char *via = source->rule->name; - assert( newfilekeys != NULL ); - assert( newcontrol != NULL ); - if( oldversion != NULL ) + assert (newfilekeys != NULL); + assert (newcontrol != NULL); + if (oldversion != NULL) (void)printf("update '%s' '%s' '%s' '%s'\n", packagename, oldversion, newversion, via); @@ -885,8 +982,8 @@ static void pull_dumplist(struct pull_distribution *distribution) { struct pull_target *u; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->upgradelist == NULL ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->upgradelist == NULL) continue; printf("Updates needed for '%s':\n", u->target->identifier); upgradelist_dump(u->upgradelist, pull_dumplistpackage); @@ -895,56 +992,56 @@ } } -retvalue pull_update(struct database *database, struct pull_distribution *distributions) { - retvalue result,r; +retvalue pull_update(struct pull_distribution *distributions) { + retvalue result, r; struct pull_distribution *d; - for( d=distributions ; d != NULL ; d=d->next) { + for (d=distributions ; d != NULL ; d=d->next) { r = distribution_prepareforwriting(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = distribution_loadalloverrides(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Calculating packages to pull...\n"); result = RET_NOTHING; - for( d=distributions ; d != NULL ; d=d->next) { - r = pull_search(stdout, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = pull_search(stdout, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; // TODO: make already here sure the files are ready? } - if( RET_WAS_ERROR(result) ) { - for( d=distributions ; d != NULL ; d=d->next) { + if (RET_WAS_ERROR(result)) { + for (d=distributions ; d != NULL ; d=d->next) { struct pull_target *u; - for( u=d->targets ; u != NULL ; u=u->next ) { + for (u=d->targets ; u != NULL ; u=u->next) { upgradelist_free(u->upgradelist); u->upgradelist = NULL; } } return result; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Installing (and possibly deleting) packages...\n"); - for( d=distributions ; d != NULL ; d=d->next) { - if( global.onlysmalldeletes ) { - if( pull_isbigdelete(d) ) { + for (d=distributions ; d != NULL ; d=d->next) { + if (global.onlysmalldeletes) { + if (pull_isbigdelete(d)) { fprintf(stderr, "Not processing '%s' because of --onlysmalldeletes\n", d->distribution->codename); continue; } } - r = pull_install(database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = pull_install(d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } logger_wait(); @@ -952,25 +1049,25 @@ return result; } -retvalue pull_checkupdate(struct database *database, struct pull_distribution *distributions) { +retvalue pull_checkupdate(struct pull_distribution *distributions) { struct pull_distribution *d; - retvalue result,r; + retvalue result, r; - for( d=distributions ; d != NULL ; d=d->next) { + for (d=distributions ; d != NULL ; d=d->next) { r = distribution_loadalloverrides(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - if( verbose >= 0 ) - fprintf(stderr,"Calculating packages to get...\n"); + if (verbose >= 0) + fprintf(stderr, "Calculating packages to get...\n"); result = RET_NOTHING; - for( d=distributions ; d != NULL ; d=d->next) { - r = pull_search(stderr, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = pull_search(stderr, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; pull_dump(d); } @@ -978,22 +1075,22 @@ return result; } -retvalue pull_dumpupdate(struct database *database, struct pull_distribution *distributions) { +retvalue pull_dumpupdate(struct pull_distribution *distributions) { struct pull_distribution *d; - retvalue result,r; + retvalue result, r; - for( d=distributions ; d != NULL ; d=d->next) { + for (d=distributions ; d != NULL ; d=d->next) { r = distribution_loadalloverrides(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } result = RET_NOTHING; - for( d=distributions ; d != NULL ; d=d->next) { - r = pull_search(NULL, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = pull_search(NULL, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; pull_dumplist(d); } diff -Nru reprepro-4.5.0/pull.h reprepro-4.6.0/pull.h --- reprepro-4.5.0/pull.h 2008-11-13 16:32:16.000000000 +0000 +++ reprepro-4.6.0/pull.h 2011-05-05 14:42:55.000000000 +0000 @@ -24,8 +24,8 @@ void pull_freedistributions(/*@only@*/struct pull_distribution *p); retvalue pull_prepare(struct distribution *, struct pull_rule *, bool fast, /*@out@*/struct pull_distribution **); -retvalue pull_update(struct database *, struct pull_distribution *); -retvalue pull_checkupdate(struct database *, struct pull_distribution *); -retvalue pull_dumpupdate(struct database *, struct pull_distribution *); +retvalue pull_update(struct pull_distribution *); +retvalue pull_checkupdate(struct pull_distribution *); +retvalue pull_dumpupdate(struct pull_distribution *); #endif diff -Nru reprepro-4.5.0/readrelease.c reprepro-4.6.0/readrelease.c --- reprepro-4.5.0/readrelease.c 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/readrelease.c 2011-05-05 14:42:55.000000000 +0000 @@ -35,38 +35,38 @@ bool foundanything = false; r = readtextfile(releasefile, releasefile, &chunk, NULL); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) return r; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( ignore[cs] ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if (ignore[cs]) { strlist_init(&files[cs]); continue; } - assert( release_checksum_names[cs] != NULL ); + assert (release_checksum_names[cs] != NULL); r = chunk_getextralinelist(chunk, release_checksum_names[cs], &files[cs]); - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&files[cs]); } free(chunk); return r; - } else if( r == RET_NOTHING ) + } else if (r == RET_NOTHING) strlist_init(&files[cs]); else foundanything = true; } free(chunk); - if( !foundanything ) { + if (!foundanything) { fprintf(stderr, "Missing checksums in Release file '%s'!\n", releasefile); return RET_ERROR; } r = checksumsarray_parse(out, files, releasefile); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&files[cs]); } return r; diff -Nru reprepro-4.5.0/readtextfile.c reprepro-4.6.0/readtextfile.c --- reprepro-4.5.0/readtextfile.c 2008-03-06 16:14:55.000000000 +0000 +++ reprepro-4.6.0/readtextfile.c 2011-05-05 14:42:55.000000000 +0000 @@ -36,10 +36,11 @@ size_t i; unsigned char c; - for( i = 0 ; i < len ; i++ ) { + for (i = 0 ; i < len ; i++) { c = (unsigned char)buffer[i]; - if( c < ' ' && c != '\t' && c != '\n' && c != '\r' ) { - fprintf(stderr, "Unexpected binary character \\%03hho in %s\n", + if (c < ' ' && c != '\t' && c != '\n' && c != '\r') { + fprintf(stderr, +"Unexpected binary character \\%03hho in %s\n", c, source); return true; } @@ -53,36 +54,36 @@ char *buffer, *h; buffer = malloc(buffersize); - if( buffer == NULL ) + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; errno = 0; - while( (readbytes = read(fd, buffer + readdata, buffersize-readdata)) - > 0 ) { + while ((readbytes = read(fd, buffer + readdata, buffersize-readdata)) + > 0) { /* text files are normaly small, so it does not hurt to check * the whole of them always */ - if( isbinarydata(buffer + readdata, (size_t)readbytes, source) ) { + if (isbinarydata(buffer + readdata, (size_t)readbytes, source)) { free(buffer); return RET_ERROR; } readdata += readbytes; - assert( readdata <= buffersize ); - if( readdata + 1024 >= buffersize ) { - if( buffersize >= 10*1024*1024 ) { + assert (readdata <= buffersize); + if (readdata + 1024 >= buffersize) { + if (buffersize >= 10*1024*1024) { fprintf(stderr, "Ridiculously large %s\n", source); free(buffer); return RET_ERROR; } buffersize += 51200; h = realloc(buffer, buffersize); - if( h == NULL ) { + if (FAILEDTOALLOC(h)) { free(buffer); return RET_ERROR_OOM; } buffer = h; } } - if( readbytes < 0 ) { + if (readbytes < 0) { int e = errno; free(buffer); fprintf(stderr, "Error reading %s: %s\n", source, @@ -90,11 +91,11 @@ return RET_ERRNO(e); } h = realloc(buffer, readdata + 1); - if( h == NULL ) { + if (h == NULL) { #ifdef SPLINT h = NULL; #endif - if( readdata >= buffersize ) { + if (readdata >= buffersize) { free(buffer); return RET_ERROR_OOM; } @@ -102,7 +103,7 @@ buffer = h; buffer[readdata] = '\0'; *data = buffer; - if( len != NULL ) + if (len != NULL) *len = readdata; return RET_OK; } @@ -113,19 +114,19 @@ int ret; fd = open(source, O_RDONLY|O_NOCTTY); - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "Error opening '%s': %s\n", sourcetoshow, strerror(e)); return RET_ERRNO(e); } r = readtextfilefd(fd, sourcetoshow, &buffer, &bufferlen); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { (void)close(fd); return r; } ret = close(fd); - if( ret != 0 ) { + if (ret != 0) { int e = errno; free(buffer); fprintf(stderr, "Error reading %s: %s\n", sourcetoshow, @@ -133,7 +134,7 @@ return RET_ERRNO(e); } *data = buffer; - if( len != NULL ) + if (len != NULL) *len = bufferlen; return RET_OK; } diff -Nru reprepro-4.5.0/reference.c reprepro-4.6.0/reference.c --- reprepro-4.5.0/reference.c 2008-10-13 09:55:30.000000000 +0000 +++ reprepro-4.6.0/reference.c 2011-05-05 14:42:55.000000000 +0000 @@ -32,20 +32,20 @@ #include "pool.h" #include "reference.h" -retvalue references_isused(struct database *database,const char *what) { - return table_gettemprecord(database->references, what, NULL, NULL); +retvalue references_isused( const char *what) { + return table_gettemprecord(rdb_references, what, NULL, NULL); } -retvalue references_check(struct database *database,const char *referee,const struct strlist *filekeys) { +retvalue references_check(const char *referee, const struct strlist *filekeys) { int i; retvalue result, r; result = RET_NOTHING; - for( i = 0 ; i < filekeys->count ; i++ ) { - r = table_checkrecord(database->references, + for (i = 0 ; i < filekeys->count ; i++) { + r = table_checkrecord(rdb_references, filekeys->values[i], referee); - if( r == RET_NOTHING ) { - fprintf(stderr,"Missing reference to '%s' by '%s'\n", + if (r == RET_NOTHING) { + fprintf(stderr, "Missing reference to '%s' by '%s'\n", filekeys->values[i], referee); r = RET_ERROR; } @@ -55,33 +55,33 @@ } /* add an reference to a file for an identifier. multiple calls */ -retvalue references_increment(struct database *database,const char *needed,const char *neededby) { +retvalue references_increment(const char *needed, const char *neededby) { retvalue r; - r = table_addrecord(database->references, needed, + r = table_addrecord(rdb_references, needed, neededby, strlen(neededby), false); - if( RET_IS_OK(r) && verbose > 8 ) - printf("Adding reference to '%s' by '%s'\n", needed,neededby); + if (RET_IS_OK(r) && verbose > 8) + printf("Adding reference to '%s' by '%s'\n", needed, neededby); return r; } /* remove reference for a file from a given reference */ -retvalue references_decrement(struct database *database,const char *needed,const char *neededby) { +retvalue references_decrement(const char *needed, const char *neededby) { retvalue r; - r = table_removerecord(database->references, needed, neededby); - if( r == RET_NOTHING ) + r = table_removerecord(rdb_references, needed, neededby); + if (r == RET_NOTHING) return r; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error while trying to removing reference to '%s' by '%s'\n", needed, neededby); return r; } - if( verbose > 8 ) - fprintf(stderr,"Removed reference to '%s' by '%s'\n", + if (verbose > 8) + fprintf(stderr, "Removed reference to '%s' by '%s'\n", needed, neededby); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { retvalue r2; r2 = pool_dereferenced(needed); RET_UPDATE(r, r2); @@ -91,34 +91,34 @@ /* Add an reference by for the given , * excluding , if it is nonNULL. */ -retvalue references_insert(struct database *database,const char *identifier, - const struct strlist *files,const struct strlist *exclude) { - retvalue result,r; +retvalue references_insert(const char *identifier, + const struct strlist *files, const struct strlist *exclude) { + retvalue result, r; int i; result = RET_NOTHING; - for( i = 0 ; i < files->count ; i++ ) { + for (i = 0 ; i < files->count ; i++) { const char *filename = files->values[i]; - if( exclude == NULL || !strlist_in(exclude,filename) ) { - r = references_increment(database, filename, identifier); - RET_UPDATE(result,r); + if (exclude == NULL || !strlist_in(exclude, filename)) { + r = references_increment(filename, identifier); + RET_UPDATE(result, r); } } return result; } /* add possible already existing references */ -retvalue references_add(struct database *database,const char *identifier,const struct strlist *files) { +retvalue references_add(const char *identifier, const struct strlist *files) { int i; retvalue r; - for( i = 0 ; i < files->count ; i++ ) { + for (i = 0 ; i < files->count ; i++) { const char *filekey = files->values[i]; - r = table_addrecord(database->references, filekey, + r = table_addrecord(rdb_references, filekey, identifier, strlen(identifier), true); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -126,20 +126,20 @@ /* Remove reference by for the given , * excluding , if it is nonNULL. */ -retvalue references_delete(struct database *database, const char *identifier, struct strlist *files, const struct strlist *exclude) { - retvalue result,r; +retvalue references_delete(const char *identifier, struct strlist *files, const struct strlist *exclude) { + retvalue result, r; int i; - assert( files != NULL ); + assert (files != NULL); result = RET_NOTHING; - for( i = 0 ; i < files->count ; i++ ) { + for (i = 0 ; i < files->count ; i++) { const char *filekey = files->values[i]; - if( exclude == NULL || !strlist_in(exclude,filekey) ) { - r = references_decrement(database, filekey, identifier); - RET_UPDATE(result,r); + if (exclude == NULL || !strlist_in(exclude, filekey)) { + r = references_decrement(filekey, identifier); + RET_UPDATE(result, r); } } return result; @@ -147,38 +147,68 @@ } /* remove all references from a given identifier */ -retvalue references_remove(struct database *database, const char *neededby) { +retvalue references_remove(const char *neededby) { struct cursor *cursor; retvalue result, r; const char *found_to, *found_by; size_t datalen, l; - r = table_newglobalcursor(database->references, &cursor); - if( !RET_IS_OK(r) ) + r = table_newglobalcursor(rdb_references, &cursor); + if (!RET_IS_OK(r)) return r; l = strlen(neededby); result = RET_NOTHING; - while( cursor_nexttempdata(database->references, cursor, - &found_to, &found_by, &datalen) ) { + while (cursor_nexttempdata(rdb_references, cursor, + &found_to, &found_by, &datalen)) { - if( datalen >= l && strncmp(found_by, neededby, l) == 0 && + if (datalen >= l && strncmp(found_by, neededby, l) == 0 && (found_by[l] == '\0' || found_by[l] == ' ')) { - if( verbose > 8 ) - fprintf(stderr,"Removing reference to '%s' by '%s'\n", - found_to,neededby); - r = cursor_delete(database->references, cursor, + if (verbose > 8) + fprintf(stderr, +"Removing reference to '%s' by '%s'\n", + found_to, neededby); + r = cursor_delete(rdb_references, cursor, found_to, NULL); RET_UPDATE(result, r); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = pool_dereferenced(found_to); RET_ENDUPDATE(result, r); } } } - r = cursor_close(database->references, cursor); + r = cursor_close(rdb_references, cursor); RET_ENDUPDATE(result, r); return result; } +/* dump all references to stdout */ +retvalue references_dump(void) { + struct cursor *cursor; + retvalue result, r; + const char *found_to, *found_by; + + r = table_newglobalcursor(rdb_references, &cursor); + if (!RET_IS_OK(r)) + return r; + + result = RET_OK; + while (cursor_nexttemp(rdb_references, cursor, + &found_to, &found_by)) { + if (fputs(found_by, stdout) == EOF || + putchar(' ') == EOF || + puts(found_to) == EOF) { + result = RET_ERROR; + break; + } + result = RET_OK; + if (interrupted()) { + result = RET_ERROR_INTERRUPTED; + break; + } + } + r = cursor_close(rdb_references, cursor); + RET_ENDUPDATE(result, r); + return result; +} diff -Nru reprepro-4.5.0/reference.h reprepro-4.6.0/reference.h --- reprepro-4.5.0/reference.h 2008-10-13 09:55:30.000000000 +0000 +++ reprepro-4.6.0/reference.h 2011-05-05 14:42:55.000000000 +0000 @@ -18,31 +18,33 @@ struct references; /* remove all references from a given identifier */ -retvalue references_remove(struct database *, const char *neededby); +retvalue references_remove(const char *neededby); /* Add an reference by for the given , * excluding , if it is nonNULL. */ -retvalue references_insert(struct database *,const char *identifer, - const struct strlist *files,const struct strlist *exclude); +retvalue references_insert(const char *, const struct strlist *, const struct strlist * /*exclude*/); /* Add an reference by for the given , * do not error out if reference already exists */ -retvalue references_add(struct database *,const char *identifer,const struct strlist *files); +retvalue references_add(const char *, const struct strlist *); /* Remove reference by for the given , * excluding , if it is nonNULL. */ -retvalue references_delete(struct database *, const char *identifer, struct strlist *files, /*@null@*/const struct strlist *exclude); +retvalue references_delete(const char *, struct strlist *, /*@null@*/const struct strlist * /*exclude*/); /* add an reference to a file for an identifier. */ -retvalue references_increment(struct database *,const char *needed,const char *needey); +retvalue references_increment(const char * /*needed*/, const char * /*needey*/); /* delete reference to a file for an identifier */ -retvalue references_decrement(struct database *,const char *needed,const char *needey); +retvalue references_decrement(const char * /*needed*/, const char * /*needey*/); /* check if an item is needed, returns RET_NOTHING if not */ -retvalue references_isused(struct database *,const char *what); +retvalue references_isused(const char *); /* check if a reference is found as expected */ -retvalue references_check(struct database *,const char *referee,const struct strlist *what); +retvalue references_check(const char * /*referee*/, const struct strlist */*what*/); + +/* output all references to stdout */ +retvalue references_dump(void); #endif diff -Nru reprepro-4.5.0/release.c reprepro-4.6.0/release.c --- reprepro-4.5.0/release.c 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/release.c 2011-05-05 14:42:55.000000000 +0000 @@ -70,7 +70,8 @@ char *fullfinalfilename; char *fulltemporaryfilename; } *files; - /* the Release file in preperation (only valid between _prepare and _finish) */ + /* the Release file in preperation + * (only valid between _prepare and _finish) */ struct signedfile *signedfile; /* the cache database for old files */ struct table *cachedb; @@ -82,19 +83,19 @@ free(release->dirofdist); free(release->fakesuite); free(release->fakecodename); - while( (e = release->files) != NULL ) { + while ((e = release->files) != NULL) { release->files = e->next; free(e->relativefilename); checksums_free(e->checksums); free(e->fullfinalfilename); - if( !global.keeptemporaries && e->fulltemporaryfilename != NULL) + if (!global.keeptemporaries && e->fulltemporaryfilename != NULL) unlink(e->fulltemporaryfilename); free(e->fulltemporaryfilename); free(e); } - if( release->signedfile != NULL ) + if (release->signedfile != NULL) signedfile_free(release->signedfile, !global.keeptemporaries); - if( release->cachedb != NULL ) { + if (release->cachedb != NULL) { table_close(release->cachedb); } free(release); @@ -107,63 +108,65 @@ static retvalue newreleaseentry(struct release *release, /*@only@*/ char *relativefilename, /*@only@*/ struct checksums *checksums, /*@only@*/ /*@null@*/ char *fullfinalfilename, - /*@only@*/ /*@null@*/ char *fulltemporaryfilename ) { - struct release_entry *n,*p; - n = malloc(sizeof(struct release_entry)); - if( n == NULL ) + /*@only@*/ /*@null@*/ char *fulltemporaryfilename) { + struct release_entry *n, *p; + n = NEW(struct release_entry); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->next = NULL; n->relativefilename = relativefilename; n->checksums = checksums; n->fullfinalfilename = fullfinalfilename; n->fulltemporaryfilename = fulltemporaryfilename; - if( release->files == NULL ) + if (release->files == NULL) release->files = n; else { p = release->files; - while( p->next != NULL ) + while (p->next != NULL) p = p->next; p->next = n; } return RET_OK; } -retvalue release_init(struct release **release, struct database *database, const char *codename, const char *suite, const char *fakecomponentprefix) { +retvalue release_init(struct release **release, const char *codename, const char *suite, const char *fakecomponentprefix) { struct release *n; size_t len, suitelen, codenamelen; retvalue r; - n = calloc(1,sizeof(struct release)); + n = zNEW(struct release); + if (FAILEDTOALLOC(n)) + return RET_ERROR_OOM; n->dirofdist = calc_dirconcat(global.distdir, codename); - if( n->dirofdist == NULL ) { + if (FAILEDTOALLOC(n->dirofdist)) { free(n); return RET_ERROR_OOM; } - if( fakecomponentprefix != NULL ) { + if (fakecomponentprefix != NULL) { len = strlen(fakecomponentprefix); codenamelen = strlen(codename); n->fakecomponentprefix = fakecomponentprefix; n->fakecomponentprefixlen = len; - if( codenamelen > len && + if (codenamelen > len && codename[codenamelen - len - 1] == '/' && memcmp(codename + (codenamelen - len), fakecomponentprefix, len) == 0) { n->fakecodename = strndup(codename, codenamelen - len - 1); - if( FAILEDTOALLOC(n->fakecodename) ) { + if (FAILEDTOALLOC(n->fakecodename)) { free(n->dirofdist); free(n); return RET_ERROR_OOM; } } - if( suite != NULL && (suitelen = strlen(suite)) > len && + if (suite != NULL && (suitelen = strlen(suite)) > len && suite[suitelen - len - 1] == '/' && memcmp(suite + (suitelen - len), fakecomponentprefix, len) == 0) { n->fakesuite = strndup(suite, suitelen - len - 1); - if( FAILEDTOALLOC(n->fakesuite) ) { + if (FAILEDTOALLOC(n->fakesuite)) { free(n->fakecodename); free(n->dirofdist); free(n); @@ -171,9 +174,9 @@ } } } - r = database_openreleasecache(database, codename, &n->cachedb); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + r = database_openreleasecache(codename, &n->cachedb); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { n->cachedb = NULL; free(n->fakecodename); free(n->fakesuite); @@ -188,16 +191,18 @@ retvalue release_initsnapshot(const char *codename, const char *name, struct release **release) { struct release *n; - n = calloc(1,sizeof(struct release)); + n = zNEW(struct release); + if (FAILEDTOALLOC(n)) + return RET_ERROR_OOM; n->dirofdist = calc_snapshotbasedir(codename, name); - if( n->dirofdist == NULL ) { + if (FAILEDTOALLOC(n->dirofdist)) { free(n); return RET_ERROR_OOM; } /* apt only removes the last /... part but we create two, * so stop it generating warnings by faking a suite */ n->fakesuite = mprintf("%s/snapshots/%s", codename, name); - if( n->fakesuite == NULL ) { + if (FAILEDTOALLOC(n->fakesuite)) { free(n->dirofdist); free(n); return RET_ERROR_OOM; @@ -211,38 +216,38 @@ return RET_OK; } -retvalue release_adddel(struct release *release,/*@only@*/char *reltmpfile) { +retvalue release_adddel(struct release *release, /*@only@*/char *reltmpfile) { char *filename; - filename = calc_dirconcat(release->dirofdist,reltmpfile); - if( filename == NULL ) { + filename = calc_dirconcat(release->dirofdist, reltmpfile); + if (FAILEDTOALLOC(filename)) { free(reltmpfile); return RET_ERROR_OOM; } free(reltmpfile); - return newreleaseentry(release,NULL,NULL,NULL,filename); + return newreleaseentry(release, NULL, NULL, NULL, filename); } -retvalue release_addnew(struct release *release,/*@only@*/char *reltmpfile,/*@only@*/char *relfilename) { +retvalue release_addnew(struct release *release, /*@only@*/char *reltmpfile, /*@only@*/char *relfilename) { retvalue r; char *filename, *finalfilename; struct checksums *checksums; - filename = calc_dirconcat(release->dirofdist,reltmpfile); - if( filename == NULL ) { + filename = calc_dirconcat(release->dirofdist, reltmpfile); + if (FAILEDTOALLOC(filename)) { free(reltmpfile); free(relfilename); return RET_ERROR_OOM; } free(reltmpfile); r = checksums_read(filename, &checksums); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(relfilename); free(filename); return r; } - finalfilename = calc_dirconcat(release->dirofdist,relfilename); - if( finalfilename == NULL ) { + finalfilename = calc_dirconcat(release->dirofdist, relfilename); + if (FAILEDTOALLOC(finalfilename)) { free(relfilename); free(filename); checksums_free(checksums); @@ -253,18 +258,18 @@ checksums, finalfilename, filename); } -retvalue release_addsilentnew(struct release *release,/*@only@*/char *reltmpfile,/*@only@*/char *relfilename) { +retvalue release_addsilentnew(struct release *release, /*@only@*/char *reltmpfile, /*@only@*/char *relfilename) { char *filename, *finalfilename; - filename = calc_dirconcat(release->dirofdist,reltmpfile); - if( filename == NULL ) { + filename = calc_dirconcat(release->dirofdist, reltmpfile); + if (FAILEDTOALLOC(filename)) { free(reltmpfile); free(relfilename); return RET_ERROR_OOM; } free(reltmpfile); - finalfilename = calc_dirconcat(release->dirofdist,relfilename); - if( finalfilename == NULL ) { + finalfilename = calc_dirconcat(release->dirofdist, relfilename); + if (FAILEDTOALLOC(finalfilename)) { free(relfilename); free(filename); return RET_ERROR_OOM; @@ -275,19 +280,19 @@ NULL, finalfilename, filename); } -retvalue release_addold(struct release *release,/*@only@*/char *relfilename) { +retvalue release_addold(struct release *release, /*@only@*/char *relfilename) { retvalue r; char *filename; struct checksums *checksums; - filename = calc_dirconcat(release->dirofdist,relfilename); - if( filename == NULL ) { + filename = calc_dirconcat(release->dirofdist, relfilename); + if (FAILEDTOALLOC(filename)) { free(filename); return RET_ERROR_OOM; } r = checksums_read(filename, &checksums); free(filename); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { free(relfilename); return r; } @@ -295,7 +300,7 @@ } static char *calc_compressedname(const char *name, enum indexcompression ic) { - switch( ic ) { + switch (ic) { case ic_uncompressed: return strdup(name); case ic_gzip: @@ -305,7 +310,7 @@ return calc_addsuffix(name, "bz2"); #endif default: - assert( "Huh?" == NULL ); + assert ("Huh?" == NULL); return NULL; } } @@ -313,7 +318,7 @@ static retvalue release_usecached(struct release *release, const char *relfilename, compressionset compressions) { - retvalue result,r; + retvalue result, r; enum indexcompression ic; char *filename[ic_count]; struct checksums *checksums[ic_count]; @@ -322,33 +327,33 @@ memset(checksums, 0, sizeof(checksums)); result = RET_OK; - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { - if( ic != ic_uncompressed && - (compressions & IC_FLAG(ic)) == 0 ) + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { + if (ic != ic_uncompressed && + (compressions & IC_FLAG(ic)) == 0) continue; filename[ic] = calc_compressedname(relfilename, ic); - if( filename[ic] == NULL ) { + if (FAILEDTOALLOC(filename[ic])) { result = RET_ERROR_OOM; break; } } - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { /* first look if the there are actual files, in case * the cache still lists them but they got lost */ - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { char *fullfilename; - if( (compressions & IC_FLAG(ic)) == 0 ) + if ((compressions & IC_FLAG(ic)) == 0) continue; - assert( filename[ic] != NULL ); + assert (filename[ic] != NULL); fullfilename = calc_dirconcat(release->dirofdist, filename[ic]); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) { result = RET_ERROR_OOM; break; } - if( !isregularfile(fullfilename) ) { + if (!isregularfile(fullfilename)) { free(fullfilename); result = RET_NOTHING; break; @@ -356,10 +361,10 @@ free(fullfilename); } } - if( RET_IS_OK(result) && release->cachedb == NULL ) + if (RET_IS_OK(result) && release->cachedb == NULL) result = RET_NOTHING; - if( !RET_IS_OK(result) ) { - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) + if (!RET_IS_OK(result)) { + for (ic = ic_uncompressed ; ic < ic_count ; ic++) free(filename[ic]); return result; } @@ -367,40 +372,40 @@ /* now that the files are there look into the cache * what checksums they have. */ - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { char *combinedchecksum; - if( filename[ic] == NULL ) + if (filename[ic] == NULL) continue; r = table_getrecord(release->cachedb, filename[ic], &combinedchecksum); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { result = r; break; } r = checksums_parse(&checksums[ic], combinedchecksum); // TODO: handle malformed checksums better? free(combinedchecksum); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { result = r; break; } } /* some files might not yet have some type of checksum available, * so calculate them (checking the other checksums match...): */ - if( RET_IS_OK(result) ) { - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { + if (RET_IS_OK(result)) { + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { char *fullfilename; - if( filename[ic] == NULL ) + if (filename[ic] == NULL) continue; fullfilename = calc_dirconcat(release->dirofdist, filename[ic]); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) r = RET_ERROR_OOM; else r = checksums_complete(&checksums[ic], fullfilename); - if( r == RET_ERROR_WRONG_MD5 ) { + if (r == RET_ERROR_WRONG_MD5) { fprintf(stderr, "WARNING: '%s' is different from recorded checksums.\n" "(This was only catched because some new checksum type was not yet available.)\n" @@ -408,15 +413,15 @@ r = RET_NOTHING; } free(fullfilename); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { result = r; break; } } } - if( !RET_IS_OK(result) ) { - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { - if( filename[ic] == NULL ) + if (!RET_IS_OK(result)) { + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { + if (filename[ic] == NULL) continue; free(filename[ic]); checksums_free(checksums[ic]); @@ -425,8 +430,8 @@ } /* everything found, commit it: */ result = RET_OK; - for( ic = ic_uncompressed ; ic < ic_count ; ic++ ) { - if( filename[ic] == NULL ) + for (ic = ic_uncompressed ; ic < ic_count ; ic++) { + if (filename[ic] == NULL) continue; r = newreleaseentry(release, filename[ic], checksums[ic], @@ -461,10 +466,10 @@ void release_abortfile(struct filetorelease *file) { enum indexcompression i; - for( i = ic_uncompressed ; i < ic_count ; i++ ) { - if( file->f[i].fd >= 0 ) { + for (i = ic_uncompressed ; i < ic_count ; i++) { + if (file->f[i].fd >= 0) { (void)close(file->f[i].fd); - if( file->f[i].fulltemporaryfilename != NULL ) + if (file->f[i].fulltemporaryfilename != NULL) (void)unlink(file->f[i].fulltemporaryfilename); } free(file->f[i].relativefilename); @@ -473,42 +478,43 @@ } free(file->buffer); free(file->gzoutputbuffer); - if( file->gzstream.next_out != NULL ) { + if (file->gzstream.next_out != NULL) { (void)deflateEnd(&file->gzstream); } #ifdef HAVE_LIBBZ2 free(file->bzoutputbuffer); - if( file->bzstream.next_out != NULL ) { + if (file->bzstream.next_out != NULL) { (void)BZ2_bzCompressEnd(&file->bzstream); } #endif } bool release_oldexists(struct filetorelease *file) { - if( file->f[ic_uncompressed].fullfinalfilename != NULL ) { - if( file->f[ic_gzip].fullfinalfilename != NULL ) { + if (file->f[ic_uncompressed].fullfinalfilename != NULL) { + if (file->f[ic_gzip].fullfinalfilename != NULL) { return isregularfile(file->f[ic_gzip].fullfinalfilename) && isregularfile(file->f[ic_uncompressed].fullfinalfilename); } else { return isregularfile(file->f[ic_uncompressed].fullfinalfilename); } } else { - assert( file->f[ic_gzip].fullfinalfilename != NULL ); + assert (file->f[ic_gzip].fullfinalfilename != NULL); return isregularfile(file->f[ic_gzip].fullfinalfilename); } } static retvalue openfile(const char *dirofdist, struct openfile *f) { - f->fullfinalfilename = calc_dirconcat(dirofdist,f->relativefilename); - if( f->fullfinalfilename == NULL ) + f->fullfinalfilename = calc_dirconcat(dirofdist, f->relativefilename); + if (FAILEDTOALLOC(f->fullfinalfilename)) return RET_ERROR_OOM; - f->fulltemporaryfilename = calc_addsuffix(f->fullfinalfilename,"new"); - if( f->fulltemporaryfilename == NULL ) + f->fulltemporaryfilename = calc_addsuffix(f->fullfinalfilename, "new"); + if (FAILEDTOALLOC(f->fulltemporaryfilename)) return RET_ERROR_OOM; (void)unlink(f->fulltemporaryfilename); - f->fd = open(f->fulltemporaryfilename,O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY,0666); - if( f->fd < 0 ) { + f->fd = open(f->fulltemporaryfilename, + O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); + if (f->fd < 0) { int e = errno; fprintf(stderr, "Error %d opening file %s for writing: %s\n", e, f->fulltemporaryfilename, strerror(e)); @@ -521,17 +527,17 @@ checksumscontext_update(&file->context, data, len); - if( file->fd < 0 ) + if (file->fd < 0) return RET_NOTHING; - while( len > 0 ) { - ssize_t written = write(file->fd,data,len); - if( written >= 0 ) { + while (len > 0) { + ssize_t written = write(file->fd, data, len); + if (written >= 0) { len -= written; data += written; } else { int e = errno; - if( e == EAGAIN || e == EINTR ) + if (e == EAGAIN || e == EINTR) continue; fprintf(stderr, "Error %d writing to %s: %s\n", e, file->fullfinalfilename, @@ -542,15 +548,15 @@ return RET_OK; } -static retvalue initgzcompression(struct filetorelease *f) { +static retvalue initgzcompression(struct filetorelease *f) { int zret; - if( (zlibCompileFlags() & (1<<17)) !=0 ) { - fprintf(stderr,"libz compiled without .gz supporting code\n"); + if ((zlibCompileFlags() & (1<<17)) !=0) { + fprintf(stderr, "libz compiled without .gz supporting code\n"); return RET_ERROR; } f->gzoutputbuffer = malloc(GZBUFSIZE); - if( f->gzoutputbuffer == NULL ) + if (FAILEDTOALLOC(f->gzoutputbuffer)) return RET_ERROR_OOM; f->gzstream.next_in = NULL; f->gzstream.avail_in = 0; @@ -572,14 +578,14 @@ Z_DEFAULT_STRATEGY ); f->gz_waiting_bytes = GZBUFSIZE - f->gzstream.avail_out; - if( zret == Z_MEM_ERROR ) + if (zret == Z_MEM_ERROR) return RET_ERROR_OOM; - if( zret != Z_OK ) { - if( f->gzstream.msg == NULL ) { - fprintf(stderr,"Error from zlib's deflateInit2: " + if (zret != Z_OK) { + if (f->gzstream.msg == NULL) { + fprintf(stderr, "Error from zlib's deflateInit2: " "unknown(%d)\n", zret); } else { - fprintf(stderr,"Error from zlib's deflateInit2: %s\n", + fprintf(stderr, "Error from zlib's deflateInit2: %s\n", f->gzstream.msg); } return RET_ERROR; @@ -589,11 +595,11 @@ #ifdef HAVE_LIBBZ2 -static retvalue initbzcompression(struct filetorelease *f) { +static retvalue initbzcompression(struct filetorelease *f) { int bzret; f->bzoutputbuffer = malloc(BZBUFSIZE); - if( f->bzoutputbuffer == NULL ) + if (FAILEDTOALLOC(f->bzoutputbuffer)) return RET_ERROR_OOM; f->bzstream.next_in = NULL; f->bzstream.avail_in = 0; @@ -610,10 +616,10 @@ /* workFaktor (1-250, 0 = default(30)) */ 0 ); - if( bzret == BZ_MEM_ERROR ) + if (bzret == BZ_MEM_ERROR) return RET_ERROR_OOM; - if( bzret != BZ_OK ) { - fprintf(stderr,"Error from libbz2's bzCompressInit: " + if (bzret != BZ_OK) { + fprintf(stderr, "Error from libbz2's bzCompressInit: " "%d\n", bzret); return RET_ERROR; } @@ -628,77 +634,78 @@ struct filetorelease *n; enum indexcompression i; - if( usecache ) { - retvalue r = release_usecached(release,filename,compressions); - if( r != RET_NOTHING ) { + if (usecache) { + retvalue r = release_usecached(release, filename, compressions); + if (r != RET_NOTHING) { free(filename); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) return RET_NOTHING; return r; } } - n = calloc(1,sizeof(struct filetorelease)); - if( n == NULL ) { + n = zNEW(struct filetorelease); + if (FAILEDTOALLOC(n)) { free(filename); return RET_ERROR_OOM; } n->buffer = malloc(INPUT_BUFFER_SIZE); - if( n->buffer == NULL ) { + if (FAILEDTOALLOC(n->buffer)) { release_abortfile(n); return RET_ERROR_OOM; } - for( i = ic_uncompressed ; i < ic_count ; i ++ ) { + for (i = ic_uncompressed ; i < ic_count ; i ++) { n->f[i].fd = -1; } n->f[ic_uncompressed].relativefilename = filename; - if( n->f[ic_uncompressed].relativefilename == NULL ) { + if (FAILEDTOALLOC(n->f[ic_uncompressed].relativefilename)) { release_abortfile(n); return RET_ERROR_OOM; } - if( (compressions & IC_FLAG(ic_uncompressed)) != 0 ) { + if ((compressions & IC_FLAG(ic_uncompressed)) != 0) { retvalue r; - r = openfile(release->dirofdist,&n->f[ic_uncompressed]); - if( RET_WAS_ERROR(r) ) { + r = openfile(release->dirofdist, &n->f[ic_uncompressed]); + if (RET_WAS_ERROR(r)) { release_abortfile(n); return r; } } - if( (compressions & IC_FLAG(ic_gzip)) != 0 ) { + if ((compressions & IC_FLAG(ic_gzip)) != 0) { retvalue r; - n->f[ic_gzip].relativefilename = calc_addsuffix(filename,"gz"); - if( n->f[ic_gzip].relativefilename == NULL ) { + n->f[ic_gzip].relativefilename = calc_addsuffix(filename, "gz"); + if (FAILEDTOALLOC(n->f[ic_gzip].relativefilename)) { release_abortfile(n); return RET_ERROR_OOM; } - r = openfile(release->dirofdist,&n->f[ic_gzip]); - if( RET_WAS_ERROR(r) ) { + r = openfile(release->dirofdist, &n->f[ic_gzip]); + if (RET_WAS_ERROR(r)) { release_abortfile(n); return r; } checksumscontext_init(&n->f[ic_gzip].context); r = initgzcompression(n); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(n); return r; } } #ifdef HAVE_LIBBZ2 - if( (compressions & IC_FLAG(ic_bzip2)) != 0 ) { + if ((compressions & IC_FLAG(ic_bzip2)) != 0) { retvalue r; - n->f[ic_bzip2].relativefilename = calc_addsuffix(filename,"bz2"); - if( n->f[ic_bzip2].relativefilename == NULL ) { + n->f[ic_bzip2].relativefilename = + calc_addsuffix(filename, "bz2"); + if (n->f[ic_bzip2].relativefilename == NULL) { release_abortfile(n); return RET_ERROR_OOM; } - r = openfile(release->dirofdist,&n->f[ic_bzip2]); - if( RET_WAS_ERROR(r) ) { + r = openfile(release->dirofdist, &n->f[ic_bzip2]); + if (RET_WAS_ERROR(r)) { release_abortfile(n); return r; } checksumscontext_init(&n->f[ic_bzip2].context); r = initbzcompression(n); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(n); return r; } @@ -709,16 +716,13 @@ return RET_OK; } -retvalue release_startfile2(struct release *release, - const char *relative_dir, const char *filename, compressionset compressions, - bool usecache, - struct filetorelease **file) { +retvalue release_startfile2(struct release *release, const char *relative_dir, const char *filename, compressionset compressions, bool usecache, struct filetorelease **file) { char *relfilename; - relfilename = calc_dirconcat(relative_dir,filename); - if( relfilename == NULL ) + relfilename = calc_dirconcat(relative_dir, filename); + if (FAILEDTOALLOC(relfilename)) return RET_ERROR_OOM; - return startfile(release,relfilename,compressions,usecache,file); + return startfile(release, relfilename, compressions, usecache, file); } retvalue release_startfile(struct release *release, const char *filename, compressionset compressions, @@ -727,27 +731,27 @@ char *relfilename; relfilename = strdup(filename); - if( relfilename == NULL ) + if (FAILEDTOALLOC(relfilename)) return RET_ERROR_OOM; - return startfile(release,relfilename,compressions,usecache,file); + return startfile(release, relfilename, compressions, usecache, file); } static retvalue releasefile(struct release *release, struct openfile *f) { struct checksums *checksums; retvalue r; - if( f->relativefilename == NULL ) { - assert( f->fullfinalfilename == NULL); - assert( f->fulltemporaryfilename == NULL); + if (f->relativefilename == NULL) { + assert (f->fullfinalfilename == NULL); + assert (f->fulltemporaryfilename == NULL); return RET_NOTHING; } assert((f->fullfinalfilename == NULL && f->fulltemporaryfilename == NULL) - || (f->fullfinalfilename != NULL + || (f->fullfinalfilename != NULL && f->fulltemporaryfilename != NULL)); r = checksums_from_context(&checksums, &f->context); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = newreleaseentry(release, f->relativefilename, checksums, f->fullfinalfilename, @@ -761,7 +765,7 @@ static retvalue writegz(struct filetorelease *f) { int zret; - assert( f->f[ic_gzip].fd >= 0 ); + assert (f->f[ic_gzip].fd >= 0); f->gzstream.next_in = f->buffer; f->gzstream.avail_in = INPUT_BUFFER_SIZE; @@ -770,20 +774,20 @@ f->gzstream.next_out = f->gzoutputbuffer + f->gz_waiting_bytes; f->gzstream.avail_out = GZBUFSIZE - f->gz_waiting_bytes; - zret = deflate(&f->gzstream,Z_NO_FLUSH); + zret = deflate(&f->gzstream, Z_NO_FLUSH); f->gz_waiting_bytes = GZBUFSIZE - f->gzstream.avail_out; - if( (zret == Z_OK && f->gz_waiting_bytes >= GZBUFSIZE / 2 ) - || zret == Z_BUF_ERROR ) { + if ((zret == Z_OK && f->gz_waiting_bytes >= GZBUFSIZE / 2) + || zret == Z_BUF_ERROR) { retvalue r; /* there should be anything to write, otherwise * better break to avoid an infinite loop */ - if( f->gz_waiting_bytes == 0 ) + if (f->gz_waiting_bytes == 0) break; r = writetofile(&f->f[ic_gzip], f->gzoutputbuffer, f->gz_waiting_bytes); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; f->gz_waiting_bytes = 0; } @@ -791,18 +795,18 @@ * should only happend when no output is possible, as that * gets possible again it should finally produce more output * and return Z_OK and always terminate. Hopefully... */ - } while( zret == Z_BUF_ERROR - || ( zret == Z_OK && f->gzstream.avail_in != 0)); + } while (zret == Z_BUF_ERROR + || (zret == Z_OK && f->gzstream.avail_in != 0)); f->gzstream.next_in = NULL; f->gzstream.avail_in = 0; - if( zret != Z_OK ) { - if( f->gzstream.msg == NULL ) { - fprintf(stderr,"Error from zlib's deflate: " + if (zret != Z_OK) { + if (f->gzstream.msg == NULL) { + fprintf(stderr, "Error from zlib's deflate: " "unknown(%d)\n", zret); } else { - fprintf(stderr,"Error from zlib's deflate: %s\n", + fprintf(stderr, "Error from zlib's deflate: %s\n", f->gzstream.msg); } return RET_ERROR; @@ -813,7 +817,7 @@ static retvalue finishgz(struct filetorelease *f) { int zret; - assert( f->f[ic_gzip].fd >= 0 ); + assert (f->f[ic_gzip].fd >= 0); f->gzstream.next_in = f->buffer; f->gzstream.avail_in = f->waiting_bytes; @@ -822,36 +826,36 @@ f->gzstream.next_out = f->gzoutputbuffer + f->gz_waiting_bytes; f->gzstream.avail_out = GZBUFSIZE - f->gz_waiting_bytes; - zret = deflate(&f->gzstream,Z_FINISH); + zret = deflate(&f->gzstream, Z_FINISH); f->gz_waiting_bytes = GZBUFSIZE - f->gzstream.avail_out; - if( zret == Z_OK || zret == Z_STREAM_END - || zret == Z_BUF_ERROR ) { + if (zret == Z_OK || zret == Z_STREAM_END + || zret == Z_BUF_ERROR) { retvalue r; - if( f->gz_waiting_bytes == 0 ) { - if( zret != Z_STREAM_END ) { + if (f->gz_waiting_bytes == 0) { + if (zret != Z_STREAM_END) { fprintf(stderr, -"Unexpected buffer error after deflate (%d)\n",zret); +"Unexpected buffer error after deflate (%d)\n", zret); return RET_ERROR; } break; } r = writetofile(&f->f[ic_gzip], f->gzoutputbuffer, f->gz_waiting_bytes); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; f->gz_waiting_bytes = 0; } /* see above */ - } while( zret == Z_BUF_ERROR || zret == Z_OK ); + } while (zret == Z_BUF_ERROR || zret == Z_OK); - if( zret != Z_STREAM_END ) { - if( f->gzstream.msg == NULL ) { - fprintf(stderr,"Error from zlib's deflate: " + if (zret != Z_STREAM_END) { + if (f->gzstream.msg == NULL) { + fprintf(stderr, "Error from zlib's deflate: " "unknown(%d)\n", zret); } else { - fprintf(stderr,"Error from zlib's deflate: %s\n", + fprintf(stderr, "Error from zlib's deflate: %s\n", f->gzstream.msg); } return RET_ERROR; @@ -860,12 +864,12 @@ zret = deflateEnd(&f->gzstream); /* to avoid deflateEnd called again */ f->gzstream.next_out = NULL; - if( zret != Z_OK ) { - if( f->gzstream.msg == NULL ) { - fprintf(stderr,"Error from zlib's deflateEnd: " + if (zret != Z_OK) { + if (f->gzstream.msg == NULL) { + fprintf(stderr, "Error from zlib's deflateEnd: " "unknown(%d)\n", zret); } else { - fprintf(stderr,"Error from zlib's deflateEnd: %s\n", + fprintf(stderr, "Error from zlib's deflateEnd: %s\n", f->gzstream.msg); } return RET_ERROR; @@ -880,7 +884,7 @@ static retvalue writebz(struct filetorelease *f) { int bzret; - assert( f->f[ic_bzip2].fd >= 0 ); + assert (f->f[ic_bzip2].fd >= 0); f->bzstream.next_in = (char*)f->buffer; f->bzstream.avail_in = INPUT_BUFFER_SIZE; @@ -889,28 +893,28 @@ f->bzstream.next_out = f->bzoutputbuffer + f->bz_waiting_bytes; f->bzstream.avail_out = BZBUFSIZE - f->bz_waiting_bytes; - bzret = BZ2_bzCompress(&f->bzstream,BZ_RUN); + bzret = BZ2_bzCompress(&f->bzstream, BZ_RUN); f->bz_waiting_bytes = BZBUFSIZE - f->bzstream.avail_out; - if( bzret == BZ_RUN_OK && - f->bz_waiting_bytes >= BZBUFSIZE / 2 ) { + if (bzret == BZ_RUN_OK && + f->bz_waiting_bytes >= BZBUFSIZE / 2) { retvalue r; - assert( f->bz_waiting_bytes > 0 ); + assert (f->bz_waiting_bytes > 0); r = writetofile(&f->f[ic_bzip2], (const unsigned char *)f->bzoutputbuffer, f->bz_waiting_bytes); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; f->bz_waiting_bytes = 0; } - } while( bzret == BZ_RUN_OK && f->bzstream.avail_in != 0 ); + } while (bzret == BZ_RUN_OK && f->bzstream.avail_in != 0); f->bzstream.next_in = NULL; f->bzstream.avail_in = 0; - if( bzret != BZ_RUN_OK ) { - fprintf(stderr,"Error from libbz2's bzCompress: " + if (bzret != BZ_RUN_OK) { + fprintf(stderr, "Error from libbz2's bzCompress: " "%d\n", bzret); return RET_ERROR; } @@ -920,7 +924,7 @@ static retvalue finishbz(struct filetorelease *f) { int bzret; - assert( f->f[ic_bzip2].fd >= 0 ); + assert (f->f[ic_bzip2].fd >= 0); f->bzstream.next_in = (char*)f->buffer; f->bzstream.avail_in = f->waiting_bytes; @@ -929,27 +933,28 @@ f->bzstream.next_out = f->bzoutputbuffer + f->bz_waiting_bytes; f->bzstream.avail_out = BZBUFSIZE - f->bz_waiting_bytes; - bzret = BZ2_bzCompress(&f->bzstream,BZ_FINISH); + bzret = BZ2_bzCompress(&f->bzstream, BZ_FINISH); f->bz_waiting_bytes = BZBUFSIZE - f->bzstream.avail_out; /* BZ_RUN_OK most likely is not possible here, but BZ_FINISH_OK * is returned when it cannot be finished in one step. * but better safe then sorry... */ - if( (bzret == BZ_RUN_OK || bzret == BZ_FINISH_OK || bzret == BZ_STREAM_END) - && f->bz_waiting_bytes > 0 ) { + if ((bzret == BZ_RUN_OK || bzret == BZ_FINISH_OK + || bzret == BZ_STREAM_END) + && f->bz_waiting_bytes > 0) { retvalue r; r = writetofile(&f->f[ic_bzip2], (const unsigned char*)f->bzoutputbuffer, f->bz_waiting_bytes); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; f->bz_waiting_bytes = 0; } - } while( bzret == BZ_RUN_OK || bzret == BZ_FINISH_OK ); + } while (bzret == BZ_RUN_OK || bzret == BZ_FINISH_OK); - if( bzret != BZ_STREAM_END ) { - fprintf(stderr,"Error from bzlib's bzCompress: " + if (bzret != BZ_STREAM_END) { + fprintf(stderr, "Error from bzlib's bzCompress: " "%d\n", bzret); return RET_ERROR; } @@ -957,8 +962,8 @@ bzret = BZ2_bzCompressEnd(&f->bzstream); /* to avoid bzCompressEnd called again */ f->bzstream.next_out = NULL; - if( bzret != BZ_OK ) { - fprintf(stderr,"Error from libbz2's bzCompressEnd: " + if (bzret != BZ_OK) { + fprintf(stderr, "Error from libbz2's bzCompressEnd: " "%d\n", bzret); return RET_ERROR; } @@ -968,10 +973,10 @@ #endif retvalue release_finishfile(struct release *release, struct filetorelease *file) { - retvalue result,r; + retvalue result, r; enum indexcompression i; - if( RET_WAS_ERROR( file->state ) ) { + if (RET_WAS_ERROR(file->state)) { r = file->state; release_abortfile(file); return r; @@ -979,12 +984,12 @@ r = writetofile(&file->f[ic_uncompressed], file->buffer, file->waiting_bytes); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(file); return r; } - if( file->f[ic_uncompressed].fd >= 0 ) { - if( close(file->f[ic_uncompressed].fd) != 0 ) { + if (file->f[ic_uncompressed].fd >= 0) { + if (close(file->f[ic_uncompressed].fd) != 0) { int e = errno; file->f[ic_uncompressed].fd = -1; release_abortfile(file); @@ -992,13 +997,13 @@ } file->f[ic_uncompressed].fd = -1; } - if( file->f[ic_gzip].fd >= 0 ) { + if (file->f[ic_gzip].fd >= 0) { r = finishgz(file); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(file); return r; } - if( close(file->f[ic_gzip].fd) != 0 ) { + if (close(file->f[ic_gzip].fd) != 0) { int e = errno; file->f[ic_gzip].fd = -1; release_abortfile(file); @@ -1007,13 +1012,13 @@ file->f[ic_gzip].fd = -1; } #ifdef HAVE_LIBBZ2 - if( file->f[ic_bzip2].fd >= 0 ) { + if (file->f[ic_bzip2].fd >= 0) { r = finishbz(file); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { release_abortfile(file); return r; } - if( close(file->f[ic_bzip2].fd) != 0 ) { + if (close(file->f[ic_bzip2].fd) != 0) { int e = errno; file->f[ic_bzip2].fd = -1; release_abortfile(file); @@ -1025,13 +1030,13 @@ release->new = true; result = RET_OK; - for( i = ic_uncompressed ; i < ic_count ; i++ ) { - r = releasefile(release,&file->f[i]); - if( RET_WAS_ERROR(r) ) { + for (i = ic_uncompressed ; i < ic_count ; i++) { + r = releasefile(release, &file->f[i]); + if (RET_WAS_ERROR(r)) { release_abortfile(file); return r; } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } free(file->buffer); free(file->gzoutputbuffer); @@ -1043,10 +1048,10 @@ } static retvalue release_processbuffer(struct filetorelease *file) { - retvalue result,r; + retvalue result, r; result = RET_OK; - assert( file->waiting_bytes == INPUT_BUFFER_SIZE ); + assert (file->waiting_bytes == INPUT_BUFFER_SIZE); /* always call this - even if there is no uncompressed file * to generate - so that checksums are calculated */ @@ -1054,15 +1059,15 @@ file->buffer, INPUT_BUFFER_SIZE); RET_UPDATE(result, r); - if( file->f[ic_gzip].relativefilename != NULL ) { + if (file->f[ic_gzip].relativefilename != NULL) { r = writegz(file); RET_UPDATE(result, r); } RET_UPDATE(file->state, result); #ifdef HAVE_LIBBZ2 - if( file->f[ic_bzip2].relativefilename != NULL ) { + if (file->f[ic_bzip2].relativefilename != NULL) { r = writebz(file); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } RET_UPDATE(file->state, result); #endif @@ -1070,16 +1075,16 @@ } retvalue release_writedata(struct filetorelease *file, const char *data, size_t len) { - retvalue result,r; + retvalue result, r; size_t free_bytes; result = RET_OK; /* move stuff into buffer, so stuff is not processed byte by byte */ free_bytes = INPUT_BUFFER_SIZE - file->waiting_bytes; - if( len < free_bytes ) { + if (len < free_bytes) { memcpy(file->buffer + file->waiting_bytes, data, len); file->waiting_bytes += len; - assert( file->waiting_bytes < INPUT_BUFFER_SIZE ); + assert (file->waiting_bytes < INPUT_BUFFER_SIZE); return RET_OK; } memcpy(file->buffer + file->waiting_bytes, data, free_bytes); @@ -1088,7 +1093,7 @@ file->waiting_bytes += free_bytes; r = release_processbuffer(file); RET_UPDATE(result, r); - while( len >= INPUT_BUFFER_SIZE ) { + while (len >= INPUT_BUFFER_SIZE) { /* should not hopefully not happen, as all this copying * is quite slow... */ memcpy(file->buffer, data, INPUT_BUFFER_SIZE); @@ -1099,7 +1104,7 @@ } memcpy(file->buffer, data, len); file->waiting_bytes = len; - assert( file->waiting_bytes < INPUT_BUFFER_SIZE ); + assert (file->waiting_bytes < INPUT_BUFFER_SIZE); return result; } @@ -1112,28 +1117,28 @@ target->relativedirectory, releasename, IC_FLAG(ic_uncompressed), onlyifneeded, &f); - if( RET_WAS_ERROR(r) || r == RET_NOTHING ) + if (RET_WAS_ERROR(r) || r == RET_NOTHING) return r; #define release_writeheader(name, data) \ - if( data != NULL ) { \ - (void)release_writestring(f,name ": "); \ - (void)release_writestring(f,data); \ - (void)release_writestring(f,"\n"); \ + if (data != NULL) { \ + (void)release_writestring(f, name ": "); \ + (void)release_writestring(f, data); \ + (void)release_writestring(f, "\n"); \ } - release_writeheader("Archive",distribution->suite); - release_writeheader("Version",distribution->version); + release_writeheader("Archive", distribution->suite); + release_writeheader("Version", distribution->version); release_writeheader("Component", - atoms_components[target->component_atom]); - release_writeheader("Origin",distribution->origin); - release_writeheader("Label",distribution->label); + atoms_components[target->component]); + release_writeheader("Origin", distribution->origin); + release_writeheader("Label", distribution->label); release_writeheader("Architecture", - atoms_architectures[target->architecture_atom]); - release_writeheader("NotAutomatic",distribution->notautomatic); + atoms_architectures[target->architecture]); + release_writeheader("NotAutomatic", distribution->notautomatic); release_writeheader("ButAutomaticUpgrades", distribution->butautomaticupgrades); - release_writeheader("Description",distribution->description); + release_writeheader("Description", distribution->description); #undef release_writeheader r = release_finishfile(release, f); return r; @@ -1148,19 +1153,19 @@ result = RET_OK; - for( file = release->files ; file != NULL ; file = file->next ) { + for (file = release->files ; file != NULL ; file = file->next) { - if( file->relativefilename == NULL ) + if (file->relativefilename == NULL) continue; r = table_deleterecord(release->cachedb, file->relativefilename, true); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = checksums_getcombined(file->checksums, &combinedchecksum, &len); RET_UPDATE(result, r); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) continue; r = table_adduniqsizedrecord(release->cachedb, @@ -1172,10 +1177,10 @@ } static inline bool componentneedsfake(const char *cn, const struct release *release) { - if( release->fakecomponentprefix == NULL ) + if (release->fakecomponentprefix == NULL) return false; - if( strncmp(cn, release->fakecomponentprefix, - release->fakecomponentprefixlen) != 0 ) + if (strncmp(cn, release->fakecomponentprefix, + release->fakecomponentprefixlen) != 0) return true; return cn[release->fakecomponentprefixlen] != '/'; } @@ -1194,121 +1199,121 @@ { "MD5Sum:\n", "SHA1:\n", "SHA256:\n" }; // TODO: check for existance of Release file here first? - if( onlyifneeded && !release->new ) { + if (onlyifneeded && !release->new) { return RET_NOTHING; } (void)time(&t); gmt = gmtime(&t); - if( gmt == NULL ) { + if (FAILEDTOALLOC(gmt)) return RET_ERROR_OOM; - } - s=strftime(buffer,99,"%a, %d %b %Y %H:%M:%S UTC",gmt); - if( s == 0 || s >= 99) { - fprintf(stderr,"strftime is doing strange things...\n"); + s=strftime(buffer, 99, "%a, %d %b %Y %H:%M:%S UTC", gmt); + if (s == 0 || s >= 99) { + fprintf(stderr, "strftime is doing strange things...\n"); return RET_ERROR; } - if( distribution->validfor > 0 ) { + if (distribution->validfor > 0) { t += distribution->validfor; gmt = gmtime(&t); - if( gmt == NULL ) { + if (FAILEDTOALLOC(gmt)) return RET_ERROR_OOM; - } - s=strftime(untilbuffer,99,"%a, %d %b %Y %H:%M:%S UTC",gmt); - if( s == 0 || s >= 99) { - fprintf(stderr,"strftime is doing strange things...\n"); + s=strftime(untilbuffer, 99, "%a, %d %b %Y %H:%M:%S UTC", gmt); + if (s == 0 || s >= 99) { + fprintf(stderr, +"strftime is doing strange things...\n"); return RET_ERROR; } } r = signature_startsignedfile(release->dirofdist, "Release", "InRelease", &release->signedfile); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } #define writestring(s) signedfile_write(release->signedfile, s, strlen(s)) #define writechar(c) {char __c = c ; signedfile_write(release->signedfile, &__c, 1); } - if( distribution->origin != NULL ) { + if (distribution->origin != NULL) { writestring("Origin: "); writestring(distribution->origin); writechar('\n'); } - if( distribution->label != NULL ) { + if (distribution->label != NULL) { writestring("Label: "); writestring(distribution->label); writechar('\n'); } - if( release->fakesuite != NULL ) { + if (release->fakesuite != NULL) { writestring("Suite: "); writestring(release->fakesuite); writechar('\n'); - } else if( distribution->suite != NULL ) { + } else if (distribution->suite != NULL) { writestring("Suite: "); writestring(distribution->suite); writechar('\n'); } writestring("Codename: "); - if( release->fakecodename != NULL ) + if (release->fakecodename != NULL) writestring(release->fakecodename); else writestring(distribution->codename); - if( distribution->version != NULL ) { + if (distribution->version != NULL) { writestring("\nVersion: "); writestring(distribution->version); } writestring("\nDate: "); writestring(buffer); - if( distribution->validfor > 0 ) { + if (distribution->validfor > 0) { writestring("\nValid-Until: "); writestring(untilbuffer); } writestring("\nArchitectures:"); - for( i = 0 ; i < distribution->architectures.count ; i++ ) { + for (i = 0 ; i < distribution->architectures.count ; i++) { architecture_t a = distribution->architectures.atoms[i]; - /* Debian's topmost Release files do not list it, so we won't either */ - if( a == architecture_source ) + /* Debian's topmost Release files do not list it, + * so we won't either */ + if (a == architecture_source) continue; writechar(' '); writestring(atoms_architectures[a]); } writestring("\nComponents:"); - for( i = 0 ; i < distribution->components.count ; i++ ) { + for (i = 0 ; i < distribution->components.count ; i++) { component_t c = distribution->components.atoms[i]; const char *cn = atoms_components[c]; writechar(' '); - if( componentneedsfake(cn, release) ) { + if (componentneedsfake(cn, release)) { writestring(release->fakecomponentprefix); writechar('/'); } writestring(cn); } - if( distribution->description != NULL ) { + if (distribution->description != NULL) { writestring("\nDescription: "); writestring(distribution->description); } - if( distribution->notautomatic != NULL ) { + if (distribution->notautomatic != NULL) { writestring("\nNotAutomatic: "); writestring(distribution->notautomatic); } - if( distribution->butautomaticupgrades != NULL ) { + if (distribution->butautomaticupgrades != NULL) { writestring("\nButAutomaticUpgrades: "); writestring(distribution->butautomaticupgrades); } writechar('\n'); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( release_checksum_headers[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (release_checksum_headers[cs] != NULL); writestring(release_checksum_headers[cs]); - for( file = release->files ; file != NULL ; file = file->next ) { + for (file = release->files ; file != NULL ; file = file->next) { const char *hash, *size; size_t hashlen, sizelen; - if( file->relativefilename == NULL ) + if (file->relativefilename == NULL) continue; - if( !checksums_gethashpart(file->checksums, cs, - &hash, &hashlen, &size, &sizelen) ) + if (!checksums_gethashpart(file->checksums, cs, + &hash, &hashlen, &size, &sizelen)) continue; writechar(' '); signedfile_write(release->signedfile, hash, hashlen); @@ -1321,7 +1326,7 @@ } r = signedfile_prepare(release->signedfile, &distribution->signwith, !global.keeptemporaries); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { signedfile_free(release->signedfile, !global.keeptemporaries); release->signedfile = NULL; return r; @@ -1331,7 +1336,7 @@ /* Generate a main "Release" file for a distribution */ retvalue release_finish(/*@only@*/struct release *release, struct distribution *distribution) { - retvalue result,r; + retvalue result, r; int e; struct release_entry *file; bool somethingwasdone; @@ -1339,12 +1344,12 @@ somethingwasdone = false; result = RET_OK; - for( file = release->files ; file != NULL ; file = file->next ) { - if( file->relativefilename == NULL - && file->fullfinalfilename == NULL ) { - assert(file->fulltemporaryfilename != NULL ); + for (file = release->files ; file != NULL ; file = file->next) { + if (file->relativefilename == NULL + && file->fullfinalfilename == NULL) { + assert (file->fulltemporaryfilename != NULL); e = unlink(file->fulltemporaryfilename); - if( e < 0 ) { + if (e < 0) { e = errno; fprintf(stderr, "Error %d deleting %s: %s. (Will be ignored)\n", @@ -1353,23 +1358,24 @@ } free(file->fulltemporaryfilename); file->fulltemporaryfilename = NULL; - } else if( file->fulltemporaryfilename != NULL ) { + } else if (file->fulltemporaryfilename != NULL) { e = rename(file->fulltemporaryfilename, file->fullfinalfilename); - if( e < 0 ) { + if (e < 0) { e = errno; - fprintf(stderr, "Error %d moving %s to %s: %s!\n", + fprintf(stderr, +"Error %d moving %s to %s: %s!\n", e, file->fulltemporaryfilename, file->fullfinalfilename, strerror(e)); r = RET_ERRNO(e); /* after something was done, do not stop * but try to do as much as possible */ - if( !somethingwasdone ) { + if (!somethingwasdone) { release_free(release); return r; } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } else { somethingwasdone = true; free(file->fulltemporaryfilename); @@ -1378,12 +1384,12 @@ } } r = signedfile_finalize(release->signedfile, &somethingwasdone); - if( RET_WAS_ERROR(r) && !somethingwasdone ) { + if (RET_WAS_ERROR(r) && !somethingwasdone) { release_free(release); return r; } - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) && somethingwasdone ) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result) && somethingwasdone) { fprintf(stderr, "ATTENTION: some files were already moved to place, some could not be.\n" "The generated index files for %s might be in a inconsistent state\n" @@ -1392,13 +1398,14 @@ "manually (via reprepro export codenames) as soon as possible!\n", distribution->codename); } - if( release->cachedb != NULL ) { + if (release->cachedb != NULL) { // TODO: split this in removing before and adding later? // remember which file were changed in case of error, so // only those are changed... - /* now update the cache database, so we find those the next time */ + /* now update the cache database, + * so we find those the next time */ r = storechecksums(release); - RET_UPDATE(result,r); + RET_UPDATE(result, r); r = table_close(release->cachedb); release->cachedb = NULL; @@ -1413,8 +1420,8 @@ char *dirname; retvalue r; - dirname = calc_dirconcat(release->dirofdist,relativedirectory); - if( dirname == NULL ) + dirname = calc_dirconcat(release->dirofdist, relativedirectory); + if (FAILEDTOALLOC(dirname)) return RET_ERROR_OOM; // TODO: in some far future, remember which dirs were created so that r = dirs_make_recursive(dirname); diff -Nru reprepro-4.5.0/release.h reprepro-4.6.0/release.h --- reprepro-4.5.0/release.h 2009-03-18 17:31:57.000000000 +0000 +++ reprepro-4.6.0/release.h 2011-05-05 14:42:55.000000000 +0000 @@ -25,41 +25,41 @@ #define IC_FLAG(a) (1<<(a)) /* Initialize Release generation */ -retvalue release_init(struct release **release, struct database *database, const char *codename, /*@null@*/const char *suite, /*@null@*/const char *fakeprefix); +retvalue release_init(struct release **, const char * /*codename*/, /*@null@*/const char * /*suite*/, /*@null@*/const char * /*fakeprefix*/); /* same but for a snapshot */ -retvalue release_initsnapshot(const char *codename, const char *name, struct release **release); +retvalue release_initsnapshot(const char *codename, const char *name, struct release **); -retvalue release_mkdir(struct release *release, const char *relativedirectory); +retvalue release_mkdir(struct release *, const char * /*relativedirectory*/); -const char *release_dirofdist(struct release *release); +const char *release_dirofdist(struct release *); -retvalue release_addnew(struct release *release,/*@only@*/char *reltmpfile,/*@only@*/char *relfilename); -retvalue release_addsilentnew(struct release *release,/*@only@*/char *reltmpfile,/*@only@*/char *relfilename); -retvalue release_adddel(struct release *release,/*@only@*/char *reltmpfile); -retvalue release_addold(struct release *release,/*@only@*/char *relfilename); +retvalue release_addnew(struct release *, /*@only@*/char *, /*@only@*/char *); +retvalue release_addsilentnew(struct release *, /*@only@*/char *, /*@only@*/char *); +retvalue release_adddel(struct release *, /*@only@*/char *); +retvalue release_addold(struct release *, /*@only@*/char *); struct filetorelease; -retvalue release_startfile2(struct release *release, const char *relative_dir, const char *filename, compressionset compressions, bool usecache, struct filetorelease **file); +retvalue release_startfile2(struct release *, const char * /*relative_dir*/, const char */*filename*/, compressionset, bool /*usecache*/, struct filetorelease **); -retvalue release_startfile(struct release *release, const char *filename, compressionset compressions, bool usecache, struct filetorelease **file); +retvalue release_startfile(struct release *, const char * /*filename*/, compressionset, bool /*usecache*/, struct filetorelease **); /* return true if an old file is already there */ -bool release_oldexists(struct filetorelease *file); +bool release_oldexists(struct filetorelease *); /* errors will be cached for release_finishfile */ -retvalue release_writedata(struct filetorelease *file, const char *data, size_t len); -#define release_writestring(file,data) release_writedata(file,data,strlen(data)) +retvalue release_writedata(struct filetorelease *, const char *, size_t); +#define release_writestring(file, data) release_writedata(file, data, strlen(data)) -void release_abortfile(/*@only@*/struct filetorelease *file); -retvalue release_finishfile(struct release *release, /*@only@*/struct filetorelease *file); +void release_abortfile(/*@only@*/struct filetorelease *); +retvalue release_finishfile(struct release *, /*@only@*/struct filetorelease *); struct distribution; struct target; -retvalue release_directorydescription(struct release *release, const struct distribution *distribution, const struct target *target, const char *filename, bool onlyifneeded); +retvalue release_directorydescription(struct release *, const struct distribution *, const struct target *, const char * /*filename*/, bool /*onlyifneeded*/); -void release_free(/*@only@*/struct release *release); -retvalue release_prepare(struct release *release, struct distribution *distribution, bool onlyneeded); -retvalue release_finish(/*@only@*/struct release *release, struct distribution *distribution); +void release_free(/*@only@*/struct release *); +retvalue release_prepare(struct release *, struct distribution *, bool /*onlyneeded*/); +retvalue release_finish(/*@only@*/struct release *, struct distribution *); #endif diff -Nru reprepro-4.5.0/remoterepository.c reprepro-4.6.0/remoterepository.c --- reprepro-4.5.0/remoterepository.c 2009-10-30 13:28:23.000000000 +0000 +++ reprepro-4.6.0/remoterepository.c 2011-05-05 14:42:55.000000000 +0000 @@ -163,7 +163,7 @@ static void remote_index_free(/*@only@*/struct remote_index *i) { - if( i == NULL ) + if (i == NULL) return; free(i->cachefilename); free(i->patchfilename); @@ -174,7 +174,7 @@ } static void remote_distribution_free(/*@only@*/struct remote_distribution *d) { - if( d == NULL ) + if (d == NULL) return; free(d->suite); signature_requirements_free(d->verify); @@ -182,7 +182,7 @@ free(d->releasegpgfile); free(d->suite_base_dir); checksumsarray_done(&d->remotefiles); - while( d->indices != NULL ) { + while (d->indices != NULL) { struct remote_index *h = d->indices; d->indices = h->next; remote_index_free(h); @@ -191,23 +191,23 @@ } void remote_repository_free(struct remote_repository *remote) { - if( remote == NULL ) + if (remote == NULL) return; - while( remote->distributions != NULL ) { + while (remote->distributions != NULL) { struct remote_distribution *h = remote->distributions; remote->distributions = h->next; remote_distribution_free(h); } - if( remote->next != NULL ) + if (remote->next != NULL) remote->next->prev = remote->prev; - if( remote->prev != NULL ) + if (remote->prev != NULL) remote->prev->next = remote->next; free(remote); return; } void cachedlistfile_freelist(struct cachedlistfile *c) { - while( c != NULL ) { + while (c != NULL) { struct cachedlistfile *n = c->next; free(c); c = n; @@ -215,10 +215,10 @@ } void cachedlistfile_deleteunneeded(const struct cachedlistfile *c) { - for( ; c != NULL ; c = c->next ) { - if( c->needed ) + for (; c != NULL ; c = c->next) { + if (c->needed) continue; - if( verbose >= 0 ) + if (verbose >= 0) printf("deleting %s\n", c->fullfilename); deletefile(c->fullfilename); } @@ -231,51 +231,51 @@ char ch; c = malloc(sizeof(struct cachedlistfile) + listdirlen + 2*len + 3); - if( FAILEDTOALLOC(c) ) + if (FAILEDTOALLOC(c)) return NULL; c->next = NULL; c->needed = false; c->deleted = false; p = c->fullfilename; - assert( (size_t)(p - (char*)c) <= sizeof(struct cachedlistfile) ); + assert ((size_t)(p - (char*)c) <= sizeof(struct cachedlistfile)); memcpy(p, global.listdir, listdirlen); p += listdirlen; *(p++) = '/'; - assert( (size_t)(p - c->fullfilename) == listdirlen + 1 ); + assert ((size_t)(p - c->fullfilename) == listdirlen + 1); c->basefilename = p; memcpy(p, basefilename, len); p += len; *(p++) = '\0'; - assert( (size_t)(p - c->fullfilename) == listdirlen + len + 2 ); + assert ((size_t)(p - c->fullfilename) == listdirlen + len + 2); c->parts[0] = p; c->partcount = 1; l = len; - while( l-- > 0 && (ch = *(basefilename++)) != '\0' ) { - if( ch == '_' ) { + while (l-- > 0 && (ch = *(basefilename++)) != '\0') { + if (ch == '_') { *(p++) = '\0'; - if( c->partcount < MAXPARTS ) + if (c->partcount < MAXPARTS) c->parts[c->partcount] = p; c->partcount++; - } else if( ch == '%' ) { + } else if (ch == '%') { char first, second; - if( len <= 1 ) { + if (len <= 1) { c->partcount = 0; return c; } first = *(basefilename++); second = *(basefilename++); - if( first >= '0' && first <= '9' ) + if (first >= '0' && first <= '9') *p = (first - '0') << 4; - else if( first >= 'a' && first <= 'f' ) + else if (first >= 'a' && first <= 'f') *p = (first - 'a' + 10) << 4; else { c->partcount = 0; return c; } - if( second >= '0' && second <= '9' ) + if (second >= '0' && second <= '9') *p |= (second - '0'); - else if( second >= 'a' && second <= 'f' ) + else if (second >= 'a' && second <= 'f') *p |= (second - 'a' + 10); else { c->partcount = 0; @@ -286,7 +286,7 @@ *(p++) = ch; } *(p++) = '\0'; - assert( (size_t)(p - c->fullfilename) <= listdirlen + 2*len + 3 ); + assert ((size_t)(p - c->fullfilename) <= listdirlen + 2*len + 3); return c; } @@ -298,22 +298,23 @@ // TODO: check if it is always created before... dir = opendir(global.listdir); - if( dir == NULL ) { + if (dir == NULL) { int e = errno; - fprintf(stderr,"Error %d opening directory '%s': %s!\n", + fprintf(stderr, +"Error %d opening directory '%s': %s!\n", e, global.listdir, strerror(e)); return RET_ERRNO(e); } next_p = &cachedfiles; - while( true ) { + while (true) { size_t namelen; int e; errno = 0; r = readdir(dir); - if( r == NULL ) { + if (r == NULL) { e = errno; - if( e == 0 ) + if (e == 0) break; /* this should not happen... */ e = errno; @@ -324,19 +325,19 @@ return RET_ERRNO(e); } namelen = _D_EXACT_NAMLEN(r); - if( namelen == 1 && r->d_name[0] == '.' ) + if (namelen == 1 && r->d_name[0] == '.') continue; - if( namelen == 2 && r->d_name[0] == '.' && r->d_name[1] == '.' ) + if (namelen == 2 && r->d_name[0] == '.' && r->d_name[1] == '.') continue; *next_p = cachedlistfile_new(r->d_name, namelen, listdirlen); - if( FAILEDTOALLOC(*next_p) ) { + if (FAILEDTOALLOC(*next_p)) { (void)closedir(dir); cachedlistfile_freelist(cachedfiles); return RET_ERROR_OOM; } next_p = &(*next_p)->next; } - if( closedir(dir) != 0 ) { + if (closedir(dir) != 0) { int e = errno; fprintf(stderr, "Error %d closing directory '%s': %s!\n", e, global.listdir, strerror(e)); @@ -349,10 +350,10 @@ static retvalue cachedlistfile_delete(struct cachedlistfile *old) { int e; - if( old->deleted ) + if (old->deleted) return RET_OK; e = deletefile(old->fullfilename); - if( e != 0 ) + if (e != 0) return RET_ERRNO(e); old->deleted = true; return RET_OK; @@ -364,8 +365,8 @@ /* calling code ensures no two with the same name are created, * so just create it... */ - n = calloc(1, sizeof(struct remote_repository)); - if( FAILEDTOALLOC(n) ) + n = zNEW(struct remote_repository); + if (FAILEDTOALLOC(n)) return NULL; n->name = name; n->method = method; @@ -373,7 +374,7 @@ n->config = config; n->next = repositories; - if( n->next != NULL ) + if (n->next != NULL) n->next->prev = n; repositories = n; @@ -383,13 +384,13 @@ /* This escaping is quite harsh, but so nothing bad can happen... */ static inline size_t escapedlen(const char *p) { size_t l = 0; - if( *p == '-' ) { + if (*p == '-') { l = 3; p++; } - while( *p != '\0' ) { - if( (*p < 'A' || *p > 'Z' ) && (*p < 'a' || *p > 'z' ) && - ( *p < '0' || *p > '9') && *p != '-' ) + while (*p != '\0') { + if ((*p < 'A' || *p > 'Z') && (*p < 'a' || *p > 'z') && + (*p < '0' || *p > '9') && *p != '-') l +=3; else l++; @@ -400,14 +401,17 @@ static inline char *escapedcopy(char *dest, const char *orig) { static char hex[16] = "0123456789ABCDEF"; - if( *orig == '-' ) { + if (*orig == '-') { orig++; *dest = '%'; dest++; *dest = '2'; dest++; *dest = 'D'; dest++; } - while( *orig != '\0' ) { - if( (*orig < 'A' || *orig > 'Z' ) && (*orig < 'a' || *orig > 'z' ) && ( *orig < '0' || *orig > '9') && *orig != '-' ) { + while (*orig != '\0') { + if ((*orig < 'A' || *orig > 'Z') + && (*orig < 'a' || *orig > 'z') + && (*orig < '0' || *orig > '9') + && *orig != '-') { *dest = '%'; dest++; *dest = hex[(*orig >> 4)& 0xF ]; dest++; *dest = hex[*orig & 0xF ]; dest++; @@ -429,32 +433,32 @@ len = 0; va_start(ap, count); - for( i = 0 ; i < count ; i++ ) { + for (i = 0 ; i < count ; i++) { fields[i] = va_arg(ap, const char*); - assert( fields[i] != NULL ); + assert (fields[i] != NULL); len += escapedlen(fields[i]) + 1; } /* check sentinel */ - assert( va_arg(ap, const char*) == NULL ); + assert (va_arg(ap, const char*) == NULL); va_end(ap); listdir_len = strlen(global.listdir); - if( type != NULL ) + if (type != NULL) type_len = strlen(type); else type_len = 0; result = malloc(listdir_len + type_len + len + 2); - if( FAILEDTOALLOC(result) ) + if (FAILEDTOALLOC(result)) return NULL; memcpy(result, global.listdir, listdir_len); p = result + listdir_len; *(p++) = '/'; - for( i = 0 ; i < count ; i++ ) { + for (i = 0 ; i < count ; i++) { p = escapedcopy(p, fields[i]); *(p++) = '_'; } - assert( (size_t)(p - result) == listdir_len + len + 1); - if( type != NULL ) + assert ((size_t)(p - result) == listdir_len + len + 1); + if (type != NULL) memcpy(p, type, type_len + 1); else *(--p) = '\0'; @@ -468,23 +472,23 @@ va_list ap; va_start(ap, count); - for( i = 0 ; i < count ; i++ ) { + for (i = 0 ; i < count ; i++) { fields[i] = va_arg(ap, const char*); - assert( fields[i] != NULL ); + assert (fields[i] != NULL); } /* check sentinel */ - assert( va_arg(ap, const char*) == NULL ); + assert (va_arg(ap, const char*) == NULL); va_end(ap); - for( file = list ; file != NULL ; file = file->next ) { - if( file->partcount != count + 1 ) + for (file = list ; file != NULL ; file = file->next) { + if (file->partcount != count + 1) continue; i = 0; - while( i < count && strcmp(file->parts[i], fields[i]) == 0 ) + while (i < count && strcmp(file->parts[i], fields[i]) == 0) i++; - if( i < count ) + if (i < count) continue; - if( strcmp(type, file->parts[i]) != 0 ) + if (strcmp(type, file->parts[i]) != 0) continue; file->needed = true; } @@ -494,13 +498,13 @@ struct remote_distribution *n, **last; enum checksumtype cs; - for( last = &repository->distributions ; (n = *last) != NULL + for (last = &repository->distributions ; (n = *last) != NULL ; last = &n->next) { - if( strcmp(n->suite, suite) != 0 ) + if (strcmp(n->suite, suite) != 0) continue; - if( n->flat != flat ) { - if( verbose >= 0 && !n->flatnonflatwarned && - !IGNORABLE(flatandnonflat) ) + if (n->flat != flat) { + if (verbose >= 0 && !n->flatnonflatwarned && + !IGNORABLE(flatandnonflat)) fprintf(stderr, "Warning: From the same remote repository '%s', distribution '%s'\n" "is requested both flat and non-flat. While this is possible\n" @@ -515,26 +519,26 @@ break; } - if( *last != NULL ) { + if (*last != NULL) { n = *last; - assert( n->flat == flat ); + assert (n->flat == flat); - if( (n->ignorerelease && !ignorerelease) || - (!n->ignorerelease && ignorerelease) ) { + if ((n->ignorerelease && !ignorerelease) || + (!n->ignorerelease && ignorerelease)) { // TODO a hint which two are at fault would be nice, // but how to get the information... - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "Warning: I was told to both ignore Release files for Suite '%s'\n" "from remote repository '%s' and to not ignore it. Going to not ignore!\n", suite, repository->name); n->ignorerelease = false; } - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( (n->ignorehashes[cs] && !ignorehashes[cs]) || - (!n->ignorehashes[cs] && ignorehashes[cs]) ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if ((n->ignorehashes[cs] && !ignorehashes[cs]) || + (!n->ignorehashes[cs] && ignorehashes[cs])) { // TODO dito - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "Warning: I was told to both ignore '%s' for Suite '%s'\n" "from remote repository '%s' and to not ignore it. Going to not ignore!\n", @@ -544,57 +548,57 @@ n->ignorehashes[cs] = false; } } - if( verifyrelease != NULL ) { + if (verifyrelease != NULL) { retvalue r; r = signature_requirement_add(&n->verify, verifyrelease); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } *out_p = n; return RET_OK; } - n = calloc(1, sizeof(struct remote_distribution)); - if( FAILEDTOALLOC(n) ) + n = zNEW(struct remote_distribution); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->repository = repository; n->suite = strdup(suite); n->ignorerelease = ignorerelease; - if( verifyrelease != NULL ) { + if (verifyrelease != NULL) { retvalue r; r = signature_requirement_add(&n->verify, verifyrelease); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { remote_distribution_free(n); return r; } } memcpy(n->ignorehashes, ignorehashes, sizeof(bool [cs_hashCOUNT])); n->flat = flat; - if( flat ) + if (flat) n->suite_base_dir = strdup(suite); else n->suite_base_dir = calc_dirconcat("dists", suite); - if( FAILEDTOALLOC(n->suite) || - FAILEDTOALLOC(n->suite_base_dir) ) { + if (FAILEDTOALLOC(n->suite) || + FAILEDTOALLOC(n->suite_base_dir)) { remote_distribution_free(n); return RET_ERROR_OOM; } /* ignorerelease can be unset later, so always calculate the filename */ - if( flat ) + if (flat) n->releasefile = genlistsfilename("Release", 3, repository->name, suite, "flat", ENDOFARGUMENTS); else n->releasefile = genlistsfilename("Release", 2, repository->name, suite, ENDOFARGUMENTS); - if( FAILEDTOALLOC(n->releasefile) ) { + if (FAILEDTOALLOC(n->releasefile)) { remote_distribution_free(n); return RET_ERROR_OOM; } n->releasegpgfile = calc_addsuffix(n->releasefile, "gpg"); - if( FAILEDTOALLOC(n->releasefile) ) { + if (FAILEDTOALLOC(n->releasefile)) { remote_distribution_free(n); return RET_ERROR_OOM; } @@ -608,27 +612,29 @@ struct checksums *checksums = NULL; /* if the file is somewhere else, copy it: */ - if( strcmp(gotfilename, wantedfilename) != 0 ) { + if (strcmp(gotfilename, wantedfilename) != 0) { /* never link index files, but copy them */ - if( verbose > 1 ) + if (verbose > 1) fprintf(stderr, "Copy file '%s' to '%s'...\n", gotfilename, wantedfilename); - r = checksums_copyfile(wantedfilename, gotfilename, false, &checksums); - if( r == RET_ERROR_EXIST ) { - fprintf(stderr, "Unexpected error: '%s' exists while it should not!\n", + r = checksums_copyfile(wantedfilename, gotfilename, false, + &checksums); + if (r == RET_ERROR_EXIST) { + fprintf(stderr, +"Unexpected error: '%s' exists while it should not!\n", wantedfilename); } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot open '%s', obtained from '%s' method.\n", gotfilename, method); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } } - if( checksums_p == NULL ) + if (checksums_p == NULL) checksums_free(checksums); else *checksums_p = checksums; @@ -641,11 +647,11 @@ static retvalue release_callback(enum queue_action action, UNUSED(void *privdata), UNUSED(void *privdata2), UNUSED(const char *uri), const char *gotfilename, const char *wantedfilename, UNUSED(/*@null@*/const struct checksums *checksums), const char *methodname) { retvalue r; - if( action != qa_got ) + if (action != qa_got) return RET_ERROR; r = copytoplace(gotfilename, wantedfilename, methodname, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return r; } @@ -654,9 +660,9 @@ struct remote_repository *repository = d->repository; retvalue r; - assert( repository->download != NULL ); + assert (repository->download != NULL); - if( d->ignorerelease ) + if (d->ignorerelease) return RET_NOTHING; (void)unlink(d->releasefile); @@ -664,16 +670,16 @@ r = aptmethod_enqueueindex(repository->download, d->suite_base_dir, "Release", "", d->releasefile, "", release_callback, NULL, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( d->verify != NULL ) { + if (d->verify != NULL) { (void)unlink(d->releasegpgfile); r = aptmethod_enqueueindex(repository->download, d->suite_base_dir, "Release", ".gpg", d->releasegpgfile, "", release_callback, NULL, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -683,16 +689,16 @@ struct remote_repository *rr; retvalue r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - for( rr = repositories ; rr != NULL ; rr = rr->next ) { - assert( rr->download == NULL ); + for (rr = repositories ; rr != NULL ; rr = rr->next) { + assert (rr->download == NULL); r = aptmethod_newmethod(run, rr->method, rr->fallback, rr->config, &rr->download); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -704,27 +710,27 @@ int i; enum compression c; - for( i = 0 ; i < files->count ; i++ ) { + for (i = 0 ; i < files->count ; i++) { const char *value = files->values[i]; - if( strncmp(value, filename, len) != 0 ) + if (strncmp(value, filename, len) != 0) continue; value += len; - if( *value == '\0' ) { + if (*value == '\0') { ri->ofs[c_none] = i; continue; } - if( *value != '.' ) + if (*value != '.') continue; - if( strcmp(value, ".diff/Index") == 0 ) { + if (strcmp(value, ".diff/Index") == 0) { ri->diff_ofs = i; continue; } - for( c = 0 ; c < c_COUNT ; c++ ) - if( strcmp(value, uncompression_suffix[c]) == 0 ) { + for (c = 0 ; c < c_COUNT ; c++) + if (strcmp(value, uncompression_suffix[c]) == 0) { ri->ofs[c] = i; break; } @@ -736,29 +742,29 @@ struct remote_index *ri; retvalue r; - if( rd->verify != NULL ) { + if (rd->verify != NULL) { r = signature_check(rd->verify, rd->releasegpgfile, rd->releasefile); - assert( r != RET_NOTHING ); - if( r == RET_NOTHING ) + assert (r != RET_NOTHING); + if (r == RET_NOTHING) r = RET_ERROR_BADSIG; - if( r == RET_ERROR_BADSIG ) { + if (r == RET_ERROR_BADSIG) { fprintf(stderr, "Error: Not enough signatures found for remote repository %s (%s %s)!\n", rr->name, rr->method, rd->suite); r = RET_ERROR_BADSIG; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } r = release_getchecksums(rd->releasefile, rd->ignorehashes, &rd->remotefiles); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* Check for our files in there */ - for( ri = rd->indices ; ri != NULL ; ri = ri->next ) { + for (ri = rd->indices ; ri != NULL ; ri = ri->next) { find_index(&rd->remotefiles.names, ri); } // TODO: move checking if not exists at all to here? @@ -770,24 +776,24 @@ struct remote_distribution *rd; retvalue r; - if( !nodownload ) { - for( rr = repositories ; rr != NULL ; rr = rr->next ) { - for( rd = rr->distributions ; rd != NULL ; - rd = rd->next ) { + if (!nodownload) { + for (rr = repositories ; rr != NULL ; rr = rr->next) { + for (rd = rr->distributions ; rd != NULL ; + rd = rd->next) { r = remote_distribution_metalistqueue(rd); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } r = aptmethod_download(run); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - for( rr = repositories ; rr != NULL ; rr = rr->next ) { - for( rd = rr->distributions ; rd != NULL ; rd = rd->next ) { - if( !rd->ignorerelease ) { + for (rr = repositories ; rr != NULL ; rr = rr->next) { + for (rd = rr->distributions ; rd != NULL ; rd = rd->next) { + if (!rd->ignorerelease) { r = process_remoterelease(rd); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } @@ -801,36 +807,36 @@ bool hashes_missing, improves; /* files without uncompressed checksum cannot be tested */ - if( ri->ofs[c_none] < 0 ) + if (ri->ofs[c_none] < 0) return true; /* if not there or the wrong files comes next, then something * has changed and we better reload everything */ - if( !donefile_nextindex(done, &basefilename, &checksums) ) + if (!donefile_nextindex(done, &basefilename, &checksums)) return true; - if( strcmp(basefilename, ri->cachebasename) != 0 ) { + if (strcmp(basefilename, ri->cachebasename) != 0) { checksums_free(checksums); return true; } /* otherwise check if the file checksums match */ - if( !checksums_check(checksums, + if (!checksums_check(checksums, ri->from->remotefiles.checksums[ri->ofs[c_none]], - &hashes_missing) ) { + &hashes_missing)) { checksums_free(checksums); return true; } - if( hashes_missing ) { + if (hashes_missing) { /* if Release has checksums we do not yet know about, * process it to make sure those match as well */ checksums_free(checksums); return true; } - if( !checksums_check(ri->from->remotefiles.checksums[ri->ofs[c_none]], - checksums, &improves) ) { + if (!checksums_check(ri->from->remotefiles.checksums[ri->ofs[c_none]], + checksums, &improves)) { /* this should not happen, but ... */ checksums_free(checksums); return true; } - if( improves ) { + if (improves) { /* assume this is our file and add the other hashes so they * will show up in the file again the next time. * This is a bit unelegant in mixing stuff, but otherwise this @@ -851,25 +857,25 @@ size_t l; enum compression c; - for( c = 0 ; c < c_COUNT ; c++ ) + for (c = 0 ; c < c_COUNT ; c++) old[c] = NULL; l = strlen(ri->cachebasename); - for( o = oldfiles ; o != NULL ; o = o->next ) { - if( o->deleted ) + for (o = oldfiles ; o != NULL ; o = o->next) { + if (o->deleted) continue; - if( strncmp(o->basefilename, ri->cachebasename, l) != 0 ) + if (strncmp(o->basefilename, ri->cachebasename, l) != 0) continue; - for( c = 0 ; c < c_COUNT ; c++ ) - if( strcmp(o->basefilename + l, - uncompression_suffix[c]) == 0 ) { + for (c = 0 ; c < c_COUNT ; c++) + if (strcmp(o->basefilename + l, + uncompression_suffix[c]) == 0) { old[c] = o; o->needed = true; break; } - if( strcmp(o->basefilename + l, ".diffindex") == 0 ) + if (strcmp(o->basefilename + l, ".diffindex") == 0) (void)cachedlistfile_delete(o); - if( strncmp(o->basefilename + l, ".diff-", 6) == 0 ) + if (strncmp(o->basefilename + l, ".diff-", 6) == 0) (void)cachedlistfile_delete(o); } } @@ -879,10 +885,10 @@ size_t l; l = strlen(ri->cachebasename); - for( o = oldfiles ; o != NULL ; o = o->next ) { - if( o->deleted ) + for (o = oldfiles ; o != NULL ; o = o->next) { + if (o->deleted) continue; - if( strncmp(o->basefilename, ri->cachebasename, l) != 0 ) + if (strncmp(o->basefilename, ri->cachebasename, l) != 0) continue; (void)cachedlistfile_delete(o); } @@ -905,27 +911,29 @@ }; int e; - if( ri->downloadas.count == 0 ) + if (ri->downloadas.count == 0) downloadas = &defaultdownloadas; else downloadas = &ri->downloadas; - for( e = ri->lasttriedencoding + 1 ; e < downloadas->count ; e++ ) { + for (e = ri->lasttriedencoding + 1 ; e < downloadas->count ; e++) { enum compression c = downloadas->requested[e].compression; - if( downloadas->requested[e].diff ) + if (downloadas->requested[e].diff) continue; - if( uncompression_supported(c) ) { + if (uncompression_supported(c)) { ri->lasttriedencoding = e; ri->compression = c; return aptmethod_enqueueindex(rd->repository->download, - rd->suite_base_dir, ri->filename_in_release, + rd->suite_base_dir, + ri->filename_in_release, + uncompression_suffix[c], + ri->cachefilename, uncompression_suffix[c], - ri->cachefilename, uncompression_suffix[c], index_callback, ri, NULL); } } - if( ri->lasttriedencoding < 0 ) + if (ri->lasttriedencoding < 0) fprintf(stderr, "ERROR: no supported compressions in DownloadListsAs for '%s' by '%s'!\n", rd->suite, rd->repository->method); @@ -941,36 +949,36 @@ /* the best unrequested but supported */ unrequested = c_COUNT; - if( ri->downloadas.count > 0 ) { + if (ri->downloadas.count > 0) { bool found = false; - for( e = ri->lasttriedencoding + 1 ; + for (e = ri->lasttriedencoding + 1 ; e < ri->downloadas.count ; - e++ ) { + e++) { struct compression_preference req; req = ri->downloadas.requested[e]; - if( req.diff ) { - if( ri->olduncompressed == NULL ) + if (req.diff) { + if (ri->olduncompressed == NULL) continue; - assert( ri->ofs[c_none] >= 0 ); - if( !req.force && ri->diff_ofs < 0 ) + assert (ri->ofs[c_none] >= 0); + if (!req.force && ri->diff_ofs < 0) continue; ri->compression = c_COUNT; ri->lasttriedencoding = e; return RET_OK; } - if( ri->ofs[req.compression] < 0 && - ( !req.force || ri->ofs[c_none] < 0) ) + if (ri->ofs[req.compression] < 0 && + (!req.force || ri->ofs[c_none] < 0)) continue; - if( uncompression_supported(req.compression) ) { + if (uncompression_supported(req.compression)) { ri->compression = req.compression; ri->lasttriedencoding = e; return RET_OK; - } else if( unsupported == c_COUNT ) + } else if (unsupported == c_COUNT) unsupported = req.compression; } - if( ri->lasttriedencoding > -1 ) { + if (ri->lasttriedencoding > -1) { /* we already tried something, and nothing else * is available, so give up */ ri->lasttriedencoding = e; @@ -981,15 +989,15 @@ * and listed in the Release file found, check what is there * to get a meaningfull error message */ - for( c = 0 ; c < c_COUNT ; c++ ) { - if( ri->ofs[c] < 0 ) + for (c = 0 ; c < c_COUNT ; c++) { + if (ri->ofs[c] < 0) continue; found = true; - if( uncompression_supported(c) ) + if (uncompression_supported(c)) unrequested = c; } - if( !found ) { + if (!found) { // TODO: might be nice to check for not-yet-even // known about compressions and say they are not // yet know yet instead then here... @@ -999,7 +1007,7 @@ return RET_ERROR_WRONG_MD5; } - if( unsupported != c_COUNT && unrequested != c_COUNT) { + if (unsupported != c_COUNT && unrequested != c_COUNT) { fprintf(stderr, "Error: '%s' only lists unusable or unrequested compressions of '%s'.\n" "Try e.g the '%s' option (or check what it is set to) to make more useable.\n" @@ -1009,7 +1017,7 @@ uncompression_config[unrequested]); return RET_ERROR; } - if( unsupported != c_COUNT ) { + if (unsupported != c_COUNT) { fprintf(stderr, "Error: '%s' only lists unusable compressions of '%s'.\n" "Try e.g the '%s' option (or check what it is set to) to make more useable.\n", @@ -1017,7 +1025,7 @@ uncompression_option[unsupported]); return RET_ERROR; } - if( unrequested != c_COUNT ) { + if (unrequested != c_COUNT) { fprintf(stderr, "Error: '%s' only lists unrequested compressions of '%s'.\n" "Try changing your DownloadListsAs to request e.g. '%s'.\n", @@ -1043,9 +1051,8 @@ * 2 means nothing c_COUNT - 2 was already tried, * and so on...*/ - if( ri->lasttriedencoding < 0 ) { - if( ri->olduncompressed != NULL - && ri->diff_ofs >= 0 ) { + if (ri->lasttriedencoding < 0) { + if (ri->olduncompressed != NULL && ri->diff_ofs >= 0) { ri->compression = c_COUNT; ri->lasttriedencoding = 0; return RET_OK; @@ -1055,21 +1062,21 @@ stopat = c_COUNT - ri->lasttriedencoding; ri->compression = c_COUNT; - for( c = 0 ; c < stopat ; c++ ) { - if( ri->ofs[c] < 0 ) + for (c = 0 ; c < stopat ; c++) { + if (ri->ofs[c] < 0) continue; - if( uncompression_supported(c) ) + if (uncompression_supported(c)) ri->compression = c; else unsupported = c; } - if( ri->compression == c_COUNT ) { - if( ri->lasttriedencoding > -1 ) { + if (ri->compression == c_COUNT) { + if (ri->lasttriedencoding > -1) { /* not the first try, no error message needed */ ri->lasttriedencoding = c_COUNT; return RET_ERROR; } - if( unsupported != c_COUNT ) { + if (unsupported != c_COUNT) { fprintf(stderr, "Error: '%s' only lists unusable compressions of '%s'.\n" "Try e.g the '%s' option (or check what it is set to) to enable more.\n", @@ -1090,7 +1097,7 @@ static inline retvalue remove_old_uncompressed(struct remote_index *ri) { retvalue r; - if( ri->olduncompressed != NULL ) { + if (ri->olduncompressed != NULL) { r = cachedlistfile_delete(ri->olduncompressed); ri->olduncompressed = NULL; return r; @@ -1105,9 +1112,9 @@ retvalue r; struct cachedlistfile *old[c_COUNT]; - if( rd->ignorerelease ) { + if (rd->ignorerelease) { ri->queued = true; - if( nodownload ) { + if (nodownload) { ri->got = true; return RET_OK; } @@ -1123,32 +1130,32 @@ remote_index_oldfiles(ri, oldfiles, old); ri->olduncompressed = NULL; ri->oldchecksums = NULL; - if( ri->ofs[c_none] < 0 && old[c_none] != NULL ) { + if (ri->ofs[c_none] < 0 && old[c_none] != NULL) { /* if we know not what it should be, * we canot use the old... */ r = cachedlistfile_delete(old[c_none]); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; old[c_none] = NULL; - } else if( old[c_none] != NULL ) { + } else if (old[c_none] != NULL) { bool improves; int uo = ri->ofs[c_none]; struct checksums **wanted_p = &rd->remotefiles.checksums[uo]; r = checksums_read(old[c_none]->fullfilename, &ri->oldchecksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "File '%s' mysteriously vanished!\n", old[c_none]->fullfilename); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( checksums_check(*wanted_p, ri->oldchecksums, &improves) ) { + if (checksums_check(*wanted_p, ri->oldchecksums, &improves)) { /* already there, nothing to do to get it... */ ri->queued = true; ri->got = true; - if( improves ) + if (improves) r = checksums_combine(wanted_p, ri->oldchecksums, NULL); else @@ -1161,37 +1168,37 @@ old[c_none] = NULL; } - assert( old[c_none] == NULL ); + assert (old[c_none] == NULL); /* make sure everything old is deleted or check if it can be used */ - for( c = 0 ; c < c_COUNT ; c++ ) { - if( old[c] == NULL ) + for (c = 0 ; c < c_COUNT ; c++) { + if (old[c] == NULL) continue; - if( c != c_none && ri->ofs[c] >= 0 ) { + if (c != c_none && ri->ofs[c] >= 0) { /* check if it can be used */ r = checksums_test(old[c]->fullfilename, rd->remotefiles.checksums[ri->ofs[c]], &rd->remotefiles.checksums[ri->ofs[c]]); - if( r == RET_ERROR_WRONG_MD5 ) + if (r == RET_ERROR_WRONG_MD5) r = RET_NOTHING; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = remove_old_uncompressed(ri); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( old[c_none] == NULL ); + assert (old[c_none] == NULL); r = uncompress_file(old[c]->fullfilename, ri->cachefilename, c); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - if( ri->ofs[c_none] >= 0 ) { + if (ri->ofs[c_none] >= 0) { r = checksums_test(ri->cachefilename, rd->remotefiles.checksums[ri->ofs[c_none]], &rd->remotefiles.checksums[ri->ofs[c_none]]); - if( r == RET_ERROR_WRONG_MD5 ) { + if (r == RET_ERROR_WRONG_MD5) { fprintf(stderr, "Error: File '%s' looked correct according to '%s',\n" "but after unpacking '%s' looks wrong.\n" @@ -1200,12 +1207,12 @@ rd->releasefile, ri->cachefilename); } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "File '%s' mysteriously vanished!\n", ri->cachefilename); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } /* already there, nothing to do to get it... */ @@ -1215,15 +1222,15 @@ } } r = cachedlistfile_delete(old[c]); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; old[c] = NULL; } /* nothing found, we'll have to download: */ - if( nodownload ) { - if( ri->olduncompressed != NULL ) + if (nodownload) { + if (ri->olduncompressed != NULL) fprintf(stderr, "Error: '%s' does not match Release file, try without --nolistsdownload to download new one!\n", ri->cachefilename); @@ -1241,20 +1248,20 @@ struct remote_repository *rr = rd->repository; retvalue r; - if( rd->ignorerelease ) + if (rd->ignorerelease) return queue_next_without_release(rd, ri); r = find_requested_encoding(ri, rd->releasefile); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - assert( ri->compression <= c_COUNT ); + assert (ri->compression <= c_COUNT); /* check if downloading a .diff/Index (aka .pdiff) is requested */ - if( ri->compression == c_COUNT ) { - assert( ri->olduncompressed != NULL ); - assert( ri->oldchecksums != NULL ); + if (ri->compression == c_COUNT) { + assert (ri->olduncompressed != NULL); + assert (ri->oldchecksums != NULL); ri->queued = true; return aptmethod_enqueueindex(rr->download, rd->suite_base_dir, @@ -1263,12 +1270,12 @@ diff_callback, ri, NULL); } - assert( ri->compression < c_COUNT ); - assert( uncompression_supported(ri->compression) ); + assert (ri->compression < c_COUNT); + assert (uncompression_supported(ri->compression)); - if( ri->compression == c_none ) { + if (ri->compression == c_none) { r = remove_old_uncompressed(ri); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } /* as those checksums might be overwritten with completed data, @@ -1290,17 +1297,18 @@ retvalue r; /* check what to get for the requested indicies */ - for( ri = rd->indices ; ri != NULL ; ri = ri->next ) { - if( ri->queued ) + for (ri = rd->indices ; ri != NULL ; ri = ri->next) { + if (ri->queued) continue; - if( !ri->needed ) { - /* if we do not know anything about it, it cannot have got - * marked as old or otherwise as unneeded */ - assert( !rd->ignorerelease ); + if (!ri->needed) { + /* if we do not know anything about it, + * it cannot have got marked as old + * or otherwise as unneeded */ + assert (!rd->ignorerelease); continue; } r = queueindex(rd, ri, nodownload, oldfiles); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -1313,25 +1321,25 @@ struct cachedlistfile *oldfiles IFSTUPIDCC(=NULL); r = cachedlists_scandir(&oldfiles); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) oldfiles = NULL; - for( rr = repositories ; rr != NULL ; rr = rr->next ) { - for( rd = rr->distributions ; rd != NULL - ; rd = rd->next ) { + for (rr = repositories ; rr != NULL ; rr = rr->next) { + for (rd = rr->distributions ; rd != NULL + ; rd = rd->next) { r = remote_distribution_listqueue(rd, nodownload, oldfiles); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cachedlistfile_freelist(oldfiles); return r; } } } r = aptmethod_download(run); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cachedlistfile_freelist(oldfiles); return r; } @@ -1345,27 +1353,27 @@ enum compression c; const char *cachebasename; - if( FAILEDTOALLOC(cachefilename) || FAILEDTOALLOC(filename) ) + if (FAILEDTOALLOC(cachefilename) || FAILEDTOALLOC(filename)) return NULL; cachebasename = dirs_basename(cachefilename); last = &rd->indices; - while( *last != NULL && strcmp((*last)->cachebasename, cachebasename) != 0 ) + while (*last != NULL && strcmp((*last)->cachebasename, cachebasename) != 0) last = &(*last)->next; - if( *last != NULL ) { + if (*last != NULL) { ri = *last; // TODO: perhaps try to calculate some form of intersections // instead of just using the shorter one... - if( downloadas != NULL && + if (downloadas != NULL && (ri->downloadas.count == 0 - || ri->downloadas.count > downloadas->count) ) + || ri->downloadas.count > downloadas->count)) ri->downloadas = *downloadas; free(cachefilename); free(filename); return ri; } - ri = calloc(1, sizeof(struct remote_index)); - if( FAILEDTOALLOC(ri) ) { + ri = zNEW(struct remote_index); + if (FAILEDTOALLOC(ri)) { free(cachefilename); free(filename); return NULL; } @@ -1375,9 +1383,9 @@ ri->cachefilename = cachefilename; ri->cachebasename = cachebasename; ri->filename_in_release = filename; - if( downloadas != NULL ) + if (downloadas != NULL) ri->downloadas = *downloadas; - for( c = 0 ; c < c_COUNT ; c++ ) + for (c = 0 ; c < c_COUNT ; c++) ri->ofs[c] = -1; ri->diff_ofs = -1; ri->lasttriedencoding = -1; @@ -1387,42 +1395,42 @@ struct remote_index *remote_index(struct remote_distribution *rd, const char *architecture, const char *component, packagetype_t packagetype, /*@null@*/const struct encoding_preferences *downloadas) { char *cachefilename, *filename_in_release; - assert( !rd->flat ); - if( packagetype == pt_deb ) { + assert (!rd->flat); + if (packagetype == pt_deb) { filename_in_release = mprintf("%s/binary-%s/Packages", component, architecture); cachefilename = genlistsfilename("Packages", 4, rd->repository->name, rd->suite, component, architecture, ENDOFARGUMENTS); - } else if( packagetype == pt_udeb ) { + } else if (packagetype == pt_udeb) { filename_in_release = mprintf( "%s/debian-installer/binary-%s/Packages", component, architecture); cachefilename = genlistsfilename("uPackages", 4, rd->repository->name, rd->suite, component, architecture, ENDOFARGUMENTS); - } else if( packagetype == pt_dsc ) { + } else if (packagetype == pt_dsc) { filename_in_release = mprintf("%s/source/Sources", component); cachefilename = genlistsfilename("Sources", 3, rd->repository->name, rd->suite, component, ENDOFARGUMENTS); } else { - assert( "Unexpected package type" == NULL ); + assert ("Unexpected package type" == NULL); } return addindex(rd, cachefilename, filename_in_release, downloadas); } void cachedlistfile_need_index(struct cachedlistfile *list, const char *repository, const char *suite, const char *architecture, const char *component, packagetype_t packagetype) { - if( packagetype == pt_deb ) { + if (packagetype == pt_deb) { cachedlistfile_need(list, "Packages", 4, repository, suite, component, architecture, ENDOFARGUMENTS); - } else if( packagetype == pt_udeb ) { + } else if (packagetype == pt_udeb) { cachedlistfile_need(list, "uPackages", 4, repository, suite, component, architecture, ENDOFARGUMENTS); - } else if( packagetype == pt_dsc ) { + } else if (packagetype == pt_dsc) { cachedlistfile_need(list, "Sources", 3, repository, suite, component, ENDOFARGUMENTS); @@ -1432,39 +1440,39 @@ struct remote_index *remote_flat_index(struct remote_distribution *rd, packagetype_t packagetype, /*@null@*/const struct encoding_preferences *downloadas) { char *cachefilename, *filename_in_release; - assert( rd->flat ); - if( packagetype == pt_deb ) { + assert (rd->flat); + if (packagetype == pt_deb) { filename_in_release = strdup("Packages"); cachefilename = genlistsfilename("Packages", 2, rd->repository->name, rd->suite, ENDOFARGUMENTS); - } else if( packagetype == pt_dsc ) { + } else if (packagetype == pt_dsc) { filename_in_release = strdup("Sources"); cachefilename = genlistsfilename("Sources", 2, rd->repository->name, rd->suite, ENDOFARGUMENTS); } else { - assert( "Unexpected package type" == NULL ); + assert ("Unexpected package type" == NULL); } return addindex(rd, cachefilename, filename_in_release, downloadas); } void cachedlistfile_need_flat_index(struct cachedlistfile *list, const char *repository, const char *suite, packagetype_t packagetype) { - if( packagetype == pt_deb ) { + if (packagetype == pt_deb) { cachedlistfile_need(list, "Packages", 2, repository, suite, ENDOFARGUMENTS); - } else if( packagetype == pt_dsc ) { + } else if (packagetype == pt_dsc) { cachedlistfile_need(list, "Sources", 1, repository, suite, ENDOFARGUMENTS); } } const char *remote_index_file(const struct remote_index *ri) { - assert( ri->needed && ri->queued && ri->got ); + assert (ri->needed && ri->queued && ri->got); return ri->cachefilename; } const char *remote_index_basefile(const struct remote_index *ri) { - assert( ri->needed && ri->queued ); + assert (ri->needed && ri->queued); return ri->cachebasename; } @@ -1473,7 +1481,7 @@ } void remote_index_markdone(const struct remote_index *ri, struct markdonefile *done) { - if( ri->ofs[c_none] < 0 ) + if (ri->ofs[c_none] < 0) return; markdone_index(done, ri->cachebasename, ri->from->remotefiles.checksums[ri->ofs[c_none]]); @@ -1485,7 +1493,7 @@ static retvalue indexfile_mark_got(struct remote_distribution *rd, struct remote_index *ri, /*@null@*/const struct checksums *gotchecksums) { struct checksums **checksums_p; - if( !rd->ignorerelease && ri->ofs[c_none] >= 0) { + if (!rd->ignorerelease && ri->ofs[c_none] >= 0) { checksums_p = &rd->remotefiles.checksums[ri->ofs[c_none]]; bool matches, improves; @@ -1496,19 +1504,19 @@ // checksums. (but if the Release not contain them, this // does not harm, does it?) - if( gotchecksums != NULL ) { + if (gotchecksums != NULL) { matches = checksums_check(*checksums_p, gotchecksums, &improves); /* that should have been tested earlier */ - assert( matches ); - if( ! matches ) + assert (matches); + if (! matches) return RET_ERROR_WRONG_MD5; - if( improves ) { + if (improves) { retvalue r; r = checksums_combine(checksums_p, gotchecksums, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } @@ -1523,7 +1531,7 @@ retvalue r; struct checksums *readchecksums = NULL; - if( failed ) { + if (failed) { // TODO: check if alternative can be used... return RET_ERROR; } @@ -1532,27 +1540,27 @@ /* even with a Release file, an old-style one might * not list the checksums for the uncompressed indices */ - if( !rd->ignorerelease && ri->ofs[c_none] >= 0 ) { + if (!rd->ignorerelease && ri->ofs[c_none] >= 0) { int ofs = ri->ofs[c_none]; const struct checksums *wantedchecksums = rd->remotefiles.checksums[ofs]; bool matches, missing = false; r = checksums_read(ri->cachefilename, &readchecksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot open '%s', though it should just have been unpacked from '%s'!\n", ri->cachefilename, compressed); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; missing = false; matches = checksums_check(readchecksums, wantedchecksums, &missing); - assert( !missing ); - if( !matches ) { + assert (!missing); + if (!matches) { fprintf(stderr, "Wrong checksum of uncompressed content of '%s':\n", compressed); checksums_printdifferences(stderr, @@ -1566,14 +1574,14 @@ * that less downloading is needed (though as apt no longer * supports such archieves, they are unlikely anyway). */ - if( strncmp(ri->cachefilename, compressed, - strlen(ri->cachefilename)) == 0 ) { + if (strncmp(ri->cachefilename, compressed, + strlen(ri->cachefilename)) == 0) { (void)unlink(compressed); } } r = indexfile_mark_got(rd, ri, readchecksums); checksums_free(readchecksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } @@ -1584,7 +1592,7 @@ struct checksums *readchecksums = NULL; retvalue r; - if( gotchecksums == NULL ) { + if (gotchecksums == NULL) { matches = true; missing = true; } else @@ -1592,38 +1600,38 @@ wantedchecksums, &missing); /* if the apt method did not generate all checksums * we want to check, we'll have to do so: */ - if( matches && missing ) { + if (matches && missing) { /* we assume that everything we know how to * extract from a Release file is something * we know how to calculate out of a file */ - assert( checksums_p == NULL || *checksums_p == NULL ); + assert (checksums_p == NULL || *checksums_p == NULL); r = checksums_read(gotfilename, &readchecksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot open '%s', though apt-method '%s' claims it is there!\n", gotfilename, methodname); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; gotchecksums = readchecksums; missing = false; matches = checksums_check(gotchecksums, wantedchecksums, &missing); - assert( !missing ); + assert (!missing); } - if( !matches ) { - fprintf(stderr, - "Wrong checksum during receive of '%s':\n", uri); + if (!matches) { + fprintf(stderr, "Wrong checksum during receive of '%s':\n", + uri); checksums_printdifferences(stderr, wantedchecksums, gotchecksums); checksums_free(readchecksums); return RET_ERROR_WRONG_MD5; } - if( checksums_p == NULL ) + if (checksums_p == NULL) checksums_free(readchecksums); - else if( readchecksums != NULL ) + else if (readchecksums != NULL) *checksums_p = readchecksums; return RET_OK; } @@ -1634,53 +1642,53 @@ struct checksums *readchecksums = NULL; retvalue r; - if( action == qa_error ) + if (action == qa_error) return queue_next_encoding(rd, ri); - if( action != qa_got ) + if (action != qa_got) return RET_ERROR; - if( ri->compression == c_none ) { - assert( strcmp(wantedfilename, ri->cachefilename) == 0 ); + if (ri->compression == c_none) { + assert (strcmp(wantedfilename, ri->cachefilename) == 0); r = copytoplace(gotfilename, wantedfilename, methodname, &readchecksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; gotfilename = wantedfilename; - if( readchecksums != NULL ) + if (readchecksums != NULL) gotchecksums = readchecksums; } - if( !rd->ignorerelease && ri->ofs[ri->compression] >= 0 ) { + if (!rd->ignorerelease && ri->ofs[ri->compression] >= 0) { int ofs = ri->ofs[ri->compression]; const struct checksums *wantedchecksums = rd->remotefiles.checksums[ofs]; r = check_checksums(methodname, uri, gotfilename, wantedchecksums, gotchecksums, &readchecksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(readchecksums); return r; } - if( readchecksums != NULL ) + if (readchecksums != NULL) gotchecksums = readchecksums; } - if( ri->compression == c_none ) { - assert( strcmp(gotfilename, wantedfilename) == 0 ); + if (ri->compression == c_none) { + assert (strcmp(gotfilename, wantedfilename) == 0); r = indexfile_mark_got(rd, ri, gotchecksums); checksums_free(readchecksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } else { checksums_free(readchecksums); r = remove_old_uncompressed(ri); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = uncompress_queue_file(gotfilename, ri->cachefilename, ri->compression, indexfile_unpacked, privdata); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } @@ -1694,40 +1702,40 @@ int i; retvalue r; - for( i = 0 ; i < ri->diffindex->patchcount ; i++ ) { + for (i = 0 ; i < ri->diffindex->patchcount ; i++) { bool improves; struct diffindex_patch *p = &ri->diffindex->patches[i]; char *patchsuffix, *c; - if( p->done ) + if (p->done) continue; - if( !checksums_check(ri->oldchecksums, p->frompackages, - &improves) ) + if (!checksums_check(ri->oldchecksums, p->frompackages, + &improves)) continue; /* p->frompackages should only have sha1 and oldchecksums * should definitly list a sha1 hash */ - assert( !improves ); + assert (!improves); p->done = true; free(ri->patchfilename); ri->patchfilename = mprintf("%s.diff-%s", ri->cachefilename, p->name); - if( FAILEDTOALLOC(ri->patchfilename) ) + if (FAILEDTOALLOC(ri->patchfilename)) return RET_ERROR_OOM; c = ri->patchfilename + strlen(ri->cachefilename); - while( *c != '\0' ) { - if( (*c < '0' || *c > '9') + while (*c != '\0') { + if ((*c < '0' || *c > '9') && (*c < 'A' || *c > 'Z') && (*c < 'a' || *c > 'z') - && *c != '.' && *c != '-' ) + && *c != '.' && *c != '-') *c = '_'; c++; } ri->selectedpatch = p; patchsuffix = mprintf(".diff/%s.gz", p->name); - if( FAILEDTOALLOC(patchsuffix) ) + if (FAILEDTOALLOC(patchsuffix)) return RET_ERROR_OOM; /* found a matching patch, tell the downloader we want it */ @@ -1756,37 +1764,37 @@ retvalue r; bool dummy; - if( ri->deletecompressedpatch ) + if (ri->deletecompressedpatch) (void)unlink(compressed); - if( failed ) + if (failed) return RET_ERROR; r = checksums_test(ri->patchfilename, p->checksums, NULL); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Mysteriously vanished file '%s'!\n", ri->patchfilename); r = RET_ERROR_MISSING; } - if( r == RET_ERROR_WRONG_MD5 ) + if (r == RET_ERROR_WRONG_MD5) fprintf(stderr, "Corrupted package diff '%s'!\n", ri->patchfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = patch_load(ri->patchfilename, checksums_getfilesize(p->checksums), &rp); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; tempfilename = calc_addsuffix(ri->cachefilename, "tmp"); - if( FAILEDTOALLOC(tempfilename) ) { + if (FAILEDTOALLOC(tempfilename)) { patch_free(rp); return RET_ERROR_OOM; } (void)unlink(tempfilename); i = rename(ri->cachefilename, tempfilename); - if( i != 0 ) { + if (i != 0) { int e = errno; fprintf(stderr, "Error %d moving '%s' to '%s': %s\n", e, ri->cachefilename, tempfilename, @@ -1796,7 +1804,7 @@ return RET_ERRNO(e); } f = fopen(ri->cachefilename, "w"); - if( f == NULL ) { + if (f == NULL) { int e = errno; fprintf(stderr, "Error %d creating '%s': %s\n", e, ri->cachefilename, strerror(e)); @@ -1814,14 +1822,14 @@ ri->patchfilename = NULL; free(tempfilename); patch_free(rp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)fclose(f); remove_old_uncompressed(ri); // TODO: fall back to downloading at once? return r; } i = ferror(f); - if( i != 0 ) { + if (i != 0) { int e = errno; (void)fclose(f); fprintf(stderr, "Error %d writing to '%s': %s\n", @@ -1830,7 +1838,7 @@ return RET_ERRNO(e); } i = fclose(f); - if( i != 0 ) { + if (i != 0) { int e = errno; fprintf(stderr, "Error %d writing to '%s': %s\n", e, ri->cachefilename, strerror(e)); @@ -1840,16 +1848,16 @@ checksums_free(ri->oldchecksums); ri->oldchecksums = NULL; r = checksums_read(ri->cachefilename, &ri->oldchecksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Myteriously vanished file '%s'!\n", ri->cachefilename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( checksums_check(ri->oldchecksums, + if (checksums_check(ri->oldchecksums, rd->remotefiles.checksums[ri->ofs[c_none]], - &dummy) ) { + &dummy)) { ri->olduncompressed->deleted = true; ri->olduncompressed = NULL; /* we have a winner */ @@ -1863,15 +1871,15 @@ struct remote_index *ri = privdata; retvalue r; - if( action == qa_error ) + if (action == qa_error) return queue_next_encoding(ri->from, ri); - if( action != qa_got ) + if (action != qa_got) return RET_ERROR; ri->deletecompressedpatch = strcmp(gotfilename, wantedfilename) == 0; r = uncompress_queue_file(gotfilename, ri->patchfilename, c_gzip, diff_uncompressed, ri); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) (void)unlink(gotfilename); return r; } @@ -1883,25 +1891,25 @@ int ofs; retvalue r; - if( action == qa_error ) + if (action == qa_error) return queue_next_encoding(rd, ri); - if( action != qa_got ) + if (action != qa_got) return RET_ERROR; r = copytoplace(gotfilename, wantedfilename, methodname, &readchecksums); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( readchecksums != NULL ) + if (readchecksums != NULL) gotchecksums = readchecksums; ofs = ri->diff_ofs; - if( ofs >= 0 ) { + if (ofs >= 0) { const struct checksums *wantedchecksums = rd->remotefiles.checksums[ofs]; bool matches, missing = false; - if( gotchecksums == NULL ) { + if (gotchecksums == NULL) { matches = true; missing = true; } else @@ -1909,27 +1917,27 @@ wantedchecksums, &missing); /* if the apt method did not generate all checksums * we want to check, we'll have to do so: */ - if( matches && missing ) { + if (matches && missing) { /* we assume that everything we know how to * extract from a Release file is something * we know how to calculate out of a file */ - assert( readchecksums == NULL ); + assert (readchecksums == NULL); r = checksums_read(gotfilename, &readchecksums); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot open '%s', though apt-method '%s' claims it is there!\n", gotfilename, methodname); r = RET_ERROR_MISSING; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; gotchecksums = readchecksums; missing = false; matches = checksums_check(gotchecksums, wantedchecksums, &missing); - assert( !missing ); + assert (!missing); } - if( !matches ) { + if (!matches) { fprintf(stderr, "Wrong checksum during receive of '%s':\n", uri); checksums_printdifferences(stderr, @@ -1942,13 +1950,13 @@ checksums_free(readchecksums); r = diffindex_read(wantedfilename, &ri->diffindex); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( ri->ofs[c_none] >= 0 ) { + if (ri->ofs[c_none] >= 0) { bool dummy; - if( !checksums_check(rd->remotefiles.checksums[ + if (!checksums_check(rd->remotefiles.checksums[ ri->ofs[c_none]], - ri->diffindex->destination, &dummy) ) { + ri->diffindex->destination, &dummy)) { fprintf(stderr, "'%s' does not match file requested in '%s'. Aborting diff processing...\n", gotfilename, rd->releasefile); diff -Nru reprepro-4.5.0/remoterepository.h reprepro-4.6.0/remoterepository.h --- reprepro-4.5.0/remoterepository.h 2009-06-02 15:41:23.000000000 +0000 +++ reprepro-4.6.0/remoterepository.h 2011-05-05 14:42:55.000000000 +0000 @@ -20,18 +20,18 @@ struct remote_index; /* register repository, strings as stored by reference */ -struct remote_repository *remote_repository_prepare(const char *name, const char *method, const char *fallback, const struct strlist *config); +struct remote_repository *remote_repository_prepare(const char * /*name*/, const char * /*method*/, const char * /*fallback*/, const struct strlist * /*config*/); /* register remote distribution of the given repository */ -retvalue remote_distribution_prepare(struct remote_repository *, const char *suite, bool ignorerelease, const char *verifyrelease, bool flat, bool *ignorehashes, /*@out@*/struct remote_distribution **out_p); +retvalue remote_distribution_prepare(struct remote_repository *, const char * /*suite*/, bool /*ignorerelease*/, const char * /*verifyrelease*/, bool /*flat*/, bool * /*ignorehashes*/, /*@out@*/struct remote_distribution **); void remote_repository_free(/*@only@*/struct remote_repository *); /* create aptmethods for all of yet created repositories */ retvalue remote_startup(struct aptmethodrun *); -retvalue remote_preparemetalists(struct aptmethodrun *, bool nodownload); -retvalue remote_preparelists(struct aptmethodrun *, bool nodownload); +retvalue remote_preparemetalists(struct aptmethodrun *, bool /*nodownload*/); +retvalue remote_preparelists(struct aptmethodrun *, bool /*nodownload*/); struct encoding_preferences { /* number of preferences, 0 means use default */ @@ -44,12 +44,12 @@ } requested[3*c_COUNT]; }; -struct remote_index *remote_index(struct remote_distribution *, const char *architecture, const char *component, packagetype_t, const struct encoding_preferences *); +struct remote_index *remote_index(struct remote_distribution *, const char * /*architecture*/, const char * /*component*/, packagetype_t, const struct encoding_preferences *); struct remote_index *remote_flat_index(struct remote_distribution *, packagetype_t, const struct encoding_preferences *); /* returns the name of the prepared uncompressed file */ -/*@observer@*/const char *remote_index_file(const struct remote_index*); -/*@observer@*/const char *remote_index_basefile(const struct remote_index*); +/*@observer@*/const char *remote_index_file(const struct remote_index *); +/*@observer@*/const char *remote_index_basefile(const struct remote_index *); /*@observer@*/struct aptmethod *remote_aptmethod(const struct remote_distribution *); bool remote_index_isnew(const struct remote_index *, struct donefile *); @@ -60,10 +60,9 @@ struct cachedlistfile; retvalue cachedlists_scandir(/*@out@*/struct cachedlistfile **); -void cachedlistfile_need_index(struct cachedlistfile *, const char *repository, const char *suite, const char *architecture, const char *component, packagetype_t); -void cachedlistfile_need_flat_index(struct cachedlistfile *, const char *repository, const char *suite, packagetype_t); -void cachedlistfile_need(struct cachedlistfile *list, const char *type, unsigned int count, ...) __attribute__((sentinel)); -void cachedlistfile_flat_markneeded(struct cachedlistfile *, packagetype_t); +void cachedlistfile_need_index(struct cachedlistfile *, const char * /*repository*/, const char * /*suite*/, const char * /*architecture*/, const char * /*component*/, packagetype_t); +void cachedlistfile_need_flat_index(struct cachedlistfile *, const char * /*repository*/, const char * /*suite*/, packagetype_t); +void cachedlistfile_need(struct cachedlistfile *, const char * /*type*/, unsigned int /*count*/, ...) __attribute__((sentinel)); void cachedlistfile_freelist(/*@only@*/struct cachedlistfile *); void cachedlistfile_deleteunneeded(const struct cachedlistfile *); #endif diff -Nru reprepro-4.5.0/rredpatch.c reprepro-4.6.0/rredpatch.c --- reprepro-4.5.0/rredpatch.c 2010-10-24 08:59:10.000000000 +0000 +++ reprepro-4.6.0/rredpatch.c 2011-05-05 14:42:55.000000000 +0000 @@ -54,7 +54,7 @@ }; void modification_freelist(struct modification *p) { - while( p != NULL ) { + while (p != NULL) { struct modification *m = p; p = m->next; free(m); @@ -64,17 +64,17 @@ struct modification *modification_dup(const struct modification *p) { struct modification *first = NULL, *last = NULL; - for( ; p != NULL ; p = p->next ) { - struct modification *m = malloc(sizeof(struct modification)); + for (; p != NULL ; p = p->next) { + struct modification *m = NEW(struct modification); - if( FAILEDTOALLOC(m) ) { + if (FAILEDTOALLOC(m)) { modification_freelist(first); return NULL; } *m = *p; m->next = NULL; m->previous = last; - if( last == NULL ) + if (last == NULL) first = m; else m->previous->next = m; @@ -86,7 +86,7 @@ struct modification *patch_getmodifications(struct rred_patch *p) { struct modification *m; - assert( !p->alreadyinuse ); + assert (!p->alreadyinuse); m = p->modifications; p->modifications = NULL; p->alreadyinuse = true; @@ -94,7 +94,7 @@ } const struct modification *patch_getconstmodifications(struct rred_patch *p) { - assert( !p->alreadyinuse ); + assert (!p->alreadyinuse); return p->modifications; } @@ -105,9 +105,9 @@ } void patch_free(/*@only@*/struct rred_patch *p) { - if( p->data != NULL ) + if (p->data != NULL) (void)munmap(p->data, p->len); - if( p->fd >= 0 ) + if (p->fd >= 0) (void)close(p->fd); modification_freelist(p->modifications); free(p); @@ -117,7 +117,7 @@ int fd; fd = open(filename, O_NOCTTY|O_RDONLY); - if( fd < 0 ) { + if (fd < 0) { int err = errno; fprintf(stderr, "Error %d opening '%s' for reading: %s\n", err, filename, strerror(err)); @@ -136,23 +136,23 @@ struct modification *n; struct stat statbuf; - patch = calloc(1, sizeof(struct rred_patch)); - if( FAILEDTOALLOC(patch) ) { + patch = zNEW(struct rred_patch); + if (FAILEDTOALLOC(patch)) { (void)close(fd); return RET_ERROR_OOM; } patch->fd = fd; i = fstat(patch->fd, &statbuf); - if( i != 0 ) { + if (i != 0) { int err = errno; fprintf(stderr, "Error %d retrieving length of '%s': %s\n", err, filename, strerror(err)); patch_free(patch); return RET_ERRNO(err); } - if( length == -1 ) + if (length == -1) length = statbuf.st_size; - if( statbuf.st_size != length ) { + if (statbuf.st_size != length) { int err = errno; fprintf(stderr, "Unexpected size of '%s': expected %lld, got %lld\n", filename, @@ -160,7 +160,7 @@ patch_free(patch); return RET_ERRNO(err); } - if( length == 0 ) { + if (length == 0) { /* handle empty patches gracefully */ close(patch->fd); patch->fd = -1; @@ -173,7 +173,7 @@ patch->len = length; patch->data = mmap(NULL, patch->len, PROT_READ, MAP_PRIVATE, patch->fd, 0); - if( patch->data == MAP_FAILED ) { + if (patch->data == MAP_FAILED) { int err = errno; fprintf(stderr, "Error %d mapping '%s' into memory: %s\n", err, filename, strerror(err)); @@ -183,22 +183,22 @@ p = patch->data; e = p + patch->len; line = 1; - while( p < e ) { + while (p < e) { /* ,(c|d)\n or (a|i|c|d) */ d = p; number = 0; number2 = -1; - while( d < e && *d >= '0' && *d <= '9' ) { + while (d < e && *d >= '0' && *d <= '9') { number = (*d - '0') + 10 * number; d++; } - if( d > p && d < e && *d == ',' ) { + if (d > p && d < e && *d == ',') { d++; number2 = 0; - while( d < e && *d >= '0' && *d <= '9' ) { + while (d < e && *d >= '0' && *d <= '9') { number2 = (*d - '0') + 10 * number2; d++; } - if( number2 < number ) { + if (number2 < number) { fprintf(stderr, "Error parsing '%s': malformed range (2nd number smaller than 1s) at line %d\n", filename, line); @@ -206,7 +206,7 @@ return RET_ERROR; } } - if( d >= e || (*d != 'c' && *d != 'i' && *d != 'a' && *d != 'd') ) { + if (d >= e || (*d != 'c' && *d != 'i' && *d != 'a' && *d != 'd')) { fprintf(stderr, "Error parsing '%s': expected rule (c,i,a or d) at line %d\n", filename, line); @@ -215,9 +215,9 @@ } type = *d; d++; - while( d < e && *d == '\r' ) + while (d < e && *d == '\r') d++; - if( d >= e || *d != '\n' ) { + if (d >= e || *d != '\n') { fprintf(stderr, "Error parsing '%s': expected newline after command at line %d\n", filename, line); @@ -227,32 +227,32 @@ d++; line++; - if( type != 'a' && number == 0 ) { + if (type != 'a' && number == 0) { fprintf(stderr, "Error parsing '%s': missing number at line %d\n", filename, line); patch_free(patch); return RET_ERROR; } - if( type != 'c' && type != 'd' && number2 >= 0 ) { + if (type != 'c' && type != 'd' && number2 >= 0) { fprintf(stderr, "Error parsing '%s': line range not allowed with %c at line %d\n", filename, (char)type, line); patch_free(patch); return RET_ERROR; } - n = calloc(1, sizeof(struct modification)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct modification); + if (FAILEDTOALLOC(n)) { patch_free(patch); return RET_ERROR_OOM; } n->next = patch->modifications; - if( n->next != NULL ) + if (n->next != NULL) n->next->previous = n; patch->modifications = n; p = d; - if( type == 'd') { + if (type == 'd') { n->content = NULL; n->len = 0; n->newlinecount = 0; @@ -260,12 +260,12 @@ int startline = line; l = p; - while( l < e ) { + while (l < e) { p = l; - while( l < e && *l != '\n' ) + while (l < e && *l != '\n') l++; - if( l >= e ) { - if( l == p + 1 && *p == '.' ) { + if (l >= e) { + if (l == p + 1 && *p == '.') { /* that is also corrupted, * but we can cure it */ break; @@ -277,11 +277,11 @@ return RET_ERROR; } l++; - if( p[0] == '.' && (p[1] == '\n' || p[1] == '\r') ) + if (p[0] == '.' && (p[1] == '\n' || p[1] == '\r')) break; line++; } - if( p[0] != '.' || ( l > p + 1 && p[1] != '\n' && p[1] != '\r' )) { + if (p[0] != '.' || (l > p + 1 && p[1] != '\n' && p[1] != '\r')) { fprintf(stderr, "Error parsing '%s': ends waiting for dot. File most likely corrupted\n", filename); @@ -294,25 +294,25 @@ p = l; line++; } - if( type == 'a' ) { + if (type == 'a') { /* appends appends after instead of before something: */ n->oldlinestart = number + 1; n->oldlinecount = 0; - } else if( type == 'i' ) { + } else if (type == 'i') { n->oldlinestart = number; n->oldlinecount = 0; } else { n->oldlinestart = number; - if( number2 < 0 ) + if (number2 < 0) n->oldlinecount = 1; else n->oldlinecount = (number2 - number) + 1; } /* make sure things are in the order diff usually * generates them, which makes line-calculation much easier: */ - if( n->next != NULL ) { - if( n->oldlinestart + n->oldlinecount - > n->next->oldlinestart ) { + if (n->next != NULL) { + if (n->oldlinestart + n->oldlinecount + > n->next->oldlinestart) { struct modification *first, *second; retvalue r; @@ -328,7 +328,7 @@ n = NULL; r = combine_patches(&n, first, second); patch->modifications = n; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { patch_free(patch); return r; } @@ -346,13 +346,13 @@ m->newlinecount -= r; lines = m->newlinecount; p = m->content; - while( lines > 0 ) { - while( *p != '\n') + while (lines > 0) { + while (*p != '\n') p++; p++; lines--; } - assert( (size_t)(p - m->content) <= m->len ); + assert ((size_t)(p - m->content) <= m->len); m->len = p - m->content; } @@ -361,13 +361,13 @@ m->newlinecount -= r; p = m->content; - while( r > 0 ) { - while( *p != '\n') + while (r > 0) { + while (*p != '\n') p++; p++; r--; } - assert( (size_t)(p - m->content) <= m->len ); + assert ((size_t)(p - m->content) <= m->len); m->len -= p - m->content; m->content = p; } @@ -378,13 +378,13 @@ /* remove from queue: */ toadd = *from_p; *from_p = toadd->next; - if( toadd->next != NULL ) { + if (toadd->next != NULL) { toadd->next->previous = NULL; toadd->next = NULL; } /* if nothing yet, make it the first */ - if( *last_p == NULL ) { + if (*last_p == NULL) { *result_p = toadd; toadd->previous = NULL; *last_p = toadd; @@ -392,18 +392,18 @@ } last = *last_p; - if( toadd->oldlinestart == last->oldlinestart + last->oldlinecount ) { + if (toadd->oldlinestart == last->oldlinestart + last->oldlinecount) { /* check if something can be combined: */ - if( toadd->newlinecount == 0 ) { + if (toadd->newlinecount == 0) { last->oldlinecount += toadd->oldlinecount; free(toadd); return; } - if( last->newlinecount == 0 ) { + if (last->newlinecount == 0) { toadd->oldlinestart = last->oldlinestart; toadd->oldlinecount += last->oldlinecount; toadd->previous = last->previous; - if( toadd->previous == NULL ) + if (toadd->previous == NULL) *result_p = toadd; else toadd->previous->next = toadd; @@ -411,7 +411,7 @@ free(last); return; } - if( last->content + last->len == toadd->content ) { + if (last->content + last->len == toadd->content) { last->oldlinecount += toadd->oldlinecount; last->newlinecount += toadd->newlinecount; last->len += toadd->len; @@ -421,7 +421,7 @@ } toadd->previous = last; last->next = toadd; - assert( last->oldlinestart + last->oldlinecount <= toadd->oldlinestart ); + assert (last->oldlinestart + last->oldlinecount <= toadd->oldlinestart); *last_p = toadd; return; } @@ -440,50 +440,51 @@ lineofs = 0; - while( a != NULL ) { + while (a != NULL) { /* modification totally before current one, * so just add it before it */ - if( p == NULL || lineofs + a->oldlinestart + a->oldlinecount - <= p->oldlinestart ) { + if (p == NULL || lineofs + a->oldlinestart + a->oldlinecount + <= p->oldlinestart) { a->oldlinestart += lineofs; move_queue(&last, &result, &a); - assert( p == NULL || p->oldlinestart >= - last->oldlinestart + last->oldlinecount ); + assert (p == NULL || p->oldlinestart >= + last->oldlinestart + last->oldlinecount); continue; } /* modification to add after current head modification, * so finalize head modification and update lineofs */ - if( lineofs + a->oldlinestart - >= p->oldlinestart + p->newlinecount ) { + if (lineofs + a->oldlinestart + >= p->oldlinestart + p->newlinecount) { lineofs += p->oldlinecount - p->newlinecount; move_queue(&last, &result, &p); - assert( lineofs + a->oldlinestart >= - last->oldlinestart + last->oldlinecount ); + assert (lineofs + a->oldlinestart >= + last->oldlinestart + last->oldlinecount); continue; } /* new modification removes everything the old one added: */ - if( lineofs + a->oldlinestart <= p->oldlinestart + if (lineofs + a->oldlinestart <= p->oldlinestart && lineofs + a->oldlinestart + a->oldlinecount - >= p->oldlinestart + p->newlinecount ) { + >= p->oldlinestart + p->newlinecount) { a->oldlinestart -= p->oldlinecount - p->newlinecount; a->oldlinecount += p->oldlinecount - p->newlinecount; lineofs += p->oldlinecount - p->newlinecount; p = modification_freehead(p); - if( a->oldlinecount == 0 && a->newlinecount == 0 ) { + if (a->oldlinecount == 0 && a->newlinecount == 0) { /* a exactly cancels p */ a = modification_freehead(a); } - /* otherwise a is not yet finished, it might modify more */ + /* otherwise a is not yet finished, + * it might modify more */ continue; } /* otherwise something overlaps, things get complicated here: */ /* start of *a removes end of *p, so reduce *p: */ - if( lineofs + a->oldlinestart > p->oldlinestart && + if (lineofs + a->oldlinestart > p->oldlinestart && lineofs + a->oldlinestart < p->oldlinestart + p->newlinecount && lineofs + a->oldlinestart + a->oldlinecount - >= p->oldlinestart + p->newlinecount ) { + >= p->oldlinestart + p->newlinecount) { int removedlines = p->oldlinestart + p->newlinecount - (lineofs + a->oldlinestart); @@ -495,37 +496,40 @@ /* and p to add less */ modification_stripendlines(p, removedlines); move_queue(&last, &result, &p); - assert( lineofs + a->oldlinestart >= - last->oldlinestart + last->oldlinecount ); + assert (lineofs + a->oldlinestart >= + last->oldlinestart + last->oldlinecount); continue; } /* end of *a remove start of *p, so finalize *a and reduce *p */ - if( lineofs + a->oldlinestart <= p->oldlinestart && + if (lineofs + a->oldlinestart <= p->oldlinestart && lineofs + a->oldlinestart + a->oldlinecount > p->oldlinestart && lineofs + a->oldlinestart + a->oldlinecount - < p->oldlinestart + p->newlinecount ) { + < p->oldlinestart + p->newlinecount) { int removedlines = lineofs + a->oldlinestart + a->oldlinecount - p->oldlinestart; /* finalize *a with less lines deleted:*/ a->oldlinestart += lineofs; a->oldlinecount -= removedlines; - if( a->oldlinecount == 0 && a->newlinecount == 0 ) { + if (a->oldlinecount == 0 && a->newlinecount == 0) { /* a only removed something and this was hereby * removed from p */ a = modification_freehead(a); } else move_queue(&last, &result, &a); /* and reduce the number of lines of *p */ - assert( removedlines < p->newlinecount ); + assert (removedlines < p->newlinecount); modification_stripstartlines(p, removedlines); - /* p->newlinecount got smaller, so less will be deleted later */ + /* p->newlinecount got smaller, + * so less will be deleted later */ lineofs -= removedlines; - if( last != NULL ) { - assert( p->oldlinestart >= last->oldlinestart + last->oldlinecount); - if( a != NULL ) - assert( lineofs + a->oldlinestart >= last->oldlinestart + last->oldlinecount); + if (last != NULL) { + assert (p->oldlinestart >= + last->oldlinestart + last->oldlinecount); + if (a != NULL) + assert (lineofs + a->oldlinestart >= + last->oldlinestart + last->oldlinecount); } /* note that a->oldlinestart+a->oldlinecount+1 * == p->oldlinestart */ @@ -533,15 +537,15 @@ } /* the most complex case left, a inside p, this * needs p split in two */ - if( lineofs + a->oldlinestart > p->oldlinestart && + if (lineofs + a->oldlinestart > p->oldlinestart && lineofs + a->oldlinestart + a->oldlinecount - < p->oldlinestart + p->newlinecount ) { + < p->oldlinestart + p->newlinecount) { struct modification *n; int removedlines = p->oldlinestart + p->newlinecount - (lineofs + a->oldlinestart); - n = calloc(1, sizeof(struct modification)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct modification); + if (FAILEDTOALLOC(n)) { modification_freelist(result); modification_freelist(p); modification_freelist(a); @@ -552,18 +556,19 @@ * that later numbers fit */ n->next = NULL; n->oldlinecount = 0; - assert( removedlines < n->newlinecount ); + assert (removedlines < n->newlinecount); modification_stripendlines(n, removedlines); lineofs += n->oldlinecount - n->newlinecount; - assert( lineofs+a->oldlinestart <= p->oldlinestart); + assert (lineofs+a->oldlinestart <= p->oldlinestart); move_queue(&last, &result, &n); - assert( n == NULL); + assert (n == NULL); /* only remove this and let the rest of the * code handle the other changes */ - modification_stripstartlines(p, p->newlinecount - removedlines); + modification_stripstartlines(p, + p->newlinecount - removedlines); assert(p->newlinecount == removedlines); - assert( lineofs + a->oldlinestart >= - last->oldlinestart + last->oldlinecount ); + assert (lineofs + a->oldlinestart >= + last->oldlinestart + last->oldlinecount); continue; } modification_freelist(result); @@ -572,7 +577,7 @@ fputs("Internal error in rred merging!\n", stderr); return RET_ERROR; } - while( p != NULL ) { + while (p != NULL) { move_queue(&last, &result, &p); } *result_p = result; @@ -584,31 +589,31 @@ int currentline, ignore, c; i = fopen(source, "r"); - if( i == NULL ) { + if (i == NULL) { 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 ); + assert (patch == NULL || patch->oldlinestart > 0); currentline = 1; do { - while( patch != NULL && patch->oldlinestart == currentline ) { + while (patch != NULL && patch->oldlinestart == currentline) { fwrite(patch->content, patch->len, 1, o); ignore = patch->oldlinecount; patch = patch->next; - while( ignore > 0 ) { + while (ignore > 0) { do { c = getc(i); - } while( c != '\n' && c != EOF); + } while (c != '\n' && c != EOF); ignore--; currentline++; } } - assert( patch == NULL || patch->oldlinestart >= currentline ); - while( (c = getc(i)) != '\n' ) { - if( c == EOF ) { - if( patch != NULL ) { + assert (patch == NULL || patch->oldlinestart >= currentline); + while ((c = getc(i)) != '\n') { + if (c == EOF) { + if (patch != NULL) { fprintf(stderr, "Error patching '%s', file shorter than expected by patches!\n", source); @@ -619,19 +624,19 @@ } putc(c, o); } - if( c == EOF ) + if (c == EOF) break; putc(c, o); currentline++; } while (1); - if( ferror(i) != 0 ) { + 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 ) { + if (fclose(i) != 0) { int e = errno; fprintf(stderr, "Error %d reading %s: %s\n", e, source, strerror(e)); @@ -645,63 +650,63 @@ char line[30]; int len; - if( m == NULL ) + if (m == NULL) return; - assert( m->previous == NULL ); + assert (m->previous == NULL); /* go to the end, as we have to print it backwards */ p = m; - while( p->next != NULL ) { - assert( p->next->previous == p ); + while (p->next != NULL) { + assert (p->next->previous == p); p = p->next; } /* then print, possibly merging things */ - while( p != NULL ) { + while (p != NULL) { int start, oldcount, newcount; start = p->oldlinestart; oldcount = p->oldlinecount; newcount = p->newlinecount; - if( p->next != NULL ) - assert( start + oldcount <= p->next->oldlinestart ); + if (p->next != NULL) + assert (start + oldcount <= p->next->oldlinestart); r = p; - for( q = p->previous ; + for (q = p->previous ; q != NULL && q->oldlinestart + q->oldlinecount == start ; - q = q->previous ) { + q = q->previous) { oldcount += q->oldlinecount; start = q->oldlinestart; newcount += q->newlinecount; r = q; } - if( newcount == 0 ) { - assert( oldcount > 0 ); - if( oldcount == 1 ) + if (newcount == 0) { + assert (oldcount > 0); + if (oldcount == 1) len = snprintf(line, sizeof(line), "%dd\n", start); else len = snprintf(line, sizeof(line), "%d,%dd\n", start, start + oldcount - 1); } else { - if( oldcount == 0 ) + if (oldcount == 0) len = snprintf(line, sizeof(line), "%da\n", start - 1); - else if( oldcount == 1 ) + else if (oldcount == 1) len = snprintf(line, sizeof(line), "%dc\n", start); else len = snprintf(line, sizeof(line), "%d,%dc\n", start, start + oldcount - 1); } - assert( len < (int)sizeof(line) ); + assert (len < (int)sizeof(line)); write_func(line, len, f); - if( newcount != 0 ) { - while( r != p->next ) { - if( r->len > 0 ) + if (newcount != 0) { + while (r != p->next) { + if (r->len > 0) write_func(r->content, r->len, f); newcount -= r->newlinecount; r = r->next; } - assert( newcount == 0 ); + assert (newcount == 0); write_func(".\n", 2, f); } p = q; @@ -720,9 +725,9 @@ pp = patch_p; /* check if this only adds things at the start and count how many */ - while( *pp != NULL ) { + while (*pp != NULL) { m = *pp; - if( m->oldlinecount > 0 || m->oldlinestart > 1 ) { + if (m->oldlinecount > 0 || m->oldlinestart > 1) { *line_p = NULL; return RET_OK; } @@ -731,7 +736,7 @@ } /* not get the next line and claim it was changed */ i = fopen(source, "r"); - if( i == NULL ) { + if (i == NULL) { int e = errno; fprintf(stderr, "Error %d opening '%s': %s\n", e, source, strerror(e)); @@ -739,8 +744,8 @@ } do { got = getline(&line, &bufsize, i); - } while( got >= 0 && lineno-- > 0 ); - if( got < 0 ) { + } while (got >= 0 && lineno-- > 0); + if (got < 0) { int e = errno; /* You should have made sure the old file is not empty */ @@ -751,8 +756,8 @@ } (void)fclose(i); - n = malloc(sizeof(struct modification)); - if( FAILEDTOALLOC(n) ) + n = NEW(struct modification); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; *pp = n; n->next = NULL; diff -Nru reprepro-4.5.0/rredpatch.h reprepro-4.6.0/rredpatch.h --- reprepro-4.5.0/rredpatch.h 2010-02-16 15:29:04.000000000 +0000 +++ reprepro-4.6.0/rredpatch.h 2011-05-05 14:42:55.000000000 +0000 @@ -12,7 +12,7 @@ struct modification *modification_dup(const struct modification *); void modification_freelist(/*@only@*/struct modification *); retvalue combine_patches(/*@out@*/struct modification **, /*@only@*/struct modification *, /*@only@*/struct modification *); -void modification_printaspatch(void *, const struct modification *, void write_func(const void *, size_t, void *)); +void modification_printaspatch(void *, const struct modification *, void (const void *, size_t, void *)); retvalue modification_addstuff(const char *source, struct modification **patch_p, /*@out@*/char **line_p); retvalue patch_file(FILE *, const char *, const struct modification *); diff -Nru reprepro-4.5.0/rredtool.c reprepro-4.6.0/rredtool.c --- reprepro-4.5.0/rredtool.c 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/rredtool.c 2011-05-05 14:42:55.000000000 +0000 @@ -75,7 +75,8 @@ " apply patches to file\n", f); } -static const char tab[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; +static const char tab[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; struct hash { char sha1[2*SHA1_DIGEST_SIZE+1]; @@ -89,7 +90,7 @@ SHA1Final(context, sha1buffer); sha1 = hash->sha1; - for( i = 0 ; i < SHA1_DIGEST_SIZE ; i++ ) { + for (i = 0 ; i < SHA1_DIGEST_SIZE ; i++) { *(sha1++) = tab[sha1buffer[i] >> 4]; *(sha1++) = tab[sha1buffer[i] & 0xF]; } @@ -106,28 +107,28 @@ int infd; struct stat s; - if( buffer == NULL ) + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; SHA1Init(&context); infd = open(fullfilename, O_RDONLY); - if( infd < 0 ) { + if (infd < 0) { e = errno; - if( (e == EACCES || e == ENOENT) && - !isregularfile(fullfilename) ) { + if ((e == EACCES || e == ENOENT) && + !isregularfile(fullfilename)) { free(buffer); return RET_NOTHING; } - fprintf(stderr,"Error %d opening '%s': %s\n", + fprintf(stderr, "Error %d opening '%s': %s\n", e, fullfilename, strerror(e)); free(buffer); return RET_ERRNO(e); } i = fstat(infd, &s); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d getting information about '%s': %s\n", + fprintf(stderr, "Error %d getting information about '%s': %s\n", e, fullfilename, strerror(e)); (void)close(infd); free(buffer); @@ -135,23 +136,23 @@ } do { sizeread = read(infd, buffer, bufsize); - if( sizeread < 0 ) { + if (sizeread < 0) { e = errno; - fprintf(stderr,"Error %d while reading %s: %s\n", + fprintf(stderr, "Error %d while reading %s: %s\n", e, fullfilename, strerror(e)); free(buffer); (void)close(infd); - return RET_ERRNO(e);; + return RET_ERRNO(e); } SHA1Update(&context, buffer, (size_t)sizeread); - } while( sizeread > 0 ); + } while (sizeread > 0); free(buffer); i = close(infd); - if( i != 0 ) { + if (i != 0) { e = errno; - fprintf(stderr,"Error %d reading %s: %s\n", + fprintf(stderr, "Error %d reading %s: %s\n", e, fullfilename, strerror(e)); - return RET_ERRNO(e);; + return RET_ERRNO(e); } finalize_sha1(&context, s.st_size, hash); return RET_OK; @@ -179,17 +180,17 @@ time_t current_time; size_t len; - assert( max == DATELEN + 1 ); + assert (max == DATELEN + 1); current_time = time(NULL); - if( current_time == ((time_t) -1) ) { + if (current_time == ((time_t) -1)) { int e = errno; fprintf(stderr, "rredtool: Error %d from time: %s\n", e, strerror(e)); return RET_ERROR; } tm = gmtime(¤t_time); - if( tm == NULL ) { + if (tm == NULL) { int e = errno; fprintf(stderr, "rredtool: Error %d from gmtime: %s\n", e, strerror(e)); @@ -197,8 +198,9 @@ } errno = 0; len = strftime(date, max, DATEFMT, tm); - if( len == 0 || len != DATELEN ) { - fprintf(stderr, "rredtool: iternal problem calling strftime!\n"); + if (len == 0 || len != DATELEN) { + fprintf(stderr, +"rredtool: internal problem calling strftime!\n"); return RET_ERROR; } return RET_OK; @@ -210,12 +212,12 @@ int fd; tempdir = getenv("TMPDIR"); - if( tempdir == NULL ) + if (tempdir == NULL) tempdir = getenv("TEMPDIR"); - if( tempdir == NULL ) + if (tempdir == NULL) tempdir = "/tmp"; filename = mprintf("%s/XXXXXX", tempdir); - if( FAILEDTOALLOC(filename) ) { + if (FAILEDTOALLOC(filename)) { errno = ENOMEM; return -1; } @@ -228,7 +230,7 @@ #error Need mkostemp or mkstemp #endif #endif - if( fd >= 0 ) + if (fd >= 0) unlink(filename); free(filename); return fd; @@ -239,7 +241,7 @@ int fd, status; fd = create_temporary_file(); - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "Error %d creating temporary file: %s\n", e, strerror(e)); @@ -247,21 +249,22 @@ } child = fork(); - if( child == (pid_t)-1 ) { + if (child == (pid_t)-1) { int e = errno; fprintf(stderr, "rredtool: Error %d forking: %s\n", e, strerror(e)); return RET_ERRNO(e); } - if( child == 0 ) { + if (child == 0) { int e, i; do { i = dup2(fd, 1); e = errno; - } while( i < 0 && (e == EINTR || e == EBUSY) ); - if( i < 0 ) { - fprintf(stderr, "rredtool: Error %d in dup2(%d, 0): %s\n", + } while (i < 0 && (e == EINTR || e == EBUSY)); + if (i < 0) { + fprintf(stderr, +"rredtool: Error %d in dup2(%d, 0): %s\n", e, fd, strerror(e)); raise(SIGUSR1); exit(EXIT_FAILURE); @@ -276,18 +279,20 @@ } do { pid = waitpid(child, &status, 0); - } while( pid == (pid_t)-1 && errno == EINTR ); - if( pid == (pid_t)-1 ) { + } while (pid == (pid_t)-1 && errno == EINTR); + if (pid == (pid_t)-1) { int e = errno; - fprintf(stderr, "rredtool: Error %d waiting for %s child %lu: %s!\n", + fprintf(stderr, +"rredtool: Error %d waiting for %s child %lu: %s!\n", e, argv[0], (unsigned long)child, strerror(e)); (void)close(fd); return RET_ERROR; } - if( WIFEXITED(status) && WEXITSTATUS(status) == expected_exit_code ) { - if( lseek(fd, 0, SEEK_SET) == (off_t)-1 ) { + if (WIFEXITED(status) && WEXITSTATUS(status) == expected_exit_code) { + if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { int e = errno; - fprintf(stderr, "rredtool: Error %d rewinding temporary file to start: %s!\n", + fprintf(stderr, +"rredtool: Error %d rewinding temporary file to start: %s!\n", e, strerror(e)); (void)close(fd); return RET_ERROR; @@ -296,13 +301,14 @@ return RET_OK; } close(fd); - if( WIFEXITED(status)) { - fprintf(stderr, "rredtool: %s returned with unexpected exit code %d\n", + if (WIFEXITED(status)) { + fprintf(stderr, +"rredtool: %s returned with unexpected exit code %d\n", argv[0], (int)(WEXITSTATUS(status))); return RET_ERROR; } - if( WIFSIGNALED(status)) { - if( WTERMSIG(status) != SIGUSR1 ) + if (WIFSIGNALED(status)) { + if (WTERMSIG(status) != SIGUSR1) fprintf(stderr, "rredtool: %s killed by signal %d\n", argv[0], (int)(WTERMSIG(status))); return RET_ERROR; @@ -324,7 +330,7 @@ }; static void old_index_done(/*@only@*/struct old_index_file *o) { - while( o->first != NULL ) { + while (o->first != NULL) { struct old_patch *p = o->first; o->first = p->next; @@ -343,16 +349,16 @@ * of this prefix with an additional +. As this might already * have happened, this has to be possibly repeated */ - while( true ) { - for( p = o->prev ; p != NULL ; p = p->prev ) { - if( p == last ) + while (true) { + for (p = o->prev ; p != NULL ; p = p->prev) { + if (p == last) continue; - if( strcmp(p->nameprefix, lookfor) == 0 ) { + if (strcmp(p->nameprefix, lookfor) == 0) { char *h; size_t l = strlen(p->nameprefix); h = realloc(p->nameprefix, l+2); - if( FAILEDTOALLOC(h) ) + if (FAILEDTOALLOC(h)) return RET_ERROR_OOM; h[l] = '+' ; h[l+1] = '\0'; @@ -362,7 +368,7 @@ break; } } - if( p == NULL ) + if (p == NULL) return RET_OK; } } @@ -377,112 +383,112 @@ * (otherwise not having merged patches would most likely break * things in ugly ways), so parsing it can be very strict and easy: */ -#define checkorfail(val) if( e - p < (intptr_t)strlen(val) || memcmp(p, val, strlen(val)) != 0) return RET_NOTHING; else { p += strlen(val); } +#define checkorfail(val) if (e - p < (intptr_t)strlen(val) || memcmp(p, val, strlen(val)) != 0) return RET_NOTHING; else { p += strlen(val); } checkorfail("SHA1-Current: "); q = strchr(p, '\n'); - if( q == NULL || q - p != 2 * SHA1_DIGEST_SIZE) + if (q == NULL || q - p != 2 * SHA1_DIGEST_SIZE) return RET_NOTHING; memcpy(oldindex->sha1, p, 2 * SHA1_DIGEST_SIZE); oldindex->sha1[2 * SHA1_DIGEST_SIZE] = '\0'; p = q; checkorfail("\nSHA1-History:\n"); - while( *p == ' ' ) { + while (*p == ' ') { p++; q = p; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') ) { + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) { p++; } - if( p - q != 2 * SHA1_DIGEST_SIZE) + if (p - q != 2 * SHA1_DIGEST_SIZE) return RET_NOTHING; - o = calloc(1, sizeof(struct old_patch)); - if( FAILEDTOALLOC(o) ) + o = zNEW(struct old_patch); + if (FAILEDTOALLOC(o)) return RET_ERROR_OOM; o->prev = oldindex->last; oldindex->last = o; - if( o->prev == NULL ) + if (o->prev == NULL) oldindex->first = o; else o->prev->next = o; memcpy(o->hash.sha1, q, 2 * SHA1_DIGEST_SIZE); - while( *p == ' ' ) + while (*p == ' ') p++; - if( *p < '0' || *p > '9' ) + if (*p < '0' || *p > '9') return RET_NOTHING; filesize = 0; - while( *p >= '0' && *p <= '9' ) { + while (*p >= '0' && *p <= '9') { filesize = 10 * filesize + (*p - '0'); p++; } o->hash.len = filesize; - if( *p != ' ' ) + if (*p != ' ') return RET_NOTHING; p++; q = strchr(p, '\n'); - if( q == NULL ) + if (q == NULL) return RET_NOTHING; o->basefilename = strndup(p, (size_t)(q-p)); - if( FAILEDTOALLOC(o->basefilename) ) + if (FAILEDTOALLOC(o->basefilename)) return RET_ERROR_OOM; p = q + 1; q = strchr(o->basefilename, '+'); - if( q == NULL ) + if (q == NULL) o->nameprefix = mprintf("%s+", o->basefilename); else o->nameprefix = strndup(o->basefilename, 1 + (size_t)(q - o->basefilename)); - if( FAILEDTOALLOC(o->nameprefix) ) + if (FAILEDTOALLOC(o->nameprefix)) return RET_ERROR_OOM; r = make_prefix_uniq(o); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* allow pseudo-empty fake patches */ - if( memcmp(o->hash.sha1, oldindex->sha1, - 2 * SHA1_DIGEST_SIZE) == 0 ) + if (memcmp(o->hash.sha1, oldindex->sha1, + 2 * SHA1_DIGEST_SIZE) == 0) continue; // TODO: verify filename and create prefix... } checkorfail("SHA1-Patches:\n"); o = oldindex->first; - while( *p == ' ' ) { + while (*p == ' ') { p++; - if( o == NULL ) + if (o == NULL) return RET_NOTHING; q = p; - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') ) { + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) { p++; } - if( p - q != 2 * SHA1_DIGEST_SIZE) + if (p - q != 2 * SHA1_DIGEST_SIZE) return RET_NOTHING; - while( *p == ' ' ) + while (*p == ' ') p++; - if( *p < '0' || *p > '9' ) + if (*p < '0' || *p > '9') return RET_NOTHING; - while( *p >= '0' && *p <= '9' ) { + while (*p >= '0' && *p <= '9') { p++; } - if( *p != ' ' ) + if (*p != ' ') return RET_NOTHING; p++; q = strchr(p, '\n'); - if( q == NULL ) + if (q == NULL) return RET_NOTHING; - if( strncmp(o->basefilename, p, (size_t)(q-p)) != 0 - || o->basefilename[q-p] != '\0' ) + if (strncmp(o->basefilename, p, (size_t)(q-p)) != 0 + || o->basefilename[q-p] != '\0') return RET_NOTHING; p = q + 1; o = o->next; } checkorfail("X-Patch-Precedence: merged\n"); - if( *p != '\0' || p != e ) + if (*p != '\0' || p != e) return RET_NOTHING; // TODO: check for dangerous stuff (like ../ in basename) // TODO: ignore patches where the filename is missing? @@ -499,11 +505,11 @@ memset(oldindex, 0, sizeof(struct old_index_file)); - if( !isregularfile(fullfilename) ) + if (!isregularfile(fullfilename)) return RET_NOTHING; fd = open(fullfilename, O_RDONLY); - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "rredtool: Error %d opening '%s': %s\n", @@ -513,14 +519,14 @@ /* index file should not be that big, so read into memory as a whole */ buffer = malloc(buffersize); - if( FAILEDTOALLOC(buffer) ) { + if (FAILEDTOALLOC(buffer)) { close(fd); return RET_ERROR_OOM; } do { bytes_read = read(fd, buffer + available, buffersize - available - 1); - if( bytes_read < 0 ) { + if (bytes_read < 0) { int e = errno; fprintf(stderr, "rredtool: Error %d reading '%s': %s\n", @@ -529,18 +535,19 @@ free(buffer); return RET_ERRNO(e); } - assert( (size_t)bytes_read < buffersize - available ); + assert ((size_t)bytes_read < buffersize - available); available += bytes_read; - if( available + 1 >= buffersize ) { - fprintf(stderr, "rredtool: Ridicilous long '%s' file!\n", + if (available + 1 >= buffersize) { + fprintf(stderr, +"rredtool: Ridicilous long '%s' file!\n", fullfilename); (void)close(fd); free(buffer); return RET_ERROR; } - } while( bytes_read > 0 ); + } while (bytes_read > 0); i = close(fd); - if( i != 0 ) { + if (i != 0) { int e = errno; fprintf(stderr, "rredtool: Error %d reading '%s': %s\n", @@ -552,15 +559,16 @@ r = parse_old_index(buffer, available, oldindex); free(buffer); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { /* wrong format, most likely a left over file */ - fprintf(stderr, "rredtool: File '%s' does not look like created by rredtool, ignoring!\n", + fprintf(stderr, +"rredtool: File '%s' does not look like created by rredtool, ignoring!\n", fullfilename); old_index_done(oldindex); memset(oldindex, 0, sizeof(struct old_index_file)); return RET_NOTHING; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { old_index_done(oldindex); memset(oldindex, 0, sizeof(struct old_index_file)); return r; @@ -577,11 +585,11 @@ }; static void patches_free(struct patch *r) { - while( r != NULL ) { + while (r != NULL) { struct patch *n = r->next; free(r->basefilename); - if( r->fullfilename != NULL ) { + if (r->fullfilename != NULL) { (void)unlink(r->fullfilename); free(r->fullfilename); } @@ -597,45 +605,46 @@ retvalue result; struct fileandhash fh; - p = calloc(1, sizeof(struct patch)); - if( FAILEDTOALLOC(p) ) + p = zNEW(struct patch); + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; - if( since == NULL ) + if (since == NULL) since = ""; p->basefilename = mprintf("%s%s", since, date); - if( FAILEDTOALLOC(p->basefilename) ) { + if (FAILEDTOALLOC(p->basefilename)) { patches_free(p); return RET_ERROR_OOM; } p->basefilename_len = strlen(p->basefilename); p->fullfilename = mprintf("%s/%s.diff/%s.gz.new", directory, relfilename, p->basefilename); - if( FAILEDTOALLOC(p->fullfilename) ) { + if (FAILEDTOALLOC(p->fullfilename)) { patches_free(p); return RET_ERROR_OOM; } /* create the file */ - while( tries-- > 0 ) { + while (tries-- > 0) { int e; fd = open(p->fullfilename, O_CREAT|O_EXCL|O_NOCTTY|O_WRONLY, 0666); - if( fd >= 0 ) + if (fd >= 0) break; e = errno; - if( e == EEXIST && tries > 0 ) + if (e == EEXIST && tries > 0) unlink(p->fullfilename); else { - fprintf(stderr, "rredtool: Error %d creating '%s': %s\n", + fprintf(stderr, +"rredtool: Error %d creating '%s': %s\n", e, p->fullfilename, strerror(e)); return RET_ERROR; } } - assert( fd > 0 ); + assert (fd > 0); /* start an child to compress connected via a pipe */ i = pipe(pipefds); - assert( pipefds[0] > 0 ); - if( i != 0 ) { + assert (pipefds[0] > 0); + if (i != 0) { int e = errno; fprintf(stderr, "rredtool: Error %d creating pipe: %s\n", e, strerror(e)); @@ -643,23 +652,24 @@ return RET_ERROR; } child = fork(); - if( child == (pid_t)-1 ) { + if (child == (pid_t)-1) { int e = errno; fprintf(stderr, "rredtool: Error %d forking: %s\n", e, strerror(e)); unlink(p->fullfilename); return RET_ERROR; } - if( child == 0 ) { + if (child == 0) { int e; close(pipefds[1]); do { i = dup2(pipefds[0], 0); e = errno; - } while( i < 0 && (e == EINTR || e == EBUSY) ); - if( i < 0 ) { - fprintf(stderr, "rredtool: Error %d in dup2(%d, 0): %s\n", + } while (i < 0 && (e == EINTR || e == EBUSY)); + if (i < 0) { + fprintf(stderr, +"rredtool: Error %d in dup2(%d, 0): %s\n", e, pipefds[0], strerror(e)); raise(SIGUSR1); exit(EXIT_FAILURE); @@ -667,9 +677,10 @@ do { i = dup2(fd, 1); e = errno; - } while( i < 0 && (e == EINTR || e == EBUSY) ); - if( i < 0 ) { - fprintf(stderr, "rredtool: Error %d in dup2(%d, 0): %s\n", + } while (i < 0 && (e == EINTR || e == EBUSY)); + if (i < 0) { + fprintf(stderr, +"rredtool: Error %d in dup2(%d, 0): %s\n", e, fd, strerror(e)); raise(SIGUSR1); exit(EXIT_FAILURE); @@ -687,9 +698,10 @@ close(fd); /* send the data to the child */ fh.f = fdopen(pipefds[1], "w"); - if( fh.f == NULL ) { + if (fh.f == NULL) { int e = errno; - fprintf(stderr, "rredtool: Error %d fdopen'ing write end of pipe to compressor: %s\n", + fprintf(stderr, +"rredtool: Error %d fdopen'ing write end of pipe to compressor: %s\n", e, strerror(e)); close(pipefds[1]); unlink(p->fullfilename); @@ -703,30 +715,32 @@ modification_printaspatch(&fh, r, hash_and_write); result = RET_OK; i = ferror(fh.f); - if( i != 0 ) { + if (i != 0) { fprintf(stderr, "rredtool: Error sending data to gzip!\n"); (void)fclose(fh.f); result = RET_ERROR; } else { i = fclose(fh.f); - if( i != 0 ) { + if (i != 0) { int e = errno; - fprintf(stderr, "rredtool: Error %d sending data to gzip: %s!\n", + fprintf(stderr, +"rredtool: Error %d sending data to gzip: %s!\n", e, strerror(e)); result = RET_ERROR; } } do { pid = waitpid(child, &status, 0); - } while( pid == (pid_t)-1 && errno == EINTR ); - if( pid == (pid_t)-1 ) { + } while (pid == (pid_t)-1 && errno == EINTR); + if (pid == (pid_t)-1) { int e = errno; - fprintf(stderr, "rredtool: Error %d waiting for gzip child %lu: %s!\n", + fprintf(stderr, +"rredtool: Error %d waiting for gzip child %lu: %s!\n", e, (unsigned long)child, strerror(e)); return RET_ERROR; } - if( WIFEXITED(status) && WEXITSTATUS(status) == 0 ) { - if( RET_IS_OK(result) ) { + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { + if (RET_IS_OK(result)) { finalize_sha1(&fh.context, fh.len, &p->hash); p->next = *root_p; *root_p = p; @@ -735,12 +749,13 @@ } unlink(p->fullfilename); patches_free(p); - if( WIFEXITED(status)) { - fprintf(stderr, "rredtool: gzip returned with non-zero exit code %d\n", + if (WIFEXITED(status)) { + fprintf(stderr, +"rredtool: gzip returned with non-zero exit code %d\n", (int)(WEXITSTATUS(status))); return RET_ERROR; } - if( WIFSIGNALED(status)) { + if (WIFSIGNALED(status)) { fprintf(stderr, "rredtool: gzip killed by signal %d\n", (int)(WTERMSIG(status))); return RET_ERROR; @@ -755,20 +770,20 @@ const struct patch *p; tries = 2; - while( tries > 0 ) { + while (tries > 0) { errno = 0; fd = open(newindexfilename, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( fd >= 0 ) + if (fd >= 0) break; - if( errno == EINTR ) + if (errno == EINTR) continue; tries--; - if( errno != EEXIST) + if (errno != EEXIST) break; unlink(newindexfilename); } - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "Error %d creating '%s': %s\n", e, newindexfilename, strerror(e)); @@ -776,29 +791,29 @@ } i = dprintf(fd, "SHA1-Current: %s\n" "SHA1-History:\n", newhash->sha1); - for( p = root ; i >= 0 && p != NULL ; p = p->next ) { + for (p = root ; i >= 0 && p != NULL ; p = p->next) { i = dprintf(fd, " %s %7ld %s\n", p->from.sha1, (long int)p->from.len, p->basefilename); } - if( i >= 0 ) + if (i >= 0) i = dprintf(fd, "SHA1-Patches:\n"); - for( p = root ; i >= 0 && p != NULL ; p = p->next ) { + for (p = root ; i >= 0 && p != NULL ; p = p->next) { i = dprintf(fd, " %s %7ld %s\n", p->hash.sha1, (long int)p->hash.len, p->basefilename); } - if( i >= 0 ) + if (i >= 0) i = dprintf(fd, "X-Patch-Precedence: merged\n"); - if( i >= 0 ) { + if (i >= 0) { i = close(fd); fd = -1; } - if( i < 0 ) { + if (i < 0) { int e = errno; fprintf(stderr, "Error %d writing to '%s': %s\n", e, newindexfilename, strerror(e)); - if( fd >= 0 ) + if (fd >= 0) (void)close(fd); unlink(newindexfilename); return RET_ERRNO(e); @@ -811,37 +826,37 @@ DIR *dir; const struct patch *p; - if( !isdirectory(diffdirectory) ) + if (!isdirectory(diffdirectory)) return; dir = opendir(diffdirectory); - if( dir == NULL ) + if (dir == NULL) return; - while( (de = readdir(dir)) != NULL ) { + while ((de = readdir(dir)) != NULL) { size_t len = strlen(de->d_name); /* special rule for that */ - if( len == 5 && strcmp(de->d_name, "Index") == 0 ) + if (len == 5 && strcmp(de->d_name, "Index") == 0) continue; /* if it does not end with .gz or .gz.new, ignore */ - if( len >= 4 && memcmp(de->d_name + len - 4, ".new", 4) == 0 ) + if (len >= 4 && memcmp(de->d_name + len - 4, ".new", 4) == 0) len -= 4; - if( len < 3 ) + if (len < 3) continue; - if( memcmp(de->d_name + len - 3, ".gz", 3) != 0 ) + if (memcmp(de->d_name + len - 3, ".gz", 3) != 0) continue; len -= 3; /* do not mark files to be deleted we still need: */ - for( p = keep ; p != NULL ; p = p->next ) { - if( p->basefilename_len != len ) + for (p = keep ; p != NULL ; p = p->next) { + if (p->basefilename_len != len) continue; - if( memcmp(p->basefilename, de->d_name, len) == 0 ) + if (memcmp(p->basefilename, de->d_name, len) == 0) break; } - if( p != NULL ) + if (p != NULL) continue; /* otherwise, tell reprepro this file is no longer needed: */ dprintf(3, "%s.diff/%s.tobedeleted\n", @@ -849,7 +864,7 @@ de->d_name); } closedir(dir); - if( isregularfile(indexfilename) && keep == NULL ) + if (isregularfile(indexfilename) && keep == NULL) dprintf(3, "%s.diff/Index.tobedeleted\n", relfilename); } @@ -867,7 +882,7 @@ argv[5] = NULL; r = execute_into_file(argv, &fd, 1); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return patch_loadfd("", fd, -1, rred_p); @@ -882,7 +897,7 @@ filename = mprintf("%s/%s.diff/%s.gz", directory, relfilename, o->basefilename); - if( !isregularfile(filename) ) + if (!isregularfile(filename)) return RET_NOTHING; args[0] = "gunzip"; args[1] = "-c"; @@ -891,7 +906,7 @@ r = execute_into_file(args, &fd, 0); free(filename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return patch_loadfd("", fd, -1, rred_p); @@ -913,19 +928,20 @@ struct modification *newdup; #endif - if( strcmp(mode, "new") == 0 ) + if (strcmp(mode, "new") == 0) m = mode_NEW; - else if( strcmp(mode, "old") == 0 ) + else if (strcmp(mode, "old") == 0) m = mode_OLD; - else if( strcmp(mode, "change") == 0 ) + else if (strcmp(mode, "change") == 0) m = mode_CHANGE; else { usage(stderr); - fprintf(stderr, "Error: 4th argument to rredtool in .diff maintenance mode must be 'new', 'old' or 'change'!\n"); + fprintf(stderr, +"Error: 4th argument to rredtool in .diff maintenance mode must be 'new', 'old' or 'change'!\n"); return RET_ERROR; } - if( m == mode_NEW ) { + if (m == mode_NEW) { /* There is no old file, nothing to do. * except checking for old diff files * and marking them to be deleted */ @@ -935,40 +951,41 @@ } r = get_date_string(date, sizeof(date)); - if (RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( m == mode_OLD || m == mode_CHANGE ); + assert (m == mode_OLD || m == mode_CHANGE); /* calculate sha1 checksum of old file */ r = gen_sha1sum(fullfilename, &oldhash); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "rredtool: expected file '%s' is missing!\n", fullfilename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( m == mode_CHANGE ) { + if (m == mode_CHANGE) { /* calculate sha1 checksum of the new file */ r = gen_sha1sum(fullnewfilename, &newhash); - if( r == RET_NOTHING ) { - fprintf(stderr, "rredtool: expected file '%s' is missing!\n", + if (r == RET_NOTHING) { + fprintf(stderr, +"rredtool: expected file '%s' is missing!\n", fullnewfilename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* if new == old, nothing to do */ - if( newhash.len == oldhash.len && - strcmp(newhash.sha1, oldhash.sha1) == 0 ) { + if (newhash.len == oldhash.len && + strcmp(newhash.sha1, oldhash.sha1) == 0) { m = mode_OLD; } } - if( oldhash.len == 0 || (m == mode_CHANGE && newhash.len == 0) ) { + if (oldhash.len == 0 || (m == mode_CHANGE && newhash.len == 0)) { /* Old or new file empty. treat as mode_NEW. * (checked here instead of letting later * more general optimisations catch this as @@ -982,20 +999,20 @@ } r = read_old_index(indexfilename, &old_index); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* ignore old Index file if it does not match the old file */ - if( memcmp(old_index.sha1, oldhash.sha1, 2*SHA1_DIGEST_SIZE) != 0 ) { + if (memcmp(old_index.sha1, oldhash.sha1, 2*SHA1_DIGEST_SIZE) != 0) { old_index_done(&old_index); memset(&old_index, 0, sizeof(old_index)); } - if( m == mode_OLD ) { + if (m == mode_OLD) { /* this index file did not change. * keep old or delete if not current */ - if( old_index.sha1[0] != '\0' ) { - for( o = old_index.first ; o != NULL ; o = o->next ) + if (old_index.sha1[0] != '\0') { + for (o = old_index.first ; o != NULL ; o = o->next) dprintf(3, "%s.diff/%s.gz.keep\n", relfilename, o->basefilename); dprintf(3, "%s.diff/Index\n", relfilename); @@ -1006,7 +1023,7 @@ old_index_done(&old_index); return RET_OK; } - assert( m == mode_CHANGE ); + assert (m == mode_CHANGE); mkdir(diffdirectory, 0777); @@ -1014,7 +1031,7 @@ /* create a fake diff to work around http://bugs.debian.org/545699 */ newdup = NULL; r = modification_addstuff(fullnewfilename, &newdup, &line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(newdup); old_index_done(&old_index); return r; @@ -1024,7 +1041,7 @@ newdup); modification_freelist(newdup); free(line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { old_index_done(&old_index); return r; } @@ -1033,18 +1050,18 @@ /* create new diff calling diff --ed */ r = ed_diff(fullfilename, fullnewfilename, &new_rred_patch); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { old_index_done(&old_index); patches_free(root); return r; } new_modifications = patch_getmodifications(new_rred_patch); - assert( new_modifications != NULL ); + assert (new_modifications != NULL); #ifdef APT_545694_WORKAROUND newdup = modification_dup(new_modifications); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(new_modifications); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1052,7 +1069,7 @@ return r; } r = modification_addstuff(fullnewfilename, &newdup, &line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(newdup); modification_freelist(new_modifications); patch_free(new_rred_patch); @@ -1072,7 +1089,7 @@ new_modifications); #endif // TODO: special handling of misparsing to cope with that better? - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(new_modifications); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1086,7 +1103,7 @@ * And as in all but extremly strange situations this * also means all older patches will get bigger when merged, * do not even bother to calculate them but remove all. */ - if( root->hash.len > newhash.len ) { + if (root->hash.len > newhash.len) { modification_freelist(new_modifications); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1098,7 +1115,7 @@ patch_count = 1; /* merge this into the old patches */ - for( o = old_index.last ; o != NULL ; o = o->prev ) { + for (o = old_index.last ; o != NULL ; o = o->prev) { struct rred_patch *old_rred_patch; struct modification *d, *merged; @@ -1106,30 +1123,30 @@ * pseudo-empty patches and to reduce the number * of patches in case the file is reverted to an * earlier state */ - if( memcmp(o->hash.sha1, old_index.sha1, - sizeof(old_index.sha1)) == 0 ) + if (memcmp(o->hash.sha1, old_index.sha1, + sizeof(old_index.sha1)) == 0) continue; - if( memcmp(o->hash.sha1, newhash.sha1, - sizeof(newhash.sha1)) == 0 ) + if (memcmp(o->hash.sha1, newhash.sha1, + sizeof(newhash.sha1)) == 0) continue; /* limit number of patches * (Index needs to be downloaded, too) */ - if( patch_count >= max_patch_count ) + if (patch_count >= max_patch_count) continue; /* empty files only make problems. * If you have a non-empty file with the sha1sum of an empty * one: Congratulations */ - if( strcmp(o->hash.sha1, - "da39a3ee5e6b4b0d3255bfef95601890afd80709") == 0 ) + if (strcmp(o->hash.sha1, + "da39a3ee5e6b4b0d3255bfef95601890afd80709") == 0) continue; r = read_old_patch(directory, relfilename, o, &old_rred_patch); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; // TODO: special handling of misparsing to cope with that better? - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(new_modifications); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1138,7 +1155,7 @@ } d = modification_dup(new_modifications); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { patch_free(old_rred_patch); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1147,7 +1164,7 @@ } r = combine_patches(&merged, patch_getmodifications(old_rred_patch), d); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(new_modifications); patch_free(old_rred_patch); patch_free(new_rred_patch); @@ -1155,7 +1172,7 @@ patches_free(root); return r; } - if( merged == NULL ) { + if (merged == NULL) { /* this should never happen as the sha1sum should * already be the same, but better safe than sorry */ patch_free(old_rred_patch); @@ -1163,7 +1180,7 @@ } #ifdef APT_545694_WORKAROUND r = modification_addstuff(fullnewfilename, &merged, &line); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(merged); patch_free(old_rred_patch); modification_freelist(new_modifications); @@ -1180,7 +1197,7 @@ free(line); #endif patch_free(old_rred_patch); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { modification_freelist(new_modifications); patch_free(new_rred_patch); old_index_done(&old_index); @@ -1190,7 +1207,7 @@ root->from = o->hash; /* remove patches that are bigger than the new file */ - if( root->hash.len >= newhash.len ) { + if (root->hash.len >= newhash.len) { struct patch *n; n = root; @@ -1205,14 +1222,14 @@ patch_free(new_rred_patch); old_index_done(&old_index); - assert( root != NULL); + assert (root != NULL); #ifdef APT_545699_WORKAROUND - assert( root->next != NULL); + assert (root->next != NULL); #endif /* write new Index file */ r = write_new_index(newindexfilename, &newhash, root); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { patches_free(root); return r; } @@ -1223,7 +1240,7 @@ /* tell reprepro to move those files to their final place * and include the Index in the Release file */ - for( p = root ; p != NULL ; p = p->next ) { + for (p = root ; p != NULL ; p = p->next) { /* the trailing . means add but do not put in Release */ dprintf(3, "%s.diff/%s.gz.new.\n", relfilename, p->basefilename); @@ -1249,7 +1266,7 @@ fullfilename = mprintf("%s/%s", directory, relfilename); fullnewfilename = mprintf("%s/%s", directory, relnewfilename); - if( FAILEDTOALLOC(fullfilename) || FAILEDTOALLOC(fullnewfilename) ) { + if (FAILEDTOALLOC(fullfilename) || FAILEDTOALLOC(fullnewfilename)) { free(fullfilename); free(fullnewfilename); return RET_ERROR_OOM; @@ -1257,8 +1274,8 @@ diffdirectory = mprintf("%s.diff", fullfilename); indexfilename = mprintf("%s.diff/Index", fullfilename); newindexfilename = mprintf("%s.diff/Index.new", fullfilename); - if( FAILEDTOALLOC(diffdirectory) || FAILEDTOALLOC(indexfilename) - || FAILEDTOALLOC(newindexfilename) ) { + if (FAILEDTOALLOC(diffdirectory) || FAILEDTOALLOC(indexfilename) + || FAILEDTOALLOC(newindexfilename)) { free(diffdirectory); free(indexfilename); free(newindexfilename); @@ -1266,7 +1283,9 @@ free(fullnewfilename); return RET_ERROR_OOM; } - r = handle_diff(directory, mode, relfilename, fullfilename, fullnewfilename, diffdirectory, indexfilename, newindexfilename); + r = handle_diff(directory, mode, relfilename, + fullfilename, fullnewfilename, diffdirectory, + indexfilename, newindexfilename); free(diffdirectory); free(indexfilename); free(newindexfilename); @@ -1291,13 +1310,14 @@ const char *sourcename IFSTUPIDCC(=NULL); int debug = 0; - while( (i = getopt_long(argc, (char**)argv, "+hVDmpR", options, NULL)) != -1 ) { + while ((i = getopt_long(argc, (char**)argv, "+hVDmpR", options, NULL)) != -1) { switch (i) { case 'h': usage(stdout); return EXIT_SUCCESS; case 'V': - printf("rred-tool from " PACKAGE_NAME " version " PACKAGE_VERSION); + printf( +"rred-tool from " PACKAGE_NAME " version " PACKAGE_VERSION); return EXIT_SUCCESS; case 'D': debug++; @@ -1321,49 +1341,52 @@ } } - if( repreprohook && mergemode ) { - fprintf(stderr, "Cannot do --reprepro-hook and --merge at the same time!\n"); + if (repreprohook && mergemode) { + fprintf(stderr, +"Cannot do --reprepro-hook and --merge at the same time!\n"); return EXIT_FAILURE; } - if( repreprohook && patchmode ) { - fprintf(stderr, "Cannot do --reprepro-hook and --patch at the same time!\n"); + if (repreprohook && patchmode) { + fprintf(stderr, +"Cannot do --reprepro-hook and --patch at the same time!\n"); return EXIT_FAILURE; } - if( repreprohook || (!mergemode && !patchmode) ) { - if( optind + 4 != argc ) { + if (repreprohook || (!mergemode && !patchmode)) { + if (optind + 4 != argc) { usage(stderr); return EXIT_FAILURE; } r = handle_diff_dir(argv + optind); - if( r == RET_ERROR_OOM ) { + if (r == RET_ERROR_OOM) { fputs("Out of memory!\n", stderr); } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return EXIT_FAILURE; return EXIT_SUCCESS; } i = optind; - if( !mergemode ) { - if( i >= argc ) { + if (!mergemode) { + if (i >= argc) { fprintf(stderr, "Not enough arguments!\n"); return EXIT_FAILURE; } sourcename = argv[i++]; } - if( mergemode && patchmode ) { - fprintf(stderr, "Cannot do --merge and --patch at the same time!\n"); + if (mergemode && patchmode) { + fprintf(stderr, +"Cannot do --merge and --patch at the same time!\n"); return EXIT_FAILURE; } count = 0; - while( i < argc ) { + while (i < argc) { r = patch_load(argv[i], -1, &patches[count]); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) count++; - if( RET_WAS_ERROR(r) ) { - if( r == RET_ERROR_OOM ) + if (RET_WAS_ERROR(r)) { + if (r == RET_ERROR_OOM) fputs("Out of memory!\n", stderr); else fputs("Aborting...\n", stderr); @@ -1371,14 +1394,14 @@ } i++; } - if( count <= 0 ) { + if (count <= 0) { fprintf(stderr, "Not enough patches for operation...\n"); return EXIT_FAILURE; } m = patch_getmodifications(patches[0]); - for( i = 1; i < count ; i++ ) { + for (i = 1; i < count ; i++) { struct modification *a = patch_getmodifications(patches[i]); - if( debug ) { + if (debug) { fputs("--------RESULT SO FAR--------\n", stderr); modification_printaspatch(stderr, m, write_to_file); fputs("--------TO BE MERGED WITH-----\n", stderr); @@ -1386,11 +1409,11 @@ fputs("-------------END--------------\n", stderr); } r = combine_patches(&m, m, a); - if( RET_WAS_ERROR(r) ) { - for( i = 0 ; i < count ; i++ ) { + if (RET_WAS_ERROR(r)) { + for (i = 0 ; i < count ; i++) { patch_free(patches[i]); } - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) fputs("Out of memory!\n", stderr); else fputs("Aborting...\n", stderr); @@ -1398,21 +1421,21 @@ } } r = RET_OK; - if( mergemode ) { + if (mergemode) { modification_printaspatch(stdout, m, write_to_file); } else { r = patch_file(stdout, sourcename, m); } - if( ferror(stdout) ) { + if (ferror(stdout)) { fputs("Error writing to stdout!\n", stderr); r = RET_ERROR; } modification_freelist(m); - for( i = 0 ; i < count ; i++ ) + for (i = 0 ; i < count ; i++) patch_free(patches[i]); - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) fputs("Out of memory!\n", stderr); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return EXIT_FAILURE; return EXIT_SUCCESS; } diff -Nru reprepro-4.5.0/sha1.c reprepro-4.6.0/sha1.c --- reprepro-4.5.0/sha1.c 2008-06-11 13:18:46.000000000 +0000 +++ reprepro-4.6.0/sha1.c 2011-05-05 14:42:55.000000000 +0000 @@ -83,11 +83,11 @@ int i; #endif - assert( sizeof(block) == 64*sizeof(uint8_t) ); + assert (sizeof(block) == 64*sizeof(uint8_t)); #ifdef WORDS_BIGENDIAN memcpy(block, buffer, sizeof(block)); #else - for( i = 0 ; i < 16 ; i++ ) { + for (i = 0 ; i < 16 ; i++) { block[i] = (buffer[4*i]<<24) | (buffer[4*i+1]<<16) | (buffer[4*i+2]<<8) | buffer[4*i+3]; } @@ -151,15 +151,15 @@ j = context->count & 63; context->count += len; - if ( j == 0 ) { - for ( i = 0 ; len >= i + 64 ; i += 64) { + if (j == 0) { + for (i = 0 ; len >= i + 64 ; i += 64) { SHA1_Transform(context->state, data + i); } j = 0; } else if ((j + len) >= 64) { memcpy(&context->buffer[j], data, (i = 64-j)); SHA1_Transform(context->state, context->buffer); - for ( ; len >= i + 64 ; i += 64) { + for (; len >= i + 64 ; i += 64) { SHA1_Transform(context->state, data + i); } j = 0; @@ -180,14 +180,14 @@ i = context->count & 63; context->buffer[i] = '\200'; i++; - if( i > 56 ) { - if( i < 64 ) + if (i > 56) { + if (i < 64) memset(context->buffer + i, 0, 64-i); SHA1_Transform(context->state, context->buffer); i = 0; } - if( i < 56 ) { - memset( context->buffer + i, 0, 56-i ); + if (i < 56) { + memset(context->buffer + i, 0, 56-i); } for (j = 7; j >= 0; j--) { context->buffer[56 + j] = bitcount & 0xFF; diff -Nru reprepro-4.5.0/sha256.h reprepro-4.6.0/sha256.h --- reprepro-4.5.0/sha256.h 2008-05-17 11:04:00.000000000 +0000 +++ reprepro-4.6.0/sha256.h 2011-05-05 14:42:55.000000000 +0000 @@ -8,7 +8,7 @@ uint64_t total; uint32_t buflen; - char buffer[128]; /* NB: always correctly aligned for uint32_t. */ + char buffer[128]; /* NB: always correctly aligned for uint32_t. */ }; #define SHA256_DIGEST_SIZE 32 diff -Nru reprepro-4.5.0/signature.c reprepro-4.6.0/signature.c --- reprepro-4.5.0/signature.c 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/signature.c 2011-05-05 14:42:55.000000000 +0000 @@ -39,11 +39,11 @@ gpgme_ctx_t context = NULL; retvalue gpgerror(gpg_error_t err) { - if( err != 0 ) { + if (err != 0) { fprintf(stderr, "gpgme gave error %s:%d: %s\n", gpg_strsource(err), gpg_err_code(err), gpg_strerror(err)); - if( gpg_err_code(err) == GPG_ERR_ENOMEM ) + if (gpg_err_code(err) == GPG_ERR_ENOMEM) return RET_ERROR_OOM; else return RET_ERROR_GPGME; @@ -59,7 +59,7 @@ msg = mprintf("%s needs a passphrase\nPlease enter passphrase%s:", (uid_hint!=NULL)?uid_hint:"key", (prev_was_bad!=0)?" again":""); - if( msg == NULL ) + if (msg == NULL) return gpg_err_make(GPG_ERR_SOURCE_USER_1, GPG_ERR_ENOMEM); p = getpass(msg); write(fd, p, strlen(p)); @@ -73,28 +73,29 @@ #ifdef HAVE_LIBGPGME gpg_error_t err; - if( context != NULL ) + if (context != NULL) return RET_NOTHING; gpgme_check_version(NULL); err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); - if( err != 0 ) + if (err != 0) return gpgerror(err); err = gpgme_new(&context); - if( err != 0 ) + if (err != 0) return gpgerror(err); - err = gpgme_set_protocol(context,GPGME_PROTOCOL_OpenPGP); - if( err != 0 ) + err = gpgme_set_protocol(context, GPGME_PROTOCOL_OpenPGP); + if (err != 0) return gpgerror(err); - if( allowpassphrase ) - gpgme_set_passphrase_cb(context,signature_getpassphrase,NULL); - gpgme_set_armor(context,1); + if (allowpassphrase) + gpgme_set_passphrase_cb(context, signature_getpassphrase, + NULL); + gpgme_set_armor(context, 1); #endif /* HAVE_LIBGPGME */ return RET_OK; } void signatures_done(void) { #ifdef HAVE_LIBGPGME - if( context != NULL ) { + if (context != NULL) { gpgme_release(context); context = NULL; } @@ -108,36 +109,36 @@ int i; signresult = gpgme_op_sign_result(context); - if( signresult != NULL && signresult->signatures != NULL ) + if (signresult != NULL && signresult->signatures != NULL) return RET_OK; /* in an ideal world, this point is never reached. * Sadly it is and people are obviously confused by it, * so do some work to give helpful messages. */ - if( options != NULL ) { + if (options != NULL) { assert (options->count > 0); uidoptions = mprintf(" -u '%s'", options->values[0]); - for( i = 1 ; + for (i = 1 ; uidoptions != NULL && i < options->count ; - i++ ) { + i++) { char *u = mprintf("%s -u '%s'", uidoptions, options->values[0]); free(uidoptions); uidoptions = u; } - if( FAILEDTOALLOC(uidoptions) ) + if (FAILEDTOALLOC(uidoptions)) return RET_ERROR_OOM; } else uidoptions = NULL; - if( signresult == NULL ) + if (signresult == NULL) fputs( "Error: gpgme returned NULL unexpectedly for gpgme_op_sign_result\n", stderr); else - fputs( "Error: gpgme created no signature!\n", stderr); + fputs("Error: gpgme created no signature!\n", stderr); fputs( "This most likely means gpg is confused or produces some error libgpgme is\n" "not able to understand. Try running\n", stderr); - if( willcleanup ) + if (willcleanup) fprintf(stderr, "gpg %s --output 'some-other-file' %s 'some-file'\n", (uidoptions==NULL)?"":uidoptions, @@ -163,17 +164,17 @@ int fd, e, ret; signature_data = gpgme_data_release_and_get_mem(dh_gpg, &signature_len); - if( signature_data == NULL ) + if (FAILEDTOALLOC(signature_data)) return RET_ERROR_OOM; fd = open(signaturename, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY|O_NOFOLLOW, 0666); - if( fd < 0 ) { + if (fd < 0) { free(signature_data); return RET_ERRNO(errno); } p = signature_data; - while( signature_len > 0 ) { + while (signature_len > 0) { written = write(fd, p, signature_len); - if( written < 0 ) { + if (written < 0) { e = errno; fprintf(stderr, "Error %d writing to %s: %s\n", e, signaturename, @@ -191,14 +192,14 @@ free(signature_data); #endif ret = close(fd); - if( ret < 0 ) { + if (ret < 0) { e = errno; fprintf(stderr, "Error %d writing to %s: %s\n", e, signaturename, strerror(e)); return RET_ERRNO(e); } - if( verbose > 1 ) { + if (verbose > 1) { printf("Successfully created '%s'\n", signaturename); } return RET_OK; @@ -210,15 +211,15 @@ retvalue r; err = gpgme_data_new(&dh_gpg); - if( err != 0 ) + if (err != 0) return gpgerror(err); err = gpgme_op_sign(context, dh, dh_gpg, clearsign?GPGME_SIG_MODE_CLEAR:GPGME_SIG_MODE_DETACH); - if( err != 0 ) + if (err != 0) return gpgerror(err); r = check_signature_created(clearsign, willcleanup, options, filename, signaturename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { gpgme_data_release(dh_gpg); return r; } @@ -236,54 +237,58 @@ gpgme_data_t dh; #endif /* HAVE_LIBGPGME */ - assert( options != NULL && options->count > 0 ); + assert (options != NULL && options->count > 0); r = signature_init(false); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* make sure it does not already exists */ ret = unlink(signaturename); - if( ret != 0 && (e = errno) != ENOENT ) { - fprintf(stderr, "Could not remove '%s' to prepare replacement: %s\n", + if (ret != 0 && (e = errno) != ENOENT) { + fprintf(stderr, +"Could not remove '%s' to prepare replacement: %s\n", signaturename, strerror(e)); return RET_ERROR; } ret = unlink(clearsignfilename); - if( ret != 0 && (e = errno) != ENOENT ) { - fprintf(stderr, "Could not remove '%s' to prepare replacement: %s\n", + if (ret != 0 && (e = errno) != ENOENT) { + fprintf(stderr, +"Could not remove '%s' to prepare replacement: %s\n", clearsignfilename, strerror(e)); return RET_ERROR; } - if( options->values[0][0] == '!' ) { + if (options->values[0][0] == '!') { // TODO: allow external programs, too - fprintf(stderr, "sign-scripts (starting with '!') not allowed yet.\n"); + fprintf(stderr, +"sign-scripts (starting with '!') not allowed yet.\n"); return RET_ERROR; } #ifdef HAVE_LIBGPGME gpgme_signers_clear(context); - if( options->count == 1 && + if (options->count == 1 && (strcasecmp(options->values[0], "yes") == 0 || - strcasecmp(options->values[0], "default") == 0) ) { + strcasecmp(options->values[0], "default") == 0)) { /* use default options */ options = NULL; - } else for( i = 0 ; i < options->count ; i++ ) { + } else for (i = 0 ; i < options->count ; i++) { const char *option = options->values[i]; gpgme_key_t key; err = gpgme_op_keylist_start(context, option, 1); - if( err != 0 ) + if (err != 0) return gpgerror(err); err = gpgme_op_keylist_next(context, &key); - if( gpg_err_code(err) == GPG_ERR_EOF ) { - fprintf(stderr, "Could not find any key matching '%s'!\n", option); + if (gpg_err_code(err) == GPG_ERR_EOF) { + fprintf(stderr, +"Could not find any key matching '%s'!\n", option); return RET_ERROR; } err = gpgme_signers_add(context, key); gpgme_key_unref(key); - if( err != 0 ) { + if (err != 0) { gpgme_op_keylist_end(context); return gpgerror(err); } @@ -291,18 +296,18 @@ } err = gpgme_data_new_from_mem(&dh, data, datalen, 0); - if( err != 0 ) { + if (err != 0) { return gpgerror(err); } r = create_signature(false, dh, options, filename, signaturename, willcleanup); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { gpgme_data_release(dh); return r; } i = gpgme_data_seek(dh, 0, SEEK_SET); - if( i < 0 ) { + if (i < 0) { e = errno; fprintf(stderr, "Error %d rewinding gpgme's data buffer to start: %s\n", @@ -313,7 +318,7 @@ r = create_signature(true, dh, options, filename, clearsignfilename, willcleanup); gpgme_data_release(dh); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; #else /* HAVE_LIBGPGME */ @@ -338,18 +343,19 @@ struct signature *sig; result = gpgme_op_verify_result(context); - if( result == NULL ) { - fprintf(stderr,"Internal error communicating with libgpgme: no result record!\n\n"); + if (result == NULL) { + fprintf(stderr, +"Internal error communicating with libgpgme: no result record!\n\n"); return RET_ERROR_GPGME; } - if( signatures_p != NULL ) { + if (signatures_p != NULL) { count = 0; - for( s = result->signatures ; s != NULL ; s = s->next ) { + for (s = result->signatures ; s != NULL ; s = s->next) { count++; } signatures = calloc(1, sizeof(struct signatures) + count * sizeof(struct signature)); - if( FAILEDTOALLOC(signatures) ) + if (FAILEDTOALLOC(signatures)) return RET_ERROR_OOM; signatures->count = count; signatures->validcount = 0; @@ -358,46 +364,46 @@ signatures = NULL; sig = NULL; } - for( s = result->signatures ; s != NULL ; s = s->next ) { + for (s = result->signatures ; s != NULL ; s = s->next) { enum signature_state state = sist_error; - if( signatures_p != NULL ) { + if (signatures_p != NULL) { sig->keyid = strdup(s->fpr); - if( FAILEDTOALLOC(sig->keyid) ) { + if (FAILEDTOALLOC(sig->keyid)) { signatures_free(signatures); return RET_ERROR_OOM; } } - switch( gpg_err_code(s->status) ) { + switch (gpg_err_code(s->status)) { case GPG_ERR_NO_ERROR: had_valid = true; state = sist_valid; - if( signatures ) + if (signatures) signatures->validcount++; break; case GPG_ERR_KEY_EXPIRED: had_valid = true; - if( verbose > 0 ) + if (verbose > 0) fprintf(stderr, "Ignoring signature with '%s' on '%s', as the key has expired.\n", s->fpr, filename); state = sist_mostly; - if( sig != NULL ) + if (sig != NULL) sig->expired_key = true; break; case GPG_ERR_CERT_REVOKED: had_valid = true; - if( verbose > 0 ) + if (verbose > 0) fprintf(stderr, "Ignoring signature with '%s' on '%s', as the key is revoked.\n", s->fpr, filename); state = sist_mostly; - if( sig != NULL ) + if (sig != NULL) sig->revoced_key = true; break; case GPG_ERR_SIG_EXPIRED: had_valid = true; - if( verbose > 0 ) { + if (verbose > 0) { time_t timestamp = s->timestamp, exp_timestamp = s->exp_timestamp; fprintf(stderr, @@ -408,19 +414,19 @@ ctime(&exp_timestamp)); } state = sist_mostly; - if( sig != NULL ) + if (sig != NULL) sig->expired_signature = true; break; case GPG_ERR_BAD_SIGNATURE: had_broken = true; - if( verbose > 0 ) { + if (verbose > 0) { fprintf(stderr, "WARNING: '%s' has a invalid signature with '%s'\n", filename, s->fpr); } state = sist_bad; break; case GPG_ERR_NO_PUBKEY: - if( verbose > 0 ) { + if (verbose > 0) { fprintf(stderr, "Could not check validity of signature with '%s' in '%s' as public key missing!\n", s->fpr, filename); @@ -441,7 +447,7 @@ default: break; } - if( state == sist_error ) { + if (state == sist_error) { fprintf(stderr, "Error checking signature (gpgme returned unexpected value %d)!\n" "Please file a bug report, so reprepro can handle this in the future.\n", @@ -449,14 +455,14 @@ signatures_free(signatures); return RET_ERROR_GPGME; } - if( sig != NULL ) { + if (sig != NULL) { sig->state = state; sig++; } } - if( broken != NULL && had_broken && ! had_valid ) + if (broken != NULL && had_broken && ! had_valid) *broken = true; - if( signatures_p != NULL ) + if (signatures_p != NULL) *signatures_p = signatures; return RET_OK; } @@ -467,49 +473,51 @@ valid if the primary key is expired */ int i; - for( i = 0 ; i < signatures->count ; i++ ) { + for (i = 0 ; i < signatures->count ; i++) { gpg_error_t err; gpgme_key_t gpgme_key = NULL; gpgme_subkey_t subkey; struct signature *sig = &signatures->signatures[i]; - if( sig->state == sist_error || sig->state == sist_missing ) { + if (sig->state == sist_error || sig->state == sist_missing) { sig->primary_keyid = strdup(sig->keyid); - if( FAILEDTOALLOC(sig->primary_keyid) ) + if (FAILEDTOALLOC(sig->primary_keyid)) return RET_ERROR_OOM; continue; } err = gpgme_get_key(context, sig->keyid, &gpgme_key, 0); - if( err != 0 ) { - fprintf(stderr, "gpgme error %s:%d retrieving key '%s': %s\n", - gpg_strsource(err), (int)gpg_err_code(err), + if (err != 0) { + fprintf(stderr, +"gpgme error %s:%d retrieving key '%s': %s\n", + gpg_strsource(err), + (int)gpg_err_code(err), sig->keyid, gpg_strerror(err)); - if( gpg_err_code(err) == GPG_ERR_ENOMEM ) + if (gpg_err_code(err) == GPG_ERR_ENOMEM) return RET_ERROR_OOM; else return RET_ERROR_GPGME; } - assert( gpgme_key != NULL ); + assert (gpgme_key != NULL); /* the first "sub"key is the primary key */ subkey = gpgme_key->subkeys; - if( subkey->revoked ) { + if (subkey->revoked) { sig->revoced_key = true; - if( sig->state == sist_valid ) { + if (sig->state == sist_valid) { sig->state = sist_mostly; signatures->validcount--; } } - if( subkey->expired ) { + if (subkey->expired) { sig->expired_key = true; - if( sig->state == sist_valid ) { + if (sig->state == sist_valid) { sig->state = sist_mostly; signatures->validcount--; } } sig->primary_keyid = strdup(subkey->keyid); gpgme_key_unref(gpgme_key); - if( FAILEDTOALLOC(sig->primary_keyid) ) + if (FAILEDTOALLOC(sig->primary_keyid)) return RET_ERROR_OOM; } return RET_OK; @@ -517,22 +525,22 @@ #endif /* HAVE_LIBGPGME */ static inline void extractchunk(const char *buffer, const char **begin, const char **end, const char **next) { - const char *startofchanges,*endofchanges,*afterchanges; + const char *startofchanges, *endofchanges, *afterchanges; startofchanges = buffer; - while( *startofchanges == ' ' || *startofchanges == '\t' || - *startofchanges == '\r' || *startofchanges =='\n' ) + while (*startofchanges == ' ' || *startofchanges == '\t' || + *startofchanges == '\r' || *startofchanges =='\n') startofchanges++; endofchanges = startofchanges; afterchanges = NULL; - while( *endofchanges != '\0' ) { - if( *endofchanges == '\n' ) { + while (*endofchanges != '\0') { + if (*endofchanges == '\n') { endofchanges++; afterchanges = endofchanges; - while( *afterchanges =='\r' ) + while (*afterchanges =='\r') afterchanges++; - if( *afterchanges == '\n' ) + if (*afterchanges == '\n') break; endofchanges = afterchanges; afterchanges = NULL; @@ -540,10 +548,10 @@ endofchanges++; } - if( afterchanges == NULL ) + if (afterchanges == NULL) afterchanges = endofchanges; else - while( *afterchanges == '\n' || *afterchanges =='\r' ) + while (*afterchanges == '\n' || *afterchanges =='\r') afterchanges++; *begin = startofchanges; *end = endofchanges; @@ -553,10 +561,10 @@ void signatures_free(struct signatures *signatures) { int i; - if( signatures == NULL ) + if (signatures == NULL) return; - for( i = 0 ; i < signatures->count ; i++ ) { + for (i = 0 ; i < signatures->count ; i++) { free(signatures->signatures[i].keyid); free(signatures->signatures[i].primary_keyid); } @@ -565,10 +573,10 @@ #ifdef HAVE_LIBGPGME static retvalue extract_signed_data(const char *buffer, size_t bufferlen, const char *filenametoshow, char **chunkread, /*@null@*/ /*@out@*/struct signatures **signatures_p, bool *brokensignature, bool *failed) { - const char *startofchanges,*endofchanges,*afterchanges; + const char *startofchanges, *endofchanges, *afterchanges; char *chunk; gpg_error_t err; - gpgme_data_t dh,dh_gpg; + gpgme_data_t dh, dh_gpg; size_t plain_len; char *plain_data; retvalue r; @@ -576,44 +584,45 @@ bool foundbroken = false; r = signature_init(false); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; err = gpgme_data_new_from_mem(&dh_gpg, buffer, bufferlen, 0); - if( err != 0 ) + if (err != 0) return gpgerror(err); err = gpgme_data_new(&dh); - if( err != 0 ) { + if (err != 0) { gpgme_data_release(dh_gpg); return gpgerror(err); } err = gpgme_op_verify(context, dh_gpg, NULL, dh); - if( gpg_err_code(err) == GPG_ERR_NO_DATA ) { - if( verbose > 5 ) - fprintf(stderr,"Data seems not to be signed trying to use directly....\n"); + if (gpg_err_code(err) == GPG_ERR_NO_DATA) { + if (verbose > 5) + fprintf(stderr, +"Data seems not to be signed trying to use directly....\n"); gpgme_data_release(dh); gpgme_data_release(dh_gpg); return RET_NOTHING; } else { - if( err != 0 ) { + if (err != 0) { gpgme_data_release(dh_gpg); gpgme_data_release(dh); return gpgerror(err); } - if( signatures_p != NULL || brokensignature != NULL ) { + if (signatures_p != NULL || brokensignature != NULL) { r = checksigs(filenametoshow, (signatures_p!=NULL)?&signatures:NULL, (brokensignature!=NULL)?&foundbroken:NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { gpgme_data_release(dh_gpg); gpgme_data_release(dh); return r; } } gpgme_data_release(dh_gpg); - plain_data = gpgme_data_release_and_get_mem(dh,&plain_len); - if( plain_data == NULL ) { + plain_data = gpgme_data_release_and_get_mem(dh, &plain_len); + if (plain_data == NULL) { fprintf(stderr, "(not yet fatal) ERROR: libgpgme failed to extract the plain data out of\n" "'%s'.\n" @@ -626,26 +635,27 @@ signatures_free(signatures); return RET_NOTHING; } - if( signatures != NULL ) { + if (signatures != NULL) { r = check_primary_keys(signatures); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { signatures_free(signatures); return r; } } } - if( plain_data == NULL ) + if (FAILEDTOALLOC(plain_data)) r = RET_ERROR_OOM; else { // TODO: check if the new extractchunk can be used... startofchanges = plain_data; - while( (size_t)(startofchanges - plain_data) < plain_len && - *startofchanges != '\0' && xisspace(*startofchanges)) { + while ((size_t)(startofchanges - plain_data) < plain_len + && *startofchanges != '\0' + && xisspace(*startofchanges)) { startofchanges++; } - if( (size_t)(startofchanges - plain_data) >= plain_len ) { + if ((size_t)(startofchanges - plain_data) >= plain_len) { fprintf(stderr, "Could only find spaces within '%s'!\n", filenametoshow); @@ -653,20 +663,22 @@ } else r = RET_OK; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { endofchanges = startofchanges; - while( (size_t)(endofchanges - plain_data) < plain_len && + while ((size_t)(endofchanges - plain_data) < plain_len && *endofchanges != '\0' && - ( *endofchanges != '\n' || *(endofchanges-1)!= '\n')) { + (*endofchanges != '\n' + || *(endofchanges-1)!= '\n')) { endofchanges++; } afterchanges = endofchanges; - while( (size_t)(afterchanges - plain_data) < plain_len && - *afterchanges != '\0' && xisspace(*afterchanges)) { + while ((size_t)(afterchanges - plain_data) < plain_len + && *afterchanges != '\0' + && xisspace(*afterchanges)) { afterchanges++; } - if( (size_t)(afterchanges - plain_data) != plain_len ) { - if( *afterchanges == '\0' ) + if ((size_t)(afterchanges - plain_data) != plain_len) { + if (*afterchanges == '\0') fprintf(stderr, "Unexpected \\0 character within '%s'!\n", filenametoshow); @@ -677,9 +689,9 @@ r = RET_ERROR; } } - if( RET_IS_OK(r) ) { - chunk = strndup(startofchanges,endofchanges-startofchanges); - if( chunk == NULL ) + if (RET_IS_OK(r)) { + chunk = strndup(startofchanges, endofchanges - startofchanges); + if (FAILEDTOALLOC(chunk)) r = RET_ERROR_OOM; else *chunkread = chunk; @@ -689,10 +701,10 @@ #else free(plain_data); #endif - if( RET_IS_OK(r) ) { - if( signatures_p != NULL ) + if (RET_IS_OK(r)) { + if (signatures_p != NULL) *signatures_p = signatures; - if( brokensignature != NULL ) + if (brokensignature != NULL) *brokensignature = foundbroken; } else { signatures_free(signatures); @@ -704,16 +716,16 @@ /* Read a single chunk from a file, that may be signed. */ retvalue signature_readsignedchunk(const char *filename, const char *filenametoshow, char **chunkread, /*@null@*/ /*@out@*/struct signatures **signatures_p, bool *brokensignature) { char *chunk, *h, *afterchunk; - const char *startofchanges,*endofchanges,*afterchanges; + const char *startofchanges, *endofchanges, *afterchanges; size_t chunklen, len; retvalue r; bool failed = false; r = readtextfile(filename, filenametoshow, &chunk, &chunklen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - if( chunklen == 0 ) { + if (chunklen == 0) { fprintf(stderr, "Unexpected empty file '%s'!\n", filenametoshow); free(chunk); @@ -721,7 +733,7 @@ } extractchunk(chunk, &startofchanges, &endofchanges, &afterchanges); - if( endofchanges == startofchanges ) { + if (endofchanges == startofchanges) { fprintf(stderr, "Could only find spaces within '%s'!\n", filenametoshow); free(chunk); @@ -729,25 +741,29 @@ } /* fast-track unsigned chunks: */ - if( startofchanges[0] != '-' && *afterchanges == '\0' ) { - if( verbose > 5 ) - fprintf(stderr,"Data seems not to be signed trying to use directly...\n"); + if (startofchanges[0] != '-' && *afterchanges == '\0') { + if (verbose > 5 && strncmp(startofchanges, "Format:", 7) != 0 + && strncmp(startofchanges, "Source:", 7) != 0) + fprintf(stderr, +"Data seems not to be signed trying to use directly...\n"); len = chunk_extract(chunk, chunk, &afterchunk); - assert( *afterchunk == '\0' ); - assert( chunk[len] == '\0' ); + assert (*afterchunk == '\0'); + assert (chunk[len] == '\0'); h = realloc(chunk, len + 1); - if( h != NULL ) + if (h != NULL) chunk = h; *chunkread = chunk; - if( signatures_p != NULL ) + if (signatures_p != NULL) *signatures_p = NULL; - if( brokensignature != NULL ) + if (brokensignature != NULL) *brokensignature = false; return RET_OK; } - if( startofchanges[0] != '-' ) { - fprintf(stderr, "Error parsing '%s': Seems not to be signed but has spurious empty line.\n", filenametoshow); + if (startofchanges[0] != '-') { + fprintf(stderr, +"Error parsing '%s': Seems not to be signed but has spurious empty line.\n", + filenametoshow); free(chunk); return RET_ERROR; } @@ -755,7 +771,7 @@ #ifdef HAVE_LIBGPGME r = extract_signed_data(chunk, chunklen, filenametoshow, chunkread, signatures_p, brokensignature, &failed); - if( r != RET_NOTHING ) { + if (r != RET_NOTHING) { free(chunk); return r; } @@ -764,7 +780,7 @@ /* We have no libgpgme, it failed, or could not find signature data, * trying to extract it manually, ignoring signatures: */ - if( *afterchanges == '\0' ) { + if (*afterchanges == '\0') { fprintf(stderr, "First non-space character is a '-' but there is no empty line in\n" "'%s'.\n" @@ -772,7 +788,7 @@ free(chunk); return RET_ERROR; } - if( strncmp(startofchanges, "-----BEGIN", 10) != 0 ) { + if (strncmp(startofchanges, "-----BEGIN", 10) != 0) { fprintf(stderr, "Strange content of '%s': First non-space character is '-',\n" "but it does not begin with '-----BEGIN'.\n", filenametoshow); @@ -787,20 +803,20 @@ len = chunk_extract(chunk, afterchanges, &afterchunk); - if( len == 0 ) { - fprintf(stderr,"Could not find any data within '%s'!\n", + if (len == 0) { + fprintf(stderr, "Could not find any data within '%s'!\n", filenametoshow); free(chunk); return RET_ERROR; } - if( *afterchunk == '\0' ) { + if (*afterchunk == '\0') { const char *endmarker; endmarker = strstr(chunk, "\n-----"); - if( endmarker != NULL ) { + if (endmarker != NULL) { endmarker++; - assert( (size_t)(endmarker-chunk) < len ); + assert ((size_t)(endmarker-chunk) < len); len = endmarker-chunk; chunk[len] = '\0'; } else { @@ -811,29 +827,29 @@ free(chunk); return RET_ERROR; } - } else if( strncmp(afterchunk, "-----", 5) != 0 ) { - fprintf(stderr,"ERROR: Spurious empty line within '%s'.\n" + } else if (strncmp(afterchunk, "-----", 5) != 0) { + fprintf(stderr, "ERROR: Spurious empty line within '%s'.\n" "Cannot determine what is data and what is not!\n", filenametoshow); free(chunk); return RET_ERROR; } - assert( chunk[len] == '\0' ); + assert (chunk[len] == '\0'); h = realloc(chunk, len + 1); - if( h != NULL ) + if (h != NULL) chunk = h; - if( signatures_p != NULL ) { + if (signatures_p != NULL) { /* pointer to structure with count 0 to make clear * it is not unsigned */ *signatures_p = calloc(1, sizeof(struct signatures)); - if( FAILEDTOALLOC(*signatures_p) ) { + if (FAILEDTOALLOC(*signatures_p)) { free(chunk); return RET_ERROR_OOM; } } *chunkread = chunk; - if( brokensignature != NULL ) + if (brokensignature != NULL) *brokensignature = false; return RET_OK; } @@ -852,16 +868,16 @@ retvalue signature_startsignedfile(const char *directory, const char *basefilename, const char *inlinefilename, struct signedfile **out) { struct signedfile *n; - n = calloc(1, sizeof(struct signedfile)); - if( n == NULL ) + n = zNEW(struct signedfile); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->plainfilename = calc_dirconcat(directory, basefilename); - if( n->plainfilename == NULL ) { + if (FAILEDTOALLOC(n->plainfilename)) { free(n); return RET_ERROR_OOM; } n->inlinefilename = calc_dirconcat(directory, inlinefilename); - if( n->inlinefilename == NULL ) { + if (FAILEDTOALLOC(n->inlinefilename)) { free(n->plainfilename); free(n); return RET_ERROR_OOM; @@ -870,7 +886,7 @@ n->bufferlen = 0; n->buffersize = DATABUFFERUNITS; n->buffer = malloc(n->buffersize); - if( FAILEDTOALLOC(n->buffer) ) { + if (FAILEDTOALLOC(n->buffer)) { free(n->plainfilename); free(n->inlinefilename); free(n); @@ -881,22 +897,22 @@ } void signedfile_free(struct signedfile *f, bool cleanup) { - if( f == NULL ) + if (f == NULL) return; - if( f->newplainfilename != NULL ) { - if( cleanup ) + if (f->newplainfilename != NULL) { + if (cleanup) (void)unlink(f->newplainfilename); free(f->newplainfilename); } free(f->plainfilename); - if( f->newsignfilename != NULL ) { - if( cleanup ) + if (f->newsignfilename != NULL) { + if (cleanup) (void)unlink(f->newsignfilename); free(f->newsignfilename); } free(f->signfilename); - if( f->newinlinefilename != NULL ) { - if( cleanup ) + if (f->newinlinefilename != NULL) { + if (cleanup) (void)unlink(f->newinlinefilename); free(f->newinlinefilename); } @@ -911,17 +927,17 @@ void signedfile_write(struct signedfile *f, const void *data, size_t len) { /* no need to try anything if there already was an error */ - if( RET_WAS_ERROR(f->result) ) + if (RET_WAS_ERROR(f->result)) return; - if( len > f->buffersize - f->bufferlen ) { + if (len > f->buffersize - f->bufferlen) { size_t blocks = (len + f->bufferlen)/DATABUFFERUNITS; size_t newsize = (blocks + 1) * DATABUFFERUNITS; char *newbuffer; /* realloc is wasteful, but should not happen too often */ newbuffer = realloc(f->buffer, newsize); - if( newbuffer == NULL ) { + if (FAILEDTOALLOC(newbuffer)) { free(f->buffer); f->buffer = NULL; f->result = RET_ERROR_OOM; @@ -929,32 +945,32 @@ } f->buffer = newbuffer; f->buffersize = newsize; - assert( f->bufferlen < f->buffersize ); + assert (f->bufferlen < f->buffersize); } - assert( len <= f->buffersize - f->bufferlen ); + assert (len <= f->buffersize - f->bufferlen); memcpy(f->buffer + f->bufferlen, data, len); f->bufferlen += len; - assert( f->bufferlen <= f->buffersize ); + assert (f->bufferlen <= f->buffersize); } retvalue signedfile_prepare(struct signedfile *f, const struct strlist *options, bool willcleanup) { size_t len, ofs; int fd, ret; - if( RET_WAS_ERROR(f->result) ) + if (RET_WAS_ERROR(f->result)) return f->result; /* write content to file */ f->newplainfilename = calc_addsuffix(f->plainfilename, "new"); - if( FAILEDTOALLOC(f->newplainfilename) ) + if (FAILEDTOALLOC(f->newplainfilename)) return RET_ERROR_OOM; (void)dirs_make_parent(f->newplainfilename); (void)unlink(f->newplainfilename); fd = open(f->newplainfilename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0666); - if( fd < 0 ) { + if (fd < 0) { int e = errno; fprintf(stderr, "Error creating file '%s': %s\n", f->newplainfilename, @@ -965,11 +981,11 @@ } ofs = 0; len = f->bufferlen; - while( len > 0 ) { + while (len > 0) { ssize_t written; written = write(fd, f->buffer + ofs, len); - if( written < 0 ) { + if (written < 0) { int e = errno; fprintf(stderr, "Error %d writing to file '%s': %s\n", e, f->newplainfilename, @@ -980,12 +996,12 @@ f->newplainfilename = NULL; return RET_ERRNO(e); } - assert( (size_t)written <= len ); + assert ((size_t)written <= len); ofs += written; len -= written; } ret = close(fd); - if( ret < 0 ) { + if (ret < 0) { int e = errno; fprintf(stderr, "Error %d writing to file '%s': %s\n", e, f->newplainfilename, @@ -996,18 +1012,18 @@ return RET_ERRNO(e); } /* now do the actual signing */ - if( options != NULL && options->count > 0 ) { + if (options != NULL && options->count > 0) { retvalue r; - assert( f->newplainfilename != NULL ); + assert (f->newplainfilename != NULL); f->signfilename = calc_addsuffix(f->plainfilename, "gpg"); - if( f->signfilename == NULL ) + if (FAILEDTOALLOC(f->signfilename)) return RET_ERROR_OOM; f->newsignfilename = calc_addsuffix(f->signfilename, "new"); - if( f->newsignfilename == NULL ) + if (FAILEDTOALLOC(f->newsignfilename)) return RET_ERROR_OOM; f->newinlinefilename = calc_addsuffix(f->inlinefilename, "new"); - if( FAILEDTOALLOC(f->newinlinefilename) ) + if (FAILEDTOALLOC(f->newinlinefilename)) return RET_ERROR_OOM; r = signature_sign(options, @@ -1016,7 +1032,7 @@ f->newsignfilename, f->newinlinefilename, willcleanup); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -1026,9 +1042,9 @@ retvalue result = RET_OK, r; int e; - if( f->newsignfilename != NULL && f->signfilename != NULL ) { + if (f->newsignfilename != NULL && f->signfilename != NULL) { e = rename(f->newsignfilename, f->signfilename); - if( e < 0 ) { + if (e < 0) { e = errno; fprintf(stderr, "Error %d moving %s to %s: %s!\n", e, f->newsignfilename, @@ -1036,7 +1052,7 @@ result = RET_ERRNO(e); /* after something was done, do not stop * but try to do as much as possible */ - if( !*toolate ) + if (!*toolate) return result; } else { /* does not need deletion any more */ @@ -1045,9 +1061,9 @@ *toolate = true; } } - if( f->newinlinefilename != NULL && f->inlinefilename != NULL ) { + if (f->newinlinefilename != NULL && f->inlinefilename != NULL) { e = rename(f->newinlinefilename, f->inlinefilename); - if( e < 0 ) { + if (e < 0) { e = errno; fprintf(stderr, "Error %d moving %s to %s: %s!\n", e, f->newinlinefilename, @@ -1055,7 +1071,7 @@ result = RET_ERRNO(e); /* after something was done, do not stop * but try to do as much as possible */ - if( !*toolate ) + if (!*toolate) return result; } else { /* does not need deletion any more */ @@ -1065,7 +1081,7 @@ } } e = rename(f->newplainfilename, f->plainfilename); - if( e < 0 ) { + if (e < 0) { e = errno; fprintf(stderr, "Error %d moving %s to %s: %s!\n", e, f->newplainfilename, diff -Nru reprepro-4.5.0/signature_check.c reprepro-4.6.0/signature_check.c --- reprepro-4.5.0/signature_check.c 2009-10-30 13:28:23.000000000 +0000 +++ reprepro-4.6.0/signature_check.c 2011-05-05 14:42:55.000000000 +0000 @@ -38,57 +38,57 @@ *allow_bad_p = false; *allow_subkeys_p = false; - while( *key != '\0' && xisspace(*key) ) + while (*key != '\0' && xisspace(*key)) key++; - if( *key == '\0' ) { - fprintf(stderr, "Error: unexpected end of VerifyRelease condition '%s'!\n", + if (*key == '\0') { + fprintf(stderr, +"Error: unexpected end of VerifyRelease condition '%s'!\n", full_condition); return RET_ERROR; } p = key; - while( (*p >= 'A' && *p <= 'F') - || (*p >= 'a' && *p <= 'f') - || (*p >= '0' && *p <= '9') ) + while ((*p >= 'A' && *p <= 'F') || (*p >= 'a' && *p <= 'f') + || (*p >= '0' && *p <= '9')) p++; - if( *p != '\0' && !xisspace(*p) && *p != '|' && *p != '!' && *p != '+' ) { + if (*p != '\0' && !xisspace(*p) && *p != '|' && *p != '!' && *p != '+') { fprintf(stderr, "Error: Unexpected character 0x%02hhx='%c' in VerifyRelease condition '%s'!\n", *p, *p, full_condition); return RET_ERROR; } kl = p - key; - if( kl < 8 ) { + if (kl < 8) { fprintf(stderr, "Error: Too short key id '%.*s' in VerifyRelease condition '%s'!\n", (int)kl, key, full_condition); return RET_ERROR; } next_key = strndup(key, kl); - if( FAILEDTOALLOC(next_key) ) + if (FAILEDTOALLOC(next_key)) return RET_ERROR_OOM; key = p; - for( q = next_key ; *q != '\0' ; q++ ) { - if( *q >= 'a' && *q <= 'f' ) + for (q = next_key ; *q != '\0' ; q++) { + if (*q >= 'a' && *q <= 'f') *q -= 'a' - 'A'; } - while( *key != '\0' && xisspace(*key) ) + while (*key != '\0' && xisspace(*key)) key++; - if( *key == '!' ) { + if (*key == '!') { *allow_bad_p = true; key++; } - while( *key != '\0' && xisspace(*key) ) + while (*key != '\0' && xisspace(*key)) key++; - if( *key == '+' ) { + if (*key == '+') { *allow_subkeys_p = true; key++; } - while( *key != '\0' && xisspace(*key) ) + while (*key != '\0' && xisspace(*key)) key++; - if( (*key >= 'A' && *key <= 'F') + if ((*key >= 'A' && *key <= 'F') || (*key >= 'a' && *key <= 'f') - || (*key >= '0' && *key <= '9') ) { + || (*key >= '0' && *key <= '9')) { free(next_key); fprintf(stderr, "Error: Space separated key-ids in VerifyRelease condition '%s'!\n" @@ -96,14 +96,14 @@ full_condition); return RET_ERROR; } - if( *key != '\0' && *key != '|' ) { + if (*key != '\0' && *key != '|') { free(next_key); fprintf(stderr, "Error: Unexpected character 0x%02hhx='%c' in VerifyRelease condition '%s'!\n", *key, *key, full_condition); return RET_ERROR; } - if( *key == '|' ) + if (*key == '|') key++; *next_key_p = next_key; *condition_p = key; @@ -136,30 +136,30 @@ bool allow_bad; }; -static retvalue found_key(struct known_key *k, int i, bool allow_subkeys, bool allow_bad, const char *full_condition, const struct known_key **key_found, int *index_found ) { - if( !allow_bad && k->subkeys[i].revoked ) { +static retvalue found_key(struct known_key *k, int i, bool allow_subkeys, bool allow_bad, const char *full_condition, const struct known_key **key_found, int *index_found) { + if (!allow_bad && k->subkeys[i].revoked) { fprintf(stderr, "VerifyRelease condition '%s' lists revoked key '%s'.\n" "(To use it anyway, append it with a '!' to force usage).\n", full_condition, k->subkeys[i].name); return RET_ERROR; } - if( !allow_bad && k->subkeys[i].expired ) { + if (!allow_bad && k->subkeys[i].expired) { fprintf(stderr, "VerifyRelease condition '%s' lists expired key '%s'.\n" "(To use it anyway, append it with a '!' to force usage).\n", full_condition, k->subkeys[i].name); return RET_ERROR; } - if( !allow_bad && !k->subkeys[i].cansign ) { + if (!allow_bad && !k->subkeys[i].cansign) { fprintf(stderr, "VerifyRelease condition '%s' lists non-signing key '%s'.\n" "(To use it anyway, append it with a '!' to force usage).\n", full_condition, k->subkeys[i].name); return RET_ERROR; } - if( allow_subkeys ) { - if( i != 0 ) { + if (allow_subkeys) { + if (i != 0) { fprintf(stderr, "VerifyRelease condition '%s' lists non-primary key '%s' with '+'.\n", full_condition, k->subkeys[i].name); @@ -173,7 +173,7 @@ } /* name must already be upper-case */ -static retvalue load_key(const char *name, bool allow_subkeys, bool allow_bad, const char *full_condition, const struct known_key **key_found, int *index_found ) { +static retvalue load_key(const char *name, bool allow_subkeys, bool allow_bad, const char *full_condition, const struct known_key **key_found, int *index_found) { gpg_error_t err; gpgme_key_t gpgme_key = NULL; gpgme_subkey_t subkey; @@ -183,13 +183,13 @@ size_t l = strlen(name); /* first look if this key was already retrieved: */ - for( k = known_keys ; k != NULL ; k = k->next ) { - for(i = 0 ; i < k->count ; i++ ) { + for (k = known_keys ; k != NULL ; k = k->next) { + for(i = 0 ; i < k->count ; i++) { struct known_subkey *s = &k->subkeys[i]; - if( s->name_len < l ) + if (s->name_len < l) continue; - if( memcmp(name, s->name + (s->name_len - l), l) != 0 ) + if (memcmp(name, s->name + (s->name_len - l), l) != 0) continue; return found_key(k, i, allow_subkeys, allow_bad, full_condition, @@ -198,27 +198,28 @@ } /* If not yet found, request it: */ err = gpgme_get_key(context, name, &gpgme_key, 0); - if( (gpg_err_code(err) == GPG_ERR_EOF) && gpgme_key == NULL ) { + if ((gpg_err_code(err) == GPG_ERR_EOF) && gpgme_key == NULL) { fprintf(stderr, "Error: unknown key '%s'!\n", name); return RET_ERROR_MISSING; } - if( err != 0 ) { + if (err != 0) { fprintf(stderr, "gpgme error %s:%d retrieving key '%s': %s\n", gpg_strsource(err), (int)gpg_err_code(err), - name, gpg_strerror(err)); - if( gpg_err_code(err) == GPG_ERR_ENOMEM ) + name, gpg_strerror(err)); + if (gpg_err_code(err) == GPG_ERR_ENOMEM) return RET_ERROR_OOM; else return RET_ERROR_GPGME; } i = 0; subkey = gpgme_key->subkeys; - while( subkey != NULL ) { + while (subkey != NULL) { subkey = subkey->next; i++; } - k = calloc(1, sizeof(struct known_key) + i * sizeof(struct known_subkey) ); - if( FAILEDTOALLOC(k) ) { + k = calloc(1, sizeof(struct known_key) + + i * sizeof(struct known_subkey)); + if (FAILEDTOALLOC(k)) { gpgme_key_unref(gpgme_key); return RET_ERROR_OOM; } @@ -227,30 +228,30 @@ known_keys = k; subkey = gpgme_key->subkeys; - for( i = 0 ; i < k->count ; i++ , subkey = subkey->next ) { + for (i = 0 ; i < k->count ; i++ , subkey = subkey->next) { struct known_subkey *s = &k->subkeys[i]; - assert( subkey != NULL ); + assert (subkey != NULL); s->revoked = subkey->revoked; s->expired = subkey->expired; s->cansign = subkey->can_sign && !subkey->invalid; s->name = strdup(subkey->keyid); - if( FAILEDTOALLOC(s->name) ) { + if (FAILEDTOALLOC(s->name)) { gpgme_key_unref(gpgme_key); return RET_ERROR_OOM; } - for( char *p = s->name ; *p != '\0' ; p++ ) { - if( *p >= 'a' && *p <= 'z' ) + for (char *p = s->name ; *p != '\0' ; p++) { + if (*p >= 'a' && *p <= 'z') *p -= 'a'-'A'; } s->name_len = strlen(s->name); - if( memcmp(name, s->name + (s->name_len - l), l) == 0 ) + if (memcmp(name, s->name + (s->name_len - l), l) == 0) found = i; } - assert( subkey == NULL ); + assert (subkey == NULL); gpgme_key_unref(gpgme_key); - if( found < 0 ) { + if (found < 0) { fprintf(stderr, "Error: not a valid key id '%s'!\n" "Use hex-igits from the end of the key as identifier\n", name); return RET_ERROR; @@ -262,14 +263,14 @@ static void free_known_key(/*@only@*/struct known_key *k) { int i; - for( i = 0 ; i < k->count ; i++ ) { + for (i = 0 ; i < k->count ; i++) { free(k->subkeys[i].name); } free(k); } void free_known_keys(void) { - while( known_keys != NULL ) { + while (known_keys != NULL) { struct known_key *k = known_keys; known_keys = k->next; free_known_key(k); @@ -293,7 +294,7 @@ #define sizeof_requirement(n) (sizeof(struct signature_requirement) + (n) * sizeof(struct requested_key)) void signature_requirements_free(struct signature_requirement *list) { - while( list != NULL ) { + while (list != NULL) { struct signature_requirement *p = list; list = p->next; @@ -306,7 +307,7 @@ const struct known_key *k = req->key; gpgme_signature_t sig; - for( sig = signatures ; sig != NULL ; sig = sig->next ) { + for (sig = signatures ; sig != NULL ; sig = sig->next) { const char *fpr = sig->fpr; size_t l = strlen(sig->fpr); int i; @@ -315,36 +316,36 @@ so we use this here... */ bool key_expired = false; - if( req->subkey < 0 ) { + if (req->subkey < 0) { /* any subkey is allowed */ - for(i = 0 ; i < k->count ; i++ ) { + for(i = 0 ; i < k->count ; i++) { const struct known_subkey *s = &k->subkeys[i]; - if( s->name_len > l ) + if (s->name_len > l) continue; - if( memcmp(s->name, fpr + (l - s->name_len), - s->name_len) != 0 ) + if (memcmp(s->name, fpr + (l - s->name_len), + s->name_len) != 0) continue; key_expired = k->subkeys[i].expired; break; } - if( i >= k->count ) + if (i >= k->count) continue; } else { const struct known_subkey *s; - assert( req->subkey < k->count ); - s = &k->subkeys[req->subkey]; - if( memcmp(s->name, fpr + (l - s->name_len), - s->name_len) != 0 ) + assert (req->subkey < k->count); + s = &k->subkeys[req->subkey]; + if (memcmp(s->name, fpr + (l - s->name_len), + s->name_len) != 0) continue; key_expired = k->subkeys[req->subkey].expired; } /* only accept perfectly good signatures and silently ignore everything else. Those are warned about or even accepted in the run with key_good_enough */ - if( gpg_err_code(sig->status) == GPG_ERR_NO_ERROR - && !key_expired ) + if (gpg_err_code(sig->status) == GPG_ERR_NO_ERROR + && !key_expired) return true; /* we have to continue otherwise, as another subkey might still follow */ @@ -358,46 +359,47 @@ const struct known_key *k = req->key; gpgme_signature_t sig; - for( sig = signatures ; sig != NULL ; sig = sig->next ) { + for (sig = signatures ; sig != NULL ; sig = sig->next) { const char *fpr = sig->fpr; size_t l = strlen(sig->fpr); int i; bool key_expired = false; /* dito */ - if( req->subkey < 0 ) { + if (req->subkey < 0) { /* any subkey is allowed */ - for(i = 0 ; i < k->count ; i++ ) { + for(i = 0 ; i < k->count ; i++) { const struct known_subkey *s = &k->subkeys[i]; - if( s->name_len > l ) + if (s->name_len > l) continue; - if( memcmp(s->name, fpr + (l - s->name_len), - s->name_len) != 0 ) + if (memcmp(s->name, fpr + (l - s->name_len), + s->name_len) != 0) continue; key_expired = k->subkeys[i].expired; break; } - if( i >= k->count ) + if (i >= k->count) continue; } else { const struct known_subkey *s; - assert( req->subkey < k->count ); - s = &k->subkeys[req->subkey]; - if( memcmp(s->name, fpr + (l - s->name_len), - s->name_len) != 0 ) + assert (req->subkey < k->count); + s = &k->subkeys[req->subkey]; + if (memcmp(s->name, fpr + (l - s->name_len), + s->name_len) != 0) continue; key_expired = k->subkeys[req->subkey].expired; } /* this key we look for. if it is acceptable, we are finished. if it is not acceptable, we still have to look at the other - signatures, as a signature with another subkey is following */ - switch( gpg_err_code(sig->status) ) { + signatures, as a signature with another subkey is following + */ + switch (gpg_err_code(sig->status)) { case GPG_ERR_NO_ERROR: - if( ! key_expired ) + if (! key_expired) return true; - if( req->allow_bad && IGNORABLE(expiredkey) ) { - if( verbose >= 0 ) + if (req->allow_bad && IGNORABLE(expiredkey)) { + if (verbose >= 0) fprintf(stderr, "WARNING: valid signature in '%s' with parent-expired '%s' is accepted as requested!\n", releasegpg, fpr); @@ -405,14 +407,14 @@ } fprintf(stderr, "Not accepting valid signature in '%s' with parent-EXPIRED '%s'\n", releasegpg, fpr); - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "(To ignore it append a ! to the key and run reprepro with --ignore=expiredkey)\n"); /* not accepted */ continue; case GPG_ERR_KEY_EXPIRED: - if( req->allow_bad && IGNORABLE(expiredkey) ) { - if( verbose >= 0 ) + if (req->allow_bad && IGNORABLE(expiredkey)) { + if (verbose >= 0) fprintf(stderr, "WARNING: valid signature in '%s' with expired '%s' is accepted as requested!\n", releasegpg, fpr); @@ -420,14 +422,14 @@ } fprintf(stderr, "Not accepting valid signature in '%s' with EXPIRED '%s'\n", releasegpg, fpr); - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "(To ignore it append a ! to the key and run reprepro with --ignore=expiredkey)\n"); /* not accepted */ continue; case GPG_ERR_CERT_REVOKED: - if( req->allow_bad && IGNORABLE(revokedkey) ) { - if( verbose >= 0 ) + if (req->allow_bad && IGNORABLE(revokedkey)) { + if (verbose >= 0) fprintf(stderr, "WARNING: valid signature in '%s' with revoked '%s' is accepted as requested!\n", releasegpg, fpr); @@ -435,14 +437,14 @@ } fprintf(stderr, "Not accepting valid signature in '%s' with REVOKED '%s'\n", releasegpg, fpr); - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "(To ignore it append a ! to the key and run reprepro with --ignore=revokedkey)\n"); /* not accepted */ continue; case GPG_ERR_SIG_EXPIRED: - if( req->allow_bad && IGNORABLE(expiredsignature) ) { - if( verbose >= 0 ) + if (req->allow_bad && IGNORABLE(expiredsignature)) { + if (verbose >= 0) fprintf(stderr, "WARNING: valid but expired signature in '%s' with '%s' is accepted as requested!\n", releasegpg, fpr); @@ -450,7 +452,7 @@ } fprintf(stderr, "Not accepting valid but EXPIRED signature in '%s' with '%s'\n", releasegpg, fpr); - if( verbose >= 0 ) + if (verbose >= 0) fprintf(stderr, "(To ignore it append a ! to the key and run reprepro with --ignore=expiredsignature)\n"); /* not accepted */ @@ -487,24 +489,24 @@ retvalue r; r = signature_init(false); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( condition == NULL || strcmp(condition, "blindtrust") == 0 ) + if (condition == NULL || strcmp(condition, "blindtrust") == 0) return RET_NOTHING; /* no need to add the same condition multiple times */ - for( req = *list_p ; req != NULL ; req = req->next ) { - if( strcmp(req->condition, condition) == 0 ) + for (req = *list_p ; req != NULL ; req = req->next) { + if (strcmp(req->condition, condition) == 0) return RET_NOTHING; } req = malloc(sizeof_requirement(1)); - if( FAILEDTOALLOC(req) ) + if (FAILEDTOALLOC(req)) return RET_ERROR_OOM; req->next = NULL; req->condition = strdup(condition); - if( FAILEDTOALLOC(req->condition) ) { + if (FAILEDTOALLOC(req->condition)) { free(req); return RET_ERROR_OOM; } @@ -516,7 +518,7 @@ r = parse_condition_part(&allow_subkeys, &allow_bad, full_condition, &condition, &next_key); ASSERT_NOT_NOTHING(r); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { signature_requirements_free(req); return r; } @@ -526,24 +528,24 @@ &req->keys[req->num_keys].key, &req->keys[req->num_keys].subkey); free(next_key); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { signature_requirements_free(req); return r; } req->num_keys++; - if( *condition != '\0' ) { + if (*condition != '\0') { struct signature_requirement *h; h = realloc(req, sizeof_requirement(req->num_keys+1)); - if( FAILEDTOALLOC(h) ) { + if (FAILEDTOALLOC(h)) { signature_requirements_free(req); return r; } req = h; } else break; - } while( true ); + } while (true); req->next = *list_p; *list_p = req; return RET_OK; @@ -554,7 +556,7 @@ struct tm *tm; time_t t; - if( s == NULL ) { + if (s == NULL) { fprintf(f, "gpgme reported no signatures in '%s':\n" "Either there are really none or something else is strange.\n" "One known reason for this effect is forgeting -b when signing.\n", @@ -563,11 +565,11 @@ } fprintf(f, "Signatures in '%s':\n", releasegpg); - for( ; s != NULL ; s = s->next ) { + for (; s != NULL ; s = s->next) { t = s->timestamp; tm = localtime(&t); strftime(timebuffer, 19, "%Y-%m-%d", tm); fprintf(f, "'%s' (signed %s): ", s->fpr, timebuffer); - switch( gpg_err_code(s->status) ) { + switch (gpg_err_code(s->status)) { case GPG_ERR_NO_ERROR: fprintf(f, "valid\n"); continue; @@ -605,35 +607,37 @@ int i; const struct signature_requirement *req; - assert( requirements != NULL ); + assert (requirements != NULL); - if( release == NULL || releasegpg == NULL ) + if (FAILEDTOALLOC(release) || FAILEDTOALLOC(releasegpg)) return RET_ERROR_OOM; - assert( context != NULL ); + assert (context != NULL); /* Read the file and its signature into memory: */ gpgfd = open(releasegpg, O_RDONLY|O_NOCTTY); - if( gpgfd < 0 ) { + if (gpgfd < 0) { int e = errno; - fprintf(stderr, "Error opening '%s': %s\n", releasegpg, strerror(e)); + fprintf(stderr, "Error opening '%s': %s\n", + releasegpg, strerror(e)); return RET_ERRNO(e); } fd = open(release, O_RDONLY|O_NOCTTY); - if( fd < 0 ) { + if (fd < 0) { int e = errno; (void)close(gpgfd); - fprintf(stderr, "Error opening '%s': %s\n", release, strerror(e)); + fprintf(stderr, "Error opening '%s': %s\n", + release, strerror(e)); return RET_ERRNO(e); } err = gpgme_data_new_from_fd(&dh_gpg, gpgfd); - if( err != 0 ) { + if (err != 0) { (void)close(gpgfd); (void)close(fd); fprintf(stderr, "Error reading '%s':\n", releasegpg); return gpgerror(err); } err = gpgme_data_new_from_fd(&dh, fd); - if( err != 0 ) { + if (err != 0) { gpgme_data_release(dh_gpg); (void)close(gpgfd); (void)close(fd); fprintf(stderr, "Error reading '%s':\n", release); @@ -645,61 +649,64 @@ err = gpgme_op_verify(context, dh_gpg, dh, NULL); gpgme_data_release(dh_gpg); gpgme_data_release(dh); - close(gpgfd);close(fd); - if( err != 0 ) { + close(gpgfd); close(fd); + if (err != 0) { fprintf(stderr, "Error verifying '%s':\n", releasegpg); return gpgerror(err); } result = gpgme_op_verify_result(context); - if( result == NULL ) { - fprintf(stderr, "Internal error communicating with libgpgme: no result record!\n\n"); + if (result == NULL) { + fprintf(stderr, +"Internal error communicating with libgpgme: no result record!\n\n"); return RET_ERROR_GPGME; } - for( req = requirements ; req != NULL ; req = req->next ) { + for (req = requirements ; req != NULL ; req = req->next) { bool fullfilled = false; /* check first for good signatures, and then for good enough signatures, to not pester the user with warnings of one of the alternate keys, if the last one is good enough */ - for( i = 0 ; (size_t)i < req->num_keys ; i++ ) { + for (i = 0 ; (size_t)i < req->num_keys ; i++) { - if( key_good(&req->keys[i], result->signatures) ) { + if (key_good(&req->keys[i], result->signatures)) { fullfilled = true; break; } } - for( i = 0 ; !fullfilled && (size_t)i < req->num_keys ; i++ ) { + for (i = 0 ; !fullfilled && (size_t)i < req->num_keys ; i++) { - if( key_good_enough(&req->keys[i], result->signatures, - releasegpg, release) ) { + if (key_good_enough(&req->keys[i], result->signatures, + releasegpg, release)) { fullfilled = true; break; } } - if( !fullfilled ) { - fprintf(stderr, "ERROR: Condition '%s' not fullfilled for '%s'.\n", + if (!fullfilled) { + fprintf(stderr, +"ERROR: Condition '%s' not fullfilled for '%s'.\n", req->condition, releasegpg); - print_signatures(stderr, result->signatures, releasegpg); + print_signatures(stderr, result->signatures, + releasegpg); return RET_ERROR_BADSIG; } - if( verbose > 10 ) { + if (verbose > 10) { fprintf(stdout, "Condition '%s' fullfilled for '%s'.\n", req->condition, releasegpg); } } - if( verbose > 20 ) + if (verbose > 20) print_signatures(stdout, result->signatures, releasegpg); return RET_OK; } #else /* HAVE_LIBGPGME */ retvalue signature_check(const struct signature_requirement *requirements, const char *releasegpg, const char *release) { - assert( requirements != NULL ); + assert (requirements != NULL); - if( release == NULL || releasegpg == NULL ) + if (FAILEDTOALLOC(release) || FAILEDTOALLOC(releasegpg)) return RET_ERROR_OOM; fprintf(stderr, "ERROR: Cannot check signatures as this reprepro binary is compiled with support\n" diff -Nru reprepro-4.5.0/signature.h reprepro-4.6.0/signature.h --- reprepro-4.5.0/signature.h 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/signature.h 2011-05-05 14:42:55.000000000 +0000 @@ -27,13 +27,19 @@ all may be false due to non-signing keys used for signing or things like that */ enum signature_state { - sist_error=0, /* internal error */ - sist_missing, /* key missing, can not be checked */ - sist_bad, /* broken signature, content may be corrupt */ - sist_invalid, /* good signature, but may not sign or al */ - sist_mostly, /* good signature, but check expire bits */ - sist_valid /* good signature, no objections */ - } state; + /* internal error: */ + sist_error=0, + /* key missing, can not be checked: */ + sist_missing, + /* broken signature, content may be corrupt: */ + sist_bad, + /* good signature, but may not sign or al: */ + sist_invalid, + /* good signature, but check expire bits: */ + sist_mostly, + /* good signature, no objections: */ + sist_valid + } state; /* subkey or primary key are expired */ bool expired_key; /* signature is expired */ diff -Nru reprepro-4.5.0/sizes.c reprepro-4.6.0/sizes.c --- reprepro-4.5.0/sizes.c 2011-01-30 15:43:05.000000000 +0000 +++ reprepro-4.6.0/sizes.c 2011-05-05 14:42:55.000000000 +0000 @@ -64,18 +64,18 @@ return memcmp(data, dist->codename, dist->codename_len) == 0; } -static retvalue count_sizes(struct database *database, struct cursor *cursor, bool specific, struct distribution_sizes *ds, unsigned long long *all_p, unsigned long long *onlyall_p) { +static retvalue count_sizes(struct cursor *cursor, bool specific, struct distribution_sizes *ds, unsigned long long *all_p, unsigned long long *onlyall_p) { const char *key, *data; size_t len; char *last_file = NULL; unsigned long long filesize = 0; - bool usedotherwise = false, onlyone = true; + bool onlyone = true; struct distribution_sizes *last_dist; struct distribution_sizes *s; bool snapshot; unsigned long long all = 0, onlyall = 0; - while (cursor_nexttempdata(database->references, cursor, + while (cursor_nexttempdata(rdb_references, cursor, &key, &data, &len)) { if (last_file == NULL || strcmp(last_file, key) != 0) { if (last_file != NULL) { @@ -90,7 +90,6 @@ return RET_ERROR_OOM; onlyone = true; filesize = 0; - usedotherwise = false; last_dist = NULL; } if (data[0] == 'u' && data[1] == '|') { @@ -128,13 +127,14 @@ const char *p; p = data; - while (*p != '\0' && *p != ' ' && *p != '|' && *p != '=') + while (*p != '\0' && *p != ' ' && *p != '|' + && *p != '=') p++; if (*p == '\0') continue; while (*s_p != NULL) s_p = &(*s_p)->next; - s = calloc(1, sizeof(struct distribution_sizes)); + s = zNEW(struct distribution_sizes); if (FAILEDTOALLOC(s)) { free(last_file); return RET_ERROR_OOM; @@ -176,8 +176,9 @@ } assert (filesize != 0); } else { - /* and this is the first time we are interested in the file */ - filesize = files_getsize(database, key); + /* and this is the first time + * we are interested in the file */ + filesize = files_getsize(key); assert (filesize != 0); if (onlyone) onlyall += filesize; @@ -202,7 +203,7 @@ return RET_OK; } -retvalue sizes_distributions(struct database *database, struct distribution *alldistributions, bool specific) { +retvalue sizes_distributions(struct distribution *alldistributions, bool specific) { struct cursor *cursor; retvalue result, r; struct distribution_sizes *ds = NULL, **lds = &ds, *s; @@ -212,7 +213,7 @@ for (d = alldistributions ; d != NULL ; d = d->next) { if (!d->selected) continue; - s = calloc(1, sizeof(struct distribution_sizes)); + s = zNEW(struct distribution_sizes); if (FAILEDTOALLOC(s)) { distribution_sizes_freelist(ds); return RET_ERROR_OOM; @@ -224,16 +225,18 @@ } if (ds == NULL) return RET_NOTHING; - r = table_newglobalcursor(database->references, &cursor); + r = table_newglobalcursor(rdb_references, &cursor); if (!RET_IS_OK(r)) { distribution_sizes_freelist(ds); return r; } - result = count_sizes(database, cursor, specific, ds, &all, &onlyall); - r = cursor_close(database->references, cursor); + result = count_sizes(cursor, specific, ds, &all, &onlyall); + r = cursor_close(rdb_references, cursor); RET_ENDUPDATE(result, r); if (RET_IS_OK(result)) { - printf("%-15s %13s %13s %13s %13s\n", "Codename", "Size", "Only", "Size(+s)", "Only(+s)"); + printf("%-15s %13s %13s %13s %13s\n", + "Codename", "Size", "Only", "Size(+s)", + "Only(+s)"); for (s = ds ; s != NULL ; s = s->next) { printf("%-15s %13llu %13llu %13llu %13llu\n", s->codename, diff -Nru reprepro-4.5.0/sizes.h reprepro-4.6.0/sizes.h --- reprepro-4.5.0/sizes.h 2011-01-30 15:43:11.000000000 +0000 +++ reprepro-4.6.0/sizes.h 2011-05-05 14:42:55.000000000 +0000 @@ -1,6 +1,6 @@ #ifndef REPREPRO_SIZES_H #define REPREPRO_SIZES_H -retvalue sizes_distributions(struct database *, struct distribution * /*all*/, bool /* specific */); +retvalue sizes_distributions(struct distribution * /*all*/, bool /* specific */); #endif diff -Nru reprepro-4.5.0/sourcecheck.c reprepro-4.6.0/sourcecheck.c --- reprepro-4.5.0/sourcecheck.c 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/sourcecheck.c 2011-05-05 14:42:55.000000000 +0000 @@ -66,7 +66,7 @@ } } -static retvalue collect_source_versions(struct database *database, struct distribution *d, struct info_source **out) { +static retvalue collect_source_versions(struct distribution *d, struct info_source **out) { struct info_source *root = NULL, *last = NULL; struct target *t; struct target_cursor target_cursor = TARGET_CURSOR_ZERO; @@ -74,9 +74,9 @@ retvalue result = RET_NOTHING, r; for (t = d->targets ; t != NULL ; t = t->next) { - if (t->architecture_atom != architecture_source) + if (t->architecture != architecture_source) continue; - r = target_openiterator(t, database, true, &target_cursor); + r = target_openiterator(t, true, &target_cursor); if (RET_WAS_ERROR(r)) { RET_UPDATE(result, r); break; @@ -126,7 +126,7 @@ } } if (into != NULL) { - last = calloc(1, sizeof(struct info_source)); + last = zNEW(struct info_source); if (FAILEDTOALLOC(last)) { free(version); result = RET_ERROR_OOM; @@ -146,12 +146,12 @@ continue; } assert (last != NULL); - assert (strcmp(name,last->name)==0); + assert (strcmp(name, last->name)==0); v = &last->version; while (strcmp(v->version, version) != 0) { if (v->next == NULL) { - v->next = calloc(1, sizeof(struct info_source_version)); + v->next = zNEW(struct info_source_version); if (FAILEDTOALLOC(v->next)) { free(version); result = RET_ERROR_OOM; @@ -182,16 +182,16 @@ return result; } -static retvalue process_binaries(struct database *db, struct distribution *d, struct info_source *sources, retvalue (*action)(struct distribution *, struct target *,const char *, const char *, const char *, const char *, void *), void *privdata) { +static retvalue process_binaries(struct distribution *d, struct info_source *sources, retvalue (*action)(struct distribution *, struct target *, const char *, const char *, const char *, const char *, void *), void *privdata) { struct target *t; struct target_cursor target_cursor = TARGET_CURSOR_ZERO; const char *name, *chunk; retvalue result = RET_NOTHING, r; for (t = d->targets ; t != NULL ; t = t->next) { - if (t->architecture_atom == architecture_source) + if (t->architecture == architecture_source) continue; - r = target_openiterator(t, db, true, &target_cursor); + r = target_openiterator(t, true, &target_cursor); if (RET_WAS_ERROR(r)) { RET_UPDATE(result, r); break; @@ -208,10 +208,10 @@ continue; } s = sources; - while (s != NULL && strcmp(source, s->name) < 0) { + while (s != NULL && strcmp(s->name, source) < 0) { s = s->next; } - if (strcmp(source, s->name) == 0) { + if (s != NULL && strcmp(source, s->name) == 0) { v = &s->version; while (v != NULL && strcmp(version, v->version) != 0) v = v->next; @@ -240,36 +240,37 @@ bool hasbinary = false, hassource = false; int i; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( pkg->refcounts[i] == 0 ) + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (pkg->refcounts[i] == 0) continue; - if( pkg->filetypes[i] == 's' ) + if (pkg->filetypes[i] == 's') hassource = true; - if( pkg->filetypes[i] == 'b' ) + if (pkg->filetypes[i] == 'b') hasbinary = true; - if( pkg->filetypes[i] == 'a' ) + if (pkg->filetypes[i] == 'a') hasbinary = true; } - if( hassource && ! hasbinary ) { - printf("%s %s %s\n", d->codename, pkg->sourcename, pkg->sourceversion); + if (hassource && ! hasbinary) { + printf("%s %s %s\n", d->codename, pkg->sourcename, + pkg->sourceversion); return RET_OK; } return RET_NOTHING; } -retvalue unusedsources(struct database *database, struct distribution *alldistributions) { +retvalue unusedsources(struct distribution *alldistributions) { struct distribution *d; retvalue result = RET_NOTHING, r; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( !atomlist_in(&d->architectures, architecture_source) ) + if (!atomlist_in(&d->architectures, architecture_source)) continue; - if( d->tracking != dt_NONE ) { - r = tracking_foreach_ro(database, d, listunusedsources); + if (d->tracking != dt_NONE) { + r = tracking_foreach_ro(d, listunusedsources); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; continue; } @@ -277,11 +278,11 @@ const struct info_source *s; const struct info_source_version *v; - r = collect_source_versions(database, d, &sources); + r = collect_source_versions(d, &sources); if (!RET_IS_OK(r)) continue; - r = process_binaries(database, d, sources, NULL, NULL); + r = process_binaries(d, sources, NULL, NULL); RET_UPDATE(result, r); for (s = sources ; s != NULL ; s = s->next) { for (v = &s->version ; v != NULL ; v = v->next) { @@ -300,23 +301,25 @@ bool hasbinary = false, hassource = false; int i; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( pkg->refcounts[i] == 0 ) + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (pkg->refcounts[i] == 0) continue; - if( pkg->filetypes[i] == 's' ) + if (pkg->filetypes[i] == 's') hassource = true; - if( pkg->filetypes[i] == 'b' ) + if (pkg->filetypes[i] == 'b') hasbinary = true; - if( pkg->filetypes[i] == 'a' ) + if (pkg->filetypes[i] == 'a') hasbinary = true; } - if( hasbinary && ! hassource ) { - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( pkg->refcounts[i] == 0 ) + if (hasbinary && ! hassource) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (pkg->refcounts[i] == 0) continue; - if( pkg->filetypes[i] != 'b' && pkg->filetypes[i] != 'a' ) + if (pkg->filetypes[i] != 'b' && pkg->filetypes[i] != 'a') continue; - printf("%s %s %s %s\n", d->codename, pkg->sourcename, pkg->sourceversion, pkg->filekeys.values[i]); + printf("%s %s %s %s\n", d->codename, pkg->sourcename, + pkg->sourceversion, + pkg->filekeys.values[i]); } return RET_OK; } @@ -336,34 +339,33 @@ return RET_OK; } -retvalue sourcemissing(struct database *database, struct distribution *alldistributions) { +retvalue sourcemissing(struct distribution *alldistributions) { struct distribution *d; retvalue result = RET_NOTHING, r; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( !atomlist_in(&d->architectures, architecture_source) ) { - if( verbose >= 0 ) + if (!atomlist_in(&d->architectures, architecture_source)) { + if (verbose >= 0) fprintf(stderr, "Not processing distribution '%s', as it has no source packages.\n", d->codename); continue; } - if( d->tracking != dt_NONE ) { - r = tracking_foreach_ro(database, d, listsourcemissing); + if (d->tracking != dt_NONE) { + r = tracking_foreach_ro(d, listsourcemissing); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } else { struct info_source *sources = NULL; - r = collect_source_versions(database, d, &sources); + r = collect_source_versions(d, &sources); if (!RET_IS_OK(r)) continue; - r = process_binaries(database, d, sources, - listmissing, NULL); + r = process_binaries(d, sources, listmissing, NULL); RET_UPDATE(result, r); free_source_info(sources); } @@ -376,21 +378,23 @@ bool hasbinary = false, hassource = false; int i; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( pkg->refcounts[i] == 0 ) + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (pkg->refcounts[i] == 0) continue; - if( pkg->filetypes[i] == 's' ) + if (pkg->filetypes[i] == 's') hassource = true; - if( pkg->filetypes[i] == 'b' ) + if (pkg->filetypes[i] == 'b') hasbinary = true; - if( pkg->filetypes[i] == 'a' ) + if (pkg->filetypes[i] == 'a') hasbinary = true; } - if( hasbinary && ! hassource ) { - printf("binaries-without-source %s %s %s\n", d->codename, pkg->sourcename, pkg->sourceversion); + if (hasbinary && ! hassource) { + printf("binaries-without-source %s %s %s\n", d->codename, + pkg->sourcename, pkg->sourceversion); return RET_OK; - } else if( hassource && ! hasbinary ) { - printf("source-without-binaries %s %s %s\n", d->codename, pkg->sourcename, pkg->sourceversion); + } else if (hassource && ! hasbinary) { + printf("source-without-binaries %s %s %s\n", d->codename, + pkg->sourcename, pkg->sourceversion); return RET_OK; } return RET_NOTHING; @@ -407,7 +411,7 @@ continue; return RET_NOTHING; } - s = calloc(1, sizeof(struct info_source)); + s = zNEW(struct info_source); if (FAILEDTOALLOC(s)) return RET_ERROR_OOM; s->name = strdup(source); @@ -425,24 +429,24 @@ return RET_OK; } -retvalue reportcruft(struct database *database, struct distribution *alldistributions) { +retvalue reportcruft(struct distribution *alldistributions) { struct distribution *d; retvalue result = RET_NOTHING, r; - for( d = alldistributions ; d != NULL ; d = d->next ) { - if( !d->selected ) + for (d = alldistributions ; d != NULL ; d = d->next) { + if (!d->selected) continue; - if( !atomlist_in(&d->architectures, architecture_source) ) { - if( verbose >= 0 ) + if (!atomlist_in(&d->architectures, architecture_source)) { + if (verbose >= 0) fprintf(stderr, "Not processing distribution '%s', as it has no source packages.\n", d->codename); continue; } - if( d->tracking != dt_NONE ) { - r = tracking_foreach_ro(database, d, listcruft); + if (d->tracking != dt_NONE) { + r = tracking_foreach_ro(d, listcruft); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; continue; } @@ -451,11 +455,11 @@ const struct info_source *s; const struct info_source_version *v; - r = collect_source_versions(database, d, &sources); + r = collect_source_versions( d, &sources); if (!RET_IS_OK(r)) continue; - r = process_binaries(database, d, sources, + r = process_binaries( d, sources, listmissingonce, &list); RET_UPDATE(result, r); for (s = sources ; s != NULL ; s = s->next) { @@ -463,7 +467,7 @@ if (v->used) continue; printf("source-without-binaries %s %s %s\n", - d->codename, s->name, v->version); + d->codename, s->name, v->version); } } free_source_info(list); diff -Nru reprepro-4.5.0/sourcecheck.h reprepro-4.6.0/sourcecheck.h --- reprepro-4.5.0/sourcecheck.h 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/sourcecheck.h 2011-05-05 14:42:55.000000000 +0000 @@ -1,8 +1,8 @@ #ifndef REPREPRO_SOURCECHECK_H #define REPREPRO_SOURCECHECK_H -retvalue unusedsources(struct database *, struct distribution *); -retvalue sourcemissing(struct database *, struct distribution *); -retvalue reportcruft(struct database *, struct distribution *); +retvalue unusedsources(struct distribution *); +retvalue sourcemissing(struct distribution *); +retvalue reportcruft(struct distribution *); #endif diff -Nru reprepro-4.5.0/sourceextraction.c reprepro-4.6.0/sourceextraction.c --- reprepro-4.5.0/sourceextraction.c 2010-02-16 15:29:07.000000000 +0000 +++ reprepro-4.6.0/sourceextraction.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,8 +43,8 @@ struct sourceextraction *sourceextraction_init(char **section_p, char **priority_p) { struct sourceextraction *n; - n = calloc(1, sizeof(struct sourceextraction)); - if( FAILEDTOALLOC(n) ) + n = zNEW(struct sourceextraction); + if (FAILEDTOALLOC(n)) return n; n->difffile = -1; n->tarfile = -1; @@ -59,29 +59,29 @@ } /* with must be a string constant, no pointer! */ -#define endswith(name, len, with) (len >= sizeof(with) && memcmp(name+(len+1-sizeof(with)), with, sizeof(with)-1) == 0 ) +#define endswith(name, len, with) (len >= sizeof(with) && memcmp(name+(len+1-sizeof(with)), with, sizeof(with)-1) == 0) /* register a file part of this source */ void sourceextraction_setpart(struct sourceextraction *e, int i, const char *basefilename) { size_t bl = strlen(basefilename); enum compression c; - if( e->failed ) + if (e->failed) return; c = compression_by_suffix(basefilename, &bl); - if( endswith(basefilename, bl, ".dsc" ) ) + if (endswith(basefilename, bl, ".dsc")) return; - else if( endswith(basefilename, bl, ".diff" ) ) { + else if (endswith(basefilename, bl, ".diff")) { e->difffile = i; e->diffcompression = c; return; - } else if( endswith(basefilename, bl, ".debian.tar" ) ) { + } else if (endswith(basefilename, bl, ".debian.tar")) { e->debiantarfile = i; e->debiancompression = c; return; - } else if( endswith(basefilename, bl, ".tar" ) ) { + } else if (endswith(basefilename, bl, ".tar")) { e->tarfile = i; e->tarcompression = c; return; @@ -93,26 +93,26 @@ /* return the next needed file */ bool sourceextraction_needs(struct sourceextraction *e, int *ofs_p) { - if( e->failed || e->completed ) + if (e->failed || e->completed) return false; - if( e->difffile >= 0 ) { - if( !uncompression_supported(e->diffcompression) ) + if (e->difffile >= 0) { + if (!uncompression_supported(e->diffcompression)) // TODO: errormessage return false; *ofs_p = e->difffile; return true; - } else if( e->debiantarfile >= 0 ) { + } else if (e->debiantarfile >= 0) { #ifdef HAVE_LIBARCHIVE - if( !uncompression_supported(e->debiancompression) ) + if (!uncompression_supported(e->debiancompression)) return false; *ofs_p = e->debiantarfile; return true; #else return false; #endif - } else if( e->tarfile >= 0 ) { + } else if (e->tarfile >= 0) { #ifdef HAVE_LIBARCHIVE - if( !uncompression_supported(e->tarcompression) ) + if (!uncompression_supported(e->tarcompression)) return false; *ofs_p = e->tarfile; return true; @@ -133,59 +133,60 @@ auto inline bool u_getline(void); inline bool u_getline(void) { do { - if( filled - used > 0 ) { + if (filled - used > 0) { char *n; p = buffer + used; n = memchr(p, '\n', filled - used); - if( n != NULL ) { + if (n != NULL) { used += 1 + (n - p); *n = '\0'; - while( --n >= p && *n == '\r' ) + while (--n >= p && *n == '\r') *n = '\0'; return true; } - } else { assert( filled == used ); + } else { assert (filled == used); filled = 0; used = 0; } - if( filled == BUFSIZE ) { - if( used == 0 ) + if (filled == BUFSIZE) { + if (used == 0) /* overlong line */ return false; memmove(buffer, buffer + used, filled - used); filled -= used; used = 0; } - bytes_read = uncompress_read(f, buffer + filled, BUFSIZE - filled); - if( bytes_read <= 0 ) + bytes_read = uncompress_read(f, buffer + filled, + BUFSIZE - filled); + if (bytes_read <= 0) return false; filled += bytes_read; - } while( true ); + } while (true); } auto inline char u_overlinegetchar(void); inline char u_overlinegetchar(void) { const char *n; char ch; - if( filled - used > 0 ) { + if (filled - used > 0) { ch = buffer[used]; - } else { assert( filled == used ); + } else { assert (filled == used); used = 0; bytes_read = uncompress_read(f, buffer, BUFSIZE); - if( bytes_read <= 0 ) { + if (bytes_read <= 0) { filled = 0; return '\0'; } filled = bytes_read; ch = buffer[0]; } - if( ch == '\n' ) + if (ch == '\n') return '\0'; /* over rest of the line */ n = memchr(buffer + used, '\n', filled - used); - if( n != NULL ) { + if (n != NULL) { used = 1 + (n - buffer); return ch; } @@ -194,10 +195,10 @@ /* need to read more to get to the end of the line */ do { /* these lines can be long */ bytes_read = uncompress_read(f, buffer, BUFSIZE); - if( bytes_read <= 0 ) + if (bytes_read <= 0) return false; n = memchr(buffer, '\n', bytes_read); - } while( n == NULL ); + } while (n == NULL); used = 1 + (n - buffer); filled = bytes_read; return ch; @@ -205,102 +206,102 @@ /* we are assuming the exact format dpkg-source generates here... */ - if( !u_getline() ) { + if (!u_getline()) { /* empty or strange file */ *found_p = false; return RET_OK; } - if( memcmp(p, "diff ", 4) == 0 ) { + if (memcmp(p, "diff ", 4) == 0) { /* one exception is allowing diff lines, * as diff -ru adds them ... */ - if( !u_getline() ) { + if (!u_getline()) { /* strange file */ *found_p = false; return RET_OK; } } - if( unlikely(memcmp(p, "--- ", 4) != 0) ) + if (unlikely(memcmp(p, "--- ", 4) != 0)) return RET_NOTHING; - if( !u_getline() ) + if (!u_getline()) /* so short a file? */ return RET_NOTHING; - if( unlikely(memcmp(p, "+++ ", 4) != 0) ) + if (unlikely(memcmp(p, "+++ ", 4) != 0)) return RET_NOTHING; p += 4; s = strchr(p, '/'); - if( unlikely(s == NULL) ) + if (unlikely(s == NULL)) return RET_NOTHING; s++; /* another exception to allow diff output directly: * +++ lines might have garbage after a tab... */ garbage = strchr(s, '\t'); - if( garbage != NULL ) + if (garbage != NULL) *garbage = '\0'; destlength = s - p; /* ignore all files that are not x/debian/control */ - while( strcmp(s, "debian/control") != 0 ) { - if( unlikely(interrupted()) ) + while (strcmp(s, "debian/control") != 0) { + if (unlikely(interrupted())) return RET_ERROR_INTERRUPTED; - if( !u_getline() ) + if (!u_getline()) return RET_NOTHING; - while( memcmp(p, "@@ -", 4) == 0) { - if( unlikely(interrupted()) ) + while (memcmp(p, "@@ -", 4) == 0) { + if (unlikely(interrupted())) return RET_ERROR_INTERRUPTED; p += 4; - while( *p != ',' && *p != ' ' ) { - if( unlikely(*p == '\0') ) + while (*p != ',' && *p != ' ') { + if (unlikely(*p == '\0')) return RET_NOTHING; p++; } - if( *p == ' ' ) + if (*p == ' ') lines_in = 1; else { p++; lines_in = 0; - while( *p >= '0' && *p <= '9' ) { + while (*p >= '0' && *p <= '9') { lines_in = 10*lines_in + (*p-'0'); p++; } } - while( *p == ' ' ) + while (*p == ' ') p++; - if( unlikely(*(p++) != '+') ) + if (unlikely(*(p++) != '+')) return RET_NOTHING; - while( *p >= '0' && *p <= '9' ) + while (*p >= '0' && *p <= '9') p++; - if( *p == ',' ) { + if (*p == ',') { p++; lines_out = 0; - while( *p >= '0' && *p <= '9' ) { + while (*p >= '0' && *p <= '9') { lines_out = 10*lines_out + (*p-'0'); p++; } - } else if( *p == ' ' ) + } else if (*p == ' ') lines_out = 1; else return RET_NOTHING; - while( *p == ' ' ) + while (*p == ' ') p++; - if( unlikely(*p != '@') ) + if (unlikely(*p != '@')) return RET_NOTHING; - while( lines_in > 0 || lines_out > 0 ) { + while (lines_in > 0 || lines_out > 0) { char ch; ch = u_overlinegetchar(); - switch( ch ) { + switch (ch) { case '+': - if( unlikely(lines_out == 0) ) + if (unlikely(lines_out == 0)) return RET_NOTHING; lines_out--; break; case ' ': - if( unlikely(lines_out == 0) ) + if (unlikely(lines_out == 0)) return RET_NOTHING; lines_out--; /* no break */ case '-': - if( unlikely(lines_in == 0) ) + if (unlikely(lines_in == 0)) return RET_NOTHING; lines_in--; break; @@ -308,135 +309,135 @@ return RET_NOTHING; } } - if( !u_getline() ) { + if (!u_getline()) { *found_p = false; /* nothing found successfully */ return RET_OK; } } - if( memcmp(p, "diff ", 4) == 0 ) { - if( !u_getline() ) { + if (memcmp(p, "diff ", 4) == 0) { + if (!u_getline()) { /* strange file, but nothing explicitly wrong */ *found_p = false; return RET_OK; } } - if( unlikely(memcmp(p, "--- ", 4) != 0) ) + if (unlikely(memcmp(p, "--- ", 4) != 0)) return RET_NOTHING; - if( !u_getline() ) + if (!u_getline()) return RET_NOTHING; - if( unlikely(memcmp(p, "+++ ", 4) != 0) ) + if (unlikely(memcmp(p, "+++ ", 4) != 0)) return RET_NOTHING; p += 4; s = strchr(p, '/'); - if( unlikely(s == NULL) ) + if (unlikely(s == NULL)) return RET_NOTHING; /* another exception to allow diff output directly: * +++ lines might have garbage after a tab... */ garbage = strchr(s, '\t'); - if( garbage != NULL ) + if (garbage != NULL) *garbage = '\0'; /* if it does not always have the same directory, then * we cannot be sure it has no debian/control, so we * have to fail... */ s++; - if( s != p + destlength ) + if (s != p + destlength) return RET_NOTHING; } /* found debian/control */ - if( !u_getline() ) + if (!u_getline()) return RET_NOTHING; - if( unlikely(memcmp(p, "@@ -", 4) != 0) ) + if (unlikely(memcmp(p, "@@ -", 4) != 0)) return RET_NOTHING; p += 4; p++; - while( *p != ',' && *p != ' ' ) { - if( unlikely(*p == '\0') ) + while (*p != ',' && *p != ' ') { + if (unlikely(*p == '\0')) return RET_NOTHING; p++; } - if( *p == ',' ) { + if (*p == ',') { p++; - while( *p >= '0' && *p <= '9' ) + while (*p >= '0' && *p <= '9') p++; } - while( *p == ' ' ) + while (*p == ' ') p++; - if( unlikely(*(p++) != '+') ) + if (unlikely(*(p++) != '+')) return RET_NOTHING; - if( *(p++) != '1' || *(p++) != ',' ) { + if (*(p++) != '1' || *(p++) != ',') { /* a diff not starting at the first line (or not being * more than one line) is not yet supported */ return RET_NOTHING; } lines_out = 0; - while( *p >= '0' && *p <= '9' ) { + while (*p >= '0' && *p <= '9') { lines_out = 10*lines_out + (*p-'0'); p++; } - while( *p == ' ' ) + while (*p == ' ') p++; - if( unlikely(*p != '@') ) + if (unlikely(*p != '@')) return RET_NOTHING; - while( lines_out > 0 ) { - if( unlikely(interrupted()) ) + while (lines_out > 0) { + if (unlikely(interrupted())) return RET_ERROR_INTERRUPTED; - if( !u_getline() ) + if (!u_getline()) return RET_NOTHING; - switch( *(p++) ) { + switch (*(p++)) { case '-': break; default: return RET_NOTHING; case ' ': case '+': - if( unlikely(lines_out == 0) ) + if (unlikely(lines_out == 0)) return RET_NOTHING; lines_out--; - if( section_p != NULL && - strncasecmp(p, "Section:", 8) == 0 ) { + if (section_p != NULL && + strncasecmp(p, "Section:", 8) == 0) { p += 8; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; s = p; - while( *s != ' ' && *s != '\t' && - *s != '\0' && *s != '\r' ) + while (*s != ' ' && *s != '\t' && + *s != '\0' && *s != '\r') s++; - if( s == p ) + if (s == p) return RET_NOTHING; *section_p = strndup(p, s-p); - if( FAILEDTOALLOC(*section_p) ) + if (FAILEDTOALLOC(*section_p)) return RET_ERROR_OOM; - while( *s == ' ' || *s == '\t' || - *s == '\r' ) + while (*s == ' ' || *s == '\t' || + *s == '\r') s++; - if( *s != '\0' ) + if (*s != '\0') return RET_NOTHING; continue; } - if( priority_p != NULL && - strncasecmp(p, "Priority:", 9) == 0 ) { + if (priority_p != NULL && + strncasecmp(p, "Priority:", 9) == 0) { p += 9; - while( *p == ' ' || *p == '\t' ) + while (*p == ' ' || *p == '\t') p++; s = p; - while( *s != ' ' && *s != '\t' && - *s != '\0' && *s != '\r' ) + while (*s != ' ' && *s != '\t' && + *s != '\0' && *s != '\r') s++; - if( s == p ) + if (s == p) return RET_NOTHING; *priority_p = strndup(p, s-p); - if( FAILEDTOALLOC(*priority_p) ) + if (FAILEDTOALLOC(*priority_p)) return RET_ERROR_OOM; - while( *s == ' ' || *s == '\t' || - *s == '\r' ) + while (*s == ' ' || *s == '\t' || + *s == '\r') s++; - if( *s != '\0' ) + if (*s != '\0') return RET_NOTHING; continue; } - if( *p == '\0' ) { + if (*p == '\0') { /* end of control data, we are * finished */ *found_p = true; @@ -457,27 +458,27 @@ char *buffer, *aftercontrol; size = archive_entry_size(entry); - if( size <= 0 ) + if (size <= 0) return RET_NOTHING; - if( size > 10*1024*1024 ) + if (size > 10*1024*1024) return RET_NOTHING; buffer = malloc(size+2); - if( FAILEDTOALLOC(buffer) ) + if (FAILEDTOALLOC(buffer)) return RET_ERROR_OOM; len = 0; - while( (got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0 - && !interrupted() ) { + while ((got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0 + && !interrupted()) { len += got; - if( len > size ) { + if (len > size) { free(buffer); return RET_NOTHING; } } - if( unlikely(interrupted()) ) { + if (unlikely(interrupted())) { free(buffer); return RET_ERROR_INTERRUPTED; } - if( got < 0 ) { + if (got < 0) { free(buffer); return RET_NOTHING; } @@ -486,9 +487,9 @@ controllen = chunk_extract(buffer, buffer, &aftercontrol); - if( e->section_p != NULL ) + if (e->section_p != NULL) (void)chunk_getvalue(buffer, "Section", e->section_p); - if( e->priority_p != NULL ) + if (e->priority_p != NULL) (void)chunk_getvalue(buffer, "Priority", e->priority_p); free(buffer); return RET_OK; @@ -518,59 +519,59 @@ int a; retvalue r, r2; - /* While an .tar, especially an .orig.tar can be very ugly (they should be - * pristine upstream tars, so dpkg-source works around a lot of ugliness), + /* While an .tar, especially an .orig.tar can be very ugly + * (they should be pristine upstream tars, so dpkg-source works around + * a lot of ugliness), * we are looking for debian/control. This is unlikely to be in an ugly * upstream tar verbatimly. */ - if( !isregularfile(filename) ) + if (!isregularfile(filename)) return RET_NOTHING; tar = archive_read_new(); - if( FAILEDTOALLOC(tar) ) { + if (FAILEDTOALLOC(tar)) return RET_ERROR_OOM; - } archive_read_support_format_tar(tar); archive_read_support_format_gnutar(tar); r = uncompress_open(&file, filename, c); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { archive_read_finish(tar); return r; } a = archive_read_open(tar, file, compressedfile_open, compressedfile_read, compressedfile_close); - if( a != ARCHIVE_OK ) { + if (a != ARCHIVE_OK) { int err = archive_errno(tar); - if( err != -EINVAL && err != 0 ) + if (err != -EINVAL && err != 0) fprintf(stderr, -"Error %d trying to extract control information from %s:\n" -"%s\n", err, filename, archive_error_string(tar)); +"Error %d trying to extract control information from %s:\n" "%s\n", + err, filename, archive_error_string(tar)); else fprintf(stderr, -"Error trying to extract control information from %s:\n" -"%s\n", filename, archive_error_string(tar)); +"Error trying to extract control information from %s:\n" "%s\n", + filename, archive_error_string(tar)); archive_read_finish(tar); uncompress_abort(file); return RET_ERROR; } - while( (a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK ) { + while ((a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK) { const char *name = archive_entry_pathname(entry); const char *s; bool iscontrol; - if( name[0] == '.' && name[1] == '/' ) + if (name[0] == '.' && name[1] == '/') name += 2; s = strchr(name, '/'); - if( s == NULL ) + if (s == NULL) // TODO: is this already enough to give up totally? iscontrol = false; else iscontrol = strcmp(s+1, "debian/control") == 0 || strcmp(name, "debian/control") == 0; - if( iscontrol ) { + if (iscontrol) { r = read_source_control_file(e, tar, entry); archive_read_finish(tar); r2 = uncompress_error(file); @@ -580,13 +581,13 @@ return r; } a = archive_read_data_skip(tar); - if( a != ARCHIVE_OK ) { + if (a != ARCHIVE_OK) { int err = archive_errno(tar); printf("Error %d skipping %s within %s: %s\n", err, name, filename, archive_error_string(tar)); archive_read_finish(tar); - if( err == 0 || err == -EINVAL ) + if (err == 0 || err == -EINVAL) r = RET_ERROR; else r = RET_ERRNO(err); @@ -595,15 +596,15 @@ uncompress_abort(file); return r; } - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; } - if( a != ARCHIVE_EOF ) { + if (a != ARCHIVE_EOF) { int err = archive_errno(tar); fprintf(stderr, "Error %d reading %s: %s\n", err, filename, archive_error_string(tar)); archive_read_finish(tar); - if( err == 0 || err == -EINVAL ) + if (err == 0 || err == -EINVAL) r = RET_ERROR; else r = RET_ERRNO(err); @@ -624,23 +625,23 @@ bool found IFSTUPIDCC(= false); #ifndef HAVE_LIBARCHIVE - assert( e->difffile >= 0 ); + assert (e->difffile >= 0); #endif - if( e->difffile >= 0 ) { + if (e->difffile >= 0) { struct compressedfile *f; - assert( uncompression_supported(e->diffcompression) ); + assert (uncompression_supported(e->diffcompression)); e->difffile = -1; r = uncompress_open(&f, fullfilename, e->diffcompression); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { e->failed = true; /* being unable to read a file is no hard error... */ return RET_NOTHING; } r = parsediff(f, e->section_p, e->priority_p, &found); - if( RET_IS_OK(r) ) { - if( !found ) + if (RET_IS_OK(r)) { + if (!found) r = uncompress_close(f); else { r = uncompress_error(f); @@ -649,21 +650,22 @@ } else { uncompress_abort(f); } - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) e->failed = true; - else if( found ) + else if (found) /* do not look in the tar, we found debian/control */ e->completed = true; return r; } #ifdef HAVE_LIBARCHIVE - if( e->debiantarfile >= 0 ) { + if (e->debiantarfile >= 0) { e->debiantarfile = -1; - r = parse_tarfile(e, fullfilename, e->debiancompression, &found); - if( !RET_IS_OK(r) ) + r = parse_tarfile(e, fullfilename, e->debiancompression, + &found); + if (!RET_IS_OK(r)) e->failed = true; - else if( found ) + else if (found) /* do not look in the tar, we found debian/control */ e->completed = true; return r; @@ -671,14 +673,14 @@ #endif /* if it's not the diff nor the .debian.tar, look into the .tar file: */ - assert( e->tarfile >= 0 ); + assert (e->tarfile >= 0); e->tarfile = -1; #ifdef HAVE_LIBARCHIVE r = parse_tarfile(e, fullfilename, e->tarcompression, &found); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) e->failed = true; - else if( found ) + else if (found) /* do not look in the tar, we found debian/control */ e->completed = true; return r; @@ -688,7 +690,7 @@ } retvalue sourceextraction_finish(struct sourceextraction *e) { - if( e->completed ) { + if (e->completed) { free(e); return RET_OK; } diff -Nru reprepro-4.5.0/sources.c reprepro-4.6.0/sources.c --- reprepro-4.5.0/sources.c 2011-02-21 16:49:42.000000000 +0000 +++ reprepro-4.6.0/sources.c 2011-05-05 14:42:55.000000000 +0000 @@ -41,80 +41,80 @@ const char *p, *fn, *fnend; char *filen; - assert( fileline != NULL ); - if( *fileline == '\0' ) + assert (fileline != NULL); + if (*fileline == '\0') return RET_NOTHING; /* the md5sums begins after the (perhaps) heading spaces ... */ p = fileline; - while( *p != '\0' && (*p == ' ' || *p == '\t') ) + while (*p != '\0' && (*p == ' ' || *p == '\t')) p++; - if( *p == '\0' ) + if (*p == '\0') return RET_NOTHING; /* ... and ends with the following spaces. */ - while( *p != '\0' && !(*p == ' ' || *p == '\t') ) + while (*p != '\0' && !(*p == ' ' || *p == '\t')) p++; - if( *p == '\0' ) { + if (*p == '\0') { fprintf(stderr, "Expecting more data after md5sum!\n"); return RET_ERROR; } /* Then the size of the file is expected: */ - while( (*p == ' ' || *p == '\t') ) + while ((*p == ' ' || *p == '\t')) p++; - while( *p !='\0' && !(*p == ' ' || *p == '\t') ) + while (*p !='\0' && !(*p == ' ' || *p == '\t')) p++; - if( *p == '\0' ) { + if (*p == '\0') { fprintf(stderr, "Expecting more data after size!\n"); return RET_ERROR; } /* Then the filename */ fn = p; - while( (*fn == ' ' || *fn == '\t') ) + while ((*fn == ' ' || *fn == '\t')) fn++; fnend = fn; - while( *fnend != '\0' && !(*fnend == ' ' || *fnend == '\t') ) + while (*fnend != '\0' && !(*fnend == ' ' || *fnend == '\t')) fnend++; filen = strndup(fn, fnend-fn); - if( FAILEDTOALLOC(filen) ) + if (FAILEDTOALLOC(filen)) return RET_ERROR_OOM; *filename = filen; return RET_OK; } -static retvalue getBasenames(const struct strlist *filelines,/*@out@*/struct strlist *basenames) { +static retvalue getBasenames(const struct strlist *filelines, /*@out@*/struct strlist *basenames) { int i; retvalue r; - assert( filelines != NULL && basenames != NULL ); + assert (filelines != NULL && basenames != NULL); - r = strlist_init_n(filelines->count,basenames); - if( RET_WAS_ERROR(r) ) + r = strlist_init_n(filelines->count, basenames); + if (RET_WAS_ERROR(r)) return r; r = RET_NOTHING; - for( i = 0 ; i < filelines->count ; i++ ) { + for (i = 0 ; i < filelines->count ; i++) { char *basefilename IFSTUPIDCC(=NULL); const char *fileline = filelines->values[i]; r = calc_parsefileline(fileline, &basefilename); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Malformed Files: line '%s'!\n", fileline); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; r = strlist_add(basenames, basefilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { break; } r = RET_OK; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(basenames); } else { - assert( filelines->count == basenames->count ); + assert (filelines->count == basenames->count); } return r; } @@ -122,11 +122,12 @@ retvalue sources_getversion(const char *control, char **version) { retvalue r; - r = chunk_getvalue(control,"Version",version); - if( RET_WAS_ERROR(r) ) + r = chunk_getvalue(control, "Version", version); + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", control); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", + control); return RET_ERROR; } return r; @@ -145,66 +146,68 @@ struct checksumsarray files; enum checksumtype cs; - assert( architecture == architecture_source ); + assert (architecture == architecture_source); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( source_checksum_names[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (source_checksum_names[cs] != NULL); r = chunk_getextralinelist(chunk, source_checksum_names[cs], &filelines[cs]); - if( r == RET_NOTHING ) { - if( cs == cs_md5sum ) { + if (r == RET_NOTHING) { + if (cs == cs_md5sum) { fprintf(stderr, -"Missing 'Files' entry in '%s'!\n", chunk); +"Missing 'Files' entry in '%s'!\n", + chunk); r = RET_ERROR; } else strlist_init(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&filelines[cs]); } return r; } } r = checksumsarray_parse(&files, filelines, packagename); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = chunk_getvalue(chunk, "Directory", &origdirectory); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { /* Flat repositories can come without this, TODO: add warnings in other cases - fprintf(stderr,"Missing 'Directory' entry in '%s'!\n",chunk); + fprintf(stderr, "Missing 'Directory' entry in '%s'!\n", chunk); r = RET_ERROR; */ origdirectory = strdup("."); - if( FAILEDTOALLOC(origdirectory) ) + if (FAILEDTOALLOC(origdirectory)) r = RET_ERROR_OOM; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksumsarray_done(&files); return r; } r = propersourcename(packagename); - assert( r != RET_NOTHING ); - if( RET_IS_OK(r) ) + assert (r != RET_NOTHING); + if (RET_IS_OK(r)) r = properfilenames(&files.names); - if( RET_WAS_ERROR(r) ) { - fprintf(stderr,"Forbidden characters in source package '%s'!\n", packagename); + if (RET_WAS_ERROR(r)) { + fprintf(stderr, +"Forbidden characters in source package '%s'!\n", packagename); free(origdirectory); checksumsarray_done(&files); return r; } - directory = calc_sourcedir(t->component_atom, packagename); - if( directory == NULL ) + directory = calc_sourcedir(t->component, packagename); + if (FAILEDTOALLOC(directory)) r = RET_ERROR_OOM; else r = calc_dirconcats(directory, &files.names, &myfilekeys); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(directory); free(origdirectory); checksumsarray_done(&files); @@ -212,14 +215,14 @@ } r = calc_inplacedirconcats(origdirectory, &files.names); free(origdirectory); - if( !RET_WAS_ERROR(r) ) { + if (!RET_WAS_ERROR(r)) { mychunk = chunk_replacefield(chunk, "Directory", directory, true); - if( mychunk == NULL ) + if (FAILEDTOALLOC(mychunk)) r = RET_ERROR_OOM; } free(directory); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&myfilekeys); checksumsarray_done(&files); return r; @@ -239,29 +242,31 @@ /* Read the directory given there */ r = chunk_getvalue(chunk, "Directory", &origdirectory); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { //TODO: check if it is even text and do not print //of looking binary?? - fprintf(stderr, "Does not look like source control: '%s'\n", chunk); + fprintf(stderr, "Does not look like source control: '%s'\n", + chunk); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = chunk_getextralinelist(chunk, "Files", &filelines); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { //TODO: check if it is even text and do not print //of looking binary?? - fprintf(stderr, "Does not look like source control: '%s'\n", chunk); + fprintf(stderr, "Does not look like source control: '%s'\n", + chunk); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); return r; } r = getBasenames(&filelines, &basenames); strlist_done(&filelines); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); return r; } @@ -281,23 +286,24 @@ /* Read the directory given there */ r = chunk_getvalue(chunk, "Directory", &origdirectory); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( source_checksum_names[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (source_checksum_names[cs] != NULL); r = chunk_getextralinelist(chunk, source_checksum_names[cs], &filelines[cs]); - if( r == RET_NOTHING ) { - if( cs == cs_md5sum ) { + if (r == RET_NOTHING) { + if (cs == cs_md5sum) { fprintf(stderr, -"Missing 'Files' entry in '%s'!\n", chunk); +"Missing 'Files' entry in '%s'!\n", + chunk); r = RET_ERROR; } else strlist_init(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&filelines[cs]); } free(origdirectory); @@ -305,17 +311,17 @@ } } r = checksumsarray_parse(&a, filelines, "source chunk"); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); return r; } r = calc_inplacedirconcats(origdirectory, &a.names); free(origdirectory); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksumsarray_done(&a); return r; } @@ -329,26 +335,26 @@ char *newchunk; retvalue r; - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; o = override_search(target->distribution->overrides.dsc, packagename); - if( o == NULL ) + if (o == NULL) return RET_NOTHING; r = override_allreplacefields(o, &fields); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; newchunk = chunk_replacefields(controlchunk, fields, "Directory", true); addfield_free(fields); - if( newchunk == NULL ) + if (FAILEDTOALLOC(newchunk)) return RET_ERROR_OOM; *newcontrolchunk = newchunk; return RET_OK; } -retvalue sources_retrack(const char *sourcename, const char *chunk, trackingdb tracks, struct database *database) { +retvalue sources_retrack(const char *sourcename, const char *chunk, trackingdb tracks) { retvalue r; char *sourceversion; struct trackedpackage *pkg; @@ -358,31 +364,32 @@ //TODO: elliminate duplicate code! assert(sourcename!=NULL); - if( interrupted() ) + if (interrupted()) return RET_ERROR_INTERRUPTED; - r = chunk_getvalue(chunk,"Version",&sourceversion); - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", chunk); + r = chunk_getvalue(chunk, "Version", &sourceversion); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", + chunk); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } r = sources_getfilekeys(chunk, &filekeys); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Malformed source control:'%s'\n", chunk); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(sourceversion); return r; } - r = tracking_getornew(tracks,sourcename,sourceversion,&pkg); + r = tracking_getornew(tracks, sourcename, sourceversion, &pkg); free(sourceversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filekeys); return r; } @@ -390,12 +397,11 @@ // TODO: error handling is suboptimal here. // is there a way to again remove old additions (esp. references) // where something fails? - for( i = 0 ; i < filekeys.count ; i++ ) { + for (i = 0 ; i < filekeys.count ; i++) { r = trackedpackage_addfilekey(tracks, pkg, - ft_SOURCE, filekeys.values[i], - true, database); + ft_SOURCE, filekeys.values[i], true); filekeys.values[i] = NULL; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&filekeys); trackedpackage_free(pkg); return r; @@ -413,16 +419,17 @@ //TODO: elliminate duplicate code! assert(packagename!=NULL); - r = chunk_getvalue(chunk,"Version",&sourceversion); - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", chunk); + r = chunk_getvalue(chunk, "Version", &sourceversion); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Version' field in chunk:'%s'\n", + chunk); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } sourcename = strdup(packagename); - if( sourcename == NULL ) { + if (FAILEDTOALLOC(sourcename)) { free(sourceversion); return RET_ERROR_OOM; } @@ -433,33 +440,35 @@ /****************************************************************/ -static inline retvalue getvalue(const char *filename,const char *chunk,const char *field,char **value) { +static inline retvalue getvalue(const char *filename, const char *chunk, const char *field, char **value) { retvalue r; - r = chunk_getvalue(chunk,field,value); - if( r == RET_NOTHING ) { - fprintf(stderr,"Missing '%s' field in %s!\n",field,filename); + r = chunk_getvalue(chunk, field, value); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing '%s' field in %s!\n", + field, filename); r = RET_ERROR; } return r; } -static inline retvalue checkvalue(const char *filename,const char *chunk,const char *field) { +static inline retvalue checkvalue(const char *filename, const char *chunk, const char *field) { retvalue r; - r = chunk_checkfield(chunk,field); - if( r == RET_NOTHING ) { - fprintf(stderr,"Cannot find '%s' field in %s!\n",field,filename); + r = chunk_checkfield(chunk, field); + if (r == RET_NOTHING) { + fprintf(stderr, "Cannot find '%s' field in %s!\n", + field, filename); r = RET_ERROR; } return r; } -static inline retvalue getvalue_n(const char *chunk,const char *field,char **value) { +static inline retvalue getvalue_n(const char *chunk, const char *field, char **value) { retvalue r; - r = chunk_getvalue(chunk,field,value); - if( r == RET_NOTHING ) { + r = chunk_getvalue(chunk, field, value); + if (r == RET_NOTHING) { *value = NULL; } return r; @@ -472,10 +481,10 @@ r = signature_readsignedchunk(filename, filenametoshow, &dsc->control, NULL, broken); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } - if( verbose > 100 ) { + if (verbose > 100) { fprintf(stderr, "Extracted control chunk from '%s': '%s'\n", filenametoshow, dsc->control); } @@ -483,55 +492,57 @@ /* first look for fields that should be there */ r = chunk_getname(dsc->control, "Source", &dsc->name, false); - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Source' field in %s!\n", filenametoshow); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Source' field in %s!\n", + filenametoshow); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - /* This is needed and cannot be ignored unless + /* This is needed and cannot be ignored unless * sources_complete is changed to not need it */ r = checkvalue(filenametoshow, dsc->control, "Format"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = checkvalue(filenametoshow, dsc->control, "Maintainer"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = getvalue(filenametoshow, dsc->control, "Version", &dsc->version); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = getvalue_n(dsc->control, SECTION_FIELDNAME, &dsc->section); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = getvalue_n(dsc->control, PRIORITY_FIELDNAME, &dsc->priority); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( source_checksum_names[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (source_checksum_names[cs] != NULL); r = chunk_getextralinelist(dsc->control, source_checksum_names[cs], &filelines[cs]); - if( r == RET_NOTHING ) { - if( cs == cs_md5sum ) { + if (r == RET_NOTHING) { + if (cs == cs_md5sum) { fprintf(stderr, -"Missing 'Files' field in '%s'!\n", filenametoshow); +"Missing 'Files' field in '%s'!\n", + filenametoshow); r = RET_ERROR; } else strlist_init(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&filelines[cs]); } return r; } } r = checksumsarray_parse(&dsc->files, filelines, filenametoshow); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&filelines[cs]); } return r; @@ -550,46 +561,46 @@ retvalue r; struct fieldtoadd *name; struct fieldtoadd *replace; - char *newchunk,*newchunk2; + char *newchunk, *newchunk2; char *newfilelines, *newsha1lines, *newsha256lines; assert(section != NULL && priority != NULL); /* first replace the "Source" with a "Package": */ - name = addfield_new("Package",dsc->name,NULL); - if( name == NULL ) + name = addfield_new("Package", dsc->name, NULL); + if (FAILEDTOALLOC(name)) return RET_ERROR_OOM; - name = deletefield_new("Source",name); - if( name == NULL ) + name = deletefield_new("Source", name); + if (FAILEDTOALLOC(name)) return RET_ERROR_OOM; newchunk2 = chunk_replacefields(dsc->control, name, "Format", true); addfield_free(name); - if( newchunk2 == NULL ) + if (FAILEDTOALLOC(newchunk2)) return RET_ERROR_OOM; r = checksumsarray_genfilelist(&dsc->files, &newfilelines, &newsha1lines, &newsha256lines); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(newchunk2); - return RET_ERROR_OOM; + return r; } - assert( newfilelines != NULL ); + assert (newfilelines != NULL); replace = aodfield_new("Checksums-Sha256", newsha256lines, NULL); - if( replace != NULL ) + if (!FAILEDTOALLOC(replace)) replace = aodfield_new("Checksums-Sha1", newsha1lines, replace); - if( replace != NULL ) + if (!FAILEDTOALLOC(replace)) replace = addfield_new("Files", newfilelines, replace); - if( replace != NULL ) - replace = addfield_new("Directory",directory,replace); - if( replace != NULL ) - replace = deletefield_new("Status",replace); - if( replace != NULL ) - replace = addfield_new(SECTION_FIELDNAME,section,replace); - if( replace != NULL ) - replace = addfield_new(PRIORITY_FIELDNAME,priority,replace); - if( replace != NULL ) - replace = override_addreplacefields(override,replace); - if( replace == NULL ) { + if (!FAILEDTOALLOC(replace)) + replace = addfield_new("Directory", directory, replace); + if (!FAILEDTOALLOC(replace)) + replace = deletefield_new("Status", replace); + if (!FAILEDTOALLOC(replace)) + replace = addfield_new(SECTION_FIELDNAME, section, replace); + if (!FAILEDTOALLOC(replace)) + replace = addfield_new(PRIORITY_FIELDNAME, priority, replace); + if (!FAILEDTOALLOC(replace)) + replace = override_addreplacefields(override, replace); + if (FAILEDTOALLOC(replace)) { free(newsha256lines); free(newsha1lines); free(newfilelines); @@ -603,7 +614,7 @@ free(newfilelines); free(newchunk2); addfield_free(replace); - if( newchunk == NULL ) { + if (FAILEDTOALLOC(newchunk)) { return RET_ERROR_OOM; } @@ -624,10 +635,10 @@ /* fake a checksumarray... */ checksums.checksums = c; checksums.names.count = filekeys->count; - checksums.names.values = calloc(filekeys->count, sizeof(char*)); - if (checksums.names.values == NULL) + checksums.names.values = nzNEW(filekeys->count, char *); + if (FAILEDTOALLOC(checksums.names.values)) return RET_ERROR_OOM; - for( i = 0 ; i < filekeys->count ; i++ ) { + for (i = 0 ; i < filekeys->count ; i++) { checksums.names.values[i] = (char*) dirs_basename(filekeys->values[i]); } @@ -635,16 +646,15 @@ r = checksumsarray_genfilelist(&checksums, &newfilelines, &newsha1lines, &newsha256lines); free(checksums.names.values); - if( RET_WAS_ERROR(r) ) { - return RET_ERROR_OOM; - } - assert( newfilelines != NULL ); + if (RET_WAS_ERROR(r)) + return r; + assert (newfilelines != NULL); replace = aodfield_new("Checksums-Sha256", newsha256lines, NULL); - if( replace != NULL ) + if (!FAILEDTOALLOC(replace)) replace = aodfield_new("Checksums-Sha1", newsha1lines, replace); - if( replace != NULL ) + if (!FAILEDTOALLOC(replace)) replace = addfield_new("Files", newfilelines, replace); - if( replace == NULL ) { + if (FAILEDTOALLOC(replace)) { free(newsha256lines); free(newsha1lines); free(newfilelines); @@ -655,7 +665,7 @@ free(newsha1lines); free(newfilelines); addfield_free(replace); - if( newchunk == NULL ) + if (FAILEDTOALLOC(newchunk)) return RET_ERROR_OOM; *out = newchunk; @@ -664,7 +674,7 @@ char *calc_source_basename(const char *name, const char *version) { const char *v = strchr(version, ':'); - if( v != NULL ) + if (v != NULL) v++; else v = version; @@ -673,14 +683,14 @@ char *calc_sourcedir(component_t component, const char *sourcename) { - assert( *sourcename != '\0' ); + assert (*sourcename != '\0'); - if( sourcename[0] == 'l' && sourcename[1] == 'i' && - sourcename[2] == 'b' && sourcename[3] != '\0' ) + if (sourcename[0] == 'l' && sourcename[1] == 'i' && + sourcename[2] == 'b' && sourcename[3] != '\0') return mprintf("pool/%s/lib%c/%s", atoms_components[component], sourcename[3], sourcename); - else if( *sourcename != '\0' ) + else if (*sourcename != '\0') return mprintf("pool/%s/%c/%s", atoms_components[component], sourcename[0], sourcename); @@ -689,12 +699,12 @@ } char *calc_filekey(component_t component, const char *sourcename, const char *filename) { - if( sourcename[0] == 'l' && sourcename[1] == 'i' && - sourcename[2] == 'b' && sourcename[3] != '\0' ) + if (sourcename[0] == 'l' && sourcename[1] == 'i' && + sourcename[2] == 'b' && sourcename[3] != '\0') return mprintf("pool/%s/lib%c/%s/%s", atoms_components[component], sourcename[3], sourcename, filename); - else if( *sourcename != '\0' ) + else if (*sourcename != '\0') return mprintf("pool/%s/%c/%s/%s", atoms_components[component], sourcename[0], sourcename, filename); @@ -703,13 +713,13 @@ } char *calc_byhanddir(component_t component, const char *sourcename, const char *version) { - if( sourcename[0] == 'l' && sourcename[1] == 'i' && - sourcename[2] == 'b' && sourcename[3] != '\0' ) + if (sourcename[0] == 'l' && sourcename[1] == 'i' && + sourcename[2] == 'b' && sourcename[3] != '\0') return mprintf("pool/%s/lib%c/%s/%s_%s_byhand", atoms_components[component], sourcename[3], sourcename, sourcename, version); - else if( *sourcename != '\0' ) + else if (*sourcename != '\0') return mprintf("pool/%s/%c/%s/%s_%s_byhand", atoms_components[component], sourcename[0], sourcename, diff -Nru reprepro-4.5.0/sources.h reprepro-4.6.0/sources.h --- reprepro-4.5.0/sources.h 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/sources.h 2011-05-05 14:42:55.000000000 +0000 @@ -9,9 +9,6 @@ #include "target.h" #endif -/* Calculate the filelines in a form suitable for chunk_replacefields: */ -retvalue sources_calcfilelines(const struct checksumsarray *, /*@out@*/char **item); - /* Functions for the target.h-stuff: */ get_version sources_getversion; get_installdata sources_getinstalldata; diff -Nru reprepro-4.5.0/strlist.c reprepro-4.6.0/strlist.c --- reprepro-4.5.0/strlist.c 2008-10-05 09:58:06.000000000 +0000 +++ reprepro-4.6.0/strlist.c 2011-05-05 14:42:55.000000000 +0000 @@ -32,13 +32,13 @@ c = strlist->count; t = strlist->values; - while( c-- != 0 ) { - if( strcmp(*(t++),element) == 0 ) + while (c-- != 0) { + if (strcmp(*(t++), element) == 0) return true; } return false; } -int strlist_ofs(const struct strlist *strlist,const char *element) { +int strlist_ofs(const struct strlist *strlist, const char *element) { int c; char **t; @@ -46,8 +46,8 @@ c = strlist->count; t = strlist->values; - while( c-- != 0 ) { - if( strcmp(*(t++),element) == 0 ) + while (c-- != 0) { + if (strcmp(*(t++), element) == 0) return (t-strlist->values)-1; } return -1; @@ -61,9 +61,9 @@ c = subset->count; t = subset->values; - while( c-- != 0 ) { - if( !strlist_in(strlist,*(t++)) ) { - if( missing != NULL ) + while (c-- != 0) { + if (!strlist_in(strlist, *(t++))) { + if (missing != NULL) *missing = *(t-1); return false; } @@ -72,26 +72,30 @@ } -retvalue strlist_init_n(int startsize,struct strlist *strlist) { +retvalue strlist_init_n(int startsize, struct strlist *strlist) { assert(strlist != NULL && startsize >= 0); - if( startsize == 0 ) + if (startsize == 0) startsize = 1; strlist->count = 0; strlist->size = startsize; - strlist->values = malloc(startsize*sizeof(char *)); - if( startsize > 0 && strlist->values == NULL ) - return RET_ERROR_OOM; + if (startsize > 0) { + strlist->values = malloc(startsize*sizeof(char *)); + if (FAILEDTOALLOC(strlist->values)) + return RET_ERROR_OOM; + } else { + strlist->values = NULL; + } return RET_OK; } -retvalue strlist_init_singleton(char *value,struct strlist *strlist) { +retvalue strlist_init_singleton(char *value, struct strlist *strlist) { assert(strlist != NULL); strlist->count = 1; strlist->size = 1; - strlist->values = malloc(sizeof(char *)); - if( strlist->values == NULL ) { + strlist->values = NEW(char *); + if (FAILEDTOALLOC(strlist->values)) { free(value); return RET_ERROR_OOM; } @@ -116,7 +120,7 @@ c = strlist->count; t = strlist->values; - while( c-- != 0 ) { + while (c-- != 0) { free(*t); t++; } @@ -129,10 +133,10 @@ assert(strlist != NULL && element != NULL); - if( strlist->count >= strlist->size ) { + if (strlist->count >= strlist->size) { strlist->size += 8; v = realloc(strlist->values, strlist->size*sizeof(char *)); - if( v == NULL ) { + if (FAILEDTOALLOC(v)) { free(element); return RET_ERROR_OOM; } @@ -146,7 +150,7 @@ retvalue strlist_add_dup(struct strlist *strlist, const char *todup) { char *element = strdup(todup); - if( element == NULL ) + if (FAILEDTOALLOC(element)) return RET_ERROR_OOM; return strlist_add(strlist, element); } @@ -156,22 +160,23 @@ assert(strlist != NULL && element != NULL); - if( strlist->count >= strlist->size ) { + if (strlist->count >= strlist->size) { strlist->size += 1; v = realloc(strlist->values, strlist->size*sizeof(char *)); - if( v == NULL ) { + if (FAILEDTOALLOC(v)) { free(element); return RET_ERROR_OOM; } strlist->values = v; } - memmove(strlist->values+1,strlist->values,strlist->count*sizeof(char *)); + memmove(strlist->values+1, strlist->values, + strlist->count*sizeof(char *)); strlist->count++; strlist->values[0] = element; return RET_OK; } -retvalue strlist_fprint(FILE *file,const struct strlist *strlist) { +retvalue strlist_fprint(FILE *file, const struct strlist *strlist) { int c; char **p; retvalue result; @@ -182,40 +187,21 @@ c = strlist->count; p = strlist->values; result = RET_OK; - while( c > 0 ) { - if( fputs(*(p++),file) == EOF ) + while (c > 0) { + if (fputs(*(p++), file) == EOF) result = RET_ERROR; - if( --c > 0 && fputc(' ',file) == EOF ) + if (--c > 0 && fputc(' ', file) == EOF) result = RET_ERROR; } return result; } -/* duplicate with content */ -retvalue strlist_dup(struct strlist *dest,const struct strlist *orig) { - int i; - - assert(dest != NULL && orig != NULL); - - dest->size = dest->count = orig->count; - dest->values = calloc(dest->count,sizeof(char*));; - if( dest->values == NULL ) - return RET_ERROR_OOM; - for( i = 0 ; i < dest->count ; i++ ) { - if( (dest->values[i] = strdup(orig->values[i])) == NULL ) { - strlist_done(dest); - return RET_ERROR_OOM; - } - } - return RET_OK; -} - /* replace the contents of dest with those from orig, which get emptied */ -void strlist_move(struct strlist *dest,struct strlist *orig) { +void strlist_move(struct strlist *dest, struct strlist *orig) { assert(dest != NULL && orig != NULL); - if( dest == orig ) + if (dest == orig) return; dest->size = orig->size; @@ -224,48 +210,22 @@ orig->size = orig->count = 0; orig->values = NULL; } -/* empty orig and add everything to the end of dest, in case of error, nothing - * was done. */ -retvalue strlist_mvadd(struct strlist *dest,struct strlist *orig) { - int i; - - assert(dest != NULL && orig != NULL && dest != orig); - - if( dest->count+orig->count >= dest->size ) { - int newsize = dest->count+orig->count+8; - char **v = realloc(dest->values, newsize*sizeof(char *)); - if( v == NULL ) { - return RET_ERROR_OOM; - } - dest->size = newsize; - dest->values = v; - } - - for( i = 0 ; i < orig->count ; i++ ) - dest->values[dest->count+i] = orig->values[i]; - dest->count += orig->count; - free(orig->values); - orig->size = orig->count = 0; - orig->values = NULL; - - return RET_OK; -} -retvalue strlist_adduniq(struct strlist *strlist,char *element) { +retvalue strlist_adduniq(struct strlist *strlist, char *element) { // TODO: is there something better feasible? - if( strlist_in(strlist,element) ) { + if (strlist_in(strlist, element)) { free(element); return RET_OK; } else - return strlist_add(strlist,element); + return strlist_add(strlist, element); } bool strlist_intersects(const struct strlist *a, const struct strlist *b) { int i; - for( i = 0 ; i < a->count ; i++ ) - if( strlist_in(b, a->values[i]) ) + for (i = 0 ; i < a->count ; i++) + if (strlist_in(b, a->values[i])) return true; return false; } @@ -280,20 +240,20 @@ suffix_len = strlen(suffix); l = prefix_len + suffix_len; - for( i = 0 ; i < list->count ; i++ ) + for (i = 0 ; i < list->count ; i++) l += strlen(list->values[i]); - if( list->count > 0 ) + if (list->count > 0) l += (list->count-1)*infix_len; c = malloc(l + 1); - if( c == NULL ) + if (FAILEDTOALLOC(c)) return c; memcpy(c, prefix, prefix_len); n = c + prefix_len; - for( i = 0 ; i < list->count ; i++ ) { + for (i = 0 ; i < list->count ; i++) { line_len = strlen(list->values[i]); memcpy(n, list->values[i], line_len); n += line_len; - if( i+1 < list->count ) { + if (i+1 < list->count) { memcpy(n, infix, infix_len); n += infix_len; } else { @@ -301,7 +261,7 @@ n += suffix_len; } } - assert( (size_t)(n-c) == l ); + assert ((size_t)(n-c) == l); *n = '\0'; return c; } @@ -313,9 +273,9 @@ assert(element != NULL); j = 0; - for( i = 0 ; i < strlist->count ; i++ ) { - if( strcmp(strlist->values[i], element) != 0 ) { - if( i != j ) + for (i = 0 ; i < strlist->count ; i++) { + if (strcmp(strlist->values[i], element) != 0) { + if (i != j) strlist->values[j] = strlist->values[i]; j++; } else diff -Nru reprepro-4.5.0/strlist.h reprepro-4.6.0/strlist.h --- reprepro-4.5.0/strlist.h 2008-10-05 09:58:06.000000000 +0000 +++ reprepro-4.6.0/strlist.h 2011-05-05 14:42:55.000000000 +0000 @@ -12,42 +12,38 @@ struct strlist { char **values; - int count,size; + int count, size; }; -void strlist_init(/*@out@*/struct strlist *strlist); -retvalue strlist_init_n(int startsize,/*@out@*/struct strlist *strlist); -retvalue strlist_init_singleton(/*@only@*/char *value,/*@out@*/struct strlist *strlist); +void strlist_init(/*@out@*/struct strlist *); +retvalue strlist_init_n(int /*startsize*/, /*@out@*/struct strlist *); +retvalue strlist_init_singleton(/*@only@*/char *, /*@out@*/struct strlist *); void strlist_done(/*@special@*/struct strlist *strlist) /*@releases strlist->values @*/; /* add a string, will get property of the strlist and free'd by it */ -retvalue strlist_add(struct strlist *strlist,/*@only@*/char *element); +retvalue strlist_add(struct strlist *, /*@only@*/char *); /* include a string at the beginning, otherwise like strlist_add */ -retvalue strlist_include(struct strlist *strlist,/*@only@*/char *element); +retvalue strlist_include(struct strlist *, /*@only@*/char *); /* add a string alphabetically, discarding if already there. */ -retvalue strlist_adduniq(struct strlist *strlist,/*@only@*/char *element); +retvalue strlist_adduniq(struct strlist *, /*@only@*/char *); /* like strlist_add, but strdup it first */ retvalue strlist_add_dup(struct strlist *strlist, const char *todup); /* print a space separated list of elements */ -retvalue strlist_fprint(FILE *file,const struct strlist *strlist); +retvalue strlist_fprint(FILE *, const struct strlist *); -/* duplicate with content */ -retvalue strlist_dup(struct strlist *dest,const struct strlist *orig); /* replace the contents of dest with those from orig, which get emptied */ void strlist_move(/*@out@*/struct strlist *dest, /*@special@*/struct strlist *orig) /*@releases orig->values @*/; -/* empty orig and add everything to the end of dest, on error nothing is freed */ -retvalue strlist_mvadd(struct strlist *dest, /*@special@*/struct strlist *orig) /*@releases orig->values @*/; -bool strlist_in(const struct strlist *strlist, const char *element); -int strlist_ofs(const struct strlist *strlist,const char *element); +bool strlist_in(const struct strlist *, const char *); +int strlist_ofs(const struct strlist *, const char *); bool strlist_intersects(const struct strlist *, const struct strlist *); /* if missing != NULL And subset no subset of strlist, set *missing to the first missing one */ -bool strlist_subset(const struct strlist *strlist, const struct strlist *subset, const char **missing); +bool strlist_subset(const struct strlist *, const struct strlist * /*subset*/, const char ** /*missing_p*/); /* concatenate */ -char *strlist_concat(const struct strlist *, const char *prefix, const char *infix, const char *suffix); +char *strlist_concat(const struct strlist *, const char * /*prefix*/, const char * /*infix*/, const char * /*suffix*/); /* remove all strings equal to the argument */ void strlist_remove(struct strlist *, const char *); diff -Nru reprepro-4.5.0/target.c reprepro-4.6.0/target.c --- reprepro-4.5.0/target.c 2011-02-21 15:34:28.000000000 +0000 +++ reprepro-4.6.0/target.c 2011-05-05 14:42:55.000000000 +0000 @@ -44,11 +44,11 @@ #include "target.h" static char *calc_identifier(const char *codename, component_t component, architecture_t architecture, packagetype_t packagetype) { - assert( strchr(codename, '|') == NULL ); - assert( codename != NULL ); assert( atom_defined(component) ); - assert( atom_defined(architecture) ); - assert( atom_defined(packagetype) ); - if( packagetype == pt_udeb ) + assert (strchr(codename, '|') == NULL); + assert (codename != NULL); assert (atom_defined(component)); + assert (atom_defined(architecture)); + assert (atom_defined(packagetype)); + if (packagetype == pt_udeb) return mprintf("u|%s|%s|%s", codename, atoms_components[component], atoms_architectures[architecture]); @@ -63,26 +63,26 @@ struct target *t; assert(exportmode != NULL); - if( directory == NULL ) + if (FAILEDTOALLOC(directory)) return RET_ERROR_OOM; - t = calloc(1,sizeof(struct target)); - if( t == NULL ) { + t = zNEW(struct target); + if (FAILEDTOALLOC(t)) { free(directory); return RET_ERROR_OOM; } t->relativedirectory = directory; t->exportmode = exportmode; t->distribution = distribution; - assert( atom_defined(component) ); - t->component_atom = component; - assert( atom_defined(architecture) ); - t->architecture_atom = architecture; - assert( atom_defined(packagetype) ); - t->packagetype_atom = packagetype; + assert (atom_defined(component)); + t->component = component; + assert (atom_defined(architecture)); + t->architecture = architecture; + assert (atom_defined(packagetype)); + t->packagetype = packagetype; t->identifier = calc_identifier(distribution->codename, component, architecture, packagetype); - if( t->identifier == NULL ) { + if (FAILEDTOALLOC(t->identifier)) { (void)target_free(t); return RET_ERROR_OOM; } @@ -104,12 +104,12 @@ const char *c = atoms_components[component]; size_t len; - if( fakecomponentprefix == NULL ) + if (fakecomponentprefix == NULL) return c; len = strlen(fakecomponentprefix); - if( strncmp(c, fakecomponentprefix, len) != 0 ) + if (strncmp(c, fakecomponentprefix, len) != 0) return c; - if( c[len] != '/' ) + if (c[len] != '/') return c; return c + len + 1; } @@ -162,14 +162,17 @@ retvalue target_free(struct target *target) { retvalue result = RET_OK; - if( target == NULL ) + if (target == NULL) return RET_OK; - if( target->packages != NULL ) { + if (target->packages != NULL) { result = target_closepackagesdb(target); } else result = RET_OK; - if( target->wasmodified ) { - fprintf(stderr,"Warning: database '%s' was modified but no index file was exported.\nChanges will only be visible after the next 'export'!\n",target->identifier); + if (target->wasmodified) { + fprintf(stderr, +"Warning: database '%s' was modified but no index file was exported.\n" +"Changes will only be visible after the next 'export'!\n", + target->identifier); } target->distribution = NULL; @@ -180,10 +183,10 @@ } /* This opens up the database, if db != NULL, *db will be set to it.. */ -retvalue target_initpackagesdb(struct target *target, struct database *database, bool readonly) { +retvalue target_initpackagesdb(struct target *target, bool readonly) { retvalue r; - if( !readonly && target->readonly ) { + if (!readonly && target->readonly) { fprintf(stderr, "Error trying to open '%s' read-write in read-only distribution '%s'\n", target->identifier, @@ -191,13 +194,13 @@ return RET_ERROR; } - assert( target->packages == NULL ); - if( target->packages != NULL ) + assert (target->packages == NULL); + if (target->packages != NULL) return RET_OK; - r = database_openpackages(database, target->identifier, readonly, + r = database_openpackages(target->identifier, readonly, &target->packages); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { target->packages = NULL; return r; } @@ -208,8 +211,8 @@ retvalue target_closepackagesdb(struct target *target) { retvalue r; - if( target->packages == NULL ) { - fprintf(stderr,"Internal Warning: Double close!\n"); + if (target->packages == NULL) { + fprintf(stderr, "Internal Warning: Double close!\n"); r = RET_OK; } else { r = table_close(target->packages); @@ -219,56 +222,55 @@ } /* Remove a package from the given target. */ -retvalue target_removereadpackage(struct target *target, struct logger *logger, struct database *database, const char *name, const char *oldcontrol, struct trackingdata *trackingdata) { +retvalue target_removereadpackage(struct target *target, struct logger *logger, const char *name, const char *oldcontrol, struct trackingdata *trackingdata) { char *oldpversion = NULL; struct strlist files; - retvalue result,r; - char *oldsource,*oldsversion; + retvalue result, r; + char *oldsource, *oldsversion; - assert( target != NULL && target->packages != NULL ); - assert( oldcontrol != NULL && name != NULL ); + assert (target != NULL && target->packages != NULL); + assert (oldcontrol != NULL && name != NULL); - if( logger != NULL ) { + if (logger != NULL) { /* need to get the version for logging, if not available */ r = target->getversion(oldcontrol, &oldpversion); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) oldpversion = NULL; } r = target->getfilekeys(oldcontrol, &files); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(oldpversion); return r; } - if( trackingdata != NULL ) { + if (trackingdata != NULL) { r = target->getsourceandversion(oldcontrol, name, &oldsource, &oldsversion); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { oldsource = oldsversion = NULL; } } else { oldsource = oldsversion = NULL; } - if( verbose > 0 ) + if (verbose > 0) printf("removing '%s' from '%s'...\n", name, target->identifier); result = table_deleterecord(target->packages, name, false); - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { target->wasmodified = true; - if( oldsource!= NULL && oldsversion != NULL ) { + if (oldsource!= NULL && oldsversion != NULL) { r = trackingdata_remove(trackingdata, oldsource, oldsversion, &files); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - if( trackingdata == NULL ) + if (trackingdata == NULL) target->staletracking = true; - if( logger != NULL ) + if (logger != NULL) logger_log(logger, target, name, NULL, oldpversion, NULL, oldcontrol, NULL, &files, NULL, NULL); - r = references_delete(database, target->identifier, &files, - NULL); + r = references_delete(target->identifier, &files, NULL); RET_UPDATE(result, r); } strlist_done(&files); @@ -277,23 +279,23 @@ } /* Remove a package from the given target. */ -retvalue target_removepackage(struct target *target, struct logger *logger, struct database *database, const char *name, struct trackingdata *trackingdata) { +retvalue target_removepackage(struct target *target, struct logger *logger, const char *name, struct trackingdata *trackingdata) { char *oldchunk; retvalue r; - assert(target != NULL && target->packages != NULL && name != NULL ); + assert(target != NULL && target->packages != NULL && name != NULL); r = table_getrecord(target->packages, name, &oldchunk); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { return r; } - else if( r == RET_NOTHING ) { - if( verbose >= 10 ) - fprintf(stderr,"Could not find '%s' in '%s'...\n", + else if (r == RET_NOTHING) { + if (verbose >= 10) + fprintf(stderr, "Could not find '%s' in '%s'...\n", name, target->identifier); return RET_NOTHING; } - r = target_removereadpackage(target, logger, database, + r = target_removereadpackage(target, logger, name, oldchunk, trackingdata); free(oldchunk); return r; @@ -301,7 +303,7 @@ /* Like target_removepackage, but delete the package record by cursor */ -retvalue target_removepackage_by_cursor(struct target_cursor *tc, struct logger *logger, struct database *database, struct trackingdata *trackingdata) { +retvalue target_removepackage_by_cursor(struct target_cursor *tc, struct logger *logger, struct trackingdata *trackingdata) { struct target * const target = tc->target; const char * const name = tc->lastname; const char * const control = tc->lastcontrol; @@ -310,50 +312,49 @@ retvalue result, r; char *oldsource, *oldsversion; - assert( target != NULL && target->packages != NULL ); - assert( name != NULL && control != NULL ); + assert (target != NULL && target->packages != NULL); + assert (name != NULL && control != NULL); - if( logger != NULL ) { + if (logger != NULL) { /* need to get the version for logging, if not available */ r = target->getversion(control, &oldpversion); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) oldpversion = NULL; } r = target->getfilekeys(control, &files); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(oldpversion); return r; } - if( trackingdata != NULL ) { + if (trackingdata != NULL) { r = target->getsourceandversion(control, name, &oldsource, &oldsversion); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { oldsource = oldsversion = NULL; } } else { oldsource = oldsversion = NULL; } - if( verbose > 0 ) + if (verbose > 0) printf("removing '%s' from '%s'...\n", name, target->identifier); result = cursor_delete(target->packages, tc->cursor, tc->lastname, NULL); - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { target->wasmodified = true; - if( oldsource != NULL && oldsversion != NULL ) { + if (oldsource != NULL && oldsversion != NULL) { r = trackingdata_remove(trackingdata, oldsource, oldsversion, &files); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } - if( trackingdata == NULL ) + if (trackingdata == NULL) target->staletracking = true; - if( logger != NULL ) + if (logger != NULL) logger_log(logger, target, name, NULL, oldpversion, NULL, control, NULL, &files, NULL, NULL); - r = references_delete(database, target->identifier, &files, - NULL); + r = references_delete(target->identifier, &files, NULL); RET_UPDATE(result, r); } strlist_done(&files); @@ -361,91 +362,79 @@ return result; } -static retvalue addpackages(struct target *target, struct database *database, - const char *packagename, const char *controlchunk, - /*@null@*/const char *oldcontrolchunk, - const char *version, /*@null@*/const char *oldversion, - const struct strlist *files, - /*@only@*//*@null@*/struct strlist *oldfiles, - /*@null@*/struct logger *logger, - /*@null@*/struct trackingdata *trackingdata, - architecture_t architecture, - /*@null@*//*@only@*/char *oldsource,/*@null@*//*@only@*/char *oldsversion, - /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom) { +static retvalue addpackages(struct target *target, const char *packagename, const char *controlchunk, /*@null@*/const char *oldcontrolchunk, const char *version, /*@null@*/const char *oldversion, const struct strlist *files, /*@only@*//*@null@*/struct strlist *oldfiles, /*@null@*/struct logger *logger, /*@null@*/struct trackingdata *trackingdata, architecture_t architecture, /*@null@*//*@only@*/char *oldsource, /*@null@*//*@only@*/char *oldsversion, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom) { - retvalue result,r; + retvalue result, r; struct table *table = target->packages; enum filetype filetype; - assert( atom_defined(architecture) ); + assert (atom_defined(architecture)); - if( architecture == architecture_source ) + if (architecture == architecture_source) filetype = ft_SOURCE; - else if( architecture == architecture_all ) + else if (architecture == architecture_all) filetype = ft_ALL_BINARY; else filetype = ft_ARCH_BINARY; /* mark it as needed by this distribution */ - r = references_insert(database, target->identifier, - files, oldfiles); + r = references_insert(target->identifier, files, oldfiles); - if( RET_WAS_ERROR(r) ) { - if( oldfiles != NULL ) + if (RET_WAS_ERROR(r)) { + if (oldfiles != NULL) strlist_done(oldfiles); return r; } /* Add package to the distribution's database */ - if( oldcontrolchunk != NULL ) { + if (oldcontrolchunk != NULL) { result = table_replacerecord(table, packagename, controlchunk); } else { result = table_adduniqrecord(table, packagename, controlchunk); } - if( RET_WAS_ERROR(result) ) { - if( oldfiles != NULL ) + if (RET_WAS_ERROR(result)) { + if (oldfiles != NULL) strlist_done(oldfiles); return result; } - if( logger != NULL ) + if (logger != NULL) logger_log(logger, target, packagename, version, oldversion, controlchunk, oldcontrolchunk, files, oldfiles, causingrule, suitefrom); r = trackingdata_insert(trackingdata, filetype, files, - oldsource, oldsversion, oldfiles, database); - RET_UPDATE(result,r); + oldsource, oldsversion, oldfiles); + RET_UPDATE(result, r); /* remove old references to files */ - if( oldfiles != NULL ) { - r = references_delete(database, target->identifier, - oldfiles, files); - RET_UPDATE(result,r); + if (oldfiles != NULL) { + r = references_delete(target->identifier, oldfiles, files); + RET_UPDATE(result, r); strlist_done(oldfiles); } return result; } -retvalue target_addpackage(struct target *target, struct logger *logger, struct database *database, const char *name, const char *version, const char *control, const struct strlist *filekeys, bool downgrade, struct trackingdata *trackingdata, enum filetype filetype, const char *causingrule, const char *suitefrom) { - struct strlist oldfilekeys,*ofk; - char *oldcontrol,*oldsource,*oldsversion; +retvalue target_addpackage(struct target *target, struct logger *logger, const char *name, const char *version, const char *control, const struct strlist *filekeys, bool downgrade, struct trackingdata *trackingdata, enum filetype filetype, const char *causingrule, const char *suitefrom) { + struct strlist oldfilekeys, *ofk; + char *oldcontrol, *oldsource, *oldsversion; char *oldpversion; retvalue r; assert(target->packages!=NULL); r = table_getrecord(target->packages, name, &oldcontrol); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { ofk = NULL; oldsource = NULL; oldsversion = NULL; @@ -454,27 +443,37 @@ } else { r = target->getversion(oldcontrol, &oldpversion); - if( RET_WAS_ERROR(r) && !IGNORING_(brokenold,"Error parsing old version!\n") ) { + if (RET_WAS_ERROR(r) && !IGNORING(brokenold, +"Error parsing old version!\n")) { free(oldcontrol); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { int versioncmp; - r = dpkgversions_cmp(version,oldpversion,&versioncmp); - if( RET_WAS_ERROR(r) ) { - if( !IGNORING_(brokenversioncmp,"Parse errors processing versions of %s.\n",name) ) { + r = dpkgversions_cmp(version, oldpversion, &versioncmp); + if (RET_WAS_ERROR(r)) { + if (!IGNORING(brokenversioncmp, +"Parse errors processing versions of %s.\n", name)) { free(oldpversion); free(oldcontrol); return r; } } else { - if( versioncmp <= 0 ) { - /* new Version is not newer than old version */ - if( downgrade ) { - fprintf(stderr,"Warning: downgrading '%s' from '%s' to '%s' in '%s'!\n",name,oldpversion,version,target->identifier); + if (versioncmp <= 0) { + /* new Version is not newer than + * old version */ + if (downgrade) { + fprintf(stderr, +"Warning: downgrading '%s' from '%s' to '%s' in '%s'!\n", name, + oldpversion, version, + target->identifier); } else { - fprintf(stderr,"Skipping inclusion of '%s' '%s' in '%s', as it has already '%s'.\n",name,version,target->identifier,oldpversion); + fprintf(stderr, +"Skipping inclusion of '%s' '%s' in '%s', as it has already '%s'.\n", + name, version, + target->identifier, + oldpversion); free(oldpversion); free(oldcontrol); return RET_NOTHING; @@ -485,8 +484,9 @@ oldpversion = NULL; r = target->getfilekeys(oldcontrol, &oldfilekeys); ofk = &oldfilekeys; - if( RET_WAS_ERROR(r) ) { - if( IGNORING_(brokenold,"Error parsing files belonging to installed version of %s!\n",name)) { + if (RET_WAS_ERROR(r)) { + if (IGNORING(brokenold, +"Error parsing files belonging to installed version of %s!\n", name)) { ofk = NULL; oldsversion = oldsource = NULL; } else { @@ -494,12 +494,13 @@ free(oldpversion); return r; } - } else if(trackingdata != NULL) { + } else if (trackingdata != NULL) { r = target->getsourceandversion(oldcontrol, name, &oldsource, &oldsversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(ofk); - if( IGNORING_(brokenold,"Error searching for source name of installed version of %s!\n",name)) { + if (IGNORING(brokenold, +"Error searching for source name of installed version of %s!\n", name)) { // TODO: free something of oldfilekeys? ofk = NULL; oldsversion = oldsource = NULL; @@ -514,15 +515,15 @@ } } - r = addpackages(target, database, name, control, oldcontrol, + r = addpackages(target, name, control, oldcontrol, version, oldpversion, filekeys, ofk, logger, trackingdata, filetype, oldsource, oldsversion, causingrule, suitefrom); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { target->wasmodified = true; - if( trackingdata == NULL ) + if (trackingdata == NULL) target->staletracking = true; } free(oldpversion); @@ -532,17 +533,17 @@ } retvalue target_checkaddpackage(struct target *target, const char *name, const char *version, bool tracking, bool permitnewerold) { - struct strlist oldfilekeys,*ofk; - char *oldcontrol,*oldsource,*oldsversion; + struct strlist oldfilekeys, *ofk; + char *oldcontrol, *oldsource, *oldsversion; char *oldpversion; retvalue r; assert(target->packages!=NULL); r = table_getrecord(target->packages, name, &oldcontrol); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { ofk = NULL; oldsource = NULL; oldsversion = NULL; @@ -552,16 +553,16 @@ int versioncmp; r = target->getversion(oldcontrol, &oldpversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error extracting version from old '%s' in '%s'. Database corrupted?\n", name, target->identifier); free(oldcontrol); return r; } - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); - r = dpkgversions_cmp(version,oldpversion,&versioncmp); - if( RET_WAS_ERROR(r) ) { + r = dpkgversions_cmp(version, oldpversion, &versioncmp); + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Parse error comparing version '%s' of '%s' with old version '%s' in '%s'\n.", version, name, oldpversion, @@ -570,19 +571,19 @@ free(oldcontrol); return r; } - if( versioncmp <= 0 ) { + if (versioncmp <= 0) { r = RET_NOTHING; - if( versioncmp < 0 ) { - if( !permitnewerold ) { + if (versioncmp < 0) { + if (!permitnewerold) { fprintf(stderr, "Error: trying to put version '%s' of '%s' in '%s',\n" "while there already is the stricly newer '%s' in there.\n" -"(To ignore this error add Permit: older_version.)\n" - ,name, version, +"(To ignore this error add Permit: older_version.)\n", + name, version, target->identifier, oldpversion); r = RET_ERROR; - } else if( verbose >= 0 ) { + } else if (verbose >= 0) { printf( "Warning: trying to put version '%s' of '%s' in '%s',\n" "while there already is '%s' in there.\n", @@ -590,7 +591,7 @@ target->identifier, oldpversion); } - } else if( verbose > 2 ) { + } else if (verbose > 2) { printf( "Will not put '%s' in '%s', as already there with same version '%s'.\n", name, target->identifier, @@ -603,7 +604,7 @@ } r = target->getfilekeys(oldcontrol, &oldfilekeys); ofk = &oldfilekeys; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error extracting installed files from old '%s' in '%s'.\nDatabase corrupted?\n", name, target->identifier); @@ -611,10 +612,10 @@ free(oldpversion); return r; } - if( tracking ) { + if (tracking) { r = target->getsourceandversion(oldcontrol, name, &oldsource, &oldsversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { fprintf(stderr, "Error extracting source name and version from '%s' in '%s'. Database corrupted?\n", name, target->identifier); @@ -634,13 +635,13 @@ return RET_OK; } -retvalue target_rereference(struct target *target, struct database *database) { - retvalue result,r; +retvalue target_rereference(struct target *target) { + retvalue result, r; struct target_cursor iterator; const char *package, *control; - if( verbose > 1 ) { - if( verbose > 2 ) + if (verbose > 1) { + if (verbose > 2) printf("Unlocking dependencies of %s...\n", target->identifier); else @@ -648,28 +649,28 @@ target->identifier); } - result = references_remove(database, target->identifier); - if( verbose > 2 ) + result = references_remove(target->identifier); + if (verbose > 2) printf("Referencing %s...\n", target->identifier); - r = target_openiterator(target, database, READONLY, &iterator); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + r = target_openiterator(target, READONLY, &iterator); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - while( target_nextpackage(&iterator, &package, &control) ) { + while (target_nextpackage(&iterator, &package, &control)) { struct strlist filekeys; r = target->getfilekeys(control, &filekeys); RET_UPDATE(result, r); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) continue; - if( verbose > 10 ) { + if (verbose > 10) { fprintf(stderr, "adding references to '%s' for '%s': ", target->identifier, package); (void)strlist_fprint(stderr, &filekeys); (void)putc('\n', stderr); } - r = references_insert(database, target->identifier, &filekeys, NULL); + r = references_insert(target->identifier, &filekeys, NULL); strlist_done(&filekeys); RET_UPDATE(result, r); } @@ -678,101 +679,119 @@ return result; } -retvalue package_referenceforsnapshot(struct database *database, UNUSED(struct distribution *di), struct target *target, const char *package, const char *chunk, void *data) { +retvalue package_referenceforsnapshot(UNUSED(struct distribution *di), struct target *target, const char *package, const char *chunk, void *data) { const char *identifier = data; struct strlist filekeys; retvalue r; r = target->getfilekeys(chunk, &filekeys); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( verbose > 15 ) { + if (verbose > 15) { fprintf(stderr, "adding references to '%s' for '%s': ", identifier, package); (void)strlist_fprint(stderr, &filekeys); (void)putc('\n', stderr); } - r = references_add(database, identifier, &filekeys); + r = references_add(identifier, &filekeys); strlist_done(&filekeys); return r; } -retvalue package_check(struct database *database, UNUSED(struct distribution *di), struct target *target, const char *package, const char *chunk, UNUSED(void *pd)) { +retvalue package_check(UNUSED(struct distribution *di), struct target *target, const char *package, const char *chunk, UNUSED(void *pd)) { struct checksumsarray files; struct strlist expectedfilekeys; char *dummy, *version; - retvalue result,r; + retvalue result = RET_OK, r; architecture_t package_architecture; r = target->getversion(chunk, &version); - if( !RET_IS_OK(r) ) { - fprintf(stderr, "Error extraction version number from package control info of '%s'!\n", package); - if( r == RET_NOTHING ) + if (!RET_IS_OK(r)) { + fprintf(stderr, +"Error extraction version number from package control info of '%s'!\n", + package); + if (r == RET_NOTHING) r = RET_ERROR_MISSING; return r; } r = target->getarchitecture(chunk, &package_architecture); - if( !RET_IS_OK(r) ) { - fprintf(stderr, "Error extraction architecture from package control info of '%s'!\n", package); - if( r == RET_NOTHING ) + if (!RET_IS_OK(r)) { + fprintf(stderr, +"Error extraction architecture from package control info of '%s'!\n", + package); + if (r == RET_NOTHING) r = RET_ERROR_MISSING; return r; } + /* check if the architecture matches the architecture where this + * package belongs to. */ + if (target->architecture != package_architecture && + package_architecture != architecture_all) { + fprintf(stderr, +"Wrong architecture '%s' of package '%s' in '%s'!\n", + atoms_architectures[package_architecture], + package, target->identifier); + result = RET_ERROR; + } r = target->getinstalldata(target, package, version, package_architecture, chunk, &dummy, &expectedfilekeys, &files); - if( RET_WAS_ERROR(r) ) { - fprintf(stderr, "Error extracting information of package '%s'!\n", + if (RET_WAS_ERROR(r)) { + fprintf(stderr, +"Error extracting information of package '%s'!\n", package); + result = r; } free(version); - result = r; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(dummy); - if( !strlist_subset(&expectedfilekeys, &files.names, NULL) || - !strlist_subset(&expectedfilekeys, &files.names, NULL) ) { - (void)fprintf(stderr, "Reparsing the package information of '%s' yields to the expectation to find:\n", package); + if (!strlist_subset(&expectedfilekeys, &files.names, NULL) || + !strlist_subset(&expectedfilekeys, &files.names, NULL)) { + (void)fprintf(stderr, +"Reparsing the package information of '%s' yields to the expectation to find:\n", + package); (void)strlist_fprint(stderr, &expectedfilekeys); (void)fputs("but found:\n", stderr); (void)strlist_fprint(stderr, &files.names); - (void)putc('\n',stderr); + (void)putc('\n', stderr); result = RET_ERROR; } strlist_done(&expectedfilekeys); } else { r = target->getchecksums(chunk, &files); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = RET_ERROR; - if( RET_WAS_ERROR(r) ) { - fprintf(stderr, "Even more errors extracting information of package '%s'!\n", + if (RET_WAS_ERROR(r)) { + fprintf(stderr, +"Even more errors extracting information of package '%s'!\n", package); return r; } } - if( verbose > 10 ) { + if (verbose > 10) { fprintf(stderr, "checking files of '%s'\n", package); } - r = files_expectfiles(database, &files.names, files.checksums); - if( RET_WAS_ERROR(r) ) { - fprintf(stderr,"Files are missing for '%s'!\n", package); + r = files_expectfiles(&files.names, files.checksums); + if (RET_WAS_ERROR(r)) { + fprintf(stderr, "Files are missing for '%s'!\n", package); } - RET_UPDATE(result,r); - if( verbose > 10 ) { + RET_UPDATE(result, r); + if (verbose > 10) { (void)fprintf(stderr, "checking references to '%s' for '%s': ", target->identifier, package); (void)strlist_fprint(stderr, &files.names); (void)putc('\n', stderr); } - r = references_check(database, target->identifier, &files.names); - RET_UPDATE(result,r); + r = references_check(target->identifier, &files.names); + RET_UPDATE(result, r); checksumsarray_done(&files); return result; } /* Reapply override information */ -retvalue target_reoverride(struct target *target, struct distribution *distribution, struct database *database) { +retvalue target_reoverride(struct target *target, struct distribution *distribution) { struct target_cursor iterator; retvalue result, r; const char *package, *controlchunk; @@ -780,30 +799,34 @@ assert(target->packages == NULL); assert(distribution != NULL); - if( verbose > 1 ) { - fprintf(stderr,"Reapplying overrides packages in '%s'...\n",target->identifier); + if (verbose > 1) { + fprintf(stderr, +"Reapplying overrides packages in '%s'...\n", + target->identifier); } - r = target_openiterator(target, database, READWRITE, &iterator); - if( !RET_IS_OK(r) ) + r = target_openiterator(target, READWRITE, &iterator); + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &package, &controlchunk) ) { + while (target_nextpackage(&iterator, &package, &controlchunk)) { char *newcontrolchunk = NULL; r = target->doreoverride(target, package, controlchunk, &newcontrolchunk); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) { - if( verbose > 0 ) - (void)fputs("target_reoverride: Stopping procession of further packages due to previous errors\n", stderr); + if (RET_WAS_ERROR(r)) { + if (verbose > 0) + (void)fputs( +"target_reoverride: Stopping procession of further packages due to previous errors\n", + stderr); break; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = cursor_replace(target->packages, iterator.cursor, newcontrolchunk, strlen(newcontrolchunk)); free(newcontrolchunk); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } @@ -817,27 +840,25 @@ /* export a database */ -retvalue target_export(struct target *target, struct database *database, bool onlyneeded, bool snapshot, struct release *release) { +retvalue target_export(struct target *target, bool onlyneeded, bool snapshot, struct release *release) { retvalue result; bool onlymissing; - if( verbose > 5 ) { - if( onlyneeded ) - printf(" looking for changes in '%s'...\n",target->identifier); + if (verbose > 5) { + if (onlyneeded) + printf(" looking for changes in '%s'...\n", + target->identifier); else - printf(" exporting '%s'...\n",target->identifier); + printf(" exporting '%s'...\n", target->identifier); } /* not exporting if file is already there? */ onlymissing = onlyneeded && !target->wasmodified; - result = export_target(target->relativedirectory, - target, database, - target->exportmode, - release, - onlymissing, snapshot); + result = export_target(target->relativedirectory, target, + target->exportmode, release, onlymissing, snapshot); - if( !RET_WAS_ERROR(result) && !snapshot ) { + if (!RET_WAS_ERROR(result) && !snapshot) { target->saved_wasmodified = target->saved_wasmodified || target->wasmodified; target->wasmodified = false; @@ -845,22 +866,26 @@ return result; } -retvalue package_rerunnotifiers(UNUSED(struct database *da), struct distribution *distribution, struct target *target, const char *package, const char *chunk, UNUSED(void *data)) { +retvalue package_rerunnotifiers(struct distribution *distribution, struct target *target, const char *package, const char *chunk, UNUSED(void *data)) { struct logger *logger = distribution->logger; struct strlist filekeys; char *version; retvalue r; r = target->getversion(chunk, &version); - if( !RET_IS_OK(r) ) { - fprintf(stderr,"Error extraction version number from package control info of '%s'!\n",package); - if( r == RET_NOTHING ) + if (!RET_IS_OK(r)) { + fprintf(stderr, +"Error extraction version number from package control info of '%s'!\n", + package); + if (r == RET_NOTHING) r = RET_ERROR_MISSING; return r; } r = target->getfilekeys(chunk, &filekeys); - if( RET_WAS_ERROR(r) ) { - fprintf(stderr,"Error extracting information about used files from package '%s'!\n",package); + if (RET_WAS_ERROR(r)) { + fprintf(stderr, +"Error extracting information about used files from package '%s'!\n", + package); free(version); return r; } diff -Nru reprepro-4.5.0/target.h reprepro-4.6.0/target.h --- reprepro-4.5.0/target.h 2011-02-21 15:34:29.000000000 +0000 +++ reprepro-4.6.0/target.h 2011-05-05 14:42:55.000000000 +0000 @@ -32,17 +32,17 @@ /* md5sums may be NULL */ typedef retvalue get_filekeys(const char *, /*@out@*/struct strlist *); typedef retvalue get_checksums(const char *, /*@out@*/struct checksumsarray *); -typedef retvalue do_reoverride(const struct target *, const char *packagename, const char *controlchunk, /*@out@*/char **newcontrolchunk); -typedef retvalue do_retrack(const char *packagename, const char *controlchunk, trackingdb, struct database *); -typedef retvalue get_sourceandversion(const char *chunk, const char *packagename, /*@out@*/char **source, /*@out@*/char **version); -typedef retvalue complete_checksums(const char *chunk, const struct strlist *, struct checksums **, /*@out@*/char **); +typedef retvalue do_reoverride(const struct target *, const char * /*packagename*/, const char *, /*@out@*/char **); +typedef retvalue do_retrack(const char * /*packagename*/, const char * /*controlchunk*/, trackingdb); +typedef retvalue get_sourceandversion(const char *, const char * /*packagename*/, /*@out@*/char ** /*source_p*/, /*@out@*/char ** /*version_p*/); +typedef retvalue complete_checksums(const char *, const struct strlist *, struct checksums **, /*@out@*/char **); struct distribution; struct target { struct distribution *distribution; - component_t component_atom; - architecture_t architecture_atom; - packagetype_t packagetype_atom; + component_t component; + architecture_t architecture; + packagetype_t packagetype; char *identifier; /* links into the correct description in distribution */ /*@dependent@*/const struct exportmode *exportmode; @@ -73,19 +73,17 @@ bool staletracking; }; -retvalue target_initialize_ubinary(/*@dependant@*/struct distribution *, component_t, architecture_t, /*@dependent@*/const struct exportmode *, bool readonly, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); -retvalue target_initialize_binary(/*@dependant@*/struct distribution *, component_t, architecture_t, /*@dependent@*/const struct exportmode *, bool readonly, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); -retvalue target_initialize_source(/*@dependant@*/struct distribution *, component_t, /*@dependent@*/const struct exportmode *, bool readonly, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); -retvalue target_free(struct target *target); +retvalue target_initialize_ubinary(/*@dependant@*/struct distribution *, component_t, architecture_t, /*@dependent@*/const struct exportmode *, bool /*readonly*/, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); +retvalue target_initialize_binary(/*@dependant@*/struct distribution *, component_t, architecture_t, /*@dependent@*/const struct exportmode *, bool /*readonly*/, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); +retvalue target_initialize_source(/*@dependant@*/struct distribution *, component_t, /*@dependent@*/const struct exportmode *, bool /*readonly*/, /*@NULL@*/const char *fakecomponentprefix, /*@out@*/struct target **); +retvalue target_free(struct target *); -retvalue target_export(struct target *target, struct database *, bool onlyneeded, bool snapshot, struct release *release); - -retvalue target_printmd5sums(const char *dirofdist,const struct target *target,FILE *out,int force); +retvalue target_export(struct target *, bool /*onlyneeded*/, bool /*snapshot*/, struct release *); /* This opens up the database, if db != NULL, *db will be set to it.. */ -retvalue target_initpackagesdb(struct target *target, struct database *, bool readonly); +retvalue target_initpackagesdb(struct target *, bool /*readonly*/); /* this closes databases... */ -retvalue target_closepackagesdb(struct target *target); +retvalue target_closepackagesdb(struct target *); struct target_cursor { /*@temp@*/struct target *target; @@ -95,17 +93,17 @@ }; #define TARGET_CURSOR_ZERO {NULL, NULL, NULL, NULL} /* wrapper around initpackagesdb and table_newglobalcursor */ -static inline retvalue target_openiterator(struct target *t, struct database *db, bool readonly, /*@out@*/struct target_cursor *tc) { +static inline retvalue target_openiterator(struct target *t, bool readonly, /*@out@*/struct target_cursor *tc) { retvalue r, r2; struct cursor *c; - r = target_initpackagesdb(t, db, readonly); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + r = target_initpackagesdb(t, readonly); + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; r = table_newglobalcursor(t->packages, &c); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { r2 = target_closepackagesdb(t); RET_UPDATE(r, r2); return r; @@ -119,7 +117,7 @@ bool success; success = cursor_nexttemp(tc->target->packages, tc->cursor, &tc->lastname, &tc->lastcontrol); - if( success ) { + if (success) { *packagename_p = tc->lastname; *chunk_p = tc->lastcontrol; } else { @@ -147,27 +145,27 @@ /* The following calls can only be called if target_initpackagesdb was called before: */ struct logger; -retvalue target_addpackage(struct target *, /*@null@*/struct logger *, struct database *, const char *name, const char *version, const char *control, const struct strlist *filekeys, bool downgrade, /*@null@*/struct trackingdata *, enum filetype, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom); -retvalue target_checkaddpackage(struct target *target, const char *name, const char *version, bool tracking, bool permitnewerold); -retvalue target_removepackage(struct target *, /*@null@*/struct logger *, struct database *, const char *name, struct trackingdata *); +retvalue target_addpackage(struct target *, /*@null@*/struct logger *, const char *name, const char *version, const char *control, const struct strlist *filekeys, bool downgrade, /*@null@*/struct trackingdata *, enum filetype, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom); +retvalue target_checkaddpackage(struct target *, const char *name, const char *version, bool tracking, bool permitnewerold); +retvalue target_removepackage(struct target *, /*@null@*/struct logger *, const char *name, struct trackingdata *); /* like target_removepackage, but do not read control data yourself but use available */ -retvalue target_removereadpackage(struct target *, /*@null@*/struct logger *, struct database *, const char *name, const char *oldcontrol, /*@null@*/struct trackingdata *); +retvalue target_removereadpackage(struct target *, /*@null@*/struct logger *, const char *name, const char *oldcontrol, /*@null@*/struct trackingdata *); /* Like target_removepackage, but delete the package record by cursor */ -retvalue target_removepackage_by_cursor(struct target_cursor *, /*@null@*/struct logger *, struct database *, /*@null@*/struct trackingdata *); +retvalue target_removepackage_by_cursor(struct target_cursor *, /*@null@*/struct logger *, /*@null@*/struct trackingdata *); -retvalue package_check(struct database *, struct distribution *, struct target *, const char *, const char *, void *); -retvalue target_rereference(struct target *, struct database *); -retvalue package_referenceforsnapshot(struct database *, struct distribution *, struct target *, const char *, const char *, void *); -retvalue target_reoverride(struct target *, struct distribution *, struct database *); +retvalue package_check(struct distribution *, struct target *, const char *, const char *, void *); +retvalue target_rereference(struct target *); +retvalue package_referenceforsnapshot(struct distribution *, struct target *, const char *, const char *, void *); +retvalue target_reoverride(struct target *, struct distribution *); -retvalue package_rerunnotifiers(struct database *, struct distribution *, struct target *, const char *, const char *, void *); +retvalue package_rerunnotifiers(struct distribution *, struct target *, const char *, const char *, void *); static inline bool target_matches(const struct target *t, const struct atomlist *components, const struct atomlist *architectures, const struct atomlist *packagetypes) { - if( limitations_missed(components, t->component_atom) ) + if (limitations_missed(components, t->component)) return false; - if( limitations_missed(architectures, t->architecture_atom) ) + if (limitations_missed(architectures, t->architecture)) return false; - if( limitations_missed(packagetypes, t->packagetype_atom) ) + if (limitations_missed(packagetypes, t->packagetype)) return false; return true; } diff -Nru reprepro-4.5.0/termdecide.c reprepro-4.6.0/termdecide.c --- reprepro-4.5.0/termdecide.c 2009-07-25 14:47:05.000000000 +0000 +++ reprepro-4.6.0/termdecide.c 2011-05-05 14:42:55.000000000 +0000 @@ -34,20 +34,20 @@ #include "termdecide.h" static inline bool check_field(enum term_comparison c, const char *value, const char *with) { - if( c == tc_none) { + if (c == tc_none) { return true; - } else if( c == tc_globmatch ) { + } else if (c == tc_globmatch) { return globmatch(value, with); - } else if(c == tc_notglobmatch ) { + } else if (c == tc_notglobmatch) { return !globmatch(value, with); } else { int i; i = strcmp(value, with); - if( i < 0 ) + if (i < 0) return c == tc_strictless || c == tc_lessorequal || c == tc_notequal; - else if( i > 0 ) + else if (i > 0) return c == tc_strictmore || c == tc_moreorequal || c == tc_notequal; @@ -61,22 +61,22 @@ retvalue term_decidechunk(const term *condition, const char *controlchunk, const void *privdata) { const struct term_atom *atom = condition; - while( atom != NULL ) { - bool correct;char *value; + while (atom != NULL) { + bool correct; char *value; enum term_comparison c = atom->comparison; retvalue r; - if( atom->isspecial ) { + if (atom->isspecial) { correct = atom->special.type->compare(c, &atom->special.comparewith, controlchunk, privdata); } else { r = chunk_getvalue(controlchunk, atom->generic.key, &value); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { - correct = ( c == tc_notequal + if (r == RET_NOTHING) { + correct = (c == tc_notequal || c == tc_notglobmatch); } else { correct = check_field(c, value, @@ -84,13 +84,13 @@ free(value); } } - if( atom->negated ) + if (atom->negated) correct = !correct; - if( correct ) { + if (correct) { atom = atom->nextiftrue; } else { atom = atom->nextiffalse; - if( atom == NULL) { + if (atom == NULL) { /* do not include */ return RET_NOTHING; } @@ -102,7 +102,7 @@ } static retvalue parsestring(enum term_comparison c, const char *value, size_t len, struct compare_with *v) { - if( c == tc_none ) { + if (c == tc_none) { fprintf(stderr, "Error: Special formula predicates (those starting with '$') are always\n" "defined, thus specifying them without parameter to compare against\n" @@ -110,7 +110,7 @@ return RET_ERROR; } v->pointer = strndup(value, len); - if( FAILEDTOALLOC(v->pointer) ) + if (FAILEDTOALLOC(v->pointer)) return RET_ERROR_OOM; return RET_OK; } @@ -126,11 +126,11 @@ // TODO: make more efficient r = chunk_getvalue(control, "Package", &package); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return false; r = target->getsourceandversion(control, package, &source, &version); free(package); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return false; free(version); matches = check_field(c, source, v->pointer); @@ -139,17 +139,17 @@ } static inline bool compare_dpkgversions(enum term_comparison c, const char *version, const char *param) { - if( c != tc_globmatch && c != tc_notglobmatch ) { + if (c != tc_globmatch && c != tc_notglobmatch) { int cmp; retvalue r; r = dpkgversions_cmp(version, param, &cmp); - if( RET_IS_OK(r) ) { - if( cmp < 0 ) + if (RET_IS_OK(r)) { + if (cmp < 0) return c == tc_strictless || c == tc_lessorequal || c == tc_notequal; - else if( cmp > 0 ) + else if (cmp > 0) return c == tc_strictmore || c == tc_moreorequal || c == tc_notequal; @@ -171,7 +171,7 @@ bool matches; r = target->getversion(control, &version); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return false; matches = compare_dpkgversions(c, version, v->pointer); free(version); @@ -186,11 +186,11 @@ // TODO: make more efficient r = chunk_getvalue(control, "Package", &package); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return false; r = target->getsourceandversion(control, package, &source, &version); free(package); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return false; free(source); matches = compare_dpkgversions(c, version, v->pointer); @@ -202,25 +202,25 @@ free(d->pointer); } static void freeatom(enum term_comparison c, struct compare_with *d) { - if( c != tc_equal && c != tc_notequal ) + if (c != tc_equal && c != tc_notequal) free(d->pointer); } static retvalue parsetype(enum term_comparison c, const char *value, size_t len, struct compare_with *v) { - if( c == tc_none ) { + if (c == tc_none) { fprintf(stderr, "Error: $Type is always defined, it does not make sense without parameter\n" "to compare against!\n"); return RET_ERROR; } - if( c != tc_equal && c != tc_notequal ) { + if (c != tc_equal && c != tc_notequal) { v->pointer = strndup(value, len); - if( FAILEDTOALLOC(v->pointer) ) + if (FAILEDTOALLOC(v->pointer)) return RET_ERROR_OOM; return RET_OK; } v->number = packagetype_find_l(value, len); - if( atom_defined(v->number) ) + if (atom_defined(v->number)) return RET_OK; fprintf(stderr, "Unknown package type '%.*s' in formula!\n", (int)len, value); @@ -228,81 +228,84 @@ } static retvalue parsearchitecture(enum term_comparison c, const char *value, size_t len, struct compare_with *v) { - if( c == tc_none ) { + if (c == tc_none) { fprintf(stderr, "Error: $Architecture is always defined, it does not make sense without parameter\n" "to compare against!\n"); return RET_ERROR; } - if( c != tc_equal && c != tc_notequal ) { + if (c != tc_equal && c != tc_notequal) { v->pointer = strndup(value, len); - if( FAILEDTOALLOC(v->pointer) ) + if (FAILEDTOALLOC(v->pointer)) return RET_ERROR_OOM; return RET_OK; } v->number = architecture_find_l(value, len); - if( atom_defined(v->number) ) + if (atom_defined(v->number)) return RET_OK; - fprintf(stderr, "Unknown architecture '%.*s' in formula (must be listed in conf/distributions to be known)!\n", + fprintf(stderr, +"Unknown architecture '%.*s' in formula (must be listed in conf/distributions to be known)!\n", (int)len, value); return RET_ERROR; } static retvalue parsecomponent(enum term_comparison c, const char *value, size_t len, struct compare_with *v) { - if( c == tc_none ) { + if (c == tc_none) { fprintf(stderr, "Error: $Component is always defined, it does not make sense without parameter\n" "to compare against!\n"); return RET_ERROR; } - if( c != tc_equal && c != tc_notequal ) { + if (c != tc_equal && c != tc_notequal) { v->pointer = strndup(value, len); - if( FAILEDTOALLOC(v->pointer) ) + if (FAILEDTOALLOC(v->pointer)) return RET_ERROR_OOM; return RET_OK; } v->number = component_find_l(value, len); - if( atom_defined(v->number) ) + if (atom_defined(v->number)) return RET_OK; - fprintf(stderr, "Unknown component '%.*s' in formula (must be listed in conf/distributions to be known)!\n", (int)len, value); + fprintf(stderr, +"Unknown component '%.*s' in formula (must be listed in conf/distributions to be known)!\n", + (int)len, value); return RET_ERROR; } static bool comparetype(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), const void *d2) { const struct target *target = d2; - if( c == tc_equal ) - return v->number == target->packagetype_atom; - else if( c == tc_notequal ) - return v->number != target->packagetype_atom; + if (c == tc_equal) + return v->number == target->packagetype; + else if (c == tc_notequal) + return v->number != target->packagetype; else return check_field(c, - atoms_packagetypes[target->packagetype_atom], + atoms_packagetypes[target->packagetype], v->pointer); } static bool comparearchitecture(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), const void *d2) { const struct target *target = d2; - if( c == tc_equal ) - return v->number == target->architecture_atom; - else if( c == tc_notequal ) - return v->number != target->architecture_atom; + if (c == tc_equal) + return v->number == target->architecture; + else if (c == tc_notequal) + return v->number != target->architecture; else return check_field(c, - atoms_architectures[target->architecture_atom], + atoms_architectures[target->architecture], v->pointer); } static bool comparecomponent(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), const void *d2) { const struct target *target = d2; - if( c == tc_equal ) - return v->number == target->component_atom; - else if( c == tc_notequal ) - return v->number != target->component_atom; + if (c == tc_equal) + return v->number == target->component; + else if (c == tc_notequal) + return v->number != target->component; else return check_field(c, - atoms_components[target->component_atom], + atoms_components[target->component], v->pointer); } diff -Nru reprepro-4.5.0/terms.c reprepro-4.6.0/terms.c --- reprepro-4.5.0/terms.c 2009-07-26 11:39:31.000000000 +0000 +++ reprepro-4.6.0/terms.c 2011-05-05 14:42:55.000000000 +0000 @@ -32,11 +32,11 @@ #include "terms.h" void term_free(term *t) { - while( t != NULL ) { + while (t != NULL) { struct term_atom *next = t->next; - if( t->isspecial ) { - if( t->special.type != NULL && - t->special.type->done != NULL ) + if (t->isspecial) { + if (t->special.type != NULL && + t->special.type->done != NULL) t->special.type->done(t->comparison, &t->special.comparewith); @@ -53,71 +53,77 @@ static retvalue parseatom(const char **formula, /*@out@*/struct term_atom **atom, int options, const struct term_special *specials) { struct term_atom *a; const char *f = *formula; -#define overspace() while( *f != '\0' && xisspace(*f) ) f++ - const char *keystart,*keyend; - const char *valuestart,*valueend; +#define overspace() while (*f != '\0' && xisspace(*f)) f++ + const char *keystart, *keyend; + const char *valuestart, *valueend; enum term_comparison comparison = tc_none; bool negated = false; const struct term_special *s; overspace(); - if( *f == '!' && ISSET(options,T_NEGATION) ) { + if (*f == '!' && ISSET(options, T_NEGATION)) { negated = true; f++; } keystart = f; // TODO: allow more strict checking again with some option? - while( *f != '\0' && *f != '(' && !xisspace(*f) && *f != ',' && *f != '|' && *f !='(' && *f != ')' && *f != '[' && *f != '!' ) + while (*f != '\0' && *f != '(' && !xisspace(*f) && *f != ',' + && *f != '|' && *f !='(' && *f != ')' + && *f != '[' && *f != '!') f++; keyend = f; - if( keystart == keyend ) { + if (keystart == keyend) { *formula = f; return RET_NOTHING; } overspace(); - if( ISSET(options,T_VERSION) && *f == '(' ) { + if (ISSET(options, T_VERSION) && *f == '(') { f++; overspace(); - switch( *f ) { + switch (*f) { case '>': f++; - if( *f == '=' ) { + if (*f == '=') { comparison = tc_moreorequal; f++; - } else if( *f == '>' ) { + } else if (*f == '>') { comparison = tc_strictmore; f++; } else { comparison = tc_moreorequal; - fprintf(stderr,"Warning: Found a '(>' without '=' or '>' in '%s'(beginning cut), will be treated as '>='.\n",*formula); + fprintf(stderr, +"Warning: Found a '(>' without '=' or '>' in '%s'(beginning cut), will be treated as '>='.\n", + *formula); } break; case '<': f++; - if( *f == '=' ) { + if (*f == '=') { comparison = tc_lessorequal; f++; - } else if( *f == '<' ) { + } else if (*f == '<') { comparison = tc_strictless; f++; } else { comparison = tc_lessorequal; - fprintf(stderr,"Warning: Found a '(<' without '=' or '<' in '%s'(begin cut), will be treated as '<='.\n",*formula); + fprintf(stderr, +"Warning: Found a '(<' without '=' or '<' in '%s'(begin cut), will be treated as '<='.\n", + *formula); } break; case '=': f++; - if( *f == '=' ) + if (*f == '=') f++; - else if( *f != ' ' ) { + else if (*f != ' ') { *formula = f; return RET_NOTHING; } comparison = tc_equal; break; case '%': - if( ISSET(options, T_GLOBMATCH) ) { + if (ISSET(options, T_GLOBMATCH)) { f++; comparison = tc_globmatch; break; @@ -125,15 +131,15 @@ *formula = f; return RET_NOTHING; case '!': - if( f[1] == '%' && - ISSET(options, T_GLOBMATCH) ) { + if (f[1] == '%' && + ISSET(options, T_GLOBMATCH)) { f += 2; comparison = tc_notglobmatch; break; } - if( ISSET(options,T_NOTEQUAL) ) { + if (ISSET(options, T_NOTEQUAL)) { f++; - if( *f != '=' ) { + if (*f != '=') { *formula = f; return RET_NOTHING; } @@ -148,13 +154,13 @@ } overspace(); valueend = valuestart = f; - while( *f != '\0' && *f != ')' ) { + while (*f != '\0' && *f != ')') { valueend = f+1; f++; - while( *f != '\0' && xisspace(*f) ) + while (*f != '\0' && xisspace(*f)) f++; } - if( *f != ')' || valueend == valuestart ) { + if (*f != ')' || valueend == valuestart) { *formula = f; return RET_NOTHING; } @@ -165,49 +171,51 @@ valuestart = valueend = NULL; } overspace(); - if( ISSET(options,T_ARCHITECTURES) && *f == '[' ) { + if (ISSET(options, T_ARCHITECTURES) && *f == '[') { //TODO: implement this one... - assert( "Not yet implemented!" == NULL); + assert ("Not yet implemented!" == NULL); } - for( s = specials ; s->name != NULL ; s++ ) { - if( strncasecmp(s->name, keystart, keyend-keystart) == 0 && - s->name[keyend-keystart] == '\0' ) + for (s = specials ; s->name != NULL ; s++) { + if (strncasecmp(s->name, keystart, keyend-keystart) == 0 && + s->name[keyend-keystart] == '\0') break; } - a = calloc(1,sizeof(struct term_atom)); - if( a == NULL ) + a = zNEW(struct term_atom); + if (FAILEDTOALLOC(a)) return RET_ERROR_OOM; a->negated = negated; a->comparison = comparison; - if( s->name != NULL ) { + if (s->name != NULL) { retvalue r; a->isspecial = true; a->special.type = s; r = s->parse(comparison, valuestart, valueend-valuestart, &a->special.comparewith); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { term_free(a); return r; } } else { a->isspecial = false; - a->generic.key = strndup(keystart,keyend-keystart); - if( FAILEDTOALLOC(a->generic.key) ) { + a->generic.key = strndup(keystart, keyend - keystart); + if (FAILEDTOALLOC(a->generic.key)) { term_free(a); return RET_ERROR_OOM; } - if( comparison != tc_none ) { - if( valueend - valuestart > 2048 && + if (comparison != tc_none) { + if (valueend - valuestart > 2048 && (comparison == tc_globmatch || - comparison == tc_notglobmatch) ) { - fprintf(stderr, "Ridicilous long globmatch '%.10s...'!\n", + comparison == tc_notglobmatch)) { + fprintf(stderr, +"Ridicilous long globmatch '%.10s...'!\n", valuestart); term_free(a); return RET_ERROR; } - a->generic.comparewith = strndup(valuestart,valueend-valuestart); - if( a->generic.comparewith == NULL ) { + a->generic.comparewith = strndup(valuestart, + valueend - valuestart); + if (FAILEDTOALLOC(a->generic.comparewith)) { term_free(a); return RET_ERROR_OOM; } @@ -228,8 +236,8 @@ static void orterm(term *termtochange, /*@dependent@*/term *termtoor) { struct term_atom *p = termtochange; - while( p != NULL ) { - while( p->nextiffalse != NULL ) + while (p != NULL) { + while (p->nextiffalse != NULL) p = p->nextiffalse; p->nextiffalse= termtoor; p = p->nextiftrue; @@ -238,8 +246,8 @@ static void andterm(term *termtochange, /*@dependent@*/term *termtoand) { struct term_atom *p = termtochange; - while( p != NULL ) { - while( p->nextiftrue != NULL ) + while (p != NULL) { + while (p->nextiftrue != NULL) p = p->nextiftrue; p->nextiftrue = termtoand; p = p->nextiffalse; @@ -249,110 +257,127 @@ retvalue term_compile(term **term_p, const char *origformula, int options, const struct term_special *specials) { const char *formula = origformula; /* for the global list */ - struct term_atom *first,*last; + struct term_atom *first, *last; /* the atom just read */ struct term_atom *atom IFSTUPIDCC(=NULL); - struct {/*@dependent@*/struct term_atom *firstinand,*firstinor;} levels[50]; + struct { + /*@dependent@*/struct term_atom *firstinand, *firstinor; + } levels[50]; int lastinitializeddepth=-1; int depth=0; retvalue r; int i; //TODO: ??? - int atbeginning = 1; char junction = '\0'; - if( ISSET(options,T_ARCHITECTURES) ) { + if (ISSET(options, T_ARCHITECTURES)) { //TODO: implement this one... - assert( "Not yet implemented!" == NULL); + assert ("Not yet implemented!" == NULL); } -#define overspace() while( *formula!='\0' && xisspace(*formula) ) formula++ +#define overspace() while (*formula!='\0' && xisspace(*formula)) formula++ lastinitializeddepth=-1; depth=0; first = last = NULL; - while( true ) { + while (true) { overspace(); - while( *formula == '(' && ISSET(options,T_BRACKETS)) { - depth++;formula++; + while (*formula == '(' && ISSET(options, T_BRACKETS)) { + depth++; formula++; overspace(); } - if( depth >= 50 ) { + if (depth >= 50) { term_free(first); - fprintf(stderr,"Nested too deep: '%s'!\n",origformula); + fprintf(stderr, +"Nested too deep: '%s'!\n", + origformula); return RET_ERROR; } r = parseatom(&formula, &atom, options, specials); - if( r == RET_NOTHING ) { - if( *formula == '\0' ) - fprintf(stderr,"Unexpected end of string parsing formula '%s'!\n",origformula); + if (r == RET_NOTHING) { + if (*formula == '\0') + fprintf(stderr, +"Unexpected end of string parsing formula '%s'!\n", + origformula); else - fprintf(stderr,"Unexpected character '%c' parsing formula '%s'!\n",*formula,origformula); + fprintf(stderr, +"Unexpected character '%c' parsing formula '%s'!\n", + *formula, origformula); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { term_free(first); return r; } - for( i=lastinitializeddepth+1 ; i <= depth ; i ++ ) { + for (i=lastinitializeddepth+1 ; i <= depth ; i ++) { levels[i].firstinand = atom; levels[i].firstinor = atom; } - if( junction != '\0' ) { - assert(lastinitializeddepth >= 0 ); - assert( first != NULL ); + if (junction != '\0') { + assert(lastinitializeddepth >= 0); + assert (first != NULL); last->next = atom; last = atom; - if( junction == ',' ) { - andterm(levels[lastinitializeddepth].firstinand,atom); + if (junction == ',') { + andterm(levels[lastinitializeddepth].firstinand, + atom); levels[lastinitializeddepth].firstinand = atom; levels[lastinitializeddepth].firstinor = atom; } else { - assert( junction == '|' ); - orterm(levels[lastinitializeddepth].firstinor,atom); + assert (junction == '|'); + orterm(levels[lastinitializeddepth].firstinor, + atom); levels[lastinitializeddepth].firstinor = atom; } } else { - assert(lastinitializeddepth == -1 ); - assert( first == NULL ); + assert(lastinitializeddepth == -1); + assert (first == NULL); first = last = atom; } lastinitializeddepth = depth; overspace(); - if( *formula == ')' && ISSET(options,T_BRACKETS)) { + if (*formula == ')' && ISSET(options, T_BRACKETS)) { formula++; - if( depth > 0 ) { + if (depth > 0) { depth--; lastinitializeddepth = depth; } else { - fprintf(stderr,"Too many ')'s in '%s'!\n",origformula); + fprintf(stderr, +"Too many ')'s in '%s'!\n", + origformula); term_free(first); return RET_ERROR; } - atbeginning = 1; overspace(); } overspace(); - if( *formula == '\0' ) + if (*formula == '\0') break; - if( *formula != ',' && ( *formula != '|' || NOTSET(options,T_OR) )) { - fprintf(stderr,"Unexpected character '%c' within '%s'!\n",*formula,origformula); + if (*formula != ',' && + (*formula != '|' || NOTSET(options, T_OR))) { + fprintf(stderr, +"Unexpected character '%c' within '%s'!\n", + *formula, origformula); term_free(first); return RET_ERROR; } junction = *formula; formula++; } - if( depth > 0 ) { - fprintf(stderr,"Missing ')' at end of formula '%s'!\n",origformula); + if (depth > 0) { + fprintf(stderr, +"Missing ')' at end of formula '%s'!\n", + origformula); term_free(first); return RET_ERROR; } - if( *formula != '\0' ) { - fprintf(stderr,"Trailing garbage at end of term: '%s'\n",formula); + if (*formula != '\0') { + fprintf(stderr, +"Trailing garbage at end of term: '%s'\n", + formula); term_free(first); return RET_ERROR; } diff -Nru reprepro-4.5.0/terms.h reprepro-4.6.0/terms.h --- reprepro-4.5.0/terms.h 2009-07-26 11:39:31.000000000 +0000 +++ reprepro-4.6.0/terms.h 2011-05-05 14:42:55.000000000 +0000 @@ -13,7 +13,7 @@ /* the next atom to look at if this is true, resp. false, * nextiftrue == NULL means total result is true, * nextiffalse == NULL means total result is false. */ - /*@dependent@*/struct term_atom *nextiftrue,*nextiffalse; + /*@dependent@*/struct term_atom *nextiftrue, *nextiffalse; bool negated, isspecial; /* architecture requirements */ bool architectures_negated; @@ -59,7 +59,7 @@ /* (% ) and (!% globpattern) are allowed */ #define T_GLOBMATCH 0x80 -retvalue term_compile(/*@out@*/term **term, const char *formula, int options, /*@null@*/const struct term_special *specials); -void term_free(/*@null@*//*@only@*/term *term); +retvalue term_compile(/*@out@*/term **, const char * /*formula*/, int /*options*/, /*@null@*/const struct term_special *specials); +void term_free(/*@null@*//*@only@*/term *); #endif diff -Nru reprepro-4.5.0/tests/atoms.test reprepro-4.6.0/tests/atoms.test --- reprepro-4.5.0/tests/atoms.test 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/tests/atoms.test 2011-05-05 14:42:55.000000000 +0000 @@ -0,0 +1,180 @@ +. "$TESTSDIR"/test.inc + +# different tests to check the error messages when accessing +# architectures components or packagetypes... + +mkdir conf +cat > conf/options < conf/distributions <#a|l#' conf/distributions + +testrun - -b . update 3<##' -e 's#component#compo|nent#' conf/distributions + +testrun - -b . update 3<> conf/distributions <package-1.0/debian/control < +Standards-Version: 0.0 + +Package: rumsrumsrums +Architecture: all +Description: a package + . + +Package: dumdidum +Architecture: another +Description: a package not build + . + +Package: troettroet +Architecture: abacus +Description: some test-package + . +END +cat >package-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 +END + +dpkg-source -b package-1.0 + +cat > conf/distributions <> conf/options < package_1.0-1_another.log +echo "package_1.0-1_another.log - -" > package-1.0/debian/files +cd package-1.0 +dpkg-genchanges -B > ../package_1.0-1_another.changes +cd .. + +testrun - -C main include test package_1.0-1_another.changes 3<onlyonearch-1.0/debian/control < +Standards-Version: 0.0 + +Package: onearch +Architecture: abacus +Description: some test-onlyonearch + . +END +cat >onlyonearch-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 +END +dpkg-source -b onlyonearch-1.0 +mkdir onlyonearch-1.0/debian/tmp +mkdir onlyonearch-1.0/debian/tmp/DEBIAN +mkdir -p onlyonearch-1.0/debian/tmp/usr/bin +touch onlyonearch-1.0/debian/tmp/usr/bin/program +cd onlyonearch-1.0 +dpkg-gencontrol -ponearch +dpkg --build debian/tmp .. +cd .. +rm -r onlyonearch-1.0 + +testrun - --delete includedsc test onlyonearch_1.0-1.dsc 3<onlyarchall-1.0/debian/control < +Standards-Version: 0.0 + +Package: archall +Architecture: all +Description: some test-arch all package + . +END +cat >onlyarchall-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 +END +dpkg-source -b onlyarchall-1.0 +mkdir onlyarchall-1.0/debian/tmp +mkdir onlyarchall-1.0/debian/tmp/DEBIAN +mkdir -p onlyarchall-1.0/debian/tmp/usr/bin +touch onlyarchall-1.0/debian/tmp/usr/bin/program +cd onlyarchall-1.0 +dpkg-gencontrol -parchall +dpkg --build debian/tmp .. +cd .. +rm -r onlyarchall-1.0 + +testrun - --delete includedsc test onlyarchall_1.0-1.dsc 3< conf/distributions < conf/options < fake1.deb +echo "fake-deb2" > fake2.deb +echo "fake-deb3" > fake3.deb + +fakedeb1md="$(md5 fake1.deb)" +fakedeb2md="$(md5 fake2.deb)" +fakedeb3md="$(md5 fake3.deb)" +fakedeb1sha1="$(sha1 fake1.deb)" +fakedeb2sha1="$(sha1 fake2.deb)" +fakedeb3sha1="$(sha1 fake3.deb)" +fakedeb1sha2="$(sha256 fake1.deb)" +fakedeb2sha2="$(sha256 fake2.deb)" +fakedeb3sha2="$(sha256 fake3.deb)" +fakesize=10 + +cat > fakeindex < pool/c/p/pseudo/fake_0_all.deb +testrun - -b . check 3<results.expected << EOF +'fake' -> 'Package: fake +Version: 0 +Source: pseudo (9999) +Architecture: all +Filename: pool/c/p/pseudo/fake_0_all.deb +Section: base +Priority: extra +Size: $fakesize +MD5Sum: $fakedeb1md +' +EOF +dodiff results.expected results +cat results + +testrun - -b . _listchecksums 3<> conf/distributions < []" >&2 - exit 1 -fi -SRCDIR="$1" -if [ "2" -le "$#" ] ; then - REPREPRO="$2" -else - REPREPRO="$SRCDIR/reprepro" -fi -TESTS="$SRCDIR/tests" -UPDATETYPE=update -export PATH="$TESTS:$PATH" -if ! [ -x "$REPREPRO" ] ; then - echo "Could not find $REPREPRO!" >&2 - exit 1 -fi -mkdir -p conf -cat > conf/distributions < test/DEBIAN/control -echo "Version: 1" >> test/DEBIAN/control -echo "Maintainer: me " >> test/DEBIAN/control -echo "Description: test" >> test/DEBIAN/control -echo " bla fasel" >> test/DEBIAN/control -mkdir -p test/usr/bin -echo "echo hallo world" > test/usr/bin/hallo -dpkg-deb -b test - -ERRORMSG="`$HELPER "$REPREPRO" -b . includedeb test test.deb 2>&1 || echo "error:$?"`" -echo $ERRORMSG -echo $ERRORMSG | grep -q "Cannot find Architecture-header" -echo $ERRORMSG | grep -q "error:255" - -echo "Package: test1" > test/DEBIAN/control -echo "Version: 1" >> test/DEBIAN/control -echo "Maintainer: me " >> test/DEBIAN/control -echo "Architecture: ${FAKEARCHITECTURE}" >> test/DEBIAN/control -echo "Description: test" >> test/DEBIAN/control -echo " bla fasel" >> test/DEBIAN/control -dpkg-deb -b test - -ERRORMSG="`$HELPER "$REPREPRO" -b . includedeb test test.deb 2>&1 || echo "error:$?"`" -echo $ERRORMSG -echo $ERRORMSG | grep -q "No section was given" -echo $ERRORMSG | grep -q "error:255" - -ERRORMSG="`$HELPER "$REPREPRO" -b . -S funnystuff includedeb test test.deb 2>&1 || echo "error:$?"`" -echo $ERRORMSG -echo $ERRORMSG | grep -q "No priority was given" -echo $ERRORMSG | grep -q "error:255" - -$HELPER "$REPREPRO" -b . -S funnystuff -P useless includedeb test test.deb -echo returned: $? - -echo "Package: test2" > test/DEBIAN/control -echo "Version: 1" >> test/DEBIAN/control -echo "Maintainer: me " >> test/DEBIAN/control -echo "Section: funnystuff" >> test/DEBIAN/control -echo "Priority: useless" >> test/DEBIAN/control -echo "Architecture: ${FAKEARCHITECTURE}" >> test/DEBIAN/control -echo "Description: test" >> test/DEBIAN/control -echo " bla fasel" >> test/DEBIAN/control -dpkg-deb -b test - -$HELPER "$REPREPRO" -b . includedeb test test.deb -echo returned: $? - -echo "Package: bla" > test/DEBIAN/control -echo "Version: 1" >> test/DEBIAN/control -echo "Maintainer: me " >> test/DEBIAN/control -echo "Section: funnystuff" >> test/DEBIAN/control -echo "Priority: useless" >> test/DEBIAN/control -echo "Architecture: ${FAKEARCHITECTURE}" >> test/DEBIAN/control -echo "Description: test" >> test/DEBIAN/control -echo " bla fasel" >> test/DEBIAN/control -(cd test/DEBIAN && tar -cvvzf ../../control.tar.gz ./control) -(cd test && tar -cvvzf ../data.tar.gz ./usr) -#wrong ar: -ar r bla.deb data.tar.gz control.tar.gz -rm *.tar.gz - -$HELPER "$REPREPRO" -b . includedeb test bla.deb -echo returned: $? - -echo -e ',g/Version/s/1/2/\nw' | ed -s test/DEBIAN/control -#not also wrong paths: -(cd test/DEBIAN && tar -cvvzf ../../control.tar.gz control) -(cd test && tar -cvvzf ../data.tar.gz usr) -ar r bla2.deb data.tar.gz control.tar.gz - -$HELPER "$REPREPRO" -b . includedeb test bla2.deb -echo returned: $? - -set +v -echo -echo "If the script is still running to show this," -echo "all tested cases seem to work. (Though writing some tests more can never harm)." -exit 0 diff -Nru reprepro-4.5.0/tests/diffgeneration.test reprepro-4.6.0/tests/diffgeneration.test --- reprepro-4.5.0/tests/diffgeneration.test 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/tests/diffgeneration.test 2011-05-05 14:42:55.000000000 +0000 @@ -0,0 +1,273 @@ +set -u +. "$TESTSDIR"/test.inc + +# testing with Sources, as they are easier to generate... + +if ! test -e "$RREDTOOL" ; then + echo "SKIPPED: rredtool not found, '$RREDTOOL' tried." + exit 0 +fi + +mkdir conf +cat > conf/distributions < test_1.tar.gz +cat > test_1.dsc < +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaa some lines to make it long enough aaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +Files: + $(mdandsize test_1.tar.gz) test_1.tar.gz +EOF +echo "Dummy file" > pre_1.tar.gz +cat > pre_1.dsc < +Section: pre +Priority: extra +Files: + $(mdandsize pre_1.tar.gz) pre_1.tar.gz +EOF +echo "New file" > pre_2.tar.gz +cat > pre_2.dsc < +Section: pre +Priority: extra +Files: + $(mdandsize pre_2.tar.gz) pre_2.tar.gz +EOF +echo "Even newer" > pre_3.tar.gz +cat > pre_3.dsc < +Section: pre +Priority: extra +Files: + $(mdandsize pre_3.tar.gz) pre_3.tar.gz +EOF + +mkdir old +testrun - includedsc test test_1.dsc 3< patches + +cat > results.expected <> results.expected <> results.expected <> results.expected <> results.expected < results.expected << EOF +1c +Package: pre +Format: 1.0 +Binary: pre +Architecture: all +Version: 3 +Maintainer: Guess Who +Priority: extra +Section: pre +Directory: pool/main/p/pre +Files: + $(mdandsize pre_3.dsc) pre_3.dsc + $(mdandsize pre_3.tar.gz) pre_3.tar.gz +Checksums-Sha1: + $(sha1andsize pre_3.dsc) pre_3.dsc + $(sha1andsize pre_3.tar.gz) pre_3.tar.gz +Checksums-Sha256: + $(sha2andsize pre_3.dsc) pre_3.dsc + $(sha2andsize pre_3.tar.gz) pre_3.tar.gz + +Package: test +. +EOF +dodiff results.expected 1.diff +rm 1.diff +cat > results.expected << EOF +17,18c + $(sha2andsize pre_3.dsc) pre_3.dsc + $(sha2andsize pre_3.tar.gz) pre_3.tar.gz +. +14,15c + $(sha1andsize pre_3.dsc) pre_3.dsc + $(sha1andsize pre_3.tar.gz) pre_3.tar.gz +. +11,12c + $(mdandsize pre_3.dsc) pre_3.dsc + $(mdandsize pre_3.tar.gz) pre_3.tar.gz +. +5c +Version: 3 +. +EOF +dodiff results.expected 2.diff +rm 2.diff +dodiff results.expected 3.diff +rm 3.diff +cat > results.expected << EOF +1c +Package: pre +. +EOF +dodiff results.expected 4.diff +rm 4.diff + +rm -r old db pool conf dists pre_*.dsc pre_*.tar.gz test_1.dsc test_1.tar.gz results.expected patches + +testsuccess diff -Nru reprepro-4.5.0/tests/dpkg-architecture reprepro-4.6.0/tests/dpkg-architecture --- reprepro-4.5.0/tests/dpkg-architecture 2007-09-17 18:01:40.000000000 +0000 +++ reprepro-4.6.0/tests/dpkg-architecture 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -#!/bin/sh - -echo ${FAKEARCHITECTURE} diff -Nru reprepro-4.5.0/tests/exporthooks.test reprepro-4.6.0/tests/exporthooks.test --- reprepro-4.5.0/tests/exporthooks.test 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/tests/exporthooks.test 2011-05-05 14:42:55.000000000 +0000 @@ -0,0 +1,81 @@ +set -u +. "$TESTSDIR"/test.inc + +mkdir conf +cat > conf/distributions < conf/distributions < conf/strange.sh <<'EOF' +#!/bin/sh +echo hook "$@" +touch "$1/$3.something.new" +echo "$3.something.new" >&3 +touch "$1/$3.something.hidden.new" +echo "$3.something.hidden.new." >&3 +exit 0 +EOF +chmod a+x conf/strange.sh + +testrun - -b . export o 3< results +cat > results.expected < results || true +cat > results.expected < conf/distributions < conf/updates.base <>conf/updates <>conf/updates < flatsource/Release + +testrun - -b . update 1234 3<> flatsource/Release + +testrun - -b . update 1234 3< flatsource/Sources.gz +gzip -c < /dev/null > flatsource/Packages.gz +cat > flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Sources < flatsource/Release < flatsource/Sources < flatsource/Release <test-1/debian/control < +Standards-Version: 0.0 + +Package: sibling +Architecture: any +Description: bla + blub + +Package: siblingtoo +Architecture: any +Description: bla + blub + +Package: mytest +Architecture: all +Description: bla + blub +END +cat >test-1/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 +END +mkdir -p test-1/debian/tmp/DEBIAN +touch test-1/debian/tmp/best-file-in-the-root +cd test-1 +DEB_HOST_ARCH="another" dpkg-gencontrol -psibling -v2 +DEB_HOST_ARCH="another" dpkg --build debian/tmp .. +DEB_HOST_ARCH="another" dpkg-gencontrol -psiblingtoo -v3 +DEB_HOST_ARCH="another" dpkg --build debian/tmp .. +DEB_HOST_ARCH="another" dpkg-gencontrol -pmytest -v2 +DEB_HOST_ARCH="another" dpkg --build debian/tmp .. +DEB_HOST_ARCH="another" dpkg-genchanges -b > ../test-1.changes +DEB_HOST_ARCH="somemore" dpkg-gencontrol -psiblingtoo -v3 +DEB_HOST_ARCH="somemore" dpkg --build debian/tmp .. +cd .. +rm -r test-1 +mkdir test-2 +mkdir test-2/debian +cat >test-2/debian/control < +Standards-Version: 0.0 + +Package: sibling +Architecture: any +Description: bla + blub + +Package: siblingalso +Architecture: any +Description: bla + blub + +Package: mytest +Architecture: all +Description: bla + blub +END +cat >test-2/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 +test (1-1) test; urgency=critical + + * new upstream release (Closes: #allofthem) + + -- me Mon, 01 Jan 1980 01:02:02 +0000 +END +mkdir -p test-2/debian/tmp/DEBIAN +touch test-2/debian/tmp/best-file-in-the-root +cd test-2 +dpkg-gencontrol -psiblingalso -v3.1 +dpkg --build debian/tmp .. +dpkg-gencontrol -pmytest -v2.4 +dpkg --build debian/tmp .. +dpkg-gencontrol -psibling -v2.2 +dpkg --build debian/tmp .. +dpkg-genchanges -b > ../test-2.changes +rm debian/files +DEB_HOST_ARCH="another" dpkg-gencontrol -psibling -v2.2 +DEB_HOST_ARCH="another" dpkg --build debian/tmp .. +dpkg-genchanges -b > ../test-2a.changes +cd .. +rm -r test-2 + +for tracking in false true ; do + +mkdir conf +cat > conf/distributions <> conf/distributions + TRACKINGTESTOPTIONS="-D t=1" +else + TRACKINGTESTOPTIONS="-D t=0" +fi + +cat >> conf/distributions <> conf/distributions +testrun - -b . retrack test 3< results.expected < results.expected < conf/incoming << EOF +Name: myrule +Allow: test>two +Options: limit_arch_all +IncomingDir: i +TempDir: tmp +EOF + +ls *.changes +mkdir i tmp +cp test-1.changes sibling_2_another.deb siblingtoo_3_another.deb mytest_2_all.deb i/ + +testrun - -b . processincoming myrule 3< results.expected < results.expected < results.expected < results.expected < debian/rules <<'EOF' +#!/usr/bin/make +tmp = $(CURDIR)/debian/tmp +binary-indep: + install -m 755 -d $(tmp)/DEBIAN $(tmp)/usr/share/doc/documentation + echo "I have told you so" > $(tmp)/usr/share/doc/documentation/NEWS + gzip -c9 debian/changelog > $(tmp)/usr/share/doc/documentation/changelog.gz + chown -R root.root $(tmp) && chmod -R go=rX $(tmp) + dpkg-gencontrol -isp + dpkg --build $(tmp) .. + echo "I forgot" >> ../manifesto.txt + echo "What?" >> ../history.txt + dpkg-distaddfile manifesto.txt byhand - + dpkg-distaddfile history.txt byhand - + +.PHONY: clean binary-arch binary-indep binary build build-indep buil-arch +EOF +chmod a+x debian/rules +cat > debian/changelog < Sat, 15 Jan 2011 17:12:05 +2700 +EOF + +cat > debian/control < +Standards-Version: Aleph_17 + +Package: documentation +Architecture: all +Description: documentation + documentation +EOF + +cd .. +dpkg-source -b documentation-9876AD "" +cd documentation-9876AD + +fakeroot make -f debian/rules binary-indep > ../documentation_9876AD_coal+all.log +dpkg-genchanges > ../test.changes +cd .. +rm -r documentation-9876AD + +ed -s test.changes < conf/distributions < conf/distributions <results.expected < conf/distributions <results.expected < conf/distributions <results.expected < conf/incoming <results.expected <> conf/incoming < results +cat > results.expected < results +cat > results.expected <> conf/distributions < conf/handle-byhand.sh <<'EOF' +#!/bin/sh +echo "byhand-script called with: " "'$*'" >&2 +EOF +cat > conf/handle-alternate.sh <<'EOF' +#!/bin/sh +echo "alternate-script called with: " "'$*'" >&2 +EOF +chmod u+x conf/handle-alternate.sh +chmod u+x conf/handle-byhand.sh + +testrun - processincoming foo 3< results +cat > results.expected < results +cat > results.expected < results +cat > results.expected <> conf/distributions < results +cat > results.expected < conf/options +cat > conf/updatelog.sh <> '$WORKDIR/updatelog' +exit 0 +EOF +cat > conf/shouldnothappen.sh <> '$WORKDIR/shouldnothappen' +exit 0 +EOF +chmod a+x conf/updatelog.sh conf/shouldnothappen.sh +cat > conf/distributions < conf/updates <=firmware/), section(<< firmware0) + +Name: 1 +From: pre1 +Suite: x + +Name: 2 +Flat: main +From: b +#without this I do not get a warning, why? +Architectures: abacus coal source +FilterFormula: section (<= firmware0) | !section +Suite: x + +Name: 5 +From: b + +Name: 6 +From: b + +Name: 7 +From: b + +Name: 8 +From: b +EOF + +DISTRI=dummy PACKAGE=aa EPOCH="" VERSION=1 REVISION=-1000 SECTION="base" genpackage.sh -sa +DISTRI=dummy PACKAGE=bb EPOCH="" VERSION=2 REVISION=-0 SECTION="firmware/base" genpackage.sh -sa +DISTRI=dummy PACKAGE=cc EPOCH="" VERSION=1 REVISION=-1000 SECTION="base" genpackage.sh -sa +DISTRI=dummy PACKAGE=dd EPOCH="" VERSION=2 REVISION=-0 SECTION="firmware/base" genpackage.sh -sa + +mkdir source1/pool source1/pool/main source1/pool/firmware +mv aa* source1/pool/main +mv bb* source1/pool/firmware +mv cc* source2 +mv dd* source2 + +mkdir source2/x +cd source2 +echo 'dpkg-scanpackages . /dev/null > x/Packages' +dpkg-scanpackages . /dev/null > x/Packages +cd .. +cat > sourcesections < x/Sources' +dpkg-scansources . ../sourcesections > x/Sources +cd .. +rm sourcesections + +cat > source2/x/Release < dists/suitename/main/source/Sources +dpkg-scanpackages pool/main /dev/null > dists/suitename/main/binary-abacus/Packages +dpkg-scanpackages -a coal pool/main /dev/null > dists/suitename/main/binary-coal/Packages +dpkg-scansources pool/firmware /dev/null > dists/suitename/firmware/source/Sources +dpkg-scanpackages pool/firmware /dev/null > dists/suitename/firmware/binary-abacus/Packages +dpkg-scanpackages -a coal pool/firmware /dev/null > dists/suitename/firmware/binary-coal/Packages +cd .. + +cat > source1/dists/suitename/Release < source1/dists/suitename/Release < source1/dists/suitename/Release < dists/suitename/main/source/Sources +dpkg-scanpackages pool/main /dev/null > dists/suitename/main/binary-abacus/Packages +dpkg-scanpackages -a coal pool/main /dev/null > dists/suitename/main/binary-coal/Packages +dpkg-scansources pool/firmware /dev/null > dists/suitename/firmware/source/Sources +dpkg-scanpackages pool/firmware /dev/null > dists/suitename/firmware/binary-abacus/Packages +dpkg-scanpackages -a coal pool/firmware /dev/null > dists/suitename/firmware/binary-coal/Packages +cd .. + +cat > source1/dists/suitename/Release < results.expected < conf/options +cat > conf/distributions < conf/updates < conf/updates < conf/updates < conf/distributions < conf/updates < conf/updates < conf/distributions < conf/updates < conf/updates < testsource/dists/codename1/Release < testsource/dists/codename2/Release < testsource/dists/codename1/Release < testsource/dists/codename2/Release <> testsource/dists/codename2/Release < results.expected +if [ $verbosity -ge 0 ] ; then +echo "Calculating packages to get..." > results.expected ; fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename2|bb|yyyyyyyyyy'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected ; fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename2|bb|x'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected ; fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename2|a|yyyyyyyyyy'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected ; fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename2|a|x'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected ; fi +dodiff results.expected results +mv results.expected results2.expected + +testout - -b . update codename1 3< results.expected +if [ $verbosity -ge 0 ] ; then +echo "Calculating packages to get..." > results.expected ; fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|bb|source'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_bb_Sources'" >>results.expected +echo " reading './lists/base_codename2_bb_Sources'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_bb_Sources'" >>results.expected +echo " reading './lists/base_codename1_bb_Sources'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|bb|yyyyyyyyyy'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected +echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected +echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|bb|x'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected +echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected +echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|a|source'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_a_Sources'" >>results.expected +echo " reading './lists/base_codename2_a_Sources'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_a_Sources'" >>results.expected +echo " reading './lists/base_codename1_a_Sources'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'u|codename1|a|yyyyyyyyyy'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_a_yyyyyyyyyy_uPackages'" >>results.expected +echo " reading './lists/base_codename2_a_yyyyyyyyyy_uPackages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_a_yyyyyyyyyy_uPackages'" >>results.expected +echo " reading './lists/base_codename1_a_yyyyyyyyyy_uPackages'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|a|yyyyyyyyyy'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected +echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected +echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'u|codename1|a|x'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_a_x_uPackages'" >>results.expected +echo " reading './lists/base_codename2_a_x_uPackages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_a_x_uPackages'" >>results.expected +echo " reading './lists/base_codename1_a_x_uPackages'" >>results.expected +fi +if [ $verbosity -ge 3 ] ; then +echo " processing updates for 'codename1|a|x'" >>results.expected ; fi +if [ $verbosity -ge 5 ] ; then +echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected +echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected +echo " marking everything to be deleted" >>results.expected +echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected +echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected +fi +dodiff results.expected results + +testrun - -b . update codename2 codename1 3< resultsboth.expected || true +grep '^ ' results2.expected >> resultsboth.expected || true +grep '^ ' results.expected >> resultsboth.expected || true +grep '^[^ C]' results.expected >> resultsboth.expected || true +dodiff resultsboth.expected results + +sed -i -e "s/Method: file:/Method: copy:/" conf/updates + +dodo rm lists/_codename* +testout - -b . update codename1 3< conf/options < conf/distributions < fake.dsc < +Files: +EOF + + +testrun - -C main includedsc test fake.dsc 3< results +cat > results.expected < results +cat > results.expected < results +cat > results.expected < results +cat > results.expected < results +cat > results.expected < results +cat > results.expected < results +cat > results.expected <conf/distributions <conf/pulls <conf/incoming <conf/options < pi.rules <>pi.rules <pull.rules <>pull.rules < conf/distributions < conf/override-c-deb < conf/override-c-dsc < conf/override-d-deb < conf/override-d-dsc < conf/distributions < fakes/1 < +Architecture: coal +Version: 0.0-1 +Filename: pool/main/5/5dchess/5dchess_0.0-1_coal.deb +MD5sum: $EMPTYMD5ONLY +Size: 0 +Description: the lazy fox + jumps over the quick brown dog. + +Package: a +Priority: critical +Section: required +Installed-Size: 1 +Maintainer: test +Architecture: all +Version: 1 +Filename: pool/main/a/a/a_1_all.deb +MD5sum: $EMPTYMD5ONLY +Size: 0 +Description: the lazy fox + jumps over the quick brown dog. + +Package: b +Source: baa +Priority: critical +Section: required +Installed-Size: 1 +Maintainer: test +Architecture: coal +Version: 2 +Filename: pool/main/b/baa/b_2_coal.deb +MD5sum: $EMPTYMD5ONLY +Size: 0 +Description: the lazy fox + jumps over the quick brown dog. +EOF + +cat > fakes/2 < +Architecture: all +Version: 2 +Filename: pool/main/a/a/a_2_all.deb +MD5sum: $EMPTYMD5ONLY +Size: 0 +Description: the lazy fox + jumps over the quick brown dog. +EOF + +testrun - -b . -C main -A coal -T deb _addpackage sourcedistribution fakes/1 a 3< addchecksums.rules < conf/updates < conf/updates </dev/null ; then + echo "SKIPPED: gpg not found!" + exit 0 +fi + +rm -rf db dists pool lists conf gpgtestdir + +mkdir -p gpgtestdir +export GNUPGHOME="`pwd`/gpgtestdir" +gpg --import $TESTSDIR/good.key $TESTSDIR/evil.key $TESTSDIR/expired.key $TESTSDIR/revoked.key + +mkdir -p conf +cat > conf/options < conf/distributions < conf/auploaders < conf/buploaders < conf/cuploaders < conf/incoming < conf/distributions < results +cat > results.expected < conf/distributions < importindex < importindex < importindex < importindex < pool/dog/f/foo/foo_0_abacus.deb + +cat > importindex < pool/dog/f/foo/foo_1.dsc +echo "tar-content" > pool/dog/f/foo/foo_1.tar.gz + +cat > importindex < references.normal +grep '^s=' results | sed -e 's/^s=\(.\)=[^ ]* /\1 contains /' > references.snapshot +dodiff -u references.normal references.snapshot +rm references.normal references.snapshot +# Remove contents from original, to make them more look alike: +for n in dists/B/Release dists/B/snapshots/now/Release dists/A/Release dists/A/snapshots/now/Release ; do + ed -s $n < conf/options < conf/distributions < conf/pulls < conf/bin < conf/src < results.expected < results.expected < results.expected < conf/distributions < results.expected < results +dodiff results.expected results +cat > conf/distributions < results.expected < results +dodiff results.expected results +# Now try with suite +cat > conf/distributions < results.expected < results +dodiff results.expected results +testrun - -b . createsymlinks 3< 'foo/updates' because of '/'. +stdout +EOF +cat >> conf/distributions < 'foo/updates' because of the '/' in it. +-v2*=Hopefully something else will link 'bla' -> 'foo' then this is not needed. +stdout +-v1*=Created ./dists/bla->foo +EOF +# check a .dsc with nothing in it: +cat > test.dsc < test.dsc < +Section: section +Priority: priority +Files: +EOF +testrun - -C a -b . includedsc foo test.dsc 3< conf/options < conf/distributions <#a|l#' conf/distributions - -testrun - -b . update 3<##' -e 's#component#compo|nent#' conf/distributions - -testrun - -b . update 3<> conf/distributions <package-1.0/debian/control < -Standards-Version: 0.0 - -Package: rumsrumsrums -Architecture: all -Description: a package - . - -Package: dumdidum -Architecture: another -Description: a package not build - . - -Package: troettroet -Architecture: $FAKEARCHITECTURE -Description: some test-package - . -END -cat >package-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 -END - -dpkg-source -b package-1.0 - -cat > conf/distributions <> conf/options < package_1.0-1_another.log -echo "package_1.0-1_another.log - -" > package-1.0/debian/files -cd package-1.0 -dpkg-genchanges -B > ../package_1.0-1_another.changes -cd .. - -testrun - -C main include test package_1.0-1_another.changes 3<onlyonearch-1.0/debian/control < -Standards-Version: 0.0 - -Package: onearch -Architecture: $FAKEARCHITECTURE -Description: some test-onlyonearch - . -END -cat >onlyonearch-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 -END -dpkg-source -b onlyonearch-1.0 -mkdir onlyonearch-1.0/debian/tmp -mkdir onlyonearch-1.0/debian/tmp/DEBIAN -mkdir -p onlyonearch-1.0/debian/tmp/usr/bin -touch onlyonearch-1.0/debian/tmp/usr/bin/program -cd onlyonearch-1.0 -dpkg-gencontrol -ponearch -dpkg --build debian/tmp .. -cd .. -rm -r onlyonearch-1.0 - -testrun - --delete includedsc test onlyonearch_1.0-1.dsc 3<onlyarchall-1.0/debian/control < -Standards-Version: 0.0 - -Package: archall -Architecture: all -Description: some test-arch all package - . -END -cat >onlyarchall-1.0/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 -END -dpkg-source -b onlyarchall-1.0 -mkdir onlyarchall-1.0/debian/tmp -mkdir onlyarchall-1.0/debian/tmp/DEBIAN -mkdir -p onlyarchall-1.0/debian/tmp/usr/bin -touch onlyarchall-1.0/debian/tmp/usr/bin/program -cd onlyarchall-1.0 -dpkg-gencontrol -parchall -dpkg --build debian/tmp .. -cd .. -rm -r onlyarchall-1.0 - -testrun - --delete includedsc test onlyarchall_1.0-1.dsc 3< conf/distributions < conf/options < fake1.deb -echo "fake-deb2" > fake2.deb -echo "fake-deb3" > fake3.deb - -fakedeb1md="$(md5 fake1.deb)" -fakedeb2md="$(md5 fake2.deb)" -fakedeb3md="$(md5 fake3.deb)" -fakedeb1sha1="$(sha1 fake1.deb)" -fakedeb2sha1="$(sha1 fake2.deb)" -fakedeb3sha1="$(sha1 fake3.deb)" -fakedeb1sha2="$(sha256 fake1.deb)" -fakedeb2sha2="$(sha256 fake2.deb)" -fakedeb3sha2="$(sha256 fake3.deb)" -fakesize=10 - -cat > fakeindex < pool/c/p/pseudo/fake_0_all.deb -testrun - -b . check 3<results.expected << EOF -'fake' -> 'Package: fake -Version: 0 -Source: pseudo (9999) -Architecture: all -Filename: pool/c/p/pseudo/fake_0_all.deb -Section: base -Priority: extra -Size: $fakesize -MD5Sum: $fakedeb1md -' -EOF -dodiff results.expected results -cat results - -testrun - -b . _listchecksums 3<> conf/distributions < conf/distributions < test_1.tar.gz -cat > test_1.dsc < -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaa some lines to make it long enough aaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -X-Data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -Files: - $(mdandsize test_1.tar.gz) test_1.tar.gz -EOF -echo "Dummy file" > pre_1.tar.gz -cat > pre_1.dsc < -Section: pre -Priority: extra -Files: - $(mdandsize pre_1.tar.gz) pre_1.tar.gz -EOF -echo "New file" > pre_2.tar.gz -cat > pre_2.dsc < -Section: pre -Priority: extra -Files: - $(mdandsize pre_2.tar.gz) pre_2.tar.gz -EOF -echo "Even newer" > pre_3.tar.gz -cat > pre_3.dsc < -Section: pre -Priority: extra -Files: - $(mdandsize pre_3.tar.gz) pre_3.tar.gz -EOF - -mkdir old -testrun - includedsc test test_1.dsc 3< patches - -cat > results.expected <> results.expected <> results.expected <> results.expected <> results.expected < results.expected << EOF -1c -Package: pre -Format: 1.0 -Binary: pre -Architecture: all -Version: 3 -Maintainer: Guess Who -Priority: extra -Section: pre -Directory: pool/main/p/pre -Files: - $(mdandsize pre_3.dsc) pre_3.dsc - $(mdandsize pre_3.tar.gz) pre_3.tar.gz -Checksums-Sha1: - $(sha1andsize pre_3.dsc) pre_3.dsc - $(sha1andsize pre_3.tar.gz) pre_3.tar.gz -Checksums-Sha256: - $(sha2andsize pre_3.dsc) pre_3.dsc - $(sha2andsize pre_3.tar.gz) pre_3.tar.gz - -Package: test -. -EOF -dodiff results.expected 1.diff -rm 1.diff -cat > results.expected << EOF -17,18c - $(sha2andsize pre_3.dsc) pre_3.dsc - $(sha2andsize pre_3.tar.gz) pre_3.tar.gz -. -14,15c - $(sha1andsize pre_3.dsc) pre_3.dsc - $(sha1andsize pre_3.tar.gz) pre_3.tar.gz -. -11,12c - $(mdandsize pre_3.dsc) pre_3.dsc - $(mdandsize pre_3.tar.gz) pre_3.tar.gz -. -5c -Version: 3 -. -EOF -dodiff results.expected 2.diff -rm 2.diff -dodiff results.expected 3.diff -rm 3.diff -cat > results.expected << EOF -1c -Package: pre -. -EOF -dodiff results.expected 4.diff -rm 4.diff - -rm -r old db pool conf dists pre_*.dsc pre_*.tar.gz test_1.dsc test_1.tar.gz results.expected patches - -else -echo -echo -echo -echo -echo "WARNING: $RREDTOOL does not exists. cannot test diff generation" -echo -echo -echo -echo -echo -fi - -testsuccess diff -Nru reprepro-4.5.0/tests/testexporthooks.sh reprepro-4.6.0/tests/testexporthooks.sh --- reprepro-4.5.0/tests/testexporthooks.sh 2009-03-18 17:16:38.000000000 +0000 +++ reprepro-4.6.0/tests/testexporthooks.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -#!/bin/bash - -set -e -if [ "x$TESTINCSETUP" != "xissetup" ] ; then - source $(dirname $0)/test.inc -fi - -mkdir conf -cat > conf/distributions < conf/distributions < conf/strange.sh <<'EOF' -#!/bin/sh -echo hook "$@" -touch "$1/$3.something.new" -echo "$3.something.new" >&3 -touch "$1/$3.something.hidden.new" -echo "$3.something.hidden.new." >&3 -exit 0 -EOF -chmod a+x conf/strange.sh - -testrun - -b . export o 3< results -cat > results.expected < results || true -cat > results.expected < conf/distributions < conf/updates.base <>conf/updates <>conf/updates < flatsource/Release - -testrun - -b . update 1234 3<> flatsource/Release - -testrun - -b . update 1234 3< flatsource/Sources.gz -gzip -c < /dev/null > flatsource/Packages.gz -cat > flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Packages < flatsource/Release < flatsource/Sources < flatsource/Release < flatsource/Sources < flatsource/Release <test-1/debian/control < -Standards-Version: 0.0 - -Package: sibling -Architecture: any -Description: bla - blub - -Package: siblingtoo -Architecture: any -Description: bla - blub - -Package: mytest -Architecture: all -Description: bla - blub -END -cat >test-1/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 -END -mkdir -p test-1/debian/tmp/DEBIAN -touch test-1/debian/tmp/best-file-in-the-root -cd test-1 -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg-gencontrol -psibling -v2 -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg --build debian/tmp .. -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg-gencontrol -psiblingtoo -v3 -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg --build debian/tmp .. -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg-gencontrol -pmytest -v2 -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg --build debian/tmp .. -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg-genchanges -b > ../test-1.changes -FAKEARCHITECTUE="somemore" DEB_HOST_ARCH="somemore" dpkg-gencontrol -psiblingtoo -v3 -FAKEARCHITECTUE="somemore" DEB_HOST_ARCH="somemore" dpkg --build debian/tmp .. -cd .. -rm -r test-1 -mkdir test-2 -mkdir test-2/debian -cat >test-2/debian/control < -Standards-Version: 0.0 - -Package: sibling -Architecture: any -Description: bla - blub - -Package: siblingalso -Architecture: any -Description: bla - blub - -Package: mytest -Architecture: all -Description: bla - blub -END -cat >test-2/debian/changelog < Mon, 01 Jan 1980 01:02:02 +0000 -test (1-1) test; urgency=critical - - * new upstream release (Closes: #allofthem) - - -- me Mon, 01 Jan 1980 01:02:02 +0000 -END -mkdir -p test-2/debian/tmp/DEBIAN -touch test-2/debian/tmp/best-file-in-the-root -cd test-2 -dpkg-gencontrol -psiblingalso -v3.1 -dpkg --build debian/tmp .. -dpkg-gencontrol -pmytest -v2.4 -dpkg --build debian/tmp .. -dpkg-gencontrol -psibling -v2.2 -dpkg --build debian/tmp .. -dpkg-genchanges -b > ../test-2.changes -rm debian/files -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg-gencontrol -psibling -v2.2 -FAKEARCHITECTUE="another" DEB_HOST_ARCH="another" dpkg --build debian/tmp .. -dpkg-genchanges -b > ../test-2a.changes -cd .. -rm -r test-2 - -for tracking in false true ; do - -mkdir conf -cat > conf/distributions <> conf/distributions - setoptions unchanged "" "" tracking -else - setoptions unchanged "" "" -fi - -cat >> conf/distributions <> conf/distributions -testrun - -b . retrack test 3< results.expected < results.expected < conf/incoming << EOF -Name: myrule -Allow: test>two -Options: limit_arch_all -IncomingDir: i -TempDir: tmp -EOF - -ls *.changes -mkdir i tmp -cp test-1.changes sibling_2_another.deb siblingtoo_3_another.deb mytest_2_all.deb i/ - -testrun - -b . processincoming myrule 3< results.expected < results.expected < results.expected < results.expected <&2 - exit 1 - ;; - esac -} - -FAKEARCHITECTURE=abacus -SRCDIR="$(realpath -s "$(dirname $0)/..")" -WORKDIR="`pwd`/testdir" -USE_VALGRIND="" -VALGRIND_SUP="" -VERBOSEDB="1" -DEFAULTVERBOSITY=6 -deleteifmarked=true - -while [ $# -gt 0 ] ; do - case "$1" in - --srcdir) - shift - SRCDIR="$(realpath -s "$1")" - shift - ;; - --neverdelete) - deleteifmarked=false - shift - ;; - --delete) - if ! $deleteifmarked ; then - rm -r "$WORKDIR" || true - fi - shift - ;; - --valgrind) - USE_VALGRIND=1 - shift - ;; - --valgrind-supp) - USE_VALGRIND=1 - shift - VALGRIND_SUP="$1" - shift - ;; - --fake-architecture) - shift - FAKEARCHITECTURE="$1" - shift - ;; - --verbosity) - shift - DEFAULTVERBOSITY="$1" - shift - ;; - --noverbosedb) - VERBOSEDB="" - shift - ;; - --*) - echo "Unsupported option $1" >&2 - exit 1 - ;; - *) - break - ;; - esac -done -export FAKEARCHITECTURE -export FALEN=${#FAKEARCHITECTURE} -# new dpkg-dev supports a fake architecture without tricks (and the old tricks no longer work): -export DEB_HOST_ARCH="$FAKEARCHITECTURE" - -if [ "2" -lt "$#" ] ; then - echo "Syntax: test.sh [] []" >&2 +if test -z "$SRCDIR" || ! test -d "$SRCDIR" ; then + echo "SRCDIR='$SRCDIR' not a valid directory!" >&2 exit 1 fi -echo "SRCDIR is '$SRCDIR'" -if [ ! -d "$SRCDIR" ] || [ ! -d "$SRCDIR/tests" ] ; then - echo "Error: Could not find source directory (tried: '$SRCDIR')!" >&2 +if test -z "$TESTSDIR" || ! test -d "$TESTSDIR" ; then + echo "TESTSDIR='$TESTSDIR' not a valid directory!" >&2 exit 1 fi -if [ "1" -le "$#" ] ; then - TESTTOOL="$(realpath -s "$1")" -else - TESTTOOL=testtool -fi -if [ "2" -le "$#" ] ; then - REPREPRO="$(realpath -s "$2")" -else - REPREPRO="$SRCDIR/reprepro" -fi -RREDTOOL="$(dirname "$REPREPRO")/rredtool" - -if [ -z "$TESTOPTIONS" ] ; then - if [ -z "$USE_VALGRIND" ] ; then - TESTOPTIONS="-e -a" - elif [ -z "$VALGRIND_SUP" ] ; then - TESTOPTIONS="-e -a --debug --leak-check=full --suppressions=$SRCDIR/valgrind.supp" - else - TESTOPTIONS="-e -a --debug --leak-check=full --suppressions=$VALGRIND_SUP" - fi +if test -z "$WORKDIR" || ! test -d "$WORKDIR" ; then + echo "WORKDIR='$WORKDIR' not a valid directory!" >&2 + exit 1 fi -MAINTESTOPTIONS="$TESTOPTIONS" +# avoid architecture dependency of the test-suite: +export DEB_HOST_ARCH="abacus" -function setoptions() { - if test $# -lt 3 ; then - echo "setoptions: Wrong argument count!" >&2 - exit 1 - fi - setverbosity "$1" - shift - TESTOPTIONS="$1 $VERBOSITYOPTIONS $MAINTESTOPTIONS" - shift - REPREPROOPTIONS="$1 $VERBOSITY" - shift - if test -n "$VERBOSEDB" ; then - TESTOPTIONS="-D x=0 -D d=1 $TESTOPTIONS" - REPREPROOPTIONS="--verbosedb $REPREPROOPTIONS" - else - TESTOPTIONS="-D x=0 -D d=0 $TESTOPTIONS" - fi - TRACKINGTESTOPTIONS="-D t=0" - while test $# -gt 0 ; do - case $1 in - tracking) - if test -n "$VERBOSEDB" ; then - TRACKINGTESTOPTIONS="-D t=1" - fi - ;; - *) - echo "setoptions: unsupported third argument!" >&2 - exit 1 - ;; - esac - shift - done - TESTOPTIONS="$TRACKINGTESTOPTIONS $TESTOPTIONS" - echo testoptions are set to: $TESTOPTIONS - echo reprepro options are set to: $REPREPROOPTIONS -} -export PATH="$SRCDIR/tests:$PATH" +export PATH="$TESTSDIR:$PATH" if ! [ -x "$REPREPRO" ] ; then echo "Could not find $REPREPRO!" >&2 exit 1 fi -TESTTOOLVERSION="`$TESTTOOL --version`" -case $TESTTOOLVERSION in - "testtool version "*) ;; - *) echo "Failed to get version of testtool($TESTTOOL)" - exit 1 - ;; -esac - -if test -d "$WORKDIR" && test -f "$WORKDIR/ThisDirectoryWillBeDeleted" && $deleteifmarked ; then - rm -r "$WORKDIR" || exit 3 -fi - -mkdir "$WORKDIR" || exit 1 -echo "Remove this file to avoid silent removal" > "$WORKDIR"/ThisDirectoryWillBeDeleted -cd "$WORKDIR" -touch results.empty -cat > empty.rules < results.log.expected LOGDATE="$(date +'%Y-%m-%d %H:')" echo normalizing "$1": DATESTR is "$LOGDATE??:??" @@ -268,16 +76,16 @@ dodiff results.log.expected logs/"$1" rm logs/"$1" } -function md5() { +md5() { md5sum "$1" | cut -d' ' -f1 } -function sha1() { +sha1() { sha1sum "$1" | cut -d' ' -f1 } -function sha256() { +sha256() { sha256sum "$1" | cut -d' ' -f1 } -function printindexpart() { +printindexpart() { FILENAME="$1" dpkg-deb -I "$FILENAME" control >"$FILENAME".control ed -s "$FILENAME".control << EOF @@ -301,49 +109,49 @@ cat "$FILENAME".control rm "$FILENAME".control } -function withoutchecksums() { +withoutchecksums() { awk 'BEGIN{inheader=0} /^Checksums-.*: / || (inheader && /^ /) {inheader = 1; next} {inheader = 0 ; print}' "$@" } -function mdandsize() { +mdandsize() { cat < empty.rules < debian/rules <<'EOF' -#!/usr/bin/make -tmp = $(CURDIR)/debian/tmp -binary-indep: - install -m 755 -d $(tmp)/DEBIAN $(tmp)/usr/share/doc/documentation - echo "I have told you so" > $(tmp)/usr/share/doc/documentation/NEWS - gzip -c9 debian/changelog > $(tmp)/usr/share/doc/documentation/changelog.gz - chown -R root.root $(tmp) && chmod -R go=rX $(tmp) - dpkg-gencontrol -isp - dpkg --build $(tmp) .. - echo "I forgot" >> ../manifesto.txt - echo "What?" >> ../history.txt - dpkg-distaddfile manifesto.txt byhand - - dpkg-distaddfile history.txt byhand - - -.PHONY: clean binary-arch binary-indep binary build build-indep buil-arch -EOF -chmod a+x debian/rules -cat > debian/changelog < Sat, 15 Jan 2011 17:12:05 +2700 -EOF - -cat > debian/control < -Standards-Version: Aleph_17 - -Package: documentation -Architecture: all -Description: documentation - documentation -EOF - -cd .. -dpkg-source -b documentation-9876AD "" -cd documentation-9876AD - -fakeroot make -f debian/rules binary-indep > ../documentation_9876AD_coal+all.log -dpkg-genchanges > ../test.changes -cd .. -rm -r documentation-9876AD - -ed -s test.changes < conf/distributions < conf/distributions <results.expected < conf/distributions <results.expected < conf/distributions <results.expected < conf/incoming <results.expected <> conf/incoming < results -cat > results.expected < results -cat > results.expected <> conf/distributions < conf/handle-byhand.sh <<'EOF' -#!/bin/sh -echo "byhand-script called with: " "'$*'" >&2 -EOF -cat > conf/handle-alternate.sh <<'EOF' -#!/bin/sh -echo "alternate-script called with: " "'$*'" >&2 -EOF -chmod u+x conf/handle-alternate.sh -chmod u+x conf/handle-byhand.sh - -testrun - processincoming foo 3< results -cat > results.expected < results -cat > results.expected < results -cat > results.expected <> conf/distributions < results -cat > results.expected < conf/options -cat > conf/updatelog.sh <> '$WORKDIR/updatelog' -exit 0 -EOF -cat > conf/shouldnothappen.sh <> '$WORKDIR/shouldnothappen' -exit 0 -EOF -chmod a+x conf/updatelog.sh conf/shouldnothappen.sh -cat > conf/distributions < conf/updates <=firmware/), section(<< firmware0) - -Name: 1 -From: pre1 -Suite: x - -Name: 2 -Flat: main -From: b -#without this I do not get a warning, why? -Architectures: $FAKEARCHITECTURE coal source -FilterFormula: section (<= firmware0) | !section -Suite: x - -Name: 5 -From: b - -Name: 6 -From: b - -Name: 7 -From: b - -Name: 8 -From: b -EOF - -DISTRI=dummy PACKAGE=aa EPOCH="" VERSION=1 REVISION=-1000 SECTION="base" genpackage.sh -sa -DISTRI=dummy PACKAGE=bb EPOCH="" VERSION=2 REVISION=-0 SECTION="firmware/base" genpackage.sh -sa -DISTRI=dummy PACKAGE=cc EPOCH="" VERSION=1 REVISION=-1000 SECTION="base" genpackage.sh -sa -DISTRI=dummy PACKAGE=dd EPOCH="" VERSION=2 REVISION=-0 SECTION="firmware/base" genpackage.sh -sa - -mkdir source1/pool source1/pool/main source1/pool/firmware -mv aa* source1/pool/main -mv bb* source1/pool/firmware -mv cc* source2 -mv dd* source2 - -mkdir source2/x -cd source2 -echo 'dpkg-scanpackages . /dev/null > x/Packages' -dpkg-scanpackages . /dev/null > x/Packages -cd .. -cat > sourcesections < x/Sources' -dpkg-scansources . ../sourcesections > x/Sources -cd .. -rm sourcesections - -cat > source2/x/Release < dists/suitename/main/source/Sources -dpkg-scanpackages pool/main /dev/null > dists/suitename/main/binary-$FAKEARCHITECTURE/Packages -dpkg-scanpackages -a coal pool/main /dev/null > dists/suitename/main/binary-coal/Packages -dpkg-scansources pool/firmware /dev/null > dists/suitename/firmware/source/Sources -dpkg-scanpackages pool/firmware /dev/null > dists/suitename/firmware/binary-$FAKEARCHITECTURE/Packages -dpkg-scanpackages -a coal pool/firmware /dev/null > dists/suitename/firmware/binary-coal/Packages -cd .. - -cat > source1/dists/suitename/Release < source1/dists/suitename/Release < source1/dists/suitename/Release < dists/suitename/main/source/Sources -dpkg-scanpackages pool/main /dev/null > dists/suitename/main/binary-$FAKEARCHITECTURE/Packages -dpkg-scanpackages -a coal pool/main /dev/null > dists/suitename/main/binary-coal/Packages -dpkg-scansources pool/firmware /dev/null > dists/suitename/firmware/source/Sources -dpkg-scanpackages pool/firmware /dev/null > dists/suitename/firmware/binary-$FAKEARCHITECTURE/Packages -dpkg-scanpackages -a coal pool/firmware /dev/null > dists/suitename/firmware/binary-coal/Packages -cd .. - -cat > source1/dists/suitename/Release < results.expected < conf/options -cat > conf/distributions < conf/updates < conf/updates < conf/updates < conf/distributions < conf/updates < conf/updates < conf/distributions < conf/updates < conf/updates < testsource/dists/codename1/Release < testsource/dists/codename2/Release < testsource/dists/codename1/Release < testsource/dists/codename2/Release <> testsource/dists/codename2/Release < results.expected -if [ $verbosity -ge 0 ] ; then -echo "Calculating packages to get..." > results.expected ; fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename2|bb|yyyyyyyyyy'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected ; fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename2|bb|x'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected ; fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename2|a|yyyyyyyyyy'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected ; fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename2|a|x'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected ; fi -dodiff results.expected results -mv results.expected results2.expected - -testout - -b . update codename1 3< results.expected -if [ $verbosity -ge 0 ] ; then -echo "Calculating packages to get..." > results.expected ; fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|bb|source'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_bb_Sources'" >>results.expected -echo " reading './lists/base_codename2_bb_Sources'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_bb_Sources'" >>results.expected -echo " reading './lists/base_codename1_bb_Sources'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|bb|yyyyyyyyyy'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected -echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_bb_yyyyyyyyyy_Packages'" >>results.expected -echo " reading './lists/base_codename1_bb_yyyyyyyyyy_Packages'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|bb|x'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected -echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_bb_x_Packages'" >>results.expected -echo " reading './lists/base_codename1_bb_x_Packages'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|a|source'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_a_Sources'" >>results.expected -echo " reading './lists/base_codename2_a_Sources'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_a_Sources'" >>results.expected -echo " reading './lists/base_codename1_a_Sources'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'u|codename1|a|yyyyyyyyyy'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_a_yyyyyyyyyy_uPackages'" >>results.expected -echo " reading './lists/base_codename2_a_yyyyyyyyyy_uPackages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_a_yyyyyyyyyy_uPackages'" >>results.expected -echo " reading './lists/base_codename1_a_yyyyyyyyyy_uPackages'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|a|yyyyyyyyyy'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected -echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_a_yyyyyyyyyy_Packages'" >>results.expected -echo " reading './lists/base_codename1_a_yyyyyyyyyy_Packages'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'u|codename1|a|x'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_a_x_uPackages'" >>results.expected -echo " reading './lists/base_codename2_a_x_uPackages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_a_x_uPackages'" >>results.expected -echo " reading './lists/base_codename1_a_x_uPackages'" >>results.expected -fi -if [ $verbosity -ge 3 ] ; then -echo " processing updates for 'codename1|a|x'" >>results.expected ; fi -if [ $verbosity -ge 5 ] ; then -echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected -echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected -echo " marking everything to be deleted" >>results.expected -echo " reading './lists/base_codename2_a_x_Packages'" >>results.expected -echo " reading './lists/base_codename1_a_x_Packages'" >>results.expected -fi -dodiff results.expected results - -testrun - -b . update codename2 codename1 3< resultsboth.expected || true -grep '^ ' results2.expected >> resultsboth.expected || true -grep '^ ' results.expected >> resultsboth.expected || true -grep '^[^ C]' results.expected >> resultsboth.expected || true -dodiff resultsboth.expected results - -sed -i -e "s/Method: file:/Method: copy:/" conf/updates - -dodo rm lists/_codename* -testout - -b . update codename1 3< conf/options < conf/distributions < fake.dsc < -Files: -EOF - - -testrun - -C main includedsc test fake.dsc 3< results -cat > results.expected < results -cat > results.expected < results -cat > results.expected < results -cat > results.expected < results -cat > results.expected < results -cat > results.expected < results -cat > results.expected <conf/distributions <conf/pulls <conf/incoming <conf/options < pi.rules <>pi.rules <pull.rules <>pull.rules < conf/distributions < conf/override-c-deb < conf/override-c-dsc < conf/override-d-deb < conf/override-d-dsc < conf/distributions < fakes/1 < -Architecture: coal -Version: 0.0-1 -Filename: pool/main/5/5dchess/5dchess_0.0-1_coal.deb -MD5sum: $EMPTYMD5ONLY -Size: 0 -Description: the lazy fox - jumps over the quick brown dog. - -Package: a -Priority: critical -Section: required -Installed-Size: 1 -Maintainer: test -Architecture: all -Version: 1 -Filename: pool/main/a/a/a_1_all.deb -MD5sum: $EMPTYMD5ONLY -Size: 0 -Description: the lazy fox - jumps over the quick brown dog. - -Package: b -Source: baa -Priority: critical -Section: required -Installed-Size: 1 -Maintainer: test -Architecture: coal -Version: 2 -Filename: pool/main/b/baa/b_2_coal.deb -MD5sum: $EMPTYMD5ONLY -Size: 0 -Description: the lazy fox - jumps over the quick brown dog. -EOF - -cat > fakes/2 < -Architecture: all -Version: 2 -Filename: pool/main/a/a/a_2_all.deb -MD5sum: $EMPTYMD5ONLY -Size: 0 -Description: the lazy fox - jumps over the quick brown dog. -EOF - -testrun - -b . -C main -A coal -T deb _addpackage sourcedistribution fakes/1 a 3< addchecksums.rules < conf/updates < conf/updates <&2 + exit 1 + ;; + *) + break + ;; + esac +done + +if [ "2" -lt "$#" ] ; then + echo "Syntax: test.sh [] []" >&2 + exit 1 +fi +echo "SRCDIR is '$SRCDIR'" +if [ ! -d "$SRCDIR" ] || [ ! -d "$SRCDIR/tests" ] ; then + echo "Error: Could not find source directory (tried: '$SRCDIR')!" >&2 + exit 1 +fi +TESTSDIR="$SRCDIR/tests" +if [ "1" -le "$#" ] ; then + TESTTOOL="$(readlink -e "$1")" +else + TESTTOOL=testtool +fi +if [ "2" -le "$#" ] ; then + REPREPRO="$(readlink -e "$2")" +else + REPREPRO="$SRCDIR/reprepro" +fi +RREDTOOL="$(dirname "$REPREPRO")/rredtool" + +if [ -z "$TESTOPTIONS" ] ; then + if [ -z "$USE_VALGRIND" ] ; then + TESTOPTIONS="-e -a" + elif [ -z "$VALGRIND_SUP" ] ; then + TESTOPTIONS="-e -a --debug --leak-check=full --suppressions=$TESTSDIR/valgrind.supp" + else + TESTOPTIONS="-e -a --debug --leak-check=full --suppressions=$VALGRIND_SUP" + fi +fi +case "$verbosity" in + -1) VERBOSITY="-s" ;; + 0) VERBOSITY="" ;; + 1) VERBOSITY="-v" ;; + 2) VERBOSITY="-vv" ;; + 3) VERBOSITY="-vvv" ;; + 4) VERBOSITY="-vvvv" ;; + 5) VERBOSITY="-vvvvv" ;; + 6) VERBOSITY="-vvvvvv" ;; + *) echo "Unsupported verbosity $verbosity" >&2 + exit 1 + ;; +esac +TESTOPTIONS="-D v=$verbosity $TESTOPTIONS" +REPREPROOPTIONS="$VERBOSITY" +if test -n "$VERBOSEDB" ; then + TESTOPTIONS="-D x=0 -D d=1 $TESTOPTIONS" + REPREPROOPTIONS="--verbosedb $REPREPROOPTIONS" +else + TESTOPTIONS="-D x=0 -D d=0 $TESTOPTIONS" +fi +TRACKINGTESTOPTIONS="-D t=0" + +if ! [ -x "$REPREPRO" ] ; then + echo "Could not find $REPREPRO!" >&2 + exit 1 +fi +TESTTOOLVERSION="`$TESTTOOL --version`" +case $TESTTOOLVERSION in + "testtool version "*) ;; + *) echo "Failed to get version of testtool($TESTTOOL)" + exit 1 + ;; +esac + +if test -d "$WORKDIR" && test -f "$WORKDIR/ThisDirectoryWillBeDeleted" && $deleteifmarked ; then + rm -r "$WORKDIR" || exit 3 +fi + +mkdir "$WORKDIR" || exit 1 +echo "Remove this file to avoid silent removal" > "$WORKDIR"/ThisDirectoryWillBeDeleted +cd "$WORKDIR" + +number_tests=0 +number_missing=0 +number_success=0 +number_skipped=0 +number_failed=0 + +runtest() { + if ! test -f "$SRCDIR/tests/$1.test" ; then + echo "Cannot find $SRCDIR/tests/$1.test!" >&2 + number_missing="$(( $number_missing + 1 ))" + return + fi + number_tests="$(( $number_tests + 1 ))" + echo "Running test '$1'.." + TESTNAME=" $1" + mkdir "dir_$1" + rc=0 + ( cd "dir_$1" || exit 1 + export TESTNAME + export SRCDIR TESTSDIR + export TESTTOOL RREDTOOL REPREPRO + export TRACKINGTESTOPTIONS TESTOPTIONS REPREPROOPTIONS verbosity + WORKDIR="$WORKDIR/dir_$1" CALLEDFROMTESTSUITE=true dash "$SRCDIR/tests/$1.test" + ) > "log_$1" 2>&1 || rc=$? + if test "$rc" -ne 0 ; then + number_failed="$(( $number_failed + 1 ))" + echo "test '$1' failed (see $WORKDIR/log_$1 for details)!" >&2 + elif grep -q -s '^SKIPPED: ' "log_$1" ; then + number_skipped="$(( $number_skipped + 1 ))" + echo "test '$1' skipped:" + sed -n -e 's/^SKIPPED://p' "log_$1" + rm -r "dir_$1" "log_$1" + else + number_success="$(( $number_success + 1 ))" + rm -r "dir_$1" "log_$1" + fi +} + +if test x"$testtorun" != x"all" ; then + runtest "$testtorun" +else + runtest srcfilterlist + runtest uploaders + runtest wrongarch + runtest flood + runtest exporthooks + runtest updatecorners + runtest packagediff + runtest includeextra + runtest atoms + runtest trackingcorruption + runtest layeredupdate + runtest layeredupdate2 + runtest uncompress + runtest check + runtest flat + runtest subcomponents + runtest snapshotcopyrestore + runtest various1 + runtest various2 + runtest various3 + runtest copy + runtest buildneeding + runtest morgue + runtest diffgeneration + runtest onlysmalldeletes + runtest override +fi +echo "$number_tests tests, $number_success succeded, $number_failed failed, $number_skipped skipped, $number_missing missing" exit 0 diff -Nru reprepro-4.5.0/tests/testsignatures.sh reprepro-4.6.0/tests/testsignatures.sh --- reprepro-4.5.0/tests/testsignatures.sh 2010-02-16 15:29:11.000000000 +0000 +++ reprepro-4.6.0/tests/testsignatures.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,318 +0,0 @@ -#!/bin/bash - -set -e - -if test "${MAINTESTOPTIONS+set}" != set ; then - source $(dirname $0)/test.inc - STANDALONE="true" -else - STANDALONE="" -fi - -rm -rf db dists pool lists conf gpgtestdir - -mkdir -p gpgtestdir -export GNUPGHOME="`pwd`/gpgtestdir" -gpg --import $SRCDIR/tests/good.key $SRCDIR/tests/evil.key $SRCDIR/tests/expired.key $SRCDIR/tests/revoked.key - -mkdir -p conf -cat > conf/options < conf/distributions < conf/auploaders < conf/buploaders < conf/cuploaders < conf/incoming < conf/distributions < results -cat > results.expected < conf/distributions < importindex < importindex < importindex < importindex < pool/dog/f/foo/foo_0_${FAKEARCHITECTURE}.deb - -cat > importindex < pool/dog/f/foo/foo_1.dsc -echo "tar-content" > pool/dog/f/foo/foo_1.tar.gz - -cat > importindex < references.normal -grep '^s=' results | sed -e 's/^s=\(.\)=[^ ]* /\1 contains /' > references.snapshot -dodiff -u references.normal references.snapshot -rm references.normal references.snapshot -# Remove contents from original, to make them more look alike: -for n in dists/B/Release dists/B/snapshots/now/Release dists/A/Release dists/A/snapshots/now/Release ; do - ed -s $n < conf/distributions < results.expected < results -dodiff results.expected results -cat > conf/distributions < results.expected < results -dodiff results.expected results -# Now try with suite -cat > conf/distributions < results.expected < results -dodiff results.expected results -testrun - -b . createsymlinks 3< 'foo/updates' because of '/'. -stdout -EOF -cat >> conf/distributions < 'foo/updates' because of the '/' in it. --v2*=Hopefully something else will link 'bla' -> 'foo' then this is not needed. -stdout --v1*=Created ./dists/bla->foo -EOF -# check a .dsc with nothing in it: -cat > test.dsc < test.dsc < -Section: section -Priority: priority -Files: -EOF -testrun - -C a -b . includedsc foo test.dsc 3< conf/options -cat > conf/distributions < 0, but was nowhere found. -*='pool/something/a/aa/aa_1-1_abacus.deb' has refcount > 0, but was nowhere found. -*='pool/something/a/aa/aa_1-1.dsc' has refcount > 0, but was nowhere found. -*='pool/something/a/aa/aa_1-1.tar.gz' has refcount > 0, but was nowhere found. -stdout --d1*=db: 'aa' '1-1' removed from tracking.db(breakme). --v1*=4 files lost their last reference. --v1*=(dumpunreferenced lists such files, use deleteunreferenced to delete them.) -EOF - -testrun - retrack breakme 3< testfile -dd if=/dev/zero bs=1024 count=1024 >> testfile -echo "" >> testfile -echo "middle" >> testfile -dd if=/dev/zero bs=1024 count=1024 >> testfile -echo "" >> testfile -echo "end" >> testfile - -echo "Ohm" > smallfile - -echo gzip -c testfile \> testfile.gz -gzip -c testfile > testfile.gz -echo bzip2 -c testfile \> testfile.bz2 -bzip2 -c testfile > testfile.bz2 -echo lzma -c testfile \> testfile.lzma -lzma -c testfile > testfile.lzma -if test -x /usr/bin/xz ; then - echo xz -c testfile \> testfile.xz - xz -c testfile > testfile.xz -fi -echo gzip -c smallfile \> smallfile.gz -gzip -c smallfile > smallfile.gz -echo bzip2 -c smallfile \> smallfile.bz2 -bzip2 -c smallfile > smallfile.bz2 -echo lzma -c smallfile \> smallfile.lzma -lzma -c smallfile > smallfile.lzma - -if test -x /usr/bin/xz ; then -echo xz -c smallfile \> smallfile.xz -xz -c smallfile > smallfile.xz -testrun - __uncompress .xz testfile.xz testfile.xz.uncompressed 3< smallfile.lzma.uncompressed exited with errorcode 1! --v0*=There have been errors! -returns 255 -EOF -dodo test ! -e smallfile.lzma.uncompressed - - -# Now check for compressed parts of an .a file: - -cat > control < control.tar.bz2 -tar -cf - ./control | bzip2 > control.tar.bz2 -rm control -echo tar -cf - testfile\* \| lzma \> data.tar.lzma -tar -cf - testfile* | lzma > data.tar.lzma -echo 2.0 > debian-binary -dodo ar qcfS fake.deb debian-binary control.tar.bz2 data.tar.lzma -rm *.tar.bz2 *.tar.lzma debian-binary - -# TODO: there could be a problem here with .deb files that have data after the -# ./control file in data.tar and using an external uncompressor. -# But how to test this when there is no way to trigger it in the default built? - -testrun - __extractcontrol fake.deb 3< debian/control < debian/dirs -dd if=/dev/zero of=debian/zzz bs=1024 count=4096 -tar -cf - debian | lzma > fake_1-1.debian.tar.lzma -mkdir fake-1 -mkdir fake-1.orig -cp -al debian fake-1/debian -cp -al debian fake-1.orig/debian -sed -e 's/1/2/' fake-1/debian/dirs > fake-1/debian.dirs.new -mv fake-1/debian.dirs.new fake-1/debian/dirs -diff -ruN fake-1.orig fake-1 | lzma > fake_1-1.diff.lzma -rm -r debian - -# .debian.tar and .diff usually do not happen at the same time, but easier testing... -cat > fake_1-1.dsc << EOF -Format: 3.0 -Source: fake -Binary: abinary -Architecture: all -Version: 17 -Maintainer: Me -Files: - $(mdandsize fake_1-1.diff.lzma) fake_1-1.diff.lzma - $(mdandsize fake_1-1.debian.tar.lzma) fake_1-1.debian.tar.lzma - 00000000000000000000000000000000 0 fake_1.orig.tar.lzma -EOF - -testrun - __extractsourcesection fake_1-1.dsc 3< fake_1-1.debian.tar.lzma -tar -cf - debian | lzma > fake_1-1.debian.tar.lzma -rm -r debian - -testrun - __extractsourcesection fake_1-1.dsc 3< fake-1/debian/control < fake-1/debian/aaaaa < fake_1-1.diff.lzma -rm -r fake-1 fake-1.orig - - -cat > fake_1-1.dsc << EOF -Format: 3.0 -Source: fake -Binary: abinary -Architecture: all -Version: 17 -Maintainer: Me -Files: - $(mdandsize fake_1-1.diff.lzma) fake_1-1.diff.lzma - $(mdandsize fake_1-1.debian.tar.lzma) fake_1-1.debian.tar.lzma - 00000000000000000000000000000000 0 fake_1.orig.tar.lzma -EOF - -testrun - __extractsourcesection fake_1-1.dsc 3< fake_1-2.diff < fake_1-2.dsc << EOF -Format: 3.0 -Source: fake -Binary: abinary -Architecture: all -Version: 17 -Maintainer: Me -Files: - $(mdandsize fake_1-2.diff.gz) fake_1-2.diff.gz - 00000000000000000000000000000000 0 fake_1.orig.tar.gz -EOF - -testrun - __extractsourcesection fake_1-2.dsc 3< test/test/test.dsc -echo "fake-gz-file" > test/test/test.tar.gz - -cat >test/dists/a/c/source/Sources < test/dists/a/Release <conf/distributions <conf/updates <>conf/updates <> conf/updates - -testrun - -b . update 3< conf/distributions < conf/options < conf/distributions < conf/distributions < conf/distributions < conf/distributions < conf/distributions < results -cat > results.expected < conf/incoming < conf/incoming < conf/incoming < conf/incoming < conf/incoming < conf/incoming < results.log.expected < results -dodiff results.empty results -find i -type f > results -dodiff results.empty results -cat > results.expected < results -dodiff results.expected results -printindexpart pool/dog/b/bird/bird_1_${FAKEARCHITECTURE}.deb > results.expected -printindexpart pool/dog/b/bird/bird-addons_1_all.deb >> results.expected -dodiff results.expected dists/B/dog/binary-${FAKEARCHITECTURE}/Packages -withoutchecksums pool/dog/b/bird/bird_1.dsc > results.expected -ed -s results.expected < results -dodiff results.expected results - -echo "DebOverride: debo" >> conf/distributions -echo "DscOverride: dsco" >> conf/distributions -echo "bird Section cat/tasty" > conf/debo -echo "bird Priority hungry" >> conf/debo -echo "bird Task lunch" >> conf/debo -echo "bird-addons Section cat/ugly" >> conf/debo -echo "bird Section cat/nest" > conf/dsco -echo "bird Priority hurry" >> conf/dsco -echo "bird Homepage gopher://tree" >> conf/dsco - -mv i2/* i/ -rmdir i2 -testrun - -b . processincoming default 3< results -dodiff results.empty results -find i -type f > results -dodiff results.empty results -cat > results.expected < results -dodiff results.expected results -printindexpart pool/cat/b/bird/bird_1_${FAKEARCHITECTURE}.deb > results.expected -printindexpart pool/cat/b/bird/bird-addons_1_all.deb >> results.expected -ed -s results.expected < results.expected -ed -s results.expected < results -dodiff results.expected results - -# now missing: checking what all can go wrong in a .changes or .dsc file... -mkdir pkg -mkdir pkg/a -touch pkg/a/b -mkdir pkg/DEBIAN -cat > pkg/DEBIAN/control < i/test.changes < i/test.changes -testrun - -b . processincoming default 3< i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -touch "$(printf 'i/\300\257.\300\257_v_funny.deb')" -testrun - -b . processincoming default 3<> i/test.changes -mv "$(printf 'i/\300\257.\300\257_v_funny.deb')" "$(printf 'i/\300\257.\300\257_v_all.deb')" -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -# TODO: this error message has to be improved: -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -# TODO: these will hopefully change to not divulge the place of the temp dir some day... -testrun - -b . processincoming default 3<" >> pkg/DEBIAN/control -dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb -DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes -testrun - -b . processincoming default 3<> pkg/DEBIAN/control -echo " a package to test reprepro" >> pkg/DEBIAN/control -dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb -DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes -testrun - -b . processincoming default 3<> pkg/DEBIAN/control -dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb -DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> pkg/DEBIAN/control -dpkg-deb -b pkg i/indebname_debfileversion~2_all.deb -DEBMD5S="$(md5sum i/indebname_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/indebname_debfileversion~2_all.deb)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DEBMD5S - - indebname_debfileversion~2_all.deb" >> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> pkg/DEBIAN/control -dpkg-deb -b pkg i/indebname_debfileversion~2_all.deb -DEBMD5S="$(md5sum i/indebname_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/indebname_debfileversion~2_all.deb)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DEBMD5S test - indebname_debfileversion~2_all.deb" >> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -checknolog logfile -testrun - -b . processincoming default 3< results -echo "pool/dog/s/sourceindeb/indebname_versionindeb~1_all.deb" > results.expected -dodiff results.expected results - -touch i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -cat > i/test.changes <> i/test.changes -testrun - -b . processincoming default 3< i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3< i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<" >> i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -checknolog logfile -testrun - -b . processincoming default 3<i/strangefile <i/dscfilename_fileversion~.dsc < -Standards-Version: 0 -Version: 1:newversion~ -Files: - md5sumindsc sizeindsc strangefile -EOF -DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" -cat >i/test.changes <> i/test.changes -# this is a stupid error message, needs to get some context -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/test.changes -testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc -DSCMD5S="$(mdandsize i/dscfilename_fileversion~.dsc)" -DSCSHA1S="$(sha1andsize i/dscfilename_fileversion~.dsc)" -DSCSHA2S="$(sha2andsize i/dscfilename_fileversion~.dsc)" -DSCFILENAMEMD5S="$DSCMD5S" -DSCFILENAMESHA1S="$DSCSHA1S" -DSCFILENAMESHA2S="$DSCSHA2S" -printf '$-1,$d\nw\nq\n' | ed -s i/test.changes -echo " $DSCMD5S dummy unneeded dscfilename_fileversion~.dsc" >> i/test.changes -echo " 33a1096ff883d52f0c1f39e652d6336f 33 - - strangefile_xyz" >> i/test.changes -testrun - -b . processincoming default 3< results -cat > results.expected < results -cat > results.expected < results -withoutchecksums pool/dog/b/bird/bird_1.dsc >bird.preprocessed -ed -s bird.preprocessed < results.expected < -Standards-Version: 0 -Version: versionindsc -Priority: can't-live-without -Section: dummy -Directory: pool/dog/d/dscfilename -Files: - $OLDDSCFILENAMEMD5S dscfilename_versionindsc.dsc -Checksums-Sha1: - $OLDDSCFILENAMESHA1S dscfilename_versionindsc.dsc -Checksums-Sha256: - $OLDDSCFILENAMESHA2S dscfilename_versionindsc.dsc - -EOF -dodiff results.expected results -testout "" -b . dumpunreferenced -dodiff results.empty results -printf '$d\nw\nq\n' | ed -s i/test.changes -echo " 31a1096ff883d52f0c1f39e652d6336f 33 - - strangefile_xyz" >> i/test.changes -checknolog logfile -testrun - -b . processincoming default 3< results -cat > results.expected < results -cat > results.expected < results -cat bird.preprocessed - > results.expected < -Standards-Version: 0 -Version: 1:newversion~ -Priority: unneeded -Section: dummy -Directory: pool/dog/d/dscfilename -Files: - $DSCFILENAMEMD5S dscfilename_newversion~.dsc - 31a1096ff883d52f0c1f39e652d6336f 33 strangefile_xyz -Checksums-Sha1: - $DSCFILENAMESHA1S dscfilename_newversion~.dsc - 4453da6ca46859b207c5b55af6213ff8369cd383 33 strangefile_xyz -Checksums-Sha256: - $DSCFILENAMESHA2S dscfilename_newversion~.dsc - c40fcf711220c0ce210159d43b22f1f59274819bf3575e11cc0057ed1988a575 33 strangefile_xyz - -EOF -dodiff results.expected results - -testout "" -b . dumpunreferenced -dodiff results.empty results - -rm -r conf db pool dists i pkg logs temp -rm results.expected results.log.expected results bird.preprocessed -testsuccess diff -Nru reprepro-4.5.0/tests/testvarious2.sh reprepro-4.6.0/tests/testvarious2.sh --- reprepro-4.5.0/tests/testvarious2.sh 2011-02-21 16:49:42.000000000 +0000 +++ reprepro-4.6.0/tests/testvarious2.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,2526 +0,0 @@ -#!/bin/bash - -set -e -if [ "x$TESTINCSETUP" != "xissetup" ] ; then - source $(dirname $0)/test.inc -fi - -echo "Running various other old test..." -mkdir -p conf logs -cat > conf/options < conf/distributions < conf/testhook <<'EOF' -#!/bin/sh -echo "testhook got $#: '$1' '$2' '$3' '$4'" -if test -f "$1/$3.deprecated" ; then - echo "$3.deprecated.tobedeleted" >&3 -fi -echo "super-compressed" > "$1/$3.super.new" -echo "$3.super.new" >&3 -EOF -chmod a+x conf/testhook - -mkdir -p "dists/test2/stupid/binary-${FAKEARCHITECTURE}" -touch "dists/test2/stupid/binary-${FAKEARCHITECTURE}/Packages.deprecated" - -set -v -checknolog logfile -testrun - -b . export test1 test2 3< dists/test1/stupid/binary-${FAKEARCHITECTURE}/Release.expected < dists/test1/ugly/binary-${FAKEARCHITECTURE}/Release.expected < "fakesuper" -FAKESUPERMD5="$(mdandsize fakesuper)" -FAKESUPERSHA1="$(sha1andsize fakesuper)" -FAKESUPERSHA2="$(sha2andsize fakesuper)" - -dodiff dists/test1/ugly/binary-${FAKEARCHITECTURE}/Release.expected dists/test1/ugly/binary-${FAKEARCHITECTURE}/Release -cat > dists/test1/Release.expected < dists/test2/stupid/binary-${FAKEARCHITECTURE}/Release.expected < dists/test2/ugly/binary-${FAKEARCHITECTURE}/Release.expected < dists/test2/Release.expected < conf/srcoverride < conf/binoverride < results -cat >results.expected < results.expected << END -test2|ugly|${FAKEARCHITECTURE}: simple 1 -test2|ugly|coal: simple-addons 1 -test2|ugly|source: simple 1 -END -dodiff results.expected results -testout "" -b . listfilter test2 'Source(==bloat+-0a9z.app)|(!Source,Package(==bloat+-0a9z.app))' -cat > results.expected << END -test2|stupid|${FAKEARCHITECTURE}: bloat+-0a9z.app 99:0.9-A:Z+a:z-0+aA.9zZ -test2|stupid|coal: bloat+-0a9z.app-addons 99:0.9-A:Z+a:z-0+aA.9zZ -test2|stupid|source: bloat+-0a9z.app 99:0.9-A:Z+a:z-0+aA.9zZ -END -dodiff results.expected results - -cat >conf/updates <${FAKEARCHITECTURE} ${FAKEARCHITECTURE} source -FilterFormula: Priority(==optional),Package(>=alpha),Package(<=zeta) -FilterList: error list -ListHook: /bin/cp -END - -cat >conf/list <> conf/updates <> conf/updates <> conf/updates < test2 -find dists/test1/ \( -name "Packages.gz" -o -name "Sources.gz" \) -print0 | xargs -0 zgrep '^Package: ' | sort > test1 -dodiff test2 test1 - -testrun - -b . check test1 test2 3<results.expected <results.expected <includeerror.rules < <.changes-file> -EOF -testrun includeerror -b . include unknown 3< results.expected < results.expected < results.expected < results.expected < conf2/distributions -testrun - -b . --confdir ./conf2 update 3<> conf2/distributions -testrun - -b . --confdir ./conf2 update 3<> conf2/distributions -testrun - -b . --confdir ./conf2 update 3< broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . include test2 broken.changes 3<> broken.changes -testrun - -b . --ignore=missingfield include test2 broken.changes 3<> broken.changes -testrun - -b . --ignore=missingfield include test2 broken.changes 3<> broken.changes -testrun - -b . --ignore=missingfield include test2 broken.changes 3<> conf/distributions <> broken.changes -touch nowhere_old.dsc - -testrun - -b . --ignore=unusedarch --ignore=surprisingarch --ignore=wrongdistribution --ignore=missingfield include test2 broken.changes 3<results.expected < broken.changes < -Description: missing -Changes: missing -Binary: none and nothing -Distribution: test2 -Files: - `md5sum 4test_b.1-1.dsc| cut -d" " -f 1` `stat -c%s 4test_b.1-1.dsc` a b differently_0another.dsc - `md5sum 4test_b.1-1_${FAKEARCHITECTURE}.deb| cut -d" " -f 1` `stat -c%s 4test_b.1-1_${FAKEARCHITECTURE}.deb` a b 4test_b.1-1_${FAKEARCHITECTURE}.deb -EOF -#todo: make it work without this.. -cp 4test_b.1-1.dsc differently_0another.dsc -testrun - -b . include test2 broken.changes 3<> broken.changes < broken.changes < -Description: missing -Changes: missing -Binary: 4test -Distribution: test2 -Files: - `md5sum 4test_b.1-1.dsc| cut -d" " -f 1` `stat -c%s 4test_b.1-1.dsc` a b 4test_0orso.dsc - `md5sum 4test_b.1-1_${FAKEARCHITECTURE}.deb| cut -d" " -f 1` `stat -c%s 4test_b.1-1_${FAKEARCHITECTURE}.deb` a b 4test_b.1-1_${FAKEARCHITECTURE}.deb - `md5sum 4test_b.1-1.tar.gz| cut -d" " -f 1` `stat -c%s 4test_b.1-1.tar.gz` a b 4test_b.1-1.tar.gz -EOF -cp 4test_b.1-1.dsc 4test_0orso.dsc -testrun - -b . include test2 broken.changes 3< conf/distributions <> conf/distributions <> conf/distributions < conf/pulls <toa froma>toa2 froma2>toa2 -Components: c1 c2 -UDebComponents: u1 u2 -EOF -testrun - -b . --export=changed pull a b 3<> conf/distributions < conf/pulls <results.expected < results.expected <results.expected < results.expected <results.expected < results.expected < results.expected < broken.changes -testrun - -b . --delete --delete include a broken.changes 3<> broken.changes -testrun - -b . --delete --delete include a broken.changes 3<results.expected < results.expected << EOF -pool/all/a/ab/ab_3-1.diff.gz -EOF -dodiff results.empty results || dodiff results.expected results -testrun - -b . deleteunreferenced 3<> conf/distributions -cat >conf/updates < results.expected < results.expected < results.expected < results.expected < results.expected <> aa)" 3< results.expected < results.expected < conf/distributions < conf/distributions < conf/updates < conf/updates < conf/updates < conf/updates < test/dists/test/Release < conf/updates < conf/updates < conf/updates < conf/updates < conf/updates < test/dists/test/Release.gpg <<'EOF' ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.9 (GNU/Linux) - -iKIEAAECAAwFAknjKV8FgwABUYAACgkQFU9je/YsbTvOMwQAhyMjhSCosJtdvMSV -l3OUSmHplKZZizJDO9YqO/018I2iSWgpnRxsEX4kmf07qwHjUOYXF3ezaEYWoK1H -B5rLqWuju5lwXpPjOF1b1X/0lzyBmLT380gbMa9Nkgjxq2viX/eP9UJKeKKidmrg -zWLyB0i6AbOlZw4eE+RCQyUqheI= -=1UvF ------END PGP SIGNATURE----- -EOF - -testrun - -b . update Test 3< test/dists/test/Release.gpg < conf/distributions < conf/updates <a2 source -Suite: test -Method: file:${WORKDIR}/test -IgnoreRelease: yes -EOF -mkdir test -mkdir test/dists -mkdir test/dists/test -mkdir test/dists/test/main -mkdir test/dists/test/main/binary-a -mkdir test/dists/test/main/source - -cat > test/dists/test/main/binary-a/Packages < test/dists/test/main/source/Sources <' -='File not found' -*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/binary-a/Packages.bz2': -*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/source/Sources.gz': -*='' -*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/source/Sources.bz2': --v1*=aptmethod got 'file:${WORKDIR}/test/dists/test/main/binary-a/Packages' --v2*=Copy file '${WORKDIR}/test/dists/test/main/binary-a/Packages' to './lists/update_test_main_a_Packages'... --v1*=aptmethod got 'file:${WORKDIR}/test/dists/test/main/source/Sources' --v2*=Copy file '${WORKDIR}/test/dists/test/main/source/Sources' to './lists/update_test_main_Sources'... -stdout --v2*=Created directory "./db" --v2*=Created directory "./lists" -*=Updates needed for 'test|main|source': -*=add 'fake1' - '0s' 'update' -*=add 'fake2' - '2s' 'update' -*=Updates needed for 'test|main|a2': -*=add 'fake2' - '2all' 'update' -EOF - -rm -r conf lists test db -testsuccess diff -Nru reprepro-4.5.0/tests/tooltest.sh reprepro-4.6.0/tests/tooltest.sh --- reprepro-4.5.0/tests/tooltest.sh 2006-09-20 16:09:56.000000000 +0000 +++ reprepro-4.6.0/tests/tooltest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,137 +0,0 @@ -#!/bin/bash - -set -e - -testrun() { -rules=$1 -shift -if test "x$rules" = "x" ; then - "$TESTTOOL" $TESTOPTIONS "$CHANGESTOOL" "$@" -elif test "x$rules" = "x-" ; then - "$TESTTOOL" -r $TESTOPTIONS "$CHANGESTOOL" "$@" -else - "$TESTTOOL" -r $TESTOPTIONS "$CHANGESTOOL" "$@" 3<"$rules".rules -fi -} -testout() { -rules=$1 -shift -if test "x$rules" = "x" ; then - "$TESTTOOL" -o results $TESTOPTIONS "$CHANGESTOOL" "$@" -elif test "x$rules" = "x-" ; then - "$TESTTOOL" -o results -r $TESTOPTIONS "$CHANGESTOOL" "$@" -else - "$TESTTOOL" -o results -r $TESTOPTIONS "$CHANGESTOOL" "$@" 3<"$rules".rules -fi -} -dogrep() { -echo grep -q "$@" -grep -q "$@" -} -dongrep() { -echo "!grep" -q "$@" -! grep -q "$@" -} -dodiff() { -echo diff -u "$@" -diff -u "$@" -} -dodo() { -echo "$@" -"$@" -} - -WORKDIR="`pwd`/testdir" - -if [ "x$1" == "x--delete" ] ; then - rm -r "$WORKDIR" || true - shift -fi - -mkdir "$WORKDIR" -cd "$WORKDIR" - -if [ "1" -gt "$#" ] || [ "3" -lt "$#" ] ; then - echo "Syntax: test.sh [] []" >&2 - exit 1 -fi -SRCDIR="$1" -if [ -z "$TESTOPTIONS" ] ; then - TESTOPTIONS="-e -a" -# TESTOPTIONS="-e -a --debug --suppressions=$SRCDIR/valgrind.supp" -fi -if [ "2" -le "$#" ] ; then - TESTTOOL="$2" -else - TESTTOOL=testtool -fi -if [ "3" -le "$#" ] ; then - CHANGESTOOL="$3" -else - CHANGESTOOL="$SRCDIR/changestool" -fi -TESTS="$SRCDIR/tests" -UPDATETYPE=update -export PATH="$TESTS:$PATH" -if ! [ -x "$CHANGESTOOL" ] ; then - echo "Could not find $CHANGESTOOL!" >&2 - exit 1 -fi -TESTTOOLVERSION="`$TESTTOOL --version`" -case $TESTTOOLVERSION in - "testtool version "*) ;; - *) echo "Failed to get version of testtool($TESTTOOL)" - exit 1 - ;; -esac -touch results.empty - -testrun - 3< -*=Possible commands include: -*= verify -returns 1 -EOF - -testrun - --help 3< -*=Possible commands include: -*= verify -returns 0 -EOF - -testrun - test.changes verify 3< test.changes -testrun - test.changes verify 3< conf/options +cat > conf/distributions < 0, but was nowhere found. +*='pool/something/a/aa/aa_1-1_abacus.deb' has refcount > 0, but was nowhere found. +*='pool/something/a/aa/aa_1-1.dsc' has refcount > 0, but was nowhere found. +*='pool/something/a/aa/aa_1-1.tar.gz' has refcount > 0, but was nowhere found. +stdout +-d1*=db: 'aa' '1-1' removed from tracking.db(breakme). +-v1*=4 files lost their last reference. +-v1*=(dumpunreferenced lists such files, use deleteunreferenced to delete them.) +EOF + +testrun - retrack breakme 3< testfile +dd if=/dev/zero bs=1024 count=1024 >> testfile +echo "" >> testfile +echo "middle" >> testfile +dd if=/dev/zero bs=1024 count=1024 >> testfile +echo "" >> testfile +echo "end" >> testfile + +echo "Ohm" > smallfile + +echo gzip -c testfile \> testfile.gz +gzip -c testfile > testfile.gz +echo bzip2 -c testfile \> testfile.bz2 +bzip2 -c testfile > testfile.bz2 +echo lzma -c testfile \> testfile.lzma +lzma -c testfile > testfile.lzma +if test -x /usr/bin/xz ; then + echo xz -c testfile \> testfile.xz + xz -c testfile > testfile.xz +fi +echo gzip -c smallfile \> smallfile.gz +gzip -c smallfile > smallfile.gz +echo bzip2 -c smallfile \> smallfile.bz2 +bzip2 -c smallfile > smallfile.bz2 +echo lzma -c smallfile \> smallfile.lzma +lzma -c smallfile > smallfile.lzma + +if test -x /usr/bin/xz ; then +echo xz -c smallfile \> smallfile.xz +xz -c smallfile > smallfile.xz +testrun - __uncompress .xz testfile.xz testfile.xz.uncompressed 3< smallfile.lzma.uncompressed exited with errorcode 1! +-v0*=There have been errors! +returns 255 +EOF +dodo test ! -e smallfile.lzma.uncompressed + + +# Now check for compressed parts of an .a file: + +cat > control < control.tar.bz2 +tar -cf - ./control | bzip2 > control.tar.bz2 +rm control +echo tar -cf - testfile\* \| lzma \> data.tar.lzma +tar -cf - testfile* | lzma > data.tar.lzma +echo 2.0 > debian-binary +dodo ar qcfS fake.deb debian-binary control.tar.bz2 data.tar.lzma +rm *.tar.bz2 *.tar.lzma debian-binary + +# TODO: there could be a problem here with .deb files that have data after the +# ./control file in data.tar and using an external uncompressor. +# But how to test this when there is no way to trigger it in the default built? + +testrun - __extractcontrol fake.deb 3< debian/control < debian/dirs +dd if=/dev/zero of=debian/zzz bs=1024 count=4096 +tar -cf - debian | lzma > fake_1-1.debian.tar.lzma +mkdir fake-1 +mkdir fake-1.orig +cp -al debian fake-1/debian +cp -al debian fake-1.orig/debian +sed -e 's/1/2/' fake-1/debian/dirs > fake-1/debian.dirs.new +mv fake-1/debian.dirs.new fake-1/debian/dirs +diff -ruN fake-1.orig fake-1 | lzma > fake_1-1.diff.lzma +rm -r debian + +# .debian.tar and .diff usually do not happen at the same time, but easier testing... +cat > fake_1-1.dsc << EOF +Format: 3.0 +Source: fake +Binary: abinary +Architecture: all +Version: 17 +Maintainer: Me +Files: + $(mdandsize fake_1-1.diff.lzma) fake_1-1.diff.lzma + $(mdandsize fake_1-1.debian.tar.lzma) fake_1-1.debian.tar.lzma + 00000000000000000000000000000000 0 fake_1.orig.tar.lzma +EOF + +testrun - __extractsourcesection fake_1-1.dsc 3< fake_1-1.debian.tar.lzma +tar -cf - debian | lzma > fake_1-1.debian.tar.lzma +rm -r debian + +testrun - __extractsourcesection fake_1-1.dsc 3< fake-1/debian/control < fake-1/debian/aaaaa < fake_1-1.diff.lzma +rm -r fake-1 fake-1.orig + + +cat > fake_1-1.dsc << EOF +Format: 3.0 +Source: fake +Binary: abinary +Architecture: all +Version: 17 +Maintainer: Me +Files: + $(mdandsize fake_1-1.diff.lzma) fake_1-1.diff.lzma + $(mdandsize fake_1-1.debian.tar.lzma) fake_1-1.debian.tar.lzma + 00000000000000000000000000000000 0 fake_1.orig.tar.lzma +EOF + +testrun - __extractsourcesection fake_1-1.dsc 3< fake_1-2.diff < fake_1-2.dsc << EOF +Format: 3.0 +Source: fake +Binary: abinary +Architecture: all +Version: 17 +Maintainer: Me +Files: + $(mdandsize fake_1-2.diff.gz) fake_1-2.diff.gz + 00000000000000000000000000000000 0 fake_1.orig.tar.gz +EOF + +testrun - __extractsourcesection fake_1-2.dsc 3< test/test/test.dsc +echo "fake-gz-file" > test/test/test.tar.gz + +cat >test/dists/a/c/source/Sources < test/dists/a/Release <conf/distributions <conf/updates <>conf/updates <> conf/updates + +testrun - -b . update 3< conf/distributions < descr1 < conf/uploaders1 < conf/uploaders2 < descrbad < descrbad < descres < descrs <> conf/uploaders2 <>conf/uploaders1 <conf/uploaders1 <conf/uploaders1 <>conf/uploaders1 <>conf/uploaders1 <conf/uploaders1 <>conf/uploaders1 <>conf/uploaders1 <conf/uploaders1 <> descr2 +sed -e 's/0000000000000000/fedcba9876542210/g' descrs >> descr3 +echo "architecture coal" >> descrs +check1takes descrs +check1takes descr2 +check2takes descr3 + +rm -r conf descr* +testsuccess diff -Nru reprepro-4.5.0/tests/various1.test reprepro-4.6.0/tests/various1.test --- reprepro-4.5.0/tests/various1.test 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/tests/various1.test 2011-05-05 14:42:55.000000000 +0000 @@ -0,0 +1,1383 @@ +set -u +. "$TESTSDIR"/test.inc + +mkdir -p conf +cat > conf/distributions < conf/options < conf/distributions < conf/distributions < conf/distributions < conf/distributions < conf/distributions < results +cat > results.expected < conf/incoming < conf/incoming < conf/incoming < conf/incoming < conf/incoming < conf/incoming < results.log.expected < results +dodiff /dev/null results +find i -type f > results +dodiff /dev/null results +cat > results.expected < results +dodiff results.expected results +printindexpart pool/dog/b/bird/bird_1_abacus.deb > results.expected +printindexpart pool/dog/b/bird/bird-addons_1_all.deb >> results.expected +dodiff results.expected dists/B/dog/binary-abacus/Packages +withoutchecksums pool/dog/b/bird/bird_1.dsc > results.expected +ed -s results.expected < results +dodiff results.expected results + +echo "DebOverride: debo" >> conf/distributions +echo "DscOverride: dsco" >> conf/distributions +echo "bird Section cat/tasty" > conf/debo +echo "bird Priority hungry" >> conf/debo +echo "bird Task lunch" >> conf/debo +echo "bird-addons Section cat/ugly" >> conf/debo +echo "bird Section cat/nest" > conf/dsco +echo "bird Priority hurry" >> conf/dsco +echo "bird Homepage gopher://tree" >> conf/dsco + +mv i2/* i/ +rmdir i2 +testrun - -b . processincoming default 3< results +dodiff /dev/null results +find i -type f > results +dodiff /dev/null results +cat > results.expected < results +dodiff results.expected results +printindexpart pool/cat/b/bird/bird_1_abacus.deb > results.expected +printindexpart pool/cat/b/bird/bird-addons_1_all.deb >> results.expected +ed -s results.expected < results.expected +ed -s results.expected < results +dodiff results.expected results + +# now missing: checking what all can go wrong in a .changes or .dsc file... +mkdir pkg +mkdir pkg/a +touch pkg/a/b +mkdir pkg/DEBIAN +cat > pkg/DEBIAN/control < i/test.changes < i/test.changes +testrun - -b . processincoming default 3< i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes < i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +touch "$(printf 'i/\300\257.\300\257_v_funny.deb')" +testrun - -b . processincoming default 3<> i/test.changes +mv "$(printf 'i/\300\257.\300\257_v_funny.deb')" "$(printf 'i/\300\257.\300\257_v_all.deb')" +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +# TODO: this error message has to be improved: +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +# TODO: these will hopefully change to not divulge the place of the temp dir some day... +testrun - -b . processincoming default 3<" >> pkg/DEBIAN/control +dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb +DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes +testrun - -b . processincoming default 3<> pkg/DEBIAN/control +echo " a package to test reprepro" >> pkg/DEBIAN/control +dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb +DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes +testrun - -b . processincoming default 3<> pkg/DEBIAN/control +dpkg-deb -b pkg i/debfilename_debfileversion~2_all.deb +DEBMD5S="$(md5sum i/debfilename_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/debfilename_debfileversion~2_all.deb)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DEBMD5S - - debfilename_debfileversion~2_all.deb" >> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> pkg/DEBIAN/control +dpkg-deb -b pkg i/indebname_debfileversion~2_all.deb +DEBMD5S="$(md5sum i/indebname_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/indebname_debfileversion~2_all.deb)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DEBMD5S - - indebname_debfileversion~2_all.deb" >> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> pkg/DEBIAN/control +dpkg-deb -b pkg i/indebname_debfileversion~2_all.deb +DEBMD5S="$(md5sum i/indebname_debfileversion~2_all.deb | cut -d' ' -f1) $(stat -c '%s' i/indebname_debfileversion~2_all.deb)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DEBMD5S test - indebname_debfileversion~2_all.deb" >> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +checknolog logfile +testrun - -b . processincoming default 3< results +echo "pool/dog/s/sourceindeb/indebname_0versionindeb~1_all.deb" > results.expected +dodiff results.expected results + +touch i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +cat > i/test.changes <> i/test.changes +testrun - -b . processincoming default 3< i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3< i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<" >> i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S - - dscfilename_fileversion~.dsc" >> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +checknolog logfile +testrun - -b . processincoming default 3<i/strangefile <i/dscfilename_fileversion~.dsc < +Standards-Version: 0 +Version: 1:newversion~ +Files: + md5sumindsc sizeindsc strangefile +EOF +DSCMD5S="$(md5sum i/dscfilename_fileversion~.dsc | cut -d' ' -f1) $(stat -c '%s' i/dscfilename_fileversion~.dsc)" +cat >i/test.changes <> i/test.changes +# this is a stupid error message, needs to get some context +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/test.changes +testrun - -b . processincoming default 3<> i/dscfilename_fileversion~.dsc +DSCMD5S="$(mdandsize i/dscfilename_fileversion~.dsc)" +DSCSHA1S="$(sha1andsize i/dscfilename_fileversion~.dsc)" +DSCSHA2S="$(sha2andsize i/dscfilename_fileversion~.dsc)" +DSCFILENAMEMD5S="$DSCMD5S" +DSCFILENAMESHA1S="$DSCSHA1S" +DSCFILENAMESHA2S="$DSCSHA2S" +printf '$-1,$d\nw\nq\n' | ed -s i/test.changes +echo " $DSCMD5S dummy unneeded dscfilename_fileversion~.dsc" >> i/test.changes +echo " 33a1096ff883d52f0c1f39e652d6336f 33 - - strangefile_xyz" >> i/test.changes +testrun - -b . processincoming default 3< results +cat > results.expected < results +cat > results.expected < results +withoutchecksums pool/dog/b/bird/bird_1.dsc >bird.preprocessed +ed -s bird.preprocessed < results.expected < +Standards-Version: 0 +Version: 0versionindsc +Priority: can't-live-without +Section: dummy +Directory: pool/dog/d/dscfilename +Files: + $OLDDSCFILENAMEMD5S dscfilename_0versionindsc.dsc +Checksums-Sha1: + $OLDDSCFILENAMESHA1S dscfilename_0versionindsc.dsc +Checksums-Sha256: + $OLDDSCFILENAMESHA2S dscfilename_0versionindsc.dsc + +EOF +dodiff results.expected results +testout "" -b . dumpunreferenced +dodiff /dev/null results +printf '$d\nw\nq\n' | ed -s i/test.changes +echo " 31a1096ff883d52f0c1f39e652d6336f 33 - - strangefile_xyz" >> i/test.changes +checknolog logfile +testrun - -b . processincoming default 3< results +cat > results.expected < results +cat > results.expected < results +cat bird.preprocessed - > results.expected < +Standards-Version: 0 +Version: 1:newversion~ +Priority: unneeded +Section: dummy +Directory: pool/dog/d/dscfilename +Files: + $DSCFILENAMEMD5S dscfilename_newversion~.dsc + 31a1096ff883d52f0c1f39e652d6336f 33 strangefile_xyz +Checksums-Sha1: + $DSCFILENAMESHA1S dscfilename_newversion~.dsc + 4453da6ca46859b207c5b55af6213ff8369cd383 33 strangefile_xyz +Checksums-Sha256: + $DSCFILENAMESHA2S dscfilename_newversion~.dsc + c40fcf711220c0ce210159d43b22f1f59274819bf3575e11cc0057ed1988a575 33 strangefile_xyz + +EOF +dodiff results.expected results + +testout "" -b . dumpunreferenced +dodiff /dev/null results + +rm -r conf db pool dists i pkg logs temp +rm results.expected results.log.expected results bird.preprocessed +testsuccess diff -Nru reprepro-4.5.0/tests/various2.test reprepro-4.6.0/tests/various2.test --- reprepro-4.5.0/tests/various2.test 1970-01-01 00:00:00.000000000 +0000 +++ reprepro-4.6.0/tests/various2.test 2011-05-05 14:42:55.000000000 +0000 @@ -0,0 +1,2406 @@ +set -u +. "$TESTSDIR"/test.inc + +echo "Running various other old test..." +mkdir -p conf logs +cat > conf/options < conf/distributions < conf/testhook <<'EOF' +#!/bin/sh +echo "testhook got $#: '$1' '$2' '$3' '$4'" +if test -f "$1/$3.deprecated" ; then + echo "$3.deprecated.tobedeleted" >&3 +fi +echo "super-compressed" > "$1/$3.super.new" +echo "$3.super.new" >&3 +EOF +chmod a+x conf/testhook + +mkdir -p "dists/test2/stupid/binary-abacus" +touch "dists/test2/stupid/binary-abacus/Packages.deprecated" + +set -v +checknolog logfile +testrun - -b . export test1 test2 3< dists/test1/stupid/binary-abacus/Release.expected < dists/test1/ugly/binary-abacus/Release.expected < "fakesuper" +FAKESUPERMD5="$(mdandsize fakesuper)" +FAKESUPERSHA1="$(sha1andsize fakesuper)" +FAKESUPERSHA2="$(sha2andsize fakesuper)" + +dodiff dists/test1/ugly/binary-abacus/Release.expected dists/test1/ugly/binary-abacus/Release +cat > dists/test1/Release.expected < dists/test2/stupid/binary-abacus/Release.expected < dists/test2/ugly/binary-abacus/Release.expected < dists/test2/Release.expected < conf/srcoverride < conf/binoverride < results +cat >results.expected < results.expected << END +test2|ugly|abacus: simple 1 +test2|ugly|coal: simple-addons 1 +test2|ugly|source: simple 1 +END +dodiff results.expected results +testout "" -b . listfilter test2 'Source(==bloat+-0a9z.app)|(!Source,Package(==bloat+-0a9z.app))' +cat > results.expected << END +test2|stupid|abacus: bloat+-0a9z.app 99:0.9-A:Z+a:z-0+aA.9zZ +test2|stupid|coal: bloat+-0a9z.app-addons 99:0.9-A:Z+a:z-0+aA.9zZ +test2|stupid|source: bloat+-0a9z.app 99:0.9-A:Z+a:z-0+aA.9zZ +END +dodiff results.expected results + +cat >conf/updates <abacus abacus source +FilterFormula: Priority(==optional),Package(>=alpha),Package(<=zeta) +FilterList: error list +ListHook: /bin/cp +END + +cat >conf/list <> conf/updates <> conf/updates <> conf/updates < test2 +find dists/test1/ \( -name "Packages.gz" -o -name "Sources.gz" \) -print0 | xargs -0 zgrep '^Package: ' | sort > test1 +dodiff test2 test1 + +testrun - -b . check test1 test2 3<results.expected <results.expected <includeerror.rules < <.changes-file> +EOF +testrun includeerror -b . include unknown 3< results.expected < results.expected < results.expected < results.expected < conf2/distributions +testrun - -b . --confdir ./conf2 update 3<> conf2/distributions +testrun - -b . --confdir ./conf2 update 3<> conf2/distributions +testrun - -b . --confdir ./conf2 update 3< broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . include test2 broken.changes 3<> broken.changes +testrun - -b . --ignore=missingfield include test2 broken.changes 3<> broken.changes +testrun - -b . --ignore=missingfield include test2 broken.changes 3<> broken.changes +testrun - -b . --ignore=missingfield include test2 broken.changes 3<> conf/distributions <> broken.changes +touch nowhere_0old.dsc + +testrun - -b . --ignore=unusedarch --ignore=surprisingarch --ignore=wrongdistribution --ignore=missingfield include test2 broken.changes 3<results.expected < broken.changes < +Description: missing +Changes: missing +Binary: none and nothing +Distribution: test2 +Files: + `md5sum 4test_0b.1-1.dsc| cut -d" " -f 1` `stat -c%s 4test_0b.1-1.dsc` a b differently_0another.dsc + `md5sum 4test_0b.1-1_abacus.deb| cut -d" " -f 1` `stat -c%s 4test_0b.1-1_abacus.deb` a b 4test_0b.1-1_abacus.deb +EOF +#todo: make it work without this.. +cp 4test_0b.1-1.dsc differently_0another.dsc +testrun - -b . include test2 broken.changes 3<> broken.changes < broken.changes < +Description: missing +Changes: missing +Binary: 4test +Distribution: test2 +Files: + `md5sum 4test_0b.1-1.dsc| cut -d" " -f 1` `stat -c%s 4test_0b.1-1.dsc` a b 4test_0orso.dsc + `md5sum 4test_0b.1-1_abacus.deb| cut -d" " -f 1` `stat -c%s 4test_0b.1-1_abacus.deb` a b 4test_0b.1-1_abacus.deb + `md5sum 4test_0b.1-1.tar.gz| cut -d" " -f 1` `stat -c%s 4test_0b.1-1.tar.gz` a b 4test_0b.1-1.tar.gz +EOF +cp 4test_0b.1-1.dsc 4test_0orso.dsc +testrun - -b . include test2 broken.changes 3< conf/distributions <> conf/distributions <> conf/distributions < conf/pulls <toa froma>toa2 froma2>toa2 +Components: c1 c2 +UDebComponents: u1 u2 +EOF +testrun - -b . --export=changed pull a b 3<> conf/distributions < conf/pulls <results.expected < results.expected <results.expected < results.expected <results.expected < results.expected < results.expected < broken.changes +testrun - -b . --delete --delete include a broken.changes 3<> broken.changes +testrun - -b . --delete --delete include a broken.changes 3<results.expected < results.expected << EOF +pool/all/a/ab/ab_3-1.diff.gz +EOF +dodiff /dev/null results || dodiff results.expected results +testrun - -b . deleteunreferenced 3<> conf/distributions +cat >conf/updates < results.expected < results.expected < results.expected < results.expected < results.expected <> aa)" 3< results.expected < results.expected < conf/distributions < conf/distributions < conf/updates < conf/updates < conf/updates < conf/updates < test/dists/test/Release < conf/updates < conf/updates < conf/updates < conf/updates < conf/updates < test/dists/test/Release.gpg <<'EOF' +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.9 (GNU/Linux) + +iKIEAAECAAwFAknjKV8FgwABUYAACgkQFU9je/YsbTvOMwQAhyMjhSCosJtdvMSV +l3OUSmHplKZZizJDO9YqO/018I2iSWgpnRxsEX4kmf07qwHjUOYXF3ezaEYWoK1H +B5rLqWuju5lwXpPjOF1b1X/0lzyBmLT380gbMa9Nkgjxq2viX/eP9UJKeKKidmrg +zWLyB0i6AbOlZw4eE+RCQyUqheI= +=1UvF +-----END PGP SIGNATURE----- +EOF + +testrun - -b . update Test 3< test/dists/test/Release.gpg < conf/distributions < conf/updates <a2 source +Suite: test +Method: file:${WORKDIR}/test +IgnoreRelease: yes +EOF +mkdir test +mkdir test/dists +mkdir test/dists/test +mkdir test/dists/test/main +mkdir test/dists/test/main/binary-a +mkdir test/dists/test/main/source + +cat > test/dists/test/main/binary-a/Packages < test/dists/test/main/source/Sources <' +='File not found' +*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/binary-a/Packages.bz2': +*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/source/Sources.gz': +*='' +*=aptmethod error receiving 'file:${WORKDIR}/test/dists/test/main/source/Sources.bz2': +-v1*=aptmethod got 'file:${WORKDIR}/test/dists/test/main/binary-a/Packages' +-v2*=Copy file '${WORKDIR}/test/dists/test/main/binary-a/Packages' to './lists/update_test_main_a_Packages'... +-v1*=aptmethod got 'file:${WORKDIR}/test/dists/test/main/source/Sources' +-v2*=Copy file '${WORKDIR}/test/dists/test/main/source/Sources' to './lists/update_test_main_Sources'... +stdout +$(odb) +-v2*=Created directory "./lists" +*=Updates needed for 'test|main|source': +*=add 'fake1' - '0s' 'update' +*=add 'fake2' - '2s' 'update' +*=Updates needed for 'test|main|a2': +*=add 'fake2' - '2all' 'update' +EOF + +rm -r conf lists test db +testsuccess diff -Nru reprepro-4.5.0/tool.c reprepro-4.6.0/tool.c --- reprepro-4.5.0/tool.c 2011-02-21 15:34:29.000000000 +0000 +++ reprepro-4.6.0/tool.c 2011-05-05 14:42:55.000000000 +0000 @@ -43,7 +43,9 @@ /* for compatibility with used code */ int verbose=0; -bool interrupted(void) {return false;} +bool interrupted(void) { + return false; +} static void about(bool help) NORETURN; static void about(bool help) { @@ -61,7 +63,7 @@ " setdistribution \n" " dumbremove \n" ); - if( help ) + if (help) exit(EXIT_SUCCESS); else exit(EXIT_FAILURE); @@ -81,7 +83,7 @@ }; static void binaryfile_free(struct binaryfile *p) { - if( p == NULL ) + if (p == NULL) return; free(p->controlchunk); @@ -133,7 +135,7 @@ }; static void dscfile_free(struct dscfile *p) { - if( p == NULL ) + if (p == NULL) return; free(p->name); @@ -151,7 +153,8 @@ struct fileentry *next; char *basename; size_t namelen; char *fullfilename; - struct checksums *checksumsfromchanges, /* NULL means was not listed there yet */ + /* NULL means was not listed there yet: */ + struct checksums *checksumsfromchanges, *realchecksums; char *section, *priority; enum filetype type; @@ -189,7 +192,7 @@ }; static void fileentry_free(/*@only@*/struct fileentry *f) { - if( f == NULL ) + if (f == NULL) return; free(f->basename); free(f->fullfilename); @@ -197,9 +200,9 @@ checksums_free(f->realchecksums); free(f->section); free(f->priority); - if( f->type == ft_DEB || f->type == ft_UDEB ) { + if (f->type == ft_DEB || f->type == ft_UDEB) { binaryfile_free(f->deb); - } else if( f->type == ft_DSC ) { + } else if (f->type == ft_DSC) { dscfile_free(f->dsc); } free(f); @@ -208,7 +211,7 @@ static void changes_free(struct changes *c) { unsigned int i; - if( c == NULL ) + if (c == NULL) return; free(c->filename); @@ -219,13 +222,13 @@ free(c->control); strlist_done(&c->architectures); strlist_done(&c->distributions); - for( i = 0 ; i < c->binarycount ; i++ ) { + for (i = 0 ; i < c->binarycount ; i++) { free(c->binaries[i].name); free(c->binaries[i].description); // .files belongs elsewhere } free(c->binaries); - while( c->files ) { + while (c->files) { struct fileentry *f = c->files; c->files = f->next; fileentry_free(f); @@ -238,15 +241,15 @@ struct fileentry *f; size_t ofs = 0; - while( (f=*fp) != NULL ) { - if( f->namelen == basenamelen && - strncmp(basefilename, f->basename, basenamelen) == 0 ) { + while ((f=*fp) != NULL) { + if (f->namelen == basenamelen && + strncmp(basefilename, f->basename, basenamelen) == 0) { break; } fp = &f->next; ofs++; } - if( ofs_p != NULL ) + if (ofs_p != NULL) *ofs_p = ofs; return fp; } @@ -256,36 +259,41 @@ struct fileentry **fp = find_fileentry(c, basefilename, len, &ofs); struct fileentry *f = *fp; - if( f == NULL ) { + if (f == NULL) { enum compression; - f = calloc(1,sizeof(struct fileentry)); - if( f == NULL ) + f = zNEW(struct fileentry); + if (FAILEDTOALLOC(f)) return NULL; - *fp = f; f->basename = strndup(basefilename, len); f->namelen = len; + if (FAILEDTOALLOC(f->basename)) { + free(f); + return NULL; + } + *fp = f; + /* guess compression */ f->compression = compression_by_suffix(f->basename, &len); /* guess type */ - for( f->type = source?ft_MaxInSource:ft_Max ; - f->type > ft_UNKNOWN ; f->type-- ) { + for (f->type = source?ft_MaxInSource:ft_Max ; + f->type > ft_UNKNOWN ; f->type--) { size_t l = typesuffix[f->type].len; - if( f->compression != c_none && - !typesuffix[f->type].allowcompressed ) + if (f->compression != c_none && + !typesuffix[f->type].allowcompressed) continue; - if( len <= l ) + if (len <= l) continue; - if( strncmp(f->basename + (len-l), + if (strncmp(f->basename + (len-l), typesuffix[f->type].suffix, - l) == 0 ) + l) == 0) break; } } - if( ofs_p != NULL ) + if (ofs_p != NULL) *ofs_p = ofs; return f; } @@ -294,11 +302,11 @@ int i; bool found; char *fullname; - if( searchfirstin != NULL ) { + if (searchfirstin != NULL) { fullname = calc_dirconcat(searchfirstin, basefilename); - if( FAILEDTOALLOC(fullname) ) + if (FAILEDTOALLOC(fullname)) return RET_ERROR_OOM; - if( isregularfile(fullname) ) { + if (isregularfile(fullname)) { *result = fullname; return RET_OK; } @@ -306,24 +314,24 @@ } fullname = calc_dirconcat(changesdir, basefilename); - if( FAILEDTOALLOC(fullname) ) + if (FAILEDTOALLOC(fullname)) return RET_ERROR_OOM; found = isregularfile(fullname); i = 0; - while( !found && searchpath != NULL && i < searchpath->count ) { + while (!found && searchpath != NULL && i < searchpath->count) { free(fullname); fullname = calc_dirconcat(searchpath->values[i], basefilename); - if( fullname == NULL ) + if (FAILEDTOALLOC(fullname)) return RET_ERROR_OOM; - if( isregularfile(fullname) ) { + if (isregularfile(fullname)) { found = true; break; } i++; } - if( found ) { + if (found) { *result = fullname; return RET_OK; } else { @@ -335,20 +343,19 @@ static retvalue findfile(const char *filename, const struct changes *c, /*@null@*/const struct strlist *searchpath, /*@null@*/const char *searchfirstin, char **result) { char *fullfilename; - if( rindex(filename,'/') == NULL ) { + if (rindex(filename, '/') == NULL) { retvalue r; r = searchforfile(c->basedir, filename, searchpath, searchfirstin, &fullfilename); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; } else { - if( !isregularfile(filename) ) + if (!isregularfile(filename)) return RET_NOTHING; fullfilename = strdup(filename); - if( fullfilename == NULL ) { + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; - } } *result = fullfilename; return RET_OK; @@ -362,15 +369,15 @@ fp = find_fileentry(c, basefilename, basenamelen, NULL); f = *fp; - if( f != NULL ) { + if (f != NULL) { *file = f; free(basefilename); free(fullfilename); return RET_NOTHING; } - assert( f == NULL ); - f = calloc(1,sizeof(struct fileentry)); - if( f == NULL ) { + assert (f == NULL); + f = zNEW(struct fileentry); + if (FAILEDTOALLOC(f)) { free(basefilename); free(fullfilename); return RET_ERROR_OOM; @@ -390,19 +397,19 @@ static struct binary *get_binary(struct changes *c, const char *p, size_t len) { unsigned int j; - for( j = 0 ; j < c->binarycount ; j++ ) { - if( strncmp(c->binaries[j].name, p, len) == 0 && - c->binaries[j].name[len] == '\0' ) + for (j = 0 ; j < c->binarycount ; j++) { + if (strncmp(c->binaries[j].name, p, len) == 0 && + c->binaries[j].name[len] == '\0') break; } - if( j == c->binarycount ) { + if (j == c->binarycount) { char *name = strndup(p, len); struct binary *n; - if( name == NULL ) + if (FAILEDTOALLOC(name)) return NULL; - n = realloc(c->binaries,(j+1)*sizeof(struct binary)); - if( n == NULL ) { + n = realloc(c->binaries, (j+1)*sizeof(struct binary)); + if (FAILEDTOALLOC(n)) { free(name); return NULL; } @@ -414,34 +421,34 @@ c->binaries[j].missedinheader = true; c->binaries[j].uncheckable = false; } - assert( j < c->binarycount ); + assert (j < c->binarycount); return &c->binaries[j]; } static retvalue parse_changes_description(struct changes *c, struct strlist *tmp) { int i; - for( i = 0 ; i < tmp->count ; i++ ) { + for (i = 0 ; i < tmp->count ; i++) { struct binary *b; const char *p = tmp->values[i]; const char *e = p; const char *d; - while( *e != '\0' && *e != ' ' && *e != '\t' ) + while (*e != '\0' && *e != ' ' && *e != '\t') e++; d = e; - while( *d == ' ' || *d == '\t' ) + while (*d == ' ' || *d == '\t') d++; - if( *d == '-' ) + if (*d == '-') d++; - while( *d == ' ' || *d == '\t' ) + while (*d == ' ' || *d == '\t') d++; b = get_binary(c, p, e-p); - if( b == NULL ) + if (FAILEDTOALLOC(b)) return RET_ERROR_OOM; b->description = strdup(d); - if( b->description == NULL ) + if (FAILEDTOALLOC(b->description)) return RET_ERROR_OOM; } return RET_OK; @@ -457,72 +464,77 @@ enum checksumtype cs; tmp = &filelines[cs_md5sum]; - hashes = calloc(tmp->count, sizeof(struct hashes)); - if( FAILEDTOALLOC(hashes) ) + hashes = nzNEW(tmp->count, struct hashes); + if (FAILEDTOALLOC(hashes)) return RET_ERROR_OOM; - for( i = 0 ; i < tmp->count ; i++ ) { + for (i = 0 ; i < tmp->count ; i++) { char *p; - const char *md5start, *md5end, *sizestart, *sizeend, *sectionstart, *sectionend, *priostart, *prioend, *filestart, *fileend; + const char *md5start, *md5end, *sizestart, *sizeend, + *sectionstart, *sectionend, *priostart, *prioend, + *filestart, *fileend; p = tmp->values[i]; #undef xisspace #define xisspace(c) (c == ' ' || c == '\t') - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; md5start = p; - while( (*p >= '0' && *p <= '9') || - (*p >= 'A' && *p <= 'F' ) || - (*p >= 'a' && *p <= 'f' ) ) { - if( *p >= 'A' && *p <= 'F' ) + while ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'F') || + (*p >= 'a' && *p <= 'f')) { + if (*p >= 'A' && *p <= 'F') (*p) += 'a' - 'A'; p++; } md5end = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - while( *p == '0' && ( '0' <= p[1] && p[1] <= '9' ) ) + while (*p == '0' && ('0' <= p[1] && p[1] <= '9')) p++; sizestart = p; - while( (*p >= '0' && *p <= '9') ) + while ((*p >= '0' && *p <= '9')) p++; sizeend = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; sectionstart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; sectionend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; priostart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; prioend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; filestart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; fileend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - if( *p != '\0' ) { - fprintf(stderr,"Unexpected sixth argument in '%s'!\n", tmp->values[i]); + if (*p != '\0') { + fprintf(stderr, +"Unexpected sixth argument in '%s'!\n", + tmp->values[i]); free(hashes); return RET_ERROR; } - if( fileend - filestart == 0 ) + if (fileend - filestart == 0) continue; f = add_fileentry(c, filestart, fileend-filestart, false, &ofs); - assert( ofs <= count ); - if( ofs == count ) + assert (ofs <= count); + if (ofs == count) count++; - if( hashes[ofs].hashes[cs_md5sum].start != NULL ) { - fprintf(stderr, "WARNING: Multiple occourance of '%s' in .changes file!\nIgnoring all but the first one.\n", + if (hashes[ofs].hashes[cs_md5sum].start != NULL) { + fprintf(stderr, +"WARNING: Multiple occourance of '%s' in .changes file!\nIgnoring all but the first one.\n", f->basename); continue; } @@ -531,73 +543,80 @@ hashes[ofs].hashes[cs_length].start = sizestart; hashes[ofs].hashes[cs_length].len = sizeend - sizestart; - if( sectionend - sectionstart == 1 && *sectionstart == '-' ) { + if (sectionend - sectionstart == 1 && *sectionstart == '-') { f->section = NULL; } else { - f->section = strndup(sectionstart,sectionend-sectionstart); - if( f->section == NULL ) + f->section = strndup(sectionstart, + sectionend - sectionstart); + if (FAILEDTOALLOC(f->section)) return RET_ERROR_OOM; } - if( prioend - priostart == 1 && *priostart == '-' ) { + if (prioend - priostart == 1 && *priostart == '-') { f->priority = NULL; } else { - f->priority = strndup(priostart,prioend-priostart); - if( f->priority == NULL ) + f->priority = strndup(priostart, prioend - priostart); + if (FAILEDTOALLOC(f->priority)) return RET_ERROR_OOM; } } const char * const hashname[cs_hashCOUNT] = {"Md5", "Sha1", "Sha256" }; - for( cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_firstEXTENDED ; cs < cs_hashCOUNT ; cs++) { tmp = &filelines[cs]; - for( i = 0 ; i < tmp->count ; i++ ) { + for (i = 0 ; i < tmp->count ; i++) { char *p; - const char *hashstart, *hashend, *sizestart, *sizeend, *filestart, *fileend;; + const char *hashstart, *hashend, *sizestart, *sizeend, + *filestart, *fileend; p = tmp->values[i]; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; hashstart = p; - while( (*p >= '0' && *p <= '9') || - (*p >= 'A' && *p <= 'F' ) || - (*p >= 'a' && *p <= 'f' ) ) { - if( *p >= 'A' && *p <= 'F' ) + while ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'F') || + (*p >= 'a' && *p <= 'f') ) { + if (*p >= 'A' && *p <= 'F') (*p) += 'a' - 'A'; p++; } hashend = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - while( *p == '0' && ( '0' <= p[1] && p[1] <= '9' ) ) + while (*p == '0' && ('0' <= p[1] && p[1] <= '9')) p++; sizestart = p; - while( (*p >= '0' && *p <= '9') ) + while ((*p >= '0' && *p <= '9')) p++; sizeend = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; filestart = p; - while( *p !='\0' && !xisspace(*p) ) + while (*p !='\0' && !xisspace(*p)) p++; fileend = p; - while( *p !='\0' && xisspace(*p) ) + while (*p !='\0' && xisspace(*p)) p++; - if( *p != '\0' ) { - fprintf(stderr,"Unexpected forth argument in '%s'!\n", tmp->values[i]); + if (*p != '\0') { + fprintf(stderr, +"Unexpected forth argument in '%s'!\n", + tmp->values[i]); return RET_ERROR; } - if( fileend - filestart == 0 ) + if (fileend - filestart == 0) continue; - f = add_fileentry(c, filestart, fileend-filestart, false, &ofs); - assert( ofs <= count ); + f = add_fileentry(c, filestart, fileend-filestart, + false, &ofs); + assert (ofs <= count); // until md5sums are no longer obligatory: - if( ofs == count ) + if (ofs == count) continue; - if( hashes[ofs].hashes[cs].start != NULL ) { - fprintf(stderr, "WARNING: Multiple occourance of '%s' in Checksums-'%s' of .changes file!\nIgnoring all but the first one.\n", + if (hashes[ofs].hashes[cs].start != NULL) { + fprintf(stderr, +"WARNING: Multiple occourance of '%s' in Checksums-'%s' of .changes file!\n" +"Ignoring all but the first one.\n", f->basename, hashname[cs]); continue; } @@ -609,13 +628,13 @@ } } ofs = 0; - for( f = c->files ; f != NULL ; f = f->next, ofs++ ) { + for (f = c->files ; f != NULL ; f = f->next, ofs++) { r = checksums_initialize(&f->checksumsfromchanges, hashes[ofs].hashes); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } - assert( count == ofs ); + assert (count == ofs); free(hashes); return RET_OK; @@ -627,60 +646,60 @@ enum checksumtype cs; retvalue r; - n = calloc(1,sizeof(struct dscfile)); - if( n == NULL ) + n = zNEW(struct dscfile); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; r = signature_readsignedchunk(fullfilename, fullfilename, &n->controlchunk, NULL, NULL); - assert( r != RET_NOTHING ); + assert (r != RET_NOTHING); // TODO: can this be ignored sometimes? - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(n); return r; } r = chunk_getname(n->controlchunk, "Source", &n->name, false); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } - r = chunk_getvalue(n->controlchunk, "Maintainer",&n->maintainer); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Maintainer", &n->maintainer); + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } - r = chunk_getvalue(n->controlchunk, "Version",&n->version); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Version", &n->version); + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } /* unusally not here, but hidden in the contents */ - r = chunk_getvalue(n->controlchunk, "Section",&n->section); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Section", &n->section); + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } /* dito */ - r = chunk_getvalue(n->controlchunk, "Priority",&n->priority); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Priority", &n->priority); + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( source_checksum_names[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (source_checksum_names[cs] != NULL); r = chunk_getextralinelist(n->controlchunk, source_checksum_names[cs], &filelines[cs]); - if( r == RET_NOTHING ) { - if( cs == cs_md5sum ) { + if (r == RET_NOTHING) { + if (cs == cs_md5sum) { fprintf(stderr, "Error: Missing 'Files' entry in '%s'!\n", fullfilename); r = RET_ERROR; } strlist_init(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&filelines[cs]); } dscfile_free(n); @@ -688,17 +707,16 @@ } } r = checksumsarray_parse(&n->expected, filelines, fullfilename); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dscfile_free(n); return r; } - if( n->expected.names.count > 0 ) { - n->uplink = calloc(n->expected.names.count, - sizeof(struct fileentry*)); - if( FAILEDTOALLOC(n->uplink) ) { + if (n->expected.names.count > 0) { + n->uplink = nzNEW(n->expected.names.count, struct fileentry *); + if (FAILEDTOALLOC(n->uplink)) { dscfile_free(n); return RET_ERROR_OOM; } @@ -712,18 +730,18 @@ retvalue r; int i; - if( dscfile->fullfilename == NULL ) + if (dscfile->fullfilename == NULL) return RET_NOTHING; r = read_dscfile(dscfile->fullfilename, &n); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; - for( i = 0 ; i < n->expected.names.count ; i++ ) { + for (i = 0 ; i < n->expected.names.count ; i++) { const char *basefilename = n->expected.names.values[i]; n->uplink[i] = add_fileentry(changes, basefilename, strlen(basefilename), true, NULL); - if( n->uplink[i] == NULL ) { + if (FAILEDTOALLOC(n->uplink[i])) { dscfile_free(n); return RET_ERROR_OOM; } @@ -746,27 +764,29 @@ char *destfilename; enum checksumtype cs; - if( flagset(DSC_WRITE_FILES) ) { + if (flagset(DSC_WRITE_FILES)) { cef = NULL; - for( cs = cs_hashCOUNT ; (cs--) > cs_md5sum ; ) { + for (cs = cs_hashCOUNT ; (cs--) > cs_md5sum ; ) { cef = cef_newfield(source_checksum_names[cs], CEF_ADD, CEF_LATE, dsc->expected.names.count, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; - for( i = 0 ; i < dsc->expected.names.count ; i++ ) { - const char *basefilename = dsc->expected.names.values[i]; + for (i = 0 ; i < dsc->expected.names.count ; i++) { + const char *basefilename = + dsc->expected.names.values[i]; const char *hash, *size; size_t hashlen, sizelen; - if( !checksums_gethashpart(dsc->expected.checksums[i], + if (!checksums_gethashpart(dsc->expected.checksums[i], cs, &hash, &hashlen, - &size, &sizelen) ) { - assert( cs != cs_md5sum ); + &size, &sizelen)) { + assert (cs != cs_md5sum); cef = cef_pop(cef); break; } - cef_setline2(cef, i, hash, hashlen, size, sizelen, + cef_setline2(cef, i, hash, hashlen, + size, sizelen, 1, basefilename, NULL); } } @@ -775,29 +795,29 @@ r = chunk_edit(dsc->controlchunk, &control, &controllen, cef); cef_free(cef); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); // TODO: try to add the signatures to it again... // TODO: add options to place changed files in different directory... - if( dscfile->fullfilename != NULL ) { + if (dscfile->fullfilename != NULL) destfilename = strdup(dscfile->fullfilename); - } else + else destfilename = strdup(dscfile->basename); - if( destfilename == NULL ) { + if (FAILEDTOALLOC(destfilename)) { free(control); return RET_ERROR_OOM; } r = checksums_replace(destfilename, control, controllen, &checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(destfilename); free(control); return r; } - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); free(dscfile->fullfilename); dscfile->fullfilename = destfilename; @@ -812,57 +832,57 @@ retvalue r; struct binaryfile *n; - n = calloc(1,sizeof(struct binaryfile)); - if( n == NULL ) + n = zNEW(struct binaryfile); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; r = extractcontrol(&n->controlchunk, fullfilename); - if( !RET_IS_OK(r)) { + if (!RET_IS_OK(r)) { free(n); - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) return r; else return RET_NOTHING; } r = chunk_getname(n->controlchunk, "Package", &n->name, false); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } r = chunk_getvalue(n->controlchunk, "Version", &n->version); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } r = chunk_getnameandversion(n->controlchunk, "Source", &n->sourcename, &n->sourceversion); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } r = chunk_getvalue(n->controlchunk, "Maintainer", &n->maintainer); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } r = chunk_getvalue(n->controlchunk, "Architecture", &n->architecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } - r = chunk_getvalue(n->controlchunk, "Section",&n->section); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Section", &n->section); + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } - r = chunk_getvalue(n->controlchunk, "Priority",&n->priority); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Priority", &n->priority); + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } - r = chunk_getvalue(n->controlchunk, "Description",&n->shortdescription); - if( RET_WAS_ERROR(r) ) { + r = chunk_getvalue(n->controlchunk, "Description", &n->shortdescription); + if (RET_WAS_ERROR(r)) { binaryfile_free(n); return r; } @@ -874,14 +894,14 @@ retvalue r; struct binaryfile *n; - if( debfile->fullfilename == NULL ) + if (debfile->fullfilename == NULL) return RET_NOTHING; r = read_binaryfile(debfile->fullfilename, &n); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - if( n->name != NULL ) { + if (n->name != NULL) { n->binary = get_binary(changes, n->name, strlen(n->name)); - if( n->binary == NULL ) { + if (FAILEDTOALLOC(n->binary)) { binaryfile_free(n); return RET_ERROR_OOM; } @@ -900,38 +920,38 @@ retvalue r; r = dirs_getdirectory(changesfilename, &dir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( file = changes->files; file != NULL ; file = file->next ) { - assert( file->fullfilename == NULL ); + for (file = changes->files; file != NULL ; file = file->next) { + assert (file->fullfilename == NULL); r = searchforfile(dir, file->basename, searchpath, NULL, &file->fullfilename); - if( RET_IS_OK(r) ) { - if( file->type == ft_DSC ) - r = parse_dsc(file,changes); - else if( file->type == ft_DEB || file->type == ft_UDEB ) - r = parse_deb(file,changes); - if( RET_WAS_ERROR(r) ) { + if (RET_IS_OK(r)) { + if (file->type == ft_DSC) + r = parse_dsc(file, changes); + else if (file->type == ft_DEB || file->type == ft_UDEB) + r = parse_deb(file, changes); + if (RET_WAS_ERROR(r)) { free(dir); return r; } } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { /* apply heuristics when not readable */ - if( file->type == ft_DSC ) { - } else if( file->type == ft_DEB || file->type == ft_UDEB ) { + if (file->type == ft_DSC) { + } else if (file->type == ft_DEB || file->type == ft_UDEB) { struct binary *b; size_t len; len = 0; - while( file->basename[len] != '_' && - file->basename[len] != '\0' ) + while (file->basename[len] != '_' && + file->basename[len] != '\0') len++; b = get_binary(changes, file->basename, len); - if( b == NULL ) { + if (FAILEDTOALLOC(b)) { free(dir); return RET_ERROR_OOM; } @@ -948,13 +968,13 @@ struct strlist tmp; struct strlist filelines[cs_hashCOUNT]; enum checksumtype cs; -#define R if( RET_WAS_ERROR(r) ) { changes_free(n); return r; } +#define R if (RET_WAS_ERROR(r)) { changes_free(n); return r; } - struct changes *n = calloc(1,sizeof(struct changes)); - if( n == NULL ) + struct changes *n = zNEW(struct changes); + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->filename = strdup(changesfile); - if( n->filename == NULL ) { + if (FAILEDTOALLOC(n->filename)) { changes_free(n); return RET_ERROR_OOM; } @@ -963,44 +983,47 @@ // TODO: do getname here? trim spaces? r = chunk_getvalue(chunk, "Source", &n->name); R; - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Source:' field in %s!\n", changesfile); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Source:' field in %s!\n", + changesfile); n->name = NULL; } r = chunk_getvalue(chunk, "Version", &n->version); R; - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Version:' field in %s!\n", changesfile); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Version:' field in %s!\n", + changesfile); n->version = NULL; } r = chunk_getwordlist(chunk, "Architecture", &n->architectures); R; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) strlist_init(&n->architectures); r = chunk_getwordlist(chunk, "Distribution", &n->distributions); R; - if( r == RET_NOTHING ) + if (r == RET_NOTHING) strlist_init(&n->distributions); r = chunk_getvalue(chunk, "Maintainer", &n->maintainer); R; - if( r == RET_NOTHING ) { - fprintf(stderr, "Missing 'Maintainer:' field in %s!\n", changesfile); + if (r == RET_NOTHING) { + fprintf(stderr, "Missing 'Maintainer:' field in %s!\n", + changesfile); n->maintainer = NULL; } r = chunk_getuniqwordlist(chunk, "Binary", &tmp); R; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { n->binaries = NULL; } else { int i; - assert( RET_IS_OK(r) ); - n->binaries = calloc(tmp.count, sizeof(struct binary)); - if( n->binaries == NULL ) { + assert (RET_IS_OK(r)); + n->binaries = nzNEW(tmp.count, struct binary); + if (FAILEDTOALLOC(n->binaries)) { changes_free(n); return RET_ERROR_OOM; } - for( i = 0 ; i < tmp.count ; i++ ) { + for (i = 0 ; i < tmp.count ; i++) { n->binaries[i].name = tmp.values[i]; } n->binarycount = tmp.count; @@ -1008,39 +1031,39 @@ } r = chunk_getextralinelist(chunk, "Description", &tmp); R; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = parse_changes_description(n, &tmp); strlist_done(&tmp); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { changes_free(n); - return RET_ERROR_OOM; + return r; } } - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - assert( changes_checksum_names[cs] != NULL ); + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + assert (changes_checksum_names[cs] != NULL); r = chunk_getextralinelist(chunk, changes_checksum_names[cs], &filelines[cs]); - if( r == RET_NOTHING ) { - if( cs == cs_md5sum ) + if (r == RET_NOTHING) { + if (cs == cs_md5sum) break; strlist_init(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { - while( cs-- > cs_md5sum ) { + if (RET_WAS_ERROR(r)) { + while (cs-- > cs_md5sum) { strlist_done(&filelines[cs]); } changes_free(n); return r; } } - if( cs == cs_hashCOUNT ) { + if (cs == cs_hashCOUNT) { r = parse_changes_files(n, filelines); - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { strlist_done(&filelines[cs]); } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { changes_free(n); - return RET_ERROR_OOM; + return r; } } r = processfiles(changesfile, n, searchpath); @@ -1058,7 +1081,7 @@ #define CHANGES_WRITE_DISTRIBUTIONS 0x40 #define CHANGES_WRITE_ALL 0xFFFF -static retvalue write_changes_file(const char *changesfilename,struct changes *c, unsigned int flags, bool fakefields) { +static retvalue write_changes_file(const char *changesfilename, struct changes *c, unsigned int flags, bool fakefields) { struct chunkeditfield *cef; char datebuffer[100]; retvalue r; @@ -1072,33 +1095,33 @@ strlist_init(&binaries); - for( f = c->files; f != NULL ; f = f->next ) { - if( f->checksumsfromchanges != NULL ) + for (f = c->files; f != NULL ; f = f->next) { + if (f->checksumsfromchanges != NULL) filecount++; } - if( flagset(CHANGES_WRITE_FILES) ) { + if (flagset(CHANGES_WRITE_FILES)) { cef = NULL; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { cef = cef_newfield(changes_checksum_names[cs], CEF_ADD, CEF_LATE, filecount, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; i = 0; - for( f = c->files; f != NULL ; f = f->next ) { + for (f = c->files; f != NULL ; f = f->next) { const char *hash, *size; size_t hashlen, sizelen; - if( f->checksumsfromchanges == NULL ) + if (f->checksumsfromchanges == NULL) continue; - if( !checksums_gethashpart(f->checksumsfromchanges, + if (!checksums_gethashpart(f->checksumsfromchanges, cs, &hash, &hashlen, - &size, &sizelen) ) { - assert( cs != cs_md5sum ); + &size, &sizelen)) { + assert (cs != cs_md5sum); cef = cef_pop(cef); break; } - if( cs == cs_md5sum ) + if (cs == cs_md5sum) cef_setline2(cef, i, hash, hashlen, size, sizelen, 3, @@ -1114,42 +1137,42 @@ f->basename, NULL); i++; } - assert( f != NULL || i == filecount ); + assert (f != NULL || i == filecount); } } else { cef = cef_newfield("Files", CEF_KEEP, CEF_LATE, 0, NULL); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( fakefields ) { + if (fakefields) { cef = cef_newfield("Changes", CEF_ADDMISSED, CEF_LATE, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; - } - cef_setdata(cef, "\n Changes information missing, as not an original .changes file"); + cef_setdata(cef, +"\n Changes information missing, as not an original .changes file"); } else { cef = cef_newfield("Changes", CEF_KEEP, CEF_LATE, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } cef = cef_newfield("Closes", CEF_KEEP, CEF_LATE, 0, cef); - if( cef == NULL ) - return RET_ERROR_OOM; - if( flagset(CHANGES_WRITE_BINARIES) ) { + if (FAILEDTOALLOC(cef)) + return RET_ERROR_OOM; + if (flagset(CHANGES_WRITE_BINARIES)) { unsigned int count = 0; - for( i = 0 ; i < c->binarycount ; i++ ) { + for (i = 0 ; i < c->binarycount ; i++) { const struct binary *b = c->binaries + i; - if( b->description != NULL ) + if (b->description != NULL) count++; } cef = cef_newfield("Description", CEF_ADD, CEF_LATE, count, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; count = 0; - for( i = 0 ; i < c->binarycount ; i++ ) { + for (i = 0 ; i < c->binarycount ; i++) { const struct binary *b = c->binaries + i; - if( b->description == NULL ) + if (b->description == NULL) continue; cef_setline(cef, count++, 3, b->name, @@ -1160,84 +1183,84 @@ } // Changed-by: line - if( flagset(CHANGES_WRITE_MAINTAINER) ) { + if (flagset(CHANGES_WRITE_MAINTAINER)) { cef = cef_newfield("Maintainer", CEF_ADD, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; cef_setdata(cef, c->maintainer); } else { cef = cef_newfield("Maintainer", CEF_KEEP, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( fakefields ) { + if (fakefields) { cef = cef_newfield("Urgency", CEF_ADDMISSED, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { return RET_ERROR_OOM; } cef_setdata(cef, "low"); } else { cef = cef_newfield("Urgency", CEF_KEEP, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } cef = cef_newfield("Distribution", CEF_KEEP, CEF_EARLY, 0, cef); - if( cef == NULL ) - return RET_ERROR_OOM; - if( c->distributions.count > 0 ) { - if( flagset(CHANGES_WRITE_DISTRIBUTIONS) ) + if (FAILEDTOALLOC(cef)) + return RET_ERROR_OOM; + if (c->distributions.count > 0) { + if (flagset(CHANGES_WRITE_DISTRIBUTIONS)) cef = cef_newfield("Distribution", CEF_ADD, CEF_EARLY, 0, cef); else cef = cef_newfield("Distribution", CEF_ADDMISSED, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; cef_setwordlist(cef, &c->distributions); - } else if( flagset(CHANGES_WRITE_DISTRIBUTIONS) ) { + } else if (flagset(CHANGES_WRITE_DISTRIBUTIONS)) { cef = cef_newfield("Distribution", CEF_DELETE, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( c->version != NULL ) { - if( flagset(CHANGES_WRITE_VERSION) ) + if (c->version != NULL) { + if (flagset(CHANGES_WRITE_VERSION)) cef = cef_newfield("Version", CEF_ADD, CEF_EARLY, 0, cef); else cef = cef_newfield("Version", CEF_ADDMISSED, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; cef_setdata(cef, c->version); - } else if( flagset(CHANGES_WRITE_VERSION) ) { + } else if (flagset(CHANGES_WRITE_VERSION)) { cef = cef_newfield("Version", CEF_DELETE, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( flagset(CHANGES_WRITE_ARCHITECTURES) ) { + if (flagset(CHANGES_WRITE_ARCHITECTURES)) { cef = cef_newfield("Architecture", CEF_ADD, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; cef_setwordlist(cef, &c->architectures); } else { cef = cef_newfield("Architecture", CEF_KEEP, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( flagset(CHANGES_WRITE_BINARIES) ) { + if (flagset(CHANGES_WRITE_BINARIES)) { r = strlist_init_n(c->binarycount, &binaries); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { cef_free(cef); return r; } - assert( RET_IS_OK(r) ); - for( i = 0 ; i < c->binarycount ; i++ ) { + assert (RET_IS_OK(r)); + for (i = 0 ; i < c->binarycount ; i++) { const struct binary *b = c->binaries + i; - if( !b->missedinheader ) { + if (!b->missedinheader) { r = strlist_add_dup(&binaries, b->name); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&binaries); cef_free(cef); return r; @@ -1245,43 +1268,43 @@ } } cef = cef_newfield("Binary", CEF_ADD, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } cef_setwordlist(cef, &binaries); } else { cef = cef_newfield("Binary", CEF_KEEP, CEF_EARLY, 0, cef); - if( cef == NULL ) + if (FAILEDTOALLOC(cef)) return RET_ERROR_OOM; } - if( c->name != NULL ) { - if( flagset(CHANGES_WRITE_SOURCE) ) + if (c->name != NULL) { + if (flagset(CHANGES_WRITE_SOURCE)) cef = cef_newfield("Source", CEF_ADD, CEF_EARLY, 0, cef); else cef = cef_newfield("Source", CEF_ADDMISSED, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } cef_setdata(cef, c->name); - } else if( flagset(CHANGES_WRITE_SOURCE) ) { + } else if (flagset(CHANGES_WRITE_SOURCE)) { cef = cef_newfield("Source", CEF_DELETE, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } } // TODO: if localized make sure this uses C locale.... t = time(NULL); - if( (tm = localtime(&t)) != NULL && + if ((tm = localtime(&t)) != NULL && strftime(datebuffer, sizeof(datebuffer)-1, - "%a, %e %b %Y %H:%M:%S %Z", tm) > 0 ) { + "%a, %e %b %Y %H:%M:%S %Z", tm) > 0) { cef = cef_newfield("Date", CEF_ADD, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } @@ -1289,35 +1312,36 @@ } else { cef = cef_newfield("Date", CEF_DELETE, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } } cef = cef_newfield("Format", CEF_ADDMISSED, CEF_EARLY, 0, cef); - if( cef == NULL ) { + if (FAILEDTOALLOC(cef)) { strlist_done(&binaries); return RET_ERROR_OOM; } cef_setdata(cef, "1.7"); - r = chunk_edit((c->control==NULL)?"":c->control, &control, &controllen, cef); + r = chunk_edit((c->control==NULL)?"":c->control, &control, &controllen, + cef); strlist_done(&binaries); cef_free(cef); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); // TODO: try to add the signatures to it again... // TODO: add options to place changed files in different directory... r = checksums_replace(changesfilename, control, controllen, NULL); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(control); return r; } - assert( RET_IS_OK(r) ); + assert (RET_IS_OK(r)); free(c->control); c->control = control; @@ -1328,16 +1352,16 @@ struct fileentry *file; retvalue r; - for( file = changes->files; file != NULL ; file = file->next ) { + for (file = changes->files; file != NULL ; file = file->next) { - if( file->fullfilename == NULL ) + if (file->fullfilename == NULL) continue; - assert( file->realchecksums == NULL ); + assert (file->realchecksums == NULL); r = checksums_read(file->fullfilename, &file->realchecksums); - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) return r; - else if( !RET_IS_OK(r) ) { + else if (!RET_IS_OK(r)) { // assume everything else is not fatal and means // a file not readable... file->realchecksums = NULL; @@ -1351,7 +1375,7 @@ size_t len = strlen(name); c = compression_by_suffix(name, &len); - if( c != c_none && !typesuffix[ft].allowcompressed ) + if (c != c_none && !typesuffix[ft].allowcompressed) return false; return strncmp(name + (len - typesuffix[ft].len), typesuffix[ft].suffix, @@ -1360,31 +1384,32 @@ static void verify_sourcefile_checksums(struct dscfile *dsc, int i, const char *dscfile) { const struct fileentry * const file = dsc->uplink[i]; - const struct checksums * const expectedchecksums = dsc->expected.checksums[i]; + const struct checksums * const expectedchecksums + = dsc->expected.checksums[i]; const char * const basefilename = dsc->expected.names.values[i]; - assert( file != NULL ); + assert (file != NULL); - if( file->checksumsfromchanges == NULL ) { - if( may_be_type(basefilename, ft_ORIG_TAR) ) { + if (file->checksumsfromchanges == NULL) { + if (may_be_type(basefilename, ft_ORIG_TAR)) { fprintf(stderr, "Not checking checksums of '%s', as not included in .changes file.\n", basefilename); return; - } else if( file->realchecksums == NULL ) { + } else if (file->realchecksums == NULL) { fprintf(stderr, "ERROR: File '%s' mentioned in '%s' was not found and is not mentioned in the .changes!\n", basefilename, dscfile); return; } } - if( file->realchecksums == NULL ) + if (file->realchecksums == NULL) /* there will be an message later about that */ return; - if( checksums_check(expectedchecksums, file->realchecksums, NULL)) + if (checksums_check(expectedchecksums, file->realchecksums, NULL)) return; - if( file->checksumsfromchanges != NULL && - checksums_check(expectedchecksums, file->checksumsfromchanges, NULL) ) + if (file->checksumsfromchanges != NULL && + checksums_check(expectedchecksums, file->checksumsfromchanges, NULL)) fprintf(stderr, "ERROR: checksums of '%s' differ from the ones listed in both '%s' and the .changes file!\n", basefilename, dscfile); @@ -1401,39 +1426,39 @@ size_t nlen, vlen, alen, slen; const char *versionwithoutepoch; - if( name == NULL ) + if (name == NULL) return; nlen = strlen(name); - if( strncmp(basefilename, name, nlen) != 0 || basefilename[nlen] != '_' ) { + if (strncmp(basefilename, name, nlen) != 0 || basefilename[nlen] != '_') { fprintf(stderr, "ERROR: '%s' does not start with '%s_' as expected!\n", basefilename, name); return; } - if( version == NULL ) + if (version == NULL) return; versionwithoutepoch = strchr(version, ':'); - if( versionwithoutepoch == NULL ) + if (versionwithoutepoch == NULL) versionwithoutepoch = version; else versionwithoutepoch++; vlen = strlen(versionwithoutepoch); - if( strncmp(basefilename+nlen+1, versionwithoutepoch, vlen) != 0 - || basefilename[nlen+1+vlen] != '_' ) { + if (strncmp(basefilename+nlen+1, versionwithoutepoch, vlen) != 0 + || basefilename[nlen+1+vlen] != '_') { fprintf(stderr, "ERROR: '%s' does not start with '%s_%s_' as expected!\n", basefilename, name, version); return; } - if( architecture == NULL ) + if (architecture == NULL) return; alen = strlen(architecture); slen = typesuffix[type].len; - if( strncmp(basefilename+nlen+1+vlen+1, architecture, alen) != 0 - || strncmp(basefilename+nlen+1+vlen+1+alen, - typesuffix[type].suffix, slen) != 0 - || strcmp(basefilename+nlen+1+vlen+1+alen+slen, - uncompression_suffix[c]) != 0 ) + if (strncmp(basefilename+nlen+1+vlen+1, architecture, alen) != 0 + || strncmp(basefilename+nlen+1+vlen+1+alen, + typesuffix[type].suffix, slen) != 0 + || strcmp(basefilename+nlen+1+vlen+1+alen+slen, + uncompression_suffix[c]) != 0) fprintf(stderr, "ERROR: '%s' is not called '%s_%s_%s%s%s' as expected!\n", basefilename, name, versionwithoutepoch, @@ -1447,64 +1472,68 @@ size_t k; printf("Checking Source packages...\n"); - for( file = changes->files; file != NULL ; file = file->next ) { + for (file = changes->files; file != NULL ; file = file->next) { const char *name, *version, *p; - size_t namelen, versionlen, l; + size_t namelen IFSTUPIDCC(=0), versionlen IFSTUPIDCC(=0), l; bool has_tar, has_diff, has_orig, has_format_tar; int i; - if( file->type != ft_DSC ) + if (file->type != ft_DSC) continue; - if( !strlist_in(&changes->architectures, "source") ) { + if (!strlist_in(&changes->architectures, "source")) { fprintf(stderr, "ERROR: '%s' contains a .dsc, but does not list Architecture 'source'!\n", changesfilename); } - if( file->fullfilename == NULL ) { + if (file->fullfilename == NULL) { fprintf(stderr, "ERROR: Could not find '%s'!\n", file->basename); continue; } - if( file->dsc == NULL ) { + if (file->dsc == NULL) { fprintf(stderr, -"WARNING: Could not read '%s', thus it cannot be checked!\n", file->fullfilename); +"WARNING: Could not read '%s', thus it cannot be checked!\n", + file->fullfilename); continue; } - if( file->dsc->name == NULL ) + if (file->dsc->name == NULL) fprintf(stderr, "ERROR: '%s' does not contain a 'Source:' header!\n", file->fullfilename); - else if( changes->name != NULL && - strcmp(changes->name, file->dsc->name) != 0 ) + else if (changes->name != NULL && + strcmp(changes->name, file->dsc->name) != 0) fprintf(stderr, "ERROR: '%s' lists Source '%s' while .changes lists '%s'!\n", file->fullfilename, file->dsc->name, changes->name); - if( file->dsc->version == NULL ) + if (file->dsc->version == NULL) fprintf(stderr, "ERROR: '%s' does not contain a 'Version:' header!\n", file->fullfilename); - else if( changes->version != NULL && - strcmp(changes->version, file->dsc->version) != 0 ) + else if (changes->version != NULL && + strcmp(changes->version, + file->dsc->version) != 0) fprintf(stderr, "ERROR: '%s' lists Version '%s' while .changes lists '%s'!\n", file->fullfilename, file->dsc->version, changes->version); - if( file->dsc->maintainer == NULL ) + if (file->dsc->maintainer == NULL) fprintf(stderr, "ERROR: No maintainer specified in '%s'!\n", file->fullfilename); - else if( changes->maintainer != NULL && - strcmp(changes->maintainer, file->dsc->maintainer) != 0 ) + else if (changes->maintainer != NULL && + strcmp(changes->maintainer, + file->dsc->maintainer) != 0) fprintf(stderr, "Warning: '%s' lists Maintainer '%s' while .changes lists '%s'!\n", file->fullfilename, file->dsc->maintainer, changes->maintainer); - if( file->dsc->section != NULL && file->section != NULL && - strcmp(file->section, file->dsc->section) != 0 ) + if (file->dsc->section != NULL && file->section != NULL && + strcmp(file->section, file->dsc->section) != 0) fprintf(stderr, "Warning: '%s' has Section '%s' while .changes says it is '%s'!\n", file->fullfilename, file->dsc->section, file->section); - if( file->dsc->priority != NULL && file->priority != NULL && - strcmp(file->priority, file->dsc->priority) != 0 ) + if (file->dsc->priority != NULL && file->priority != NULL + && strcmp(file->priority, + file->dsc->priority) != 0) fprintf(stderr, "Warning: '%s' has Priority '%s' while .changes says it is '%s'!\n", file->fullfilename, @@ -1512,26 +1541,26 @@ // Todo: check types of files it contains... // check names are sensible p = file->basename; - while( *p != '\0' && *p != '_' ) + while (*p != '\0' && *p != '_') p++; - if( *p == '_' ) { + if (*p == '_') { l = strlen(p+1); - assert( l >= 4 ); /* It ends in ".dsc" to come here */ + assert (l >= 4); /* It ends in ".dsc" to come here */ } else l = 0; - if( file->dsc->name != NULL ) { + if (file->dsc->name != NULL) { name = file->dsc->name; namelen = strlen(name); } else { // TODO: more believe file name or changes name? - if( changes->name != NULL ) { + if (changes->name != NULL) { name = changes->name; #ifdef STUPIDCC namelen = strlen(name); #endif } else { - if( *p != '_' ) { + if (*p != '_') { name = NULL; namelen = 0; fprintf(stderr, @@ -1543,21 +1572,21 @@ } } } - if( file->dsc->version != NULL ) { + if (file->dsc->version != NULL) { version = file->dsc->version; versionlen = strlen(version); } else { // TODO: dito - if( changes->version != NULL ) { + if (changes->version != NULL) { version = changes->version; versionlen = strlen(version); } else { - if( *p != '_' ) { + if (*p != '_') { version = NULL; #ifdef STUPIDCC versionlen = 0; #endif - if( name != NULL ) + if (name != NULL) fprintf(stderr, "ERROR: '%s' does not contain a '_' separating name and version!\n", file->basename); @@ -1567,19 +1596,19 @@ } } } - if( version != NULL ) { + if (version != NULL) { const char *colon = strchr(version, ':'); - if( colon != NULL ) { + if (colon != NULL) { colon++; versionlen -= (colon-version); version = colon; } } - if( name != NULL && version != NULL ) { - if( *p != '_' + if (name != NULL && version != NULL) { + if (*p != '_' || (size_t)(p-file->basename) != namelen || l-4 != versionlen || strncmp(p+1, version, versionlen) != 0 - || strncmp(file->basename, name, namelen) != 0 ) + || strncmp(file->basename, name, namelen) != 0) fprintf(stderr, "ERROR: '%s' is not called '%*s_%*s.dsc' as expected!\n", file->basename, @@ -1590,14 +1619,15 @@ has_format_tar = false; has_diff = false; has_orig = false; - for( i = 0 ; i < file->dsc->expected.names.count ; i++ ) { - const char *basefilename = file->dsc->expected.names.values[i]; + for (i = 0 ; i < file->dsc->expected.names.count ; i++) { + const char *basefilename + = file->dsc->expected.names.values[i]; const struct fileentry *sfile = file->dsc->uplink[i]; size_t expectedversionlen, expectedformatlen; const char *expectedformat; bool istar = false, versionok; - switch( sfile->type ) { + switch (sfile->type) { case ft_UNKNOWN: fprintf(stderr, "ERROR: '%s' lists a file '%s' with unrecognized suffix!\n", @@ -1609,27 +1639,27 @@ has_tar = true; break; case ft_ORIG_TAR: - if( has_orig ) + if (has_orig) fprintf(stderr, "ERROR: '%s' lists multiple .orig..tar files!\n", file->fullfilename); has_orig = true; break; case ft_DIFF: - if( has_diff ) + if (has_diff) fprintf(stderr, "ERROR: '%s' lists multiple .diff files!\n", file->fullfilename); has_diff = true; break; default: - assert( sfile->type == ft_UNKNOWN ); + assert (sfile->type == ft_UNKNOWN); } - if( name == NULL ) // TODO: try extracting it from this + if (name == NULL) // TODO: try extracting it from this continue; - if( strncmp(sfile->basename, name, namelen) != 0 - || sfile->basename[namelen] != '_' ) { + if (strncmp(sfile->basename, name, namelen) != 0 + || sfile->basename[namelen] != '_') { fprintf(stderr, "ERROR: '%s' does not begin with '%*s_' as expected!\n", sfile->basename, @@ -1638,17 +1668,17 @@ continue; } - if( version == NULL ) + if (version == NULL) continue; - if( sfile->type == ft_ORIG_TAR ) { + if (sfile->type == ft_ORIG_TAR) { const char *q, *revision; revision = NULL; - for( q = version; *q != '\0'; q++ ) { - if( *q == '-' ) + for (q = version; *q != '\0'; q++) { + if (*q == '-') revision = q; } - if( revision == NULL ) + if (revision == NULL) expectedversionlen = versionlen; else expectedversionlen = revision - version; @@ -1657,10 +1687,8 @@ versionok = strncmp(sfile->basename+namelen+1, version, expectedversionlen) == 0; - if( istar ) { - const char *dot; - - if( !versionok ) { + if (istar) { + if (!versionok) { fprintf(stderr, "ERROR: '%s' does not start with '%*s_%*s' as expected!\n", sfile->basename, @@ -1671,22 +1699,28 @@ } expectedformat = sfile->basename + namelen + 1 + expectedversionlen; - if( strncmp(expectedformat, ".tar.", 5) == 0 ) - expectedformatlen = 0; - else if( (dot = strchr(expectedformat + 1, '.') ) == NULL ) + if (strncmp(expectedformat, ".tar.", 5) == 0) expectedformatlen = 0; else { - expectedformatlen = dot - expectedformat; - has_format_tar = true; + const char *dot; + + dot = strchr(expectedformat + 1, '.'); + if (dot == NULL) + expectedformatlen = 0; + else { + expectedformatlen = + dot - expectedformat; + has_format_tar = true; + } } } else { expectedformat = ""; expectedformatlen = 0; } - if( sfile->type == ft_UNKNOWN ) + if (sfile->type == ft_UNKNOWN) continue; - if( versionok + if (versionok && strncmp(sfile->basename+namelen+1 +expectedversionlen +expectedformatlen, @@ -1697,7 +1731,7 @@ +expectedformatlen +typesuffix[sfile->type].len, uncompression_suffix[sfile->compression]) - == 0 ) + == 0) continue; fprintf(stderr, "ERROR: '%s' is not called '%.*s_%.*s%.*s%s%s' as expected!\n", @@ -1710,8 +1744,8 @@ typesuffix[sfile->type].suffix, uncompression_suffix[sfile->compression]); } - if( !has_tar && !has_orig ) - if( has_diff ) + if (!has_tar && !has_orig) + if (has_diff) fprintf(stderr, "ERROR: '%s' lists only a .diff, but no .orig.tar!\n", file->fullfilename); @@ -1719,48 +1753,49 @@ fprintf(stderr, "ERROR: '%s' lists no source files!\n", file->fullfilename); - else if( has_diff && !has_orig ) + else if (has_diff && !has_orig) fprintf(stderr, "ERROR: '%s' lists a .diff, but the .tar is not called .orig.tar!\n", file->fullfilename); - else if( !has_format_tar && !has_diff && has_orig ) + else if (!has_format_tar && !has_diff && has_orig) fprintf(stderr, "ERROR: '%s' lists a .orig.tar, but no .diff!\n", file->fullfilename); } printf("Checking Binary consistency...\n"); - for( k = 0 ; k < changes->binarycount ; k++ ) { + for (k = 0 ; k < changes->binarycount ; k++) { struct binary *b = &changes->binaries[k]; - if( b->files == NULL && !b->uncheckable ) { - /* no files - not even conjectured -, headers must be wrong */ + if (b->files == NULL && !b->uncheckable) { + /* no files - not even conjectured -, + * headers must be wrong */ - if( b->description != NULL && !b->missedinheader ) { + if (b->description != NULL && !b->missedinheader) { fprintf(stderr, "ERROR: '%s' has binary '%s' in 'Binary:' and 'Description:' header, but no files for it found!\n", changesfilename, b->name); - } else if( b->description != NULL) { + } else if (b->description != NULL) { fprintf(stderr, "ERROR: '%s' has unexpected description of '%s'\n", changesfilename, b->name); } else { - assert( !b->missedinheader ); + assert (!b->missedinheader); fprintf(stderr, "ERROR: '%s' has unexpected Binary: '%s'\n", changesfilename, b->name); } } - if( b->files == NULL ) + if (b->files == NULL) continue; /* files are there, make sure they are listed and * have a description*/ - if( b->description == NULL ) { + if (b->description == NULL) { fprintf(stderr, "ERROR: '%s' has no description for '%s'\n", changesfilename, b->name); } - if( b->missedinheader ) { + if (b->missedinheader) { fprintf(stderr, "ERROR: '%s' does not list '%s' in its Binary header!\n", changesfilename, b->name); @@ -1768,18 +1803,18 @@ // TODO: check if the files have the names they should // have an architectures as they are listed... } - for( file = changes->files; file != NULL ; file = file->next ) { + for (file = changes->files; file != NULL ; file = file->next) { const struct binary *b; const struct binaryfile *deb; - if( file->type != ft_DEB && file->type != ft_UDEB ) + if (file->type != ft_DEB && file->type != ft_UDEB) continue; - if( file->fullfilename == NULL ) { + if (file->fullfilename == NULL) { fprintf(stderr, "ERROR: Could not find '%s'!\n", file->basename); continue; } - if( file->deb == NULL ) { + if (file->deb == NULL) { fprintf(stderr, "WARNING: Could not read '%s', thus it cannot be checked!\n", file->fullfilename); continue; @@ -1787,82 +1822,84 @@ deb = file->deb; b = deb->binary; - if( deb->shortdescription == NULL ) + if (deb->shortdescription == NULL) fprintf(stderr, "Warning: '%s' contains no description!\n", file->fullfilename); - else if( b->description != NULL && - strcmp( b->description, deb->shortdescription) != 0 ) + else if (b->description != NULL && + strcmp(b->description, deb->shortdescription) != 0) fprintf(stderr, "Warning: '%s' says '%s' has description '%s' while '%s' has '%s'!\n", changesfilename, b->name, b->description, file->fullfilename, deb->shortdescription); - if( deb->name == NULL ) + if (deb->name == NULL) fprintf(stderr, "ERROR: '%s' does not contain a 'Package:' header!\n", file->fullfilename); - if( deb->sourcename != NULL ) { - if( strcmp(changes->name, deb->sourcename) != 0 ) + if (deb->sourcename != NULL) { + if (strcmp(changes->name, deb->sourcename) != 0) fprintf(stderr, "ERROR: '%s' lists Source '%s' while .changes lists '%s'!\n", file->fullfilename, deb->sourcename, changes->name); - } else if( deb->name != NULL && - strcmp(changes->name, deb->name) != 0 ) { + } else if (deb->name != NULL && + strcmp(changes->name, deb->name) != 0) { fprintf(stderr, "ERROR: '%s' lists Source '%s' while .changes lists '%s'!\n", file->fullfilename, deb->name, changes->name); } - if( deb->version == NULL ) + if (deb->version == NULL) fprintf(stderr, "ERROR: '%s' does not contain a 'Version:' header!\n", file->fullfilename); - if( deb->sourceversion != NULL ) { - if( strcmp(changes->version, deb->sourceversion) != 0 ) + if (deb->sourceversion != NULL) { + if (strcmp(changes->version, deb->sourceversion) != 0) fprintf(stderr, "ERROR: '%s' lists Source version '%s' while .changes lists '%s'!\n", file->fullfilename, deb->sourceversion, changes->version); - } else if( deb->version != NULL && - strcmp(changes->version, deb->version) != 0 ) { + } else if (deb->version != NULL && + strcmp(changes->version, deb->version) != 0) { fprintf(stderr, "ERROR: '%s' lists Source version '%s' while .changes lists '%s'!\n", file->fullfilename, deb->version, changes->name); } - if( deb->maintainer == NULL ) + if (deb->maintainer == NULL) fprintf(stderr, "ERROR: No maintainer specified in '%s'!\n", file->fullfilename); - else if( changes->maintainer != NULL && - strcmp(changes->maintainer, deb->maintainer) != 0 ) + else if (changes->maintainer != NULL && + strcmp(changes->maintainer, + deb->maintainer) != 0) fprintf(stderr, "Warning: '%s' lists Maintainer '%s' while .changes lists '%s'!\n", file->fullfilename, deb->maintainer, changes->maintainer); - if( deb->section == NULL ) + if (deb->section == NULL) fprintf(stderr, "ERROR: No section specified in '%s'!\n", file->fullfilename); - else if( file->section != NULL && - strcmp(file->section, deb->section) != 0 ) + else if (file->section != NULL && + strcmp(file->section, deb->section) != 0) fprintf(stderr, "Warning: '%s' has Section '%s' while .changes says it is '%s'!\n", file->fullfilename, deb->section, file->section); - if( deb->priority == NULL ) + if (deb->priority == NULL) fprintf(stderr, "ERROR: No priority specified in '%s'!\n", file->fullfilename); - else if( file->priority != NULL && - strcmp(file->priority, deb->priority) != 0 ) + else if (file->priority != NULL && + strcmp(file->priority, deb->priority) != 0) fprintf(stderr, "Warning: '%s' has Priority '%s' while .changes says it is '%s'!\n", file->fullfilename, deb->priority, file->priority); verify_binary_name(file->basename, deb->name, deb->version, deb->architecture, file->type, file->compression); - if( deb->architecture != NULL - && !strlist_in(&changes->architectures, deb->architecture) ) { + if (deb->architecture != NULL + && !strlist_in(&changes->architectures, + deb->architecture)) { fprintf(stderr, "ERROR: '%s' does not list Architecture: '%s' needed for '%s'!\n", changesfilename, deb->architecture, @@ -1873,42 +1910,49 @@ printf("Checking checksums...\n"); r = getchecksums(changes); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( file = changes->files; file != NULL ; file = file->next ) { + for (file = changes->files; file != NULL ; file = file->next) { - if( file->checksumsfromchanges == NULL ) + if (file->checksumsfromchanges == NULL) /* nothing to check here */ continue; - if( file->fullfilename == NULL ) { - fprintf(stderr, "WARNING: Could not check checksums of '%s' as file not found!\n", file->basename); - if( file->type == ft_DSC ) { - fprintf(stderr, "WARNING: This file most likely contains additional checksums which could also not be checked because it was not found!\n"); + if (file->fullfilename == NULL) { + fprintf(stderr, +"WARNING: Could not check checksums of '%s' as file not found!\n", + file->basename); + if (file->type == ft_DSC) { + fprintf(stderr, +"WARNING: This file most likely contains additional checksums which could also not be checked because it was not found!\n"); } continue; } - if( file->realchecksums == NULL ) { - fprintf(stderr, "WARNING: Could not check checksums of '%s'! File vanished while checking or not readable?\n", file->basename); - } else if( !checksums_check(file->realchecksums, file->checksumsfromchanges, NULL)) { - fprintf(stderr, "ERROR: checksums of '%s' differ from those listed in .changes:\n", + if (file->realchecksums == NULL) { + fprintf(stderr, +"WARNING: Could not check checksums of '%s'! File vanished while checking or not readable?\n", + file->basename); + } else if (!checksums_check(file->realchecksums, + file->checksumsfromchanges, NULL)) { + fprintf(stderr, +"ERROR: checksums of '%s' differ from those listed in .changes:\n", file->fullfilename); checksums_printdifferences(stderr, file->checksumsfromchanges, file->realchecksums); } - if( file->type == ft_DSC ) { + if (file->type == ft_DSC) { int i; - if( file->dsc == NULL ) { + if (file->dsc == NULL) { fprintf(stderr, "WARNING: Could not read '%s', thus the content cannot be checked\n" " and may be faulty and other things depending on it may be incorrect!\n", file->basename); continue; } - for( i = 0 ; i < file->dsc->expected.names.count ; i++ ) { + for (i = 0 ; i < file->dsc->expected.names.count ; i++) { verify_sourcefile_checksums(file->dsc, i, file->fullfilename); } @@ -1919,8 +1963,8 @@ } static bool isarg(int argc, char **argv, const char *name) { - while( argc > 0 ) { - if( strcmp(*argv, name) == 0 ) + while (argc > 0) { + if (strcmp(*argv, name) == 0) return true; argc--; argv++; @@ -1932,31 +1976,31 @@ enum checksumtype cs; struct fileentry *file; - for( cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++ ) { - if( !improvedfilehashes[cs] ) + for (cs = cs_md5sum ; cs < cs_hashCOUNT ; cs++) { + if (!improvedfilehashes[cs]) continue; - for( file = c->files; file != NULL ; file = file->next ) { + for (file = c->files; file != NULL ; file = file->next) { const char *dummy1, *dummy3; size_t dummy2, dummy4; - if( file->checksumsfromchanges == NULL ) + if (file->checksumsfromchanges == NULL) continue; - if( !checksums_gethashpart(file->checksumsfromchanges, + if (!checksums_gethashpart(file->checksumsfromchanges, cs, &dummy1, &dummy2, &dummy3, &dummy4)) break; } - if( file == NULL ) + if (file == NULL) return true; } return false; } static bool anyset(bool *list, size_t count) { - while( count > 0 ) - if( list[--count] ) + while (count > 0) + if (list[--count]) return true; return false; } @@ -1967,17 +2011,17 @@ bool improvedfilehashes[cs_hashCOUNT]; r = getchecksums(c); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - /* first update all .dsc files and perhaps recalculate their checksums */ - for( file = c->files; file != NULL ; file = file->next ) { + /* first update all .dsc files and perhaps recalculate their checksums*/ + for (file = c->files; file != NULL ; file = file->next) { int i; bool improvedhash[cs_hashCOUNT]; - if( file->type != ft_DSC ) + if (file->type != ft_DSC) continue; - if( file->dsc == NULL ) { + if (file->dsc == NULL) { fprintf(stderr, "WARNING: Could not read '%s', hopeing the content and its checksums are correct!\n", file->basename); @@ -1985,8 +2029,8 @@ } memset(improvedhash, 0, sizeof(improvedhash)); - assert( file->fullfilename != NULL ); - for( i = 0 ; i < file->dsc->expected.names.count ; i++ ) { + assert (file->fullfilename != NULL); + for (i = 0 ; i < file->dsc->expected.names.count ; i++) { const char *basefilename = file->dsc->expected.names.values[i]; const struct fileentry *sfile = file->dsc->uplink[i]; struct checksums **expected_p = &file->dsc->expected.checksums[i]; @@ -1996,42 +2040,47 @@ bool doit; bool improves; - assert( expected != NULL ); - assert( basefilename != NULL ); + assert (expected != NULL); + assert (basefilename != NULL); doit = isarg(argc, argv, basefilename); - if( argc > 0 && !doit ) + if (argc > 0 && !doit) continue; - assert( sfile != NULL ); - if( sfile->checksumsfromchanges == NULL ) { - if( !doit ) { + assert (sfile != NULL); + if (sfile->checksumsfromchanges == NULL) { + if (!doit) { fprintf(stderr, "Not checking/updating '%s' as not in .changes and not specified on command line.\n", basefilename); continue; } - if( sfile->realchecksums == NULL ) { - fprintf(stderr, "WARNING: Could not check checksums of '%s'!\n", basefilename); + if (sfile->realchecksums == NULL) { + fprintf(stderr, +"WARNING: Could not check checksums of '%s'!\n", basefilename); continue; } } else { - if( sfile->realchecksums == NULL ) { - fprintf(stderr, "WARNING: Could not check checksums of '%s'!\n", basefilename); + if (sfile->realchecksums == NULL) { + fprintf(stderr, +"WARNING: Could not check checksums of '%s'!\n", + basefilename); continue; } } - if( checksums_check(expected, sfile->realchecksums, &improves) ) { - if( !improves ) { + if (checksums_check(expected, sfile->realchecksums, + &improves)) { + if (!improves) { /* already correct */ continue; } - /* future versions might be able to store them in the dsc */ + /* future versions might be able to store them + * in the dsc */ r = checksums_combine(expected_p, sfile->realchecksums, improvedhash); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; continue; } @@ -2048,38 +2097,41 @@ hashes1, hashes2); checksums_free(*expected_p); *expected_p = checksums_dup(sfile->realchecksums); - if( *expected_p == NULL ) + if (FAILEDTOALLOC(*expected_p)) return RET_ERROR_OOM; file->dsc->modified = true; } checksumsarray_resetunsupported(&file->dsc->expected, improvedhash); - if( file->dsc->modified | anyset(improvedhash, cs_hashCOUNT) ) { + if (file->dsc->modified | anyset(improvedhash, cs_hashCOUNT)) { r = write_dsc_file(file, DSC_WRITE_FILES); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } } memset(improvedfilehashes, 0, sizeof(improvedfilehashes)); - for( file = c->files; file != NULL ; file = file->next ) { + for (file = c->files; file != NULL ; file = file->next) { bool improves; const char *hashes1, *hashes2; size_t dummy; - if( file->checksumsfromchanges == NULL ) + if (file->checksumsfromchanges == NULL) /* nothing to check here */ continue; - if( file->realchecksums == NULL ) { - fprintf(stderr, "WARNING: Could not check checksums of '%s'! Leaving it as it is.\n", file->basename); + if (file->realchecksums == NULL) { + fprintf(stderr, +"WARNING: Could not check checksums of '%s'! Leaving it as it is.\n", + file->basename); continue; } - if( checksums_check(file->checksumsfromchanges, file->realchecksums, &improves) ) { - if( !improves ) + if (checksums_check(file->checksumsfromchanges, + file->realchecksums, &improves)) { + if (!improves) continue; /* future versions might store sha sums in .changes: */ r = checksums_combine(&file->checksumsfromchanges, - file->realchecksums, improvedfilehashes); - if( RET_WAS_ERROR(r) ) + file->realchecksums, improvedfilehashes); + if (RET_WAS_ERROR(r)) return r; continue; } @@ -2097,14 +2149,14 @@ hashes1, hashes2); checksums_free(file->checksumsfromchanges); file->checksumsfromchanges = checksums_dup(file->realchecksums); - if( file->checksumsfromchanges == NULL ) + if (FAILEDTOALLOC(file->checksumsfromchanges)) return RET_ERROR_OOM; c->modified = true; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_FILES, false); - } else if( improvedchecksum_supported(c, improvedfilehashes) ) { + } else if (improvedchecksum_supported(c, improvedfilehashes)) { return write_changes_file(changesfilename, c, CHANGES_WRITE_FILES, false); } else @@ -2114,56 +2166,56 @@ static retvalue includeallsources(const char *changesfilename, struct changes *c, int argc, char **argv) { struct fileentry *file; - for( file = c->files; file != NULL ; file = file->next ) { + for (file = c->files; file != NULL ; file = file->next) { int i; - if( file->type != ft_DSC ) + if (file->type != ft_DSC) continue; - if( file->dsc == NULL ) { + if (file->dsc == NULL) { fprintf(stderr, "WARNING: Could not read '%s', thus cannot determine if it depends on unlisted files!\n", file->basename); continue; } - assert( file->fullfilename != NULL ); - for( i = 0 ; i < file->dsc->expected.names.count ; i++ ) { + assert (file->fullfilename != NULL); + for (i = 0 ; i < file->dsc->expected.names.count ; i++) { const char *basefilename = file->dsc->expected.names.values[i]; struct fileentry * const sfile = file->dsc->uplink[i]; struct checksums **expected_p = &file->dsc->expected.checksums[i]; const struct checksums * const expected = *expected_p; - assert( expected != NULL ); - assert( basefilename != NULL ); - assert( sfile != NULL ); + assert (expected != NULL); + assert (basefilename != NULL); + assert (sfile != NULL); - if( sfile->checksumsfromchanges != NULL ) + if (sfile->checksumsfromchanges != NULL) continue; - if( argc > 0 && !isarg(argc, argv, basefilename) ) + if (argc > 0 && !isarg(argc, argv, basefilename)) continue; sfile->checksumsfromchanges = checksums_dup(expected); - if( sfile->checksumsfromchanges == NULL ) + if (FAILEDTOALLOC(sfile->checksumsfromchanges)) return RET_ERROR_OOM; /* copy section and priority information from the dsc */ - if( sfile->section == NULL && file->section != NULL ) { + if (sfile->section == NULL && file->section != NULL) { sfile->section = strdup(file->section); - if( sfile->section == NULL ) + if (FAILEDTOALLOC(sfile->section)) return RET_ERROR_OOM; } - if( sfile->priority == NULL && file->priority != NULL ) { + if (sfile->priority == NULL && file->priority != NULL) { sfile->priority = strdup(file->priority); - if( sfile->priority == NULL ) + if (FAILEDTOALLOC(sfile->priority)) return RET_ERROR_OOM; } - fprintf(stderr, -"Going to add '%s' to '%s'.\n", basefilename, changesfilename); + fprintf(stderr, "Going to add '%s' to '%s'.\n", + basefilename, changesfilename); c->modified = true; } } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_FILES, false); } else @@ -2180,23 +2232,23 @@ int i; r = findfile(dscfilename, c, searchpath, ".", &fullfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot find '%s'!\n", dscfilename); return RET_ERROR_MISSING; } r = read_dscfile(fullfilename, &dsc); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error reading '%s'!\n", fullfilename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } - if( dsc->name == NULL || dsc->version == NULL ) { - if( dsc->name == NULL ) + if (dsc->name == NULL || dsc->version == NULL) { + if (dsc->name == NULL) fprintf(stderr, "Could not extract name of '%s'!\n", fullfilename); else @@ -2206,8 +2258,8 @@ free(fullfilename); return RET_ERROR; } - if( c->name != NULL ) { - if( strcmp(c->name, dsc->name) != 0 ) { + if (c->name != NULL) { + if (strcmp(c->name, dsc->name) != 0) { fprintf(stderr, "ERROR: '%s' lists source '%s' while '%s' already is '%s'!\n", fullfilename, dsc->name, @@ -2218,21 +2270,21 @@ } } else { c->name = strdup(dsc->name); - if( c->name == NULL ) { + if (FAILEDTOALLOC(c->name)) { dscfile_free(dsc); free(fullfilename); return RET_ERROR_OOM; } } - if( c->version != NULL ) { - if( strcmp(c->version, dsc->version) != 0 ) + if (c->version != NULL) { + if (strcmp(c->version, dsc->version) != 0) fprintf(stderr, "WARNING: '%s' lists version '%s' while '%s' already lists '%s'!\n", fullfilename, dsc->version, c->filename, c->version); } else { c->version = strdup(dsc->version); - if( c->version == NULL ) { + if (FAILEDTOALLOC(c->version)) { dscfile_free(dsc); free(fullfilename); return RET_ERROR_OOM; @@ -2241,36 +2293,38 @@ // TODO: make sure if the .changes name/version are modified they will // also be written... v = strchr(dsc->version, ':'); - if( v != NULL ) + if (v != NULL) v++; else v = dsc->version; basefilename = mprintf("%s_%s.dsc", dsc->name, v); - if( FAILEDTOALLOC(basefilename) ) { + if (FAILEDTOALLOC(basefilename)) { dscfile_free(dsc); free(fullfilename); return RET_ERROR_OOM; } r = dirs_getdirectory(fullfilename, &origdirectory); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dscfile_free(dsc); free(origdirectory); free(fullfilename); - return RET_ERROR_OOM; + return r; } // TODO: add rename/copy option to be activated when old and new // basefilename differ r = add_file(c, basefilename, fullfilename, ft_DSC, &f); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { dscfile_free(dsc); free(origdirectory); return r; } - if( r == RET_NOTHING ) { - fprintf(stderr, "ERROR: '%s' already contains a file of the same name!\n", c->filename); + if (r == RET_NOTHING) { + fprintf(stderr, +"ERROR: '%s' already contains a file of the same name!\n", + c->filename); dscfile_free(dsc); free(origdirectory); // TODO: check instead if it is already the same... @@ -2280,22 +2334,22 @@ f->dsc = dsc; /* now include the files needed by this */ - for( i = 0 ; i < dsc->expected.names.count ; i++ ) { + for (i = 0 ; i < dsc->expected.names.count ; i++) { struct fileentry *file; const char *b = dsc->expected.names.values[i]; const struct checksums *checksums = dsc->expected.checksums[i]; file = add_fileentry(c, b, strlen(b), true, NULL); - if( file == NULL ) { + if (FAILEDTOALLOC(file)) { free(origdirectory); return RET_ERROR_OOM; } dsc->uplink[i] = file; /* make them appear in the .changes file if not there: */ // TODO: add missing checksums here from file - if( file->checksumsfromchanges == NULL ) { + if (file->checksumsfromchanges == NULL) { file->checksumsfromchanges = checksums_dup(checksums); - if( file->checksumsfromchanges == NULL ) { + if (FAILEDTOALLOC(file->checksumsfromchanges)) { free(origdirectory); return RET_ERROR_OOM; } @@ -2304,103 +2358,104 @@ c->modified = true; r = checksums_read(f->fullfilename, &f->realchecksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); return r; } f->checksumsfromchanges = checksums_dup(f->realchecksums); - if( f->checksumsfromchanges == NULL ) { + if (FAILEDTOALLOC(f->checksumsfromchanges)) { free(origdirectory); - return RET_ERROR_OOM;; + return RET_ERROR_OOM; } /* for a "extended" dsc with section or priority */ - if( dsc->section != NULL ) { + if (dsc->section != NULL) { free(f->section); f->section = strdup(dsc->section); - if( FAILEDTOALLOC(f->section) ) { + if (FAILEDTOALLOC(f->section)) { free(origdirectory); return RET_ERROR_OOM; } } - if( dsc->priority != NULL ) { + if (dsc->priority != NULL) { free(f->priority); f->priority = strdup(dsc->priority); - if( FAILEDTOALLOC(f->priority) ) { + if (FAILEDTOALLOC(f->priority)) { free(origdirectory); return RET_ERROR_OOM; } } - if( f->section == NULL || f->priority == NULL ) { + if (f->section == NULL || f->priority == NULL) { struct sourceextraction *extraction; int j; extraction = sourceextraction_init( (f->section == NULL)?&f->section:NULL, (f->priority == NULL)?&f->priority:NULL); - if( FAILEDTOALLOC(extraction) ) { + if (FAILEDTOALLOC(extraction)) { free(origdirectory); return RET_ERROR_OOM; } - for( j = 0 ; j < dsc->expected.names.count ; j++ ) { + for (j = 0 ; j < dsc->expected.names.count ; j++) { sourceextraction_setpart(extraction, j, dsc->expected.names.values[j]); } - while( sourceextraction_needs(extraction, &j) ) { - if( dsc->uplink[j]->fullfilename == NULL ) { + while (sourceextraction_needs(extraction, &j)) { + if (dsc->uplink[j]->fullfilename == NULL) { /* look for file */ r = findfile(dsc->expected.names.values[j], c, searchpath, origdirectory, &dsc->uplink[j]->fullfilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { sourceextraction_abort(extraction); free(origdirectory); return r; } - if( r == RET_NOTHING || - dsc->uplink[j]->fullfilename == NULL ) + if (r == RET_NOTHING || + dsc->uplink[j]->fullfilename == NULL) break; } r = sourceextraction_analyse(extraction, dsc->uplink[j]->fullfilename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { sourceextraction_abort(extraction); free(origdirectory); return r; } } r = sourceextraction_finish(extraction); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(origdirectory); return r; } } free(origdirectory); /* update information in the main .changes file if not there already */ - if( c->maintainer == NULL && dsc->maintainer != NULL ) { + if (c->maintainer == NULL && dsc->maintainer != NULL) { c->maintainer = strdup(dsc->maintainer); - if( c->maintainer == NULL ) + if (FAILEDTOALLOC(c->maintainer)) return RET_ERROR_OOM; } - if( !strlist_in(&c->architectures, "source") ) { + if (!strlist_in(&c->architectures, "source")) { r = strlist_add_dup(&c->architectures, "source"); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; } static retvalue adddscs(const char *changesfilename, struct changes *c, int argc, char **argv, const struct strlist *searchpath, bool fakefields) { - if( argc <= 0 ) { - fprintf(stderr, "Filenames of .dsc files to include expected!\n"); + if (argc <= 0) { + fprintf(stderr, +"Filenames of .dsc files to include expected!\n"); return RET_ERROR; } - while( argc > 0 ) { + while (argc > 0) { retvalue r = adddsc(c, argv[0], searchpath); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; argc--; argv++; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_ALL, fakefields); } else @@ -2417,51 +2472,54 @@ const char *v; r = findfile(debfilename, c, searchpath, ".", &fullfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot find '%s'!\n", debfilename); return RET_ERROR_MISSING; } r = read_binaryfile(fullfilename, &deb); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Error reading '%s'!\n", fullfilename); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); return r; } // TODO: check if there are other things but the name to distinguish them - if( strlen(fullfilename) > 5 && - strcmp(fullfilename+strlen(fullfilename)-5,".udeb") == 0 ) { + if (strlen(fullfilename) > 5 && + strcmp(fullfilename+strlen(fullfilename)-5, ".udeb") == 0) { packagetype = "udeb"; type = ft_UDEB; } else { packagetype = "deb"; type = ft_DEB; } - if( deb->name == NULL || deb->version == NULL || deb->architecture == NULL ) { - if( deb->name == NULL ) - fprintf(stderr, "Could not extract packagename of '%s'!\n", + if (deb->name == NULL || deb->version == NULL || deb->architecture == NULL) { + if (deb->name == NULL) + fprintf(stderr, +"Could not extract packagename of '%s'!\n", fullfilename); - else if( deb->version == NULL ) - fprintf(stderr, "Could not extract version of '%s'!\n", + else if (deb->version == NULL) + fprintf(stderr, +"Could not extract version of '%s'!\n", fullfilename); else - fprintf(stderr, "Could not extract architecture of '%s'!\n", + fprintf(stderr, +"Could not extract architecture of '%s'!\n", fullfilename); binaryfile_free(deb); free(fullfilename); return RET_ERROR; } - if( c->name != NULL ) { + if (c->name != NULL) { const char *sourcename; - if( deb->sourcename != NULL ) + if (deb->sourcename != NULL) sourcename = deb->sourcename; else sourcename = deb->name; - if( strcmp(c->name,sourcename) != 0 ) { + if (strcmp(c->name, sourcename) != 0) { fprintf(stderr, "ERROR: '%s' lists source '%s' while '%s' already is '%s'!\n", fullfilename, sourcename, @@ -2471,33 +2529,33 @@ return RET_ERROR; } } else { - if( deb->sourcename != NULL ) + if (deb->sourcename != NULL) c->name = strdup(deb->sourcename); else c->name = strdup(deb->name); - if( c->name == NULL ) { + if (FAILEDTOALLOC(c->name)) { binaryfile_free(deb); free(fullfilename); return RET_ERROR_OOM; } } - if( c->version != NULL ) { + if (c->version != NULL) { const char *sourceversion; - if( deb->sourceversion != NULL ) + if (deb->sourceversion != NULL) sourceversion = deb->sourceversion; else sourceversion = deb->version; - if( strcmp(c->version,sourceversion) != 0 ) + if (strcmp(c->version, sourceversion) != 0) fprintf(stderr, "WARNING: '%s' lists source version '%s' while '%s' already lists '%s'!\n", fullfilename, sourceversion, c->filename, c->version); } else { - if( deb->sourceversion != NULL ) + if (deb->sourceversion != NULL) c->version = strdup(deb->sourceversion); else c->version = strdup(deb->version); - if( c->version == NULL ) { + if (FAILEDTOALLOC(c->version)) { binaryfile_free(deb); free(fullfilename); return RET_ERROR_OOM; @@ -2506,13 +2564,13 @@ // TODO: make sure if the .changes name/version are modified they will // also be written... v = strchr(deb->version, ':'); - if( v != NULL ) + if (v != NULL) v++; else v = deb->version; basefilename = mprintf("%s_%s_%s.%s", deb->name, v, deb->architecture, packagetype); - if( basefilename == NULL ) { + if (FAILEDTOALLOC(basefilename)) { binaryfile_free(deb); free(fullfilename); return RET_ERROR_OOM; @@ -2522,12 +2580,14 @@ // basefilename differ r = add_file(c, basefilename, fullfilename, type, &f); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { binaryfile_free(deb); return r; } - if( r == RET_NOTHING ) { - fprintf(stderr, "ERROR: '%s' already contains a file of the same name!\n", c->filename); + if (r == RET_NOTHING) { + fprintf(stderr, +"ERROR: '%s' already contains a file of the same name!\n", + c->filename); binaryfile_free(deb); // TODO: check instead if it is already the same... return RET_ERROR; @@ -2535,62 +2595,60 @@ /* f owns deb, fullfilename and basefilename now */ f->deb = deb; deb->binary = get_binary(c, deb->name, strlen(deb->name)); - if( deb->binary == NULL ) { + if (FAILEDTOALLOC(deb->binary)) return RET_ERROR_OOM; - } deb->next = deb->binary->files; deb->binary->files = deb; deb->binary->missedinheader = false; c->modified = true; r = checksums_read(f->fullfilename, &f->realchecksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) return r; - } f->checksumsfromchanges = checksums_dup(f->realchecksums); - if( f->checksumsfromchanges == NULL ) { - return RET_ERROR_OOM;; - } - if( deb->shortdescription != NULL ) { - if( deb->binary->description == NULL ) { + if (FAILEDTOALLOC(f->checksumsfromchanges)) + return RET_ERROR_OOM; + if (deb->shortdescription != NULL) { + if (deb->binary->description == NULL) { deb->binary->description = strdup(deb->shortdescription); deb->binary->missedinheader = false; - } else if( strcmp(deb->binary->description, - deb->shortdescription) != 0 ) { + } else if (strcmp(deb->binary->description, + deb->shortdescription) != 0) { fprintf(stderr, "WARNING: '%s' already lists a different description for '%s' than contained in '%s'!\n", c->filename, deb->name, fullfilename); } } - if( deb->section != NULL ) { + if (deb->section != NULL) { free(f->section); f->section = strdup(deb->section); } - if( deb->priority != NULL ) { + if (deb->priority != NULL) { free(f->priority); f->priority = strdup(deb->priority); } - if( c->maintainer == NULL && deb->maintainer != NULL ) { + if (c->maintainer == NULL && deb->maintainer != NULL) { c->maintainer = strdup(deb->maintainer); } - if( deb->architecture != NULL && - !strlist_in(&c->architectures, deb->architecture) ) { + if (deb->architecture != NULL && + !strlist_in(&c->architectures, deb->architecture)) { strlist_add_dup(&c->architectures, deb->architecture); } return RET_OK; } static retvalue adddebs(const char *changesfilename, struct changes *c, int argc, char **argv, const struct strlist *searchpath, bool fakefields) { - if( argc <= 0 ) { - fprintf(stderr, "Filenames of .deb files to include expected!\n"); + if (argc <= 0) { + fprintf(stderr, +"Filenames of .deb files to include expected!\n"); return RET_ERROR; } - while( argc > 0 ) { + while (argc > 0) { retvalue r = adddeb(c, argv[0], searchpath); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; argc--; argv++; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_ALL, fakefields); } else @@ -2604,19 +2662,19 @@ struct checksums *checksums; r = findfile(filename, c, searchpath, ".", &fullfilename); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { fprintf(stderr, "Cannot find '%s'!\n", filename); return RET_ERROR_MISSING; } basefilename = strdup(dirs_basename(filename)); - if( basefilename == NULL ) { + if (FAILEDTOALLOC(basefilename)) { free(fullfilename); return RET_ERROR_OOM; } r = checksums_read(fullfilename, &checksums); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(fullfilename); free(basefilename); return r; @@ -2625,23 +2683,28 @@ // fullfilename and basefilename now belong to *f or are already free'd basefilename = NULL; fullfilename = NULL; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { checksums_free(checksums); return r; } - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { - assert( f != NULL ); + assert (f != NULL); - if( f->checksumsfromchanges != NULL ) { + if (f->checksumsfromchanges != NULL) { /* already listed in .changes */ - if( !checksums_check(f->checksumsfromchanges, checksums, NULL) ) { - fprintf(stderr, "ERROR: '%s' already contains a file with name '%s' but different checksums!\n", c->filename, f->basename); + if (!checksums_check(f->checksumsfromchanges, checksums, + NULL)) { + fprintf(stderr, +"ERROR: '%s' already contains a file with name '%s' but different checksums!\n", + c->filename, f->basename); checksums_free(checksums); return RET_ERROR; } - printf("'%s' already lists '%s' with same checksums. Doing nothing.\n", c->filename, f->basename); + printf( +"'%s' already lists '%s' with same checksums. Doing nothing.\n", + c->filename, f->basename); checksums_free(checksums); return RET_NOTHING; } else { @@ -2652,28 +2715,29 @@ } c->modified = true; - assert( f->checksumsfromchanges == NULL ); + assert (f->checksumsfromchanges == NULL); f->checksumsfromchanges = checksums; checksums = NULL; - if( f->realchecksums == NULL ) + if (f->realchecksums == NULL) f->realchecksums = checksums_dup(f->checksumsfromchanges); - if( f->realchecksums == NULL ) - return RET_ERROR_OOM;; + if (FAILEDTOALLOC(f->realchecksums)) + return RET_ERROR_OOM; return RET_OK; } static retvalue addrawfiles(const char *changesfilename, struct changes *c, int argc, char **argv, const struct strlist *searchpath, bool fakefields) { - if( argc <= 0 ) { - fprintf(stderr, "Filenames of files to add (without further parsing) expected!\n"); + if (argc <= 0) { + fprintf(stderr, +"Filenames of files to add (without further parsing) expected!\n"); return RET_ERROR; } - while( argc > 0 ) { + while (argc > 0) { retvalue r = addrawfile(c, argv[0], searchpath); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; argc--; argv++; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_FILES, fakefields); } else @@ -2681,27 +2745,27 @@ } static retvalue addfiles(const char *changesfilename, struct changes *c, int argc, char **argv, const struct strlist *searchpath, bool fakefields) { - if( argc <= 0 ) { + if (argc <= 0) { fprintf(stderr, "Filenames of files to add expected!\n"); return RET_ERROR; } - while( argc > 0 ) { + while (argc > 0) { retvalue r; const char *filename = argv[0]; size_t l = strlen(filename); - if( (l > 4 && strcmp(filename+l-4, ".deb") == 0) || - (l > 5 && strcmp(filename+l-5, ".udeb") == 0) ) + if ((l > 4 && strcmp(filename+l-4, ".deb") == 0) || + (l > 5 && strcmp(filename+l-5, ".udeb") == 0)) r = adddeb(c, filename, searchpath); - else if( (l > 4 && strcmp(filename+l-4, ".dsc") == 0) ) + else if ((l > 4 && strcmp(filename+l-4, ".dsc") == 0)) r = adddsc(c, filename, searchpath); else r = addrawfile(c, argv[0], searchpath); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; argc--; argv++; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_ALL, fakefields); } else @@ -2709,20 +2773,22 @@ } static retvalue dumbremovefiles(const char *changesfilename, struct changes *c, int argc, char **argv) { - if( argc <= 0 ) { - fprintf(stderr, "Filenames of files to remove (without further parsing) expected!\n"); + if (argc <= 0) { + fprintf(stderr, +"Filenames of files to remove (without further parsing) expected!\n"); return RET_ERROR; } - while( argc > 0 ) { + while (argc > 0) { struct fileentry **fp; /*@null@*/ struct fileentry *f; fp = find_fileentry(c, argv[0], strlen(argv[0]), NULL); - f = *fp; - if( f == NULL ) { - fprintf(stderr, "Not removing '%s' as not listed in '%s'!\n", + f = *fp; + if (f == NULL) { + fprintf(stderr, +"Not removing '%s' as not listed in '%s'!\n", argv[0], c->filename); - } else if( f->checksumsfromchanges != NULL ) { + } else if (f->checksumsfromchanges != NULL) { /* removing its checksums makes it vanish from the * .changes file generated, while still keeping pointers * from other files intact */ @@ -2732,7 +2798,7 @@ } argc--; argv++; } - if( c->modified ) { + if (c->modified) { return write_changes_file(changesfilename, c, CHANGES_WRITE_FILES, false); } else @@ -2744,16 +2810,16 @@ struct strlist distributions; int i; - if( argc <= 0 ) { + if (argc <= 0) { fprintf(stderr, "expected Distribution name to set!\n"); return RET_ERROR; } r = strlist_init_n(argc, &distributions); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( i = 0 ; i < argc ; i++ ) { + for (i = 0 ; i < argc ; i++) { r = strlist_add_dup(&distributions, argv[i]); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { strlist_done(&distributions); return r; } @@ -2768,37 +2834,39 @@ const char *command = argv[0]; retvalue r; - assert( argc > 0 ); + assert (argc > 0); - if( strcasecmp(command, "verify") == 0 ) { - if( argc > 1 ) { + if (strcasecmp(command, "verify") == 0) { + if (argc > 1) { fprintf(stderr, "Too many arguments!\n"); r = RET_ERROR; - } else if( file_exists ) + } else if (file_exists) r = verify(changesfilename, changesdata); else { fprintf(stderr, "No such file '%s'!\n", changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "updatechecksums") == 0 ) { - if( file_exists ) - r = updatechecksums(changesfilename, changesdata, argc-1, argv+1); + } else if (strcasecmp(command, "updatechecksums") == 0) { + if (file_exists) + r = updatechecksums(changesfilename, changesdata, + argc-1, argv+1); else { fprintf(stderr, "No such file '%s'!\n", changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "includeallsources") == 0 ) { - if( file_exists ) - r = includeallsources(changesfilename, changesdata, argc-1, argv+1); + } else if (strcasecmp(command, "includeallsources") == 0) { + if (file_exists) + r = includeallsources(changesfilename, changesdata, + argc-1, argv+1); else { fprintf(stderr, "No such file '%s'!\n", changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "addrawfile") == 0 ) { - if( file_exists || create_file ) + } else if (strcasecmp(command, "addrawfile") == 0) { + if (file_exists || create_file) r = addrawfiles(changesfilename, changesdata, argc-1, argv+1, searchpath, fakefields); else { @@ -2806,8 +2874,8 @@ changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "adddsc") == 0 ) { - if( file_exists || create_file ) + } else if (strcasecmp(command, "adddsc") == 0) { + if (file_exists || create_file) r = adddscs(changesfilename, changesdata, argc-1, argv+1, searchpath, fakefields); else { @@ -2815,8 +2883,8 @@ changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "adddeb") == 0 ) { - if( file_exists || create_file ) + } else if (strcasecmp(command, "adddeb") == 0) { + if (file_exists || create_file) r = adddebs(changesfilename, changesdata, argc-1, argv+1, searchpath, fakefields); else { @@ -2824,8 +2892,8 @@ changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "add") == 0 ) { - if( file_exists || create_file ) + } else if (strcasecmp(command, "add") == 0) { + if (file_exists || create_file) r = addfiles(changesfilename, changesdata, argc-1, argv+1, searchpath, fakefields); else { @@ -2833,8 +2901,8 @@ changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "setdistribution") == 0 ) { - if( file_exists ) + } else if (strcasecmp(command, "setdistribution") == 0) { + if (file_exists) r = setdistribution(changesfilename, changesdata, argc-1, argv+1); else { @@ -2842,8 +2910,8 @@ changesfilename); r = RET_ERROR; } - } else if( strcasecmp(command, "dumbremove") == 0 ) { - if( file_exists ) + } else if (strcasecmp(command, "dumbremove") == 0) { + if (file_exists) r = dumbremovefiles(changesfilename, changesdata, argc-1, argv+1); else { @@ -2862,14 +2930,14 @@ retvalue r; const char *next; - while( (next = index(path, ':')) != NULL ) { - if( next > path ) { + while ((next = index(path, ':')) != NULL) { + if (next > path) { char *dir = strndup(path, next-path); - if( dir == NULL ) { + if (FAILEDTOALLOC(dir)) { return RET_ERROR_OOM; } r = strlist_add(list, dir); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } path = next+1; @@ -2877,7 +2945,7 @@ return strlist_add_dup(list, path); } -int main(int argc,char *argv[]) { +int main(int argc, char *argv[]) { static int longoption = 0; static const struct option longopts[] = { {"help", no_argument, NULL, 'h'}, @@ -2898,15 +2966,16 @@ bool all_fields = false; struct strlist searchpath; struct changes *changesdata IFSTUPIDCC(=NULL); - char *gunzip = NULL, *bunzip2 = NULL, *unlzma = NULL, *unxz = NULL, *lunzip = NULL; + char *gunzip = NULL, *bunzip2 = NULL, *unlzma = NULL, + *unxz = NULL, *lunzip = NULL; retvalue r; strlist_init(&searchpath); - while( (c = getopt_long(argc,argv,"+hi:s:",longopts,NULL)) != -1 ) { - switch( c ) { + while ((c = getopt_long(argc, argv, "+hi:s:", longopts, NULL)) != -1) { + switch (c) { case '\0': - switch( longoption ) { + switch (longoption) { case 1: gunzip = strdup(optarg); break; @@ -2935,57 +3004,62 @@ break; case 's': r = splitpath(&searchpath, optarg); - if( RET_WAS_ERROR(r) ) { - if( r == RET_ERROR_OOM ) - fprintf(stderr, "Out of memory!\n"); + if (RET_WAS_ERROR(r)) { + if (r == RET_ERROR_OOM) + fprintf(stderr, +"Out of memory!\n"); exit(EXIT_FAILURE); } break; } } - if( argc - optind < 2 ) { + if (argc - optind < 2) { about(false); } signature_init(false); uncompressions_check(gunzip, bunzip2, unlzma, unxz, lunzip); changesfilename = argv[optind]; - if( strcmp(changesfilename,"-") != 0 && !endswith(changesfilename,".changes") ) { + if (strcmp(changesfilename, "-") != 0 && + !endswith(changesfilename, ".changes")) { fprintf(stderr, "first argument not ending with '.changes'\n"); exit(EXIT_FAILURE); } file_exists = isregularfile(changesfilename); - if( file_exists ) { + if (file_exists) { char *changes; r = signature_readsignedchunk(changesfilename, changesfilename, &changes, NULL, NULL); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { signatures_done(); - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) fprintf(stderr, "Out of memory!\n"); exit(EXIT_FAILURE); } - r = parse_changes(changesfilename, changes, &changesdata, &searchpath); - if( RET_IS_OK(r) ) + r = parse_changes(changesfilename, changes, + &changesdata, &searchpath); + if (RET_IS_OK(r)) changesdata->control = changes; else { free(changes); changesdata = NULL; } } else { - changesdata = calloc(1,sizeof(struct changes)); - if( changesdata != NULL ) - changesdata->filename = strdup(changesfilename); - if( changesdata == NULL || changesdata->filename == NULL ) + changesdata = zNEW(struct changes); + if (FAILEDTOALLOC(changesdata)) r = RET_ERROR_OOM; else { - r = dirs_getdirectory(changesfilename, - &changesdata->basedir); + changesdata->filename = strdup(changesfilename); + if (FAILEDTOALLOC(changesdata->filename)) + r = RET_ERROR_OOM; + else + r = dirs_getdirectory(changesfilename, + &changesdata->basedir); } } - if( !RET_WAS_ERROR(r) ) { + if (!RET_WAS_ERROR(r)) { argc -= (optind+1); argv += (optind+1); r = execute_command(argc, argv, changesfilename, &searchpath, @@ -2995,9 +3069,9 @@ changes_free(changesdata); signatures_done(); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) exit(EXIT_SUCCESS); - if( r == RET_ERROR_OOM ) + if (r == RET_ERROR_OOM) fprintf(stderr, "Out of memory!\n"); exit(EXIT_FAILURE); } diff -Nru reprepro-4.5.0/tracking.c reprepro-4.6.0/tracking.c --- reprepro-4.5.0/tracking.c 2010-10-24 08:59:11.000000000 +0000 +++ reprepro-4.6.0/tracking.c 2011-05-05 14:42:55.000000000 +0000 @@ -49,7 +49,7 @@ retvalue tracking_done(trackingdb db) { retvalue r; - if( db == NULL ) + if (db == NULL) return RET_OK; r = table_close(db->table); @@ -58,24 +58,23 @@ return r; } -retvalue tracking_initialize(/*@out@*/trackingdb *db, struct database *database, const struct distribution *distribution, bool readonly) { +retvalue tracking_initialize(/*@out@*/trackingdb *db, const struct distribution *distribution, bool readonly) { struct s_tracking *t; retvalue r; - t = calloc(1,sizeof(struct s_tracking)); - if( t == NULL ) { + t = zNEW(struct s_tracking); + if (FAILEDTOALLOC(t)) return RET_ERROR_OOM; - } t->codename = strdup(distribution->codename); - if( t->codename == NULL ) { + if (FAILEDTOALLOC(t->codename)) { free(t); return RET_ERROR_OOM; } - assert( distribution->tracking != dt_NONE || readonly ); + assert (distribution->tracking != dt_NONE || readonly); t->type = distribution->tracking; t->options = distribution->trackingoptions; - r = database_opentracking(database, t->codename, readonly, &t->table); - if( !RET_IS_OK(r) ) { + r = database_opentracking(t->codename, readonly, &t->table); + if (!RET_IS_OK(r)) { free(t->codename); free(t); return r; @@ -85,7 +84,7 @@ } static inline enum filetype filetypechar(enum filetype filetype) { - switch( filetype ) { + switch (filetype) { case ft_LOG: case ft_CHANGES: case ft_ALL_BINARY: @@ -98,118 +97,130 @@ return ft_XTRA_DATA; } -retvalue trackedpackage_addfilekey(trackingdb tracks, struct trackedpackage *pkg, enum filetype filetype, char *filekey, bool used, struct database *database) { +retvalue trackedpackage_addfilekey(trackingdb tracks, struct trackedpackage *pkg, enum filetype filetype, char *filekey, bool used) { char *id; enum filetype ft = filetypechar(filetype); int i, *newrefcounts; enum filetype *newfiletypes; retvalue r; - if( filekey == NULL ) + if (FAILEDTOALLOC(filekey)) return RET_ERROR_OOM; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( strcmp(pkg->filekeys.values[i],filekey) == 0 ) { - if( pkg->filetypes[i] != ft ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (strcmp(pkg->filekeys.values[i], filekey) == 0) { + if (pkg->filetypes[i] != ft) { /* if old file has refcount 0, just repair: */ - if( pkg->refcounts[i] <= 0 ) { + if (pkg->refcounts[i] <= 0) { free(filekey); pkg->filetypes[i] = ft; - if( used ) + if (used) pkg->refcounts[i] = 1; return RET_OK; } - fprintf(stderr,"Filekey '%s' already registered for '%s_%s' as type '%c' is tried to be reregistered as type '%c'!\n",filekey,pkg->sourcename,pkg->sourceversion,pkg->filetypes[i],ft); + fprintf(stderr, +"Filekey '%s' already registered for '%s_%s' as type '%c' is tried to be reregistered as type '%c'!\n", + filekey, pkg->sourcename, + pkg->sourceversion, + pkg->filetypes[i], ft); free(filekey); return RET_ERROR; } free(filekey); - if( used ) + if (used) pkg->refcounts[i]++; return RET_OK; } } - newrefcounts = realloc(pkg->refcounts,sizeof(int)*(pkg->filekeys.count+1)); - if( newrefcounts == NULL ) { + newrefcounts = realloc(pkg->refcounts, + (pkg->filekeys.count + 1) * sizeof(int)); + if (FAILEDTOALLOC(newrefcounts)) { free(filekey); return RET_ERROR_OOM; } - if( used ) + if (used) newrefcounts[pkg->filekeys.count]=1; else newrefcounts[pkg->filekeys.count]=0; pkg->refcounts = newrefcounts; - newfiletypes = realloc(pkg->filetypes,sizeof(enum filetype)*(pkg->filekeys.count+1)); - if( newfiletypes == NULL ) { + newfiletypes = realloc(pkg->filetypes, + (pkg->filekeys.count + 1) * sizeof(enum filetype)); + if (FAILEDTOALLOC(newfiletypes)) { free(filekey); return RET_ERROR_OOM; } newfiletypes[pkg->filekeys.count] = filetype; pkg->filetypes = newfiletypes; - r = strlist_add(&pkg->filekeys,filekey); - if( RET_WAS_ERROR(r) ) + r = strlist_add(&pkg->filekeys, filekey); + if (RET_WAS_ERROR(r)) return r; id = calc_trackreferee(tracks->codename, pkg->sourcename, pkg->sourceversion); - if( id == NULL ) + if (FAILEDTOALLOC(id)) return RET_ERROR_OOM; - r = references_increment(database, filekey, id); + r = references_increment(filekey, id); free(id); return r; } -retvalue trackedpackage_adddupfilekeys(trackingdb tracks, struct trackedpackage *pkg, enum filetype filetype, const struct strlist *filekeys, bool used, struct database *database) { +retvalue trackedpackage_adddupfilekeys(trackingdb tracks, struct trackedpackage *pkg, enum filetype filetype, const struct strlist *filekeys, bool used) { int i; - retvalue result,r; - assert( filekeys != NULL ); + retvalue result, r; + assert (filekeys != NULL); result = RET_OK; - for( i = 0 ; i < filekeys->count ; i++ ) { + for (i = 0 ; i < filekeys->count ; i++) { char *filekey = strdup(filekeys->values[i]); r = trackedpackage_addfilekey(tracks, pkg, filetype, - filekey, used, database); - RET_UPDATE(result,r); + filekey, used); + RET_UPDATE(result, r); } return result; } -static inline retvalue trackedpackage_removefilekey(trackingdb tracks,struct trackedpackage *pkg,const char *filekey) { +static inline retvalue trackedpackage_removefilekey(trackingdb tracks, struct trackedpackage *pkg, const char *filekey) { int i; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( strcmp(pkg->filekeys.values[i],filekey) == 0 ) { - if( pkg->refcounts[i] > 0 ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (strcmp(pkg->filekeys.values[i], filekey) == 0) { + if (pkg->refcounts[i] > 0) { pkg->refcounts[i]--; } else - fprintf(stderr,"Warning: tracking database of %s has inconsistent refcounts of %s_%s.\n",tracks->codename,pkg->sourcename,pkg->sourceversion); + fprintf(stderr, +"Warning: tracking database of %s has inconsistent refcounts of %s_%s.\n", + tracks->codename, + pkg->sourcename, + pkg->sourceversion); return RET_OK; } } - fprintf(stderr,"Warning: tracking database of %s missed files for %s_%s.\n",tracks->codename,pkg->sourcename,pkg->sourceversion); + fprintf(stderr, +"Warning: tracking database of %s missed files for %s_%s.\n", + tracks->codename, pkg->sourcename, pkg->sourceversion); return RET_OK; } -retvalue trackedpackage_removefilekeys(trackingdb tracks,struct trackedpackage *pkg,const struct strlist *filekeys) { +retvalue trackedpackage_removefilekeys(trackingdb tracks, struct trackedpackage *pkg, const struct strlist *filekeys) { int i; - retvalue result,r; - assert( filekeys != NULL ); + retvalue result, r; + assert (filekeys != NULL); result = RET_OK; - for( i = 0 ; i < filekeys->count ; i++ ) { + for (i = 0 ; i < filekeys->count ; i++) { const char *filekey = filekeys->values[i]; - r = trackedpackage_removefilekey(tracks,pkg,filekey); - RET_UPDATE(result,r); + r = trackedpackage_removefilekey(tracks, pkg, filekey); + RET_UPDATE(result, r); } return result; } void trackedpackage_free(struct trackedpackage *pkg) { - if( pkg != NULL ) { + if (pkg != NULL) { free(pkg->sourcename); free(pkg->sourceversion); strlist_done(&pkg->filekeys); @@ -219,35 +230,35 @@ } } -static inline int parsenumber(const char **d,size_t *s) { +static inline int parsenumber(const char **d, size_t *s) { int count; count = 0; do { - if( **d < '0' || **d > '7' ) + if (**d < '0' || **d > '7') return -1; count = (count*8) + (**d-'0'); (*d)++; (*s)--; - if( *s == 0 ) + if (*s == 0) return -1; - } while( **d != '\0' ); + } while (**d != '\0'); (*d)++; (*s)--; return count; } -static retvalue tracking_new(const char *sourcename,const char *version,/*@out@*/struct trackedpackage **pkg) { +static retvalue tracking_new(const char *sourcename, const char *version, /*@out@*/struct trackedpackage **pkg) { struct trackedpackage *p; - assert( pkg != NULL && sourcename != NULL && version != NULL ); + assert (pkg != NULL && sourcename != NULL && version != NULL); - p = calloc(1,sizeof(struct trackedpackage)); - if( p == NULL ) + p = zNEW(struct trackedpackage); + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->sourcename = strdup(sourcename); p->sourceversion = strdup(version); p->flags.isnew = true; - if( p->sourcename == NULL || p->sourceversion == NULL ) { + if (FAILEDTOALLOC(p->sourcename) || FAILEDTOALLOC(p->sourceversion)) { trackedpackage_free(p); return RET_ERROR_OOM; } @@ -259,26 +270,27 @@ struct trackedpackage *p; int i; - p = calloc(1,sizeof(struct trackedpackage)); - if( p == NULL ) + p = zNEW(struct trackedpackage); + if (FAILEDTOALLOC(p)) return RET_ERROR_OOM; p->sourcename = strdup(name); p->sourceversion = strdup(version); - if( p->sourcename == NULL || p->sourceversion == NULL /*|| - p->sourcedir == NULL */ ) { + if (FAILEDTOALLOC(p->sourcename) + || FAILEDTOALLOC(p->sourceversion) + /* || FAILEDTOALLOC(p->sourcedir) */) { trackedpackage_free(p); return RET_ERROR_OOM; } - while( datalen > 0 && *data != '\0' ) { + while (datalen > 0 && *data != '\0') { char *filekey; const char *separator; size_t filekeylen; retvalue r; - if( ((p->filekeys.count)&31) == 0 ) { + if (((p->filekeys.count)&31) == 0) { enum filetype *n = realloc(p->filetypes, (p->filekeys.count+32)*sizeof(enum filetype)); - if( n == NULL ) { + if (FAILEDTOALLOC(n)) { trackedpackage_free(p); return RET_ERROR_OOM; } @@ -287,19 +299,21 @@ p->filetypes[p->filekeys.count] = *data; data++; datalen--; separator = memchr(data, '\0', datalen); - if( separator == NULL ) { - fprintf(stderr,"Internal Error: Corrupt tracking data for %s %s\n",name,version); + if (separator == NULL) { + fprintf(stderr, +"Internal Error: Corrupt tracking data for %s %s\n", + name, version); trackedpackage_free(p); return RET_ERROR; } filekeylen = separator - data; filekey = strndup(data, filekeylen); - if( filekey == NULL ) { + if (FAILEDTOALLOC(filekey)) { trackedpackage_free(p); return RET_ERROR_OOM; } r = strlist_add(&p->filekeys, filekey); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { trackedpackage_free(p); return r; } @@ -307,19 +321,21 @@ datalen -= filekeylen + 1; } data++; datalen--; - p->refcounts = calloc(p->filekeys.count,sizeof(int)); - if( p->refcounts == NULL ) { + p->refcounts = nzNEW(p->filekeys.count, int); + if (FAILEDTOALLOC(p->refcounts)) { trackedpackage_free(p); return RET_ERROR_OOM; } - for( i = 0 ; i < p->filekeys.count ; i++ ) { - if( (p->refcounts[i] = parsenumber(&data, &datalen)) < 0 ) { - fprintf(stderr,"Internal Error: Corrupt tracking data for %s %s\n",name,version); + for (i = 0 ; i < p->filekeys.count ; i++) { + if ((p->refcounts[i] = parsenumber(&data, &datalen)) < 0) { + fprintf(stderr, +"Internal Error: Corrupt tracking data for %s %s\n", + name, version); trackedpackage_free(p); return RET_ERROR; } } - if( datalen > 0 ) { + if (datalen > 0) { fprintf(stderr, "Internal Error: Trailing garbage in tracking data for %s %s\n (%ld bytes)", name, version, (long)datalen); @@ -338,81 +354,80 @@ size_t datalen; retvalue r; - assert( pkg != NULL && sourcename != NULL && version != NULL ); + assert (pkg != NULL && sourcename != NULL && version != NULL); - versionlen = strlen(version); r = table_getpair(t->table, sourcename, version, &data, &datalen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; return parse_data(sourcename, version, data, datalen, pkg); } -retvalue tracking_getornew(trackingdb tracks,const char *name,const char *version,/*@out@*/struct trackedpackage **pkg) { +retvalue tracking_getornew(trackingdb tracks, const char *name, const char *version, /*@out@*/struct trackedpackage **pkg) { retvalue r; r = tracking_get(tracks, name, version, pkg); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = tracking_new(name, version, pkg); return r; } static retvalue gen_data(struct trackedpackage *pkg, /*@out@*/char **newdata_p, /*@out@*/size_t *newdatalen_p) { - size_t versionsize = strlen(pkg->sourceversion)+1; + size_t versionsize = strlen(pkg->sourceversion)+1; int i; char *d, *data; size_t datalen; datalen = versionsize + 1; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { size_t l; l = strlen(pkg->filekeys.values[i]); - if( l > 0 ) + if (l > 0) datalen += l+9; } data = malloc(datalen + 1); - if( data == NULL ) + if (FAILEDTOALLOC(data)) return RET_ERROR_OOM; memcpy(data, pkg->sourceversion, versionsize); d = data + versionsize; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { size_t l; l = strlen(pkg->filekeys.values[i]); - if( l > 0 ) { + if (l > 0) { *d = pkg->filetypes[i]; d++; - memcpy(d,pkg->filekeys.values[i],l+1); + memcpy(d, pkg->filekeys.values[i], l + 1); d+=l+1; } } - *d ='\0';d++; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + *d ='\0'; d++; + for (i = 0 ; i < pkg->filekeys.count ; i++) { int j; #define MAXREFCOUNTOCTETS 7 char countstring[MAXREFCOUNTOCTETS]; size_t count = pkg->refcounts[i]; countstring[MAXREFCOUNTOCTETS-1] = '\0'; - for( j = MAXREFCOUNTOCTETS-2 ; j >= 0 ; j-- ) { + for (j = MAXREFCOUNTOCTETS-2 ; j >= 0 ; j--) { countstring[j] = '0' + (count & 7); count >>= 3; - if( count == 0 ) + if (count == 0) break; } #undef MAXREFCOUNTOCTETS - assert( count == 0 ); + assert (count == 0); - memcpy(d,countstring+j,7-j); + memcpy(d, countstring+j, 7 - j); d+=7-j; datalen -= j; } *d ='\0'; - assert( (size_t)(d-data) == datalen ); + assert ((size_t)(d-data) == datalen); *newdata_p = data; *newdatalen_p = datalen; return RET_OK; } static retvalue tracking_saveatcursor(trackingdb t, struct cursor *cursor, struct trackedpackage *pkg) { - if( pkg->flags.deleted ) { + if (pkg->flags.deleted) { /* delete if delete is requested * (all unreferencing has to be done before) */ return cursor_delete(t->table, cursor, @@ -423,8 +438,9 @@ retvalue r; r = gen_data(pkg, &newdata, &newdatalen); - if( RET_IS_OK(r) ) { - r = cursor_replace(t->table, cursor, newdata, newdatalen); + if (RET_IS_OK(r)) { + r = cursor_replace(t->table, cursor, + newdata, newdatalen); free(newdata); } return r; @@ -436,18 +452,21 @@ char *newdata; size_t newdatalen; - assert( pkg != NULL ); + assert (pkg != NULL); - if( !pkg->flags.isnew ) { + if (!pkg->flags.isnew) { struct cursor *cursor; r = table_newpairedcursor(t->table, pkg->sourcename, pkg->sourceversion, &cursor, NULL, NULL); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( r == RET_NOTHING ) { - fprintf(stderr, "Internal error: tracking_save with isnew=false called but could not find %s_%s in %s!\n", pkg->sourcename, pkg->sourceversion, t->codename); + if (r == RET_NOTHING) { + fprintf(stderr, +"Internal error: tracking_save with isnew=false called but could not find %s_%s in %s!\n", + pkg->sourcename, pkg->sourceversion, + t->codename); pkg->flags.isnew = true; } else { r = tracking_saveatcursor(t, cursor, pkg); @@ -457,44 +476,44 @@ } } - if( pkg->flags.deleted ) + if (pkg->flags.deleted) return RET_OK; r = gen_data(pkg, &newdata, &newdatalen); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) return r; r = table_addrecord(t->table, pkg->sourcename, newdata, newdatalen, false); free(newdata); - if( verbose > 18 ) - fprintf(stderr,"Adding tracked package '%s'_'%s' to '%s'\n", + if (verbose > 18) + fprintf(stderr, "Adding tracked package '%s'_'%s' to '%s'\n", pkg->sourcename, pkg->sourceversion, t->codename); return r; } retvalue tracking_save(trackingdb t, struct trackedpackage *pkg) { - retvalue r = tracking_saveonly(t,pkg); + retvalue r = tracking_saveonly(t, pkg); trackedpackage_free(pkg); return r; } -retvalue tracking_listdistributions(struct database *db, struct strlist *distributions) { - return database_listsubtables(db, "tracking.db", distributions); +retvalue tracking_listdistributions(struct strlist *distributions) { + return database_listsubtables("tracking.db", distributions); } -retvalue tracking_drop(struct database *db, const char *codename) { +retvalue tracking_drop(const char *codename) { retvalue result, r; - result = database_dropsubtable(db, "tracking.db", codename); - r = references_remove(db, codename); + result = database_dropsubtable("tracking.db", codename); + r = references_remove(codename); RET_UPDATE(result, r); return result; } -static retvalue tracking_recreatereferences(trackingdb t, struct database *database) { +static retvalue tracking_recreatereferences(trackingdb t) { struct cursor *cursor; retvalue result, r; struct trackedpackage *pkg IFSTUPIDCC(=NULL); @@ -504,28 +523,28 @@ size_t datalen; r = table_newglobalcursor(t->table, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nextpair(t->table, cursor, - &key, &value, &data, &datalen) ) { + while (cursor_nextpair(t->table, cursor, + &key, &value, &data, &datalen)) { r = parse_data(key, value, data, datalen, &pkg); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)cursor_close(t->table, cursor); return r; } id = calc_trackreferee(t->codename, pkg->sourcename, pkg->sourceversion); - if( id == NULL ) { + if (FAILEDTOALLOC(id)) { trackedpackage_free(pkg); (void)cursor_close(t->table, cursor); return RET_ERROR_OOM; } - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { const char *filekey = pkg->filekeys.values[i]; - r = references_increment(database, filekey, id); + r = references_increment(filekey, id); RET_UPDATE(result, r); } free(id); @@ -536,25 +555,25 @@ return result; } -retvalue tracking_rereference(struct database *database, struct distribution *distribution) { +retvalue tracking_rereference(struct distribution *distribution) { retvalue result, r; trackingdb tracks; - result = references_remove(database, distribution->codename); - if( distribution->tracking == dt_NONE ) + result = references_remove(distribution->codename); + if (distribution->tracking == dt_NONE) return result; - r = tracking_initialize(&tracks, database, distribution, true); + r = tracking_initialize(&tracks, distribution, true); RET_UPDATE(result, r); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return result; - r = tracking_recreatereferences(tracks, database); + r = tracking_recreatereferences(tracks); RET_UPDATE(result, r); r = tracking_done(tracks); RET_ENDUPDATE(result, r); return result; } -retvalue tracking_remove(trackingdb t, const char *sourcename, const char *version, struct database *database) { +retvalue tracking_remove(trackingdb t, const char *sourcename, const char *version) { retvalue result, r; struct cursor *cursor; const char *data; @@ -564,30 +583,30 @@ r = table_newpairedcursor(t->table, sourcename, version, &cursor, &data, &datalen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; id = calc_trackreferee(t->codename, sourcename, version); - if( id == NULL ) { + if (FAILEDTOALLOC(id)) { (void)cursor_close(t->table, cursor); return RET_ERROR_OOM; } result = parse_data(sourcename, version, data, datalen, &pkg); - if( RET_IS_OK(r) ) { - r = references_delete(database, id, &pkg->filekeys, NULL); + if (RET_IS_OK(r)) { + r = references_delete(id, &pkg->filekeys, NULL); RET_UPDATE(result, r); trackedpackage_free(pkg); } else { RET_UPDATE(result, r); fprintf(stderr, "Could not parse data, removing all references blindly...\n"); - r = references_remove(database, id); + r = references_remove(id); RET_UPDATE(result, r); } free(id); r = cursor_delete(t->table, cursor, sourcename, version); - if( RET_IS_OK(r) ) + if (RET_IS_OK(r)) fprintf(stderr, "Removed %s_%s from %s.\n", sourcename, version, t->codename); RET_UPDATE(result, r); @@ -596,20 +615,20 @@ return result; } -static void print(const char *codename,const struct trackedpackage *pkg){ +static void print(const char *codename, const struct trackedpackage *pkg){ int i; - printf("Distribution: %s\n",codename); - printf("Source: %s\n",pkg->sourcename); - printf("Version: %s\n",pkg->sourceversion); + printf("Distribution: %s\n", codename); + printf("Source: %s\n", pkg->sourcename); + printf("Version: %s\n", pkg->sourceversion); printf("Files:\n"); - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { const char *filekey = pkg->filekeys.values[i]; - printf(" %s %c %d\n",filekey, - pkg->filetypes[i],pkg->refcounts[i]); + printf(" %s %c %d\n", filekey, + pkg->filetypes[i], pkg->refcounts[i]); } - (void)fputs("\n",stdout); + (void)fputs("\n", stdout); } retvalue tracking_printall(trackingdb t) { @@ -620,15 +639,15 @@ size_t datalen; r = table_newglobalcursor(t->table, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nextpair(t->table, cursor, - &key, &value, &data, &datalen) ) { + while (cursor_nextpair(t->table, cursor, + &key, &value, &data, &datalen)) { r = parse_data(key, value, data, datalen, &pkg); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { print(t->codename, pkg); trackedpackage_free(pkg); } @@ -639,7 +658,7 @@ return result; } -retvalue tracking_foreach_ro(struct database *db, struct distribution *d, tracking_foreach_ro_action *action) { +retvalue tracking_foreach_ro(struct distribution *d, tracking_foreach_ro_action *action) { trackingdb t; struct cursor *cursor; retvalue result, r; @@ -647,26 +666,26 @@ const char *key, *value, *data; size_t datalen; - r = tracking_initialize(&t, db, d, true); - if( !RET_IS_OK(r) ) + r = tracking_initialize(&t, d, true); + if (!RET_IS_OK(r)) return r; r = table_newglobalcursor(t->table, &cursor); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { (void)tracking_done(t); return r; } result = RET_NOTHING; - while( cursor_nextpair(t->table, cursor, - &key, &value, &data, &datalen) ) { + while (cursor_nextpair(t->table, cursor, + &key, &value, &data, &datalen)) { r = parse_data(key, value, data, datalen, &pkg); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { r = action(d, pkg); trackedpackage_free(pkg); } RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } r = cursor_close(t->table, cursor); @@ -699,31 +718,32 @@ retvalue r; int modecount; - assert( d->tracking == dt_NONE ); + assert (d->tracking == dt_NONE); memset(flags, 0, sizeof(flags)); r = config_getflags(iter, "Tracking", trackingflags, flags, IGNORABLE(unknownfield), ""); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; modecount = flags[tf_keep]?1:0 + flags[tf_minimal]?1:0 + flags[tf_all]?1:0; - if( modecount > 1 ) { + if (modecount > 1) { fprintf(stderr, "Error parsing config file %s, line %u:\n" "Only one of 'keep','all' or 'minimal' can be in one Tracking header.\n", config_filename(iter), config_line(iter)); return RET_ERROR; } - if( modecount < 1 ) { + if (modecount < 1) { fprintf(stderr, "Error parsing config file %s, line %u, column %u:\n" "Tracking mode ('keep','all' or 'minimal') expected.\n", - config_filename(iter), config_line(iter), config_column(iter)); + config_filename(iter), config_line(iter), + config_column(iter)); return RET_ERROR; } - if( flags[tf_keep] ) + if (flags[tf_keep]) d->tracking = dt_KEEP; - else if( flags[tf_minimal] ) + else if (flags[tf_minimal]) d->tracking = dt_MINIMAL; else d->tracking = dt_ALL; @@ -733,13 +753,13 @@ d->trackingoptions.includelogs = flags[tf_includelogs]; d->trackingoptions.keepsources = flags[tf_keepsources]; d->trackingoptions.needsources = flags[tf_needsources]; - if( flags[tf_needsources] ) + if (flags[tf_needsources]) fprintf(stderr, "Warning parsing config file %s, line %u:\n" "'needsources' ignored as not yet supported.\n", config_filename(iter), config_line(iter)); d->trackingoptions.embargoalls = flags[tf_embargoalls]; - if( flags[tf_embargoalls] ) + if (flags[tf_embargoalls]) fprintf(stderr, "Warning parsing config file %s, line %u:\n" "'embargoall' ignored as not yet supported.\n", @@ -747,11 +767,11 @@ return RET_OK; } -static retvalue trackingdata_remember(struct trackingdata *td,/*@only@*/char*name,/*@only@*/char*version) { +static retvalue trackingdata_remember(struct trackingdata *td, /*@only@*/char*name, /*@only@*/char*version) { struct trackingdata_remember *r; - r = malloc(sizeof(*r)); - if( r == NULL ) + r = NEW(struct trackingdata_remember); + if (FAILEDTOALLOC(r)) return RET_ERROR_OOM; r->name = name; r->version = version; @@ -760,13 +780,13 @@ return RET_OK; } -retvalue trackingdata_summon(trackingdb tracks,const char *name,const char *version,struct trackingdata *data) { +retvalue trackingdata_summon(trackingdb tracks, const char *name, const char *version, struct trackingdata *data) { struct trackedpackage *pkg; retvalue r; - r = tracking_getornew(tracks,name,version,&pkg); - assert( r != RET_NOTHING ); - if( RET_IS_OK(r) ) { + r = tracking_getornew(tracks, name, version, &pkg); + assert (r != RET_NOTHING); + if (RET_IS_OK(r)) { data->tracks = tracks; data->pkg = pkg; data->remembered = NULL; @@ -775,7 +795,7 @@ return r; } -retvalue trackingdata_new(trackingdb tracks,struct trackingdata *data) { +retvalue trackingdata_new(trackingdb tracks, struct trackingdata *data) { data->tracks = tracks; data->pkg = NULL; @@ -786,12 +806,12 @@ retvalue trackingdata_switch(struct trackingdata *data, const char *source, const char *version) { retvalue r; - if( data->pkg != NULL ) { - if( strcmp(data->pkg->sourcename, source) == 0 && - strcmp(data->pkg->sourceversion, version) == 0 ) + if (data->pkg != NULL) { + if (strcmp(data->pkg->sourcename, source) == 0 && + strcmp(data->pkg->sourceversion, version) == 0) return RET_OK; r = tracking_saveonly(data->tracks, data->pkg); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; r = trackingdata_remember(data, data->pkg->sourcename, data->pkg->sourceversion); @@ -800,21 +820,21 @@ free(data->pkg->filetypes); free(data->pkg); data->pkg = NULL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } r = tracking_getornew(data->tracks, source, version, &data->pkg); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) return r; return RET_OK; } -retvalue trackingdata_insert(struct trackingdata *data,enum filetype filetype,const struct strlist *filekeys,/*@null@*//*@only@*/char*oldsource,/*@null@*//*@only@*/char*oldversion,/*@null@*/const struct strlist *oldfilekeys,struct database *database) { - retvalue result,r; +retvalue trackingdata_insert(struct trackingdata *data, enum filetype filetype, const struct strlist *filekeys, /*@null@*//*@only@*/char*oldsource, /*@null@*//*@only@*/char*oldversion, /*@null@*/const struct strlist *oldfilekeys) { + retvalue result, r; struct trackedpackage *pkg; - if( data == NULL) { + if (data == NULL) { assert(oldversion == NULL && oldsource == NULL); free(oldversion); free(oldsource); @@ -822,71 +842,77 @@ } assert(data->pkg != NULL); result = trackedpackage_adddupfilekeys(data->tracks, data->pkg, - filetype, filekeys, true, database); - if( RET_WAS_ERROR(result) ) { - free(oldsource);free(oldversion); + filetype, filekeys, true); + if (RET_WAS_ERROR(result)) { + free(oldsource); free(oldversion); return result; } - if( oldsource == NULL || oldversion == NULL || oldfilekeys == NULL ) { + if (oldsource == NULL || oldversion == NULL || oldfilekeys == NULL) { assert(oldsource==NULL&&oldversion==NULL&&oldfilekeys==NULL); return RET_OK; } - if( strcmp(oldversion,data->pkg->sourceversion) == 0 && - strcmp(oldsource,data->pkg->sourcename) == 0 ) { + if (strcmp(oldversion, data->pkg->sourceversion) == 0 && + strcmp(oldsource, data->pkg->sourcename) == 0) { /* Unlikely, but it may also be the same source version as * the package we are currently adding */ - free(oldsource);free(oldversion); - return trackedpackage_removefilekeys(data->tracks,data->pkg,oldfilekeys); - } - r = tracking_get(data->tracks,oldsource,oldversion,&pkg); - if( RET_WAS_ERROR(r) ) { - free(oldsource);free(oldversion); + free(oldsource); free(oldversion); + return trackedpackage_removefilekeys(data->tracks, data->pkg, + oldfilekeys); + } + r = tracking_get(data->tracks, oldsource, oldversion, &pkg); + if (RET_WAS_ERROR(r)) { + free(oldsource); free(oldversion); return r; } - if( r == RET_NOTHING) { - fprintf(stderr,"Could not found tracking data for %s_%s in %s to remove old files from it.\n",oldsource,oldversion,data->tracks->codename); - free(oldsource);free(oldversion); + if (r == RET_NOTHING) { + fprintf(stderr, +"Could not found tracking data for %s_%s in %s to remove old files from it.\n", + oldsource, oldversion, data->tracks->codename); + free(oldsource); free(oldversion); return result; } - r = trackedpackage_removefilekeys(data->tracks,pkg,oldfilekeys); - RET_UPDATE(result,r); - r = tracking_save(data->tracks,pkg); - RET_UPDATE(result,r); - r = trackingdata_remember(data,oldsource,oldversion); - RET_UPDATE(result,r); + r = trackedpackage_removefilekeys(data->tracks, pkg, oldfilekeys); + RET_UPDATE(result, r); + r = tracking_save(data->tracks, pkg); + RET_UPDATE(result, r); + r = trackingdata_remember(data, oldsource, oldversion); + RET_UPDATE(result, r); return result; } -retvalue trackingdata_remove(struct trackingdata *data,/*@only@*/char*oldsource,/*@only@*/char*oldversion,const struct strlist *oldfilekeys) { - retvalue result,r; +retvalue trackingdata_remove(struct trackingdata *data, /*@only@*/char*oldsource, /*@only@*/char*oldversion, const struct strlist *oldfilekeys) { + retvalue result, r; struct trackedpackage *pkg; assert(oldsource != NULL && oldversion != NULL && oldfilekeys != NULL); - if( data->pkg != NULL && - strcmp(oldversion,data->pkg->sourceversion) == 0 && - strcmp(oldsource,data->pkg->sourcename) == 0 ) { + if (data->pkg != NULL && + strcmp(oldversion, data->pkg->sourceversion) == 0 && + strcmp(oldsource, data->pkg->sourcename) == 0) { /* Unlikely, but it may also be the same source version as * the package we are currently adding */ - free(oldsource);free(oldversion); - return trackedpackage_removefilekeys(data->tracks,data->pkg,oldfilekeys); - } - result = tracking_get(data->tracks,oldsource,oldversion,&pkg); - if( RET_WAS_ERROR(result) ) { - free(oldsource);free(oldversion); + free(oldsource); free(oldversion); + return trackedpackage_removefilekeys(data->tracks, + data->pkg, oldfilekeys); + } + result = tracking_get(data->tracks, oldsource, oldversion, &pkg); + if (RET_WAS_ERROR(result)) { + free(oldsource); free(oldversion); return result; } - if( result == RET_NOTHING) { - fprintf(stderr,"Could not found tracking data for %s_%s in %s to remove old files from it.\n",oldsource,oldversion,data->tracks->codename); - free(oldsource);free(oldversion); + if (result == RET_NOTHING) { + fprintf(stderr, +"Could not found tracking data for %s_%s in %s to remove old files from it.\n", + oldsource, oldversion, data->tracks->codename); + free(oldsource); free(oldversion); return RET_OK; } - r = trackedpackage_removefilekeys(data->tracks,pkg,oldfilekeys); - RET_UPDATE(result,r); - r = tracking_save(data->tracks,pkg); - RET_UPDATE(result,r); - r = trackingdata_remember(data,oldsource,oldversion); - RET_UPDATE(result,r); + r = trackedpackage_removefilekeys(data->tracks, pkg, oldfilekeys); + RET_UPDATE(result, r); + r = tracking_save(data->tracks, pkg); + RET_UPDATE(result, r); + r = trackingdata_remember(data, oldsource, oldversion); + RET_UPDATE(result, r); return result; } @@ -895,7 +921,7 @@ trackedpackage_free(d->pkg); d->pkg = NULL; d->tracks = NULL; - while( d->remembered != NULL ) { + while (d->remembered != NULL) { struct trackingdata_remember *h = d->remembered; d->remembered = h->next; free(h->name); @@ -905,53 +931,55 @@ } -static inline retvalue trackedpackage_removeall(trackingdb tracks, struct trackedpackage *pkg, struct database *database) { - retvalue result = RET_OK,r; +static inline retvalue trackedpackage_removeall(trackingdb tracks, struct trackedpackage *pkg) { + retvalue result = RET_OK, r; char *id; -// printf("[trackedpackage_removeall %s %s %s]\n",tracks->codename,pkg->sourcename,pkg->sourceversion); - id = calc_trackreferee(tracks->codename, pkg->sourcename, pkg->sourceversion); - if( id == NULL ) +// printf("[trackedpackage_removeall %s %s %s]\n", tracks->codename, pkg->sourcename, pkg->sourceversion); + id = calc_trackreferee(tracks->codename, pkg->sourcename, + pkg->sourceversion); + if (FAILEDTOALLOC(id)) return RET_ERROR_OOM; pkg->flags.deleted = true; - r = references_delete(database, id, &pkg->filekeys, NULL); + r = references_delete(id, &pkg->filekeys, NULL); + RET_UPDATE(result, r); free(id); strlist_done(&pkg->filekeys); strlist_init(&pkg->filekeys); - free(pkg->refcounts);pkg->refcounts = NULL; + free(pkg->refcounts); pkg->refcounts = NULL; return result; } static inline bool tracking_needed(trackingdb tracks, struct trackedpackage *pkg, int ofs) { - if( pkg->refcounts[ofs] > 0 ) + if (pkg->refcounts[ofs] > 0) return true; // TODO: add checks so that only .changes and .log files belonging // to still existing binaries are kept in minimal mode - if( pkg->filetypes[ofs] == ft_LOG && tracks->options.includelogs ) + if (pkg->filetypes[ofs] == ft_LOG && tracks->options.includelogs) return true; - if( pkg->filetypes[ofs] == ft_CHANGES && tracks->options.includechanges ) + if (pkg->filetypes[ofs] == ft_CHANGES && tracks->options.includechanges) return true; - if( pkg->filetypes[ofs] == ft_XTRA_DATA ) + if (pkg->filetypes[ofs] == ft_XTRA_DATA) return true; - if( pkg->filetypes[ofs] == ft_SOURCE && tracks->options.keepsources ) + if (pkg->filetypes[ofs] == ft_SOURCE && tracks->options.keepsources) return true; return false; } -static inline retvalue trackedpackage_removeunneeded(trackingdb tracks, struct trackedpackage *pkg, struct database *database) { - retvalue result = RET_OK,r; +static inline retvalue trackedpackage_removeunneeded(trackingdb tracks, struct trackedpackage *pkg) { + retvalue result = RET_OK, r; char *id = NULL; - int i,j, count; + int i, j, count; assert(tracks->type == dt_MINIMAL); count = pkg->filekeys.count; j = 0; - for( i = 0 ; i < count ; i++ ) { - if( tracking_needed(tracks, pkg, i) ) { - if( j < i ) { + for (i = 0 ; i < count ; i++) { + if (tracking_needed(tracks, pkg, i)) { + if (j < i) { pkg->filekeys.values[j] = pkg->filekeys.values[i]; pkg->refcounts[j] = pkg->refcounts[i]; pkg->filetypes[j] = pkg->filetypes[i]; @@ -960,60 +988,60 @@ } else { char *filekey = pkg->filekeys.values[i]; pkg->filekeys.values[i] = NULL; - if( id == NULL ) { + if (FAILEDTOALLOC(id)) { id = calc_trackreferee(tracks->codename, pkg->sourcename, pkg->sourceversion); - if( id == NULL ) + if (id == NULL) result = RET_ERROR_OOM; } - if( id != NULL ) { -// printf("[trackedpackage_removeunneeded %s %s %s: '%s']\n",tracks->codename,pkg->sourcename,pkg->sourceversion, filekey); - r = references_decrement(database, filekey, id); - RET_UPDATE(result,r); + if (id != NULL) { +// printf("[trackedpackage_removeunneeded %s %s %s: '%s']\n", tracks->codename, pkg->sourcename, pkg->sourceversion, filekey); + r = references_decrement(filekey, id); + RET_UPDATE(result, r); } free(filekey); } } - assert( j <= pkg->filekeys.count ); + assert (j <= pkg->filekeys.count); pkg->filekeys.count = j; free(id); return result; } -static inline retvalue trackedpackage_tidy(trackingdb tracks, struct trackedpackage *pkg, struct database *database) { +static inline retvalue trackedpackage_tidy(trackingdb tracks, struct trackedpackage *pkg) { int i; - if( tracks->type == dt_KEEP ) + if (tracks->type == dt_KEEP) return RET_OK; /* look if anything clings to this package */ - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { - if( pkg->refcounts[i] > 0 ) + for (i = 0 ; i < pkg->filekeys.count ; i++) { + if (pkg->refcounts[i] > 0) break; } - if( i >= pkg->filekeys.count ) + if (i >= pkg->filekeys.count) /* nothing left, remove it all */ - return trackedpackage_removeall(tracks, pkg, database); + return trackedpackage_removeall(tracks, pkg); - else if( tracks->type == dt_MINIMAL ) + else if (tracks->type == dt_MINIMAL) /* remove all files no longer needed */ - return trackedpackage_removeunneeded(tracks, pkg, database); + return trackedpackage_removeunneeded(tracks, pkg); else return RET_OK; } -retvalue trackingdata_finish(trackingdb tracks, struct trackingdata *d, struct database *database) { +retvalue trackingdata_finish(trackingdb tracks, struct trackingdata *d) { retvalue r; - assert( d->tracks == tracks ); - if( d->pkg != NULL ) { - r = trackedpackage_tidy(tracks, d->pkg, database); + assert (d->tracks == tracks); + if (d->pkg != NULL) { + r = trackedpackage_tidy(tracks, d->pkg); r = tracking_save(tracks, d->pkg); } else r = RET_OK; d->pkg = NULL; /* call for all remembered actions... */ - while( d->remembered != NULL ) { + while (d->remembered != NULL) { struct trackingdata_remember *h = d->remembered; struct trackedpackage *pkg; d->remembered = h->next; @@ -1021,8 +1049,8 @@ free(h->name); free(h->version); free(h); - if( RET_IS_OK(r) ) { - r = trackedpackage_tidy(tracks, pkg, database); + if (RET_IS_OK(r)) { + r = trackedpackage_tidy(tracks, pkg); r = tracking_save(tracks, pkg); } } @@ -1031,7 +1059,7 @@ } -retvalue tracking_tidyall(trackingdb t, struct database *database) { +retvalue tracking_tidyall(trackingdb t) { struct cursor *cursor; retvalue result, r; struct trackedpackage *pkg IFSTUPIDCC(=NULL); @@ -1039,19 +1067,19 @@ size_t datalen; r = table_newglobalcursor(t->table, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nextpair(t->table, cursor, - &key, &value, &data, &datalen) ) { + while (cursor_nextpair(t->table, cursor, + &key, &value, &data, &datalen)) { r = parse_data(key, value, data, datalen, &pkg); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - r = trackedpackage_tidy(t, pkg, database); + r = trackedpackage_tidy(t, pkg); RET_UPDATE(result, r); r = tracking_saveatcursor(t, cursor, pkg); RET_UPDATE(result, r); @@ -1072,28 +1100,28 @@ int i; r = table_newglobalcursor(t->table, &cursor); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; - while( cursor_nextpair(t->table, cursor, - &key, &value, &data, &datalen) ) { + while (cursor_nextpair(t->table, cursor, + &key, &value, &data, &datalen)) { // this would perhaps be more stable if it just replaced // everything within the string just received... result = parse_data(key, value, data, datalen, &pkg); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; - for( i = 0 ; i < pkg->filekeys.count ; i++ ) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { pkg->refcounts[i] = 0; } result = gen_data(pkg, &newdata, &newdatalen); trackedpackage_free(pkg); - if( RET_IS_OK(result) ) + if (RET_IS_OK(result)) result = cursor_replace(t->table, cursor, newdata, newdatalen); free(newdata); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) break; } r = cursor_close(t->table, cursor); @@ -1101,7 +1129,7 @@ return result; } -static retvalue tracking_foreachversion(trackingdb t, struct database *db, struct distribution *distribution, const char *sourcename, retvalue (action)(trackingdb t,struct trackedpackage *,struct database *,struct distribution *)) { +static retvalue tracking_foreachversion(trackingdb t, struct distribution *distribution, const char *sourcename, retvalue (action)(trackingdb t, struct trackedpackage *, struct distribution *)) { struct cursor *cursor; retvalue result, r; struct trackedpackage *pkg IFSTUPIDCC(=NULL); @@ -1110,113 +1138,116 @@ r = table_newduplicatecursor(t->table, sourcename, &cursor, &value, &data, &datalen); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; do { r = parse_data(sourcename, value, data, datalen, &pkg); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - if( verbose > 10 ) + if (verbose > 10) printf("Processing track of '%s' version '%s'\n", pkg->sourcename, pkg->sourceversion); - r = action(t, pkg, db, distribution); + r = action(t, pkg, distribution); RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)cursor_close(t->table, cursor); trackedpackage_free(pkg); return r; } - r = trackedpackage_tidy(t, pkg, db); + r = trackedpackage_tidy(t, pkg); RET_ENDUPDATE(result, r); r = tracking_saveatcursor(t, cursor, pkg); RET_UPDATE(result, r); trackedpackage_free(pkg); - } while( cursor_nextpair(t->table, cursor, NULL, - &value, &data, &datalen) ); + } while (cursor_nextpair(t->table, cursor, NULL, + &value, &data, &datalen)); r = cursor_close(t->table, cursor); RET_UPDATE(result, r); return result; } -static retvalue targetremovesourcepackage(trackingdb t, struct trackedpackage *pkg, struct database *database, struct distribution *distribution, struct target *target) { +static retvalue targetremovesourcepackage(trackingdb t, struct trackedpackage *pkg, struct distribution *distribution, struct target *target) { size_t component_len, arch_len; retvalue result, r; int i; + const char *packagetype = atoms_packagetypes[target->packagetype]; + const char *architecture = atoms_architectures[target->architecture]; + const char *component = atoms_components[target->component]; result = RET_NOTHING; - component_len = strlen(atoms_components[target->component_atom]); - arch_len = strlen(atoms_architectures[target->architecture_atom]); - for( i = 0 ; i < pkg->filekeys.count ; i++) { + component_len = strlen(component); + arch_len = strlen(architecture); + for (i = 0 ; i < pkg->filekeys.count ; i++) { const char *s, *basefilename, *filekey = pkg->filekeys.values[i]; char *package, *control, *source, *version; struct strlist filekeys; bool savedstaletracking; - if( pkg->refcounts[i] <= 0 ) + if (pkg->refcounts[i] <= 0) continue; - if( strncmp(filekey, "pool/", 5) != 0 ) + if (strncmp(filekey, "pool/", 5) != 0) continue; - if( strncmp(filekey+5, atoms_components[target->component_atom], - component_len) != 0 ) + if (strncmp(filekey+5, component, + component_len) != 0) continue; - if( filekey[5+component_len] != '/' ) + if (filekey[5+component_len] != '/') continue; /* check this file could actuall be in this target */ - if( pkg->filetypes[i] == ft_ALL_BINARY ) { - if( target->packagetype_atom == pt_dsc ) + if (pkg->filetypes[i] == ft_ALL_BINARY) { + if (target->packagetype == pt_dsc) continue; s = strrchr(filekey, '.'); - if( s == NULL ) + if (s == NULL) continue; - if( strcmp(s+1, atoms_packagetypes[target->packagetype_atom]) != 0) + if (strcmp(s+1, packagetype) != 0) continue; - } else if( pkg->filetypes[i] == ft_SOURCE ) { - if( target->packagetype_atom != pt_dsc ) + } else if (pkg->filetypes[i] == ft_SOURCE) { + if (target->packagetype != pt_dsc) continue; s = strrchr(filekey, '.'); - if( s == NULL ) + if (s == NULL) continue; - if( strcmp(s+1, "dsc") != 0) + if (strcmp(s+1, "dsc") != 0) continue; - } else if( pkg->filetypes[i] == ft_ARCH_BINARY ) { - if( target->packagetype_atom == pt_dsc ) + } else if (pkg->filetypes[i] == ft_ARCH_BINARY) { + if (target->packagetype == pt_dsc) continue; s = strrchr(filekey, '_'); - if( s == NULL ) + if (s == NULL) continue; s++; - if( strncmp(s, atoms_architectures[target->architecture_atom], arch_len) != 0 + if (strncmp(s, architecture, arch_len) != 0 || s[arch_len] != '.' - || strcmp(s+arch_len+1, atoms_packagetypes[target->packagetype_atom]) != 0) + || strcmp(s+arch_len+1, packagetype) != 0) continue; } else continue; /* get this package, check it has the right source and version, * and if yes, remove... */ basefilename = strrchr(filekey, '/'); - if( basefilename == NULL ) + if (basefilename == NULL) basefilename = filekey; else basefilename++; s = strchr(basefilename, '_'); package = strndup(basefilename, s - basefilename); - if( package == NULL ) - return RET_ERROR_OOM; + if (FAILEDTOALLOC(package)) + return RET_ERROR_OOM; r = table_getrecord(target->packages, package, &control); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(package); return r; } - if( r == RET_NOTHING ) { - if( pkg->filetypes[i] != ft_ALL_BINARY - && verbose >= -1 ) { + if (r == RET_NOTHING) { + if (pkg->filetypes[i] != ft_ALL_BINARY + && verbose >= -1) { fprintf(stderr, "Warning: tracking data might be incosistent:\n" "cannot find '%s' in '%s', but '%s' should be there.\n", @@ -1228,15 +1259,15 @@ } r = target->getsourceandversion(control, package, &source, &version); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(package); free(control); return r; } - if( strcmp(source, pkg->sourcename) != 0 ) { - if( pkg->filetypes[i] != ft_ALL_BINARY - && verbose >= -1 ) { + if (strcmp(source, pkg->sourcename) != 0) { + if (pkg->filetypes[i] != ft_ALL_BINARY + && verbose >= -1) { fprintf(stderr, "Warning: tracking data might be incosistent:\n" "'%s' has '%s' of source '%s', but source '%s' contains '%s'.\n", @@ -1251,9 +1282,9 @@ continue; } free(source); - if( strcmp(version, pkg->sourceversion) != 0 ) { - if( pkg->filetypes[i] != ft_ALL_BINARY - && verbose >= -1 ) { + if (strcmp(version, pkg->sourceversion) != 0) { + if (pkg->filetypes[i] != ft_ALL_BINARY + && verbose >= -1) { fprintf(stderr, "Warning: tracking data might be incosistent:\n" "'%s' has '%s' of source version '%s', but version '%s' contains '%s'.\n", @@ -1268,8 +1299,8 @@ } free(version); r = target->getfilekeys(control, &filekeys); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { free(package); free(control); return r; @@ -1283,12 +1314,12 @@ /* that is a bit wasteful, as it parses some stuff again, but * but that is better than reimplementing logger here */ r = target_removereadpackage(target, distribution->logger, - database, package, control, NULL); + package, control, NULL); target->staletracking = savedstaletracking; free(control); free(package); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { strlist_done(&filekeys); return r; } @@ -1300,35 +1331,36 @@ } /* Try to remove all packages causing refcounts in this tracking record */ -static retvalue removesourcepackage(trackingdb t, struct trackedpackage *pkg, struct database *database, struct distribution *distribution) { +static retvalue removesourcepackage(trackingdb t, struct trackedpackage *pkg, struct distribution *distribution) { struct target *target; retvalue result, r; int i; result = RET_NOTHING; - for( target = distribution->targets ; target != NULL ; target = target->next ) { - r = target_initpackagesdb(target, database, READWRITE); + for (target = distribution->targets ; target != NULL ; + target = target->next) { + r = target_initpackagesdb(target, READWRITE); RET_ENDUPDATE(result, r); - if( RET_IS_OK(r) ) { - r = targetremovesourcepackage(t, pkg, database, + if (RET_IS_OK(r)) { + r = targetremovesourcepackage(t, pkg, distribution, target); RET_UPDATE(result, r); RET_UPDATE(distribution->status, r); r = target_closepackagesdb(target); RET_ENDUPDATE(result, r); RET_ENDUPDATE(distribution->status, r); - if( RET_WAS_ERROR(result) ) + if (RET_WAS_ERROR(result)) return result; } } - for( i = 0 ; i < pkg->filekeys.count ; i++) { + for (i = 0 ; i < pkg->filekeys.count ; i++) { const char *filekey = pkg->filekeys.values[i]; - if( pkg->refcounts[i] <= 0 ) + if (pkg->refcounts[i] <= 0) continue; - if( pkg->filetypes[i] != ft_ALL_BINARY && + if (pkg->filetypes[i] != ft_ALL_BINARY && pkg->filetypes[i] != ft_SOURCE && - pkg->filetypes[i] != ft_ARCH_BINARY ) + pkg->filetypes[i] != ft_ARCH_BINARY) continue; fprintf(stderr, "There was an inconsistency in the tracking data of '%s':\n" @@ -1340,18 +1372,18 @@ return result; } -retvalue tracking_removepackages(trackingdb t, struct database *database, struct distribution *distribution, const char *sourcename, /*@null@*/const char *version) { +retvalue tracking_removepackages(trackingdb t, struct distribution *distribution, const char *sourcename, /*@null@*/const char *version) { struct trackedpackage *pkg; retvalue result, r; - if( version == NULL ) - return tracking_foreachversion(t, database, distribution, + if (version == NULL) + return tracking_foreachversion(t, distribution, sourcename, removesourcepackage); result = tracking_get(t, sourcename, version, &pkg); - if( RET_IS_OK(result) ) { - result = removesourcepackage(t, pkg, database, distribution); - if( RET_IS_OK(result) ) { - r = trackedpackage_tidy(t, pkg, database); + if (RET_IS_OK(result)) { + result = removesourcepackage(t, pkg, distribution); + if (RET_IS_OK(result)) { + r = trackedpackage_tidy(t, pkg); RET_ENDUPDATE(result, r); r = tracking_save(t, pkg); RET_ENDUPDATE(result, r); @@ -1361,50 +1393,49 @@ return result; } -static retvalue package_retrack(struct database *database, UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *controlchunk, void *data) { +static retvalue package_retrack(UNUSED(struct distribution *di), struct target *target, const char *packagename, const char *controlchunk, void *data) { trackingdb tracks = data; - return target->doretrack(packagename, controlchunk, - tracks, database); + return target->doretrack(packagename, controlchunk, tracks); } -retvalue tracking_retrack(struct database *database, struct distribution *d, bool needsretrack) { +retvalue tracking_retrack(struct distribution *d, bool needsretrack) { struct target *t; trackingdb tracks; retvalue r, rr; - if( d->tracking == dt_NONE ) + if (d->tracking == dt_NONE) return RET_NOTHING; - for( t = d->targets ; !needsretrack && t != NULL ; t = t->next ) { - if( t->staletracking ) + for (t = d->targets ; !needsretrack && t != NULL ; t = t->next) { + if (t->staletracking) needsretrack = true; } - if( !needsretrack ) + if (!needsretrack) return RET_NOTHING; - if( verbose > 0 ) + if (verbose > 0) printf("Retracking %s...\n", d->codename); - r = tracking_initialize(&tracks, database, d, false); - if( !RET_IS_OK(r) ) + r = tracking_initialize(&tracks, d, false); + if (!RET_IS_OK(r)) return r; /* first forget that any package is there*/ r = tracking_reset(tracks); - if( !RET_WAS_ERROR(r) ) { + if (!RET_WAS_ERROR(r)) { /* add back information about actually used files */ - r = distribution_foreach_package(d, database, + r = distribution_foreach_package(d, atom_unknown, atom_unknown, atom_unknown, package_retrack, NULL, tracks); } - if( RET_IS_OK(r) ) { - for( t = d->targets ; t != NULL ; t = t->next ) { + if (RET_IS_OK(r)) { + for (t = d->targets ; t != NULL ; t = t->next) { t->staletracking = false; } } - if( !RET_WAS_ERROR(r) ) { + if (!RET_WAS_ERROR(r)) { /* now remove everything no longer needed */ - r = tracking_tidyall(tracks, database); + r = tracking_tidyall(tracks); } rr = tracking_done(tracks); RET_ENDUPDATE(r, rr); diff -Nru reprepro-4.5.0/tracking.h reprepro-4.6.0/tracking.h --- reprepro-4.5.0/tracking.h 2009-08-24 13:35:08.000000000 +0000 +++ reprepro-4.6.0/tracking.h 2011-05-05 14:42:55.000000000 +0000 @@ -15,38 +15,38 @@ retvalue tracking_parse(struct distribution *, struct configiterator *); /* high-level retrack of the whole distribution */ -retvalue tracking_retrack(struct database *, struct distribution *, bool /*evenifnotstale*/); +retvalue tracking_retrack(struct distribution *, bool /*evenifnotstale*/); -retvalue tracking_initialize(/*@out@*/trackingdb *, struct database *, const struct distribution *, bool readonly); +retvalue tracking_initialize(/*@out@*/trackingdb *, const struct distribution *, bool readonly); retvalue tracking_done(trackingdb); -retvalue tracking_listdistributions(struct database *, /*@out@*/struct strlist *); -retvalue tracking_drop(struct database *, const char *); +retvalue tracking_listdistributions(/*@out@*/struct strlist *); +retvalue tracking_drop(const char *); retvalue tracking_reset(trackingdb); -retvalue tracking_rereference(struct database *, struct distribution *); +retvalue tracking_rereference(struct distribution *); -retvalue trackedpackage_addfilekey(trackingdb, struct trackedpackage *, enum filetype, /*@only@*/char *filekey, bool used, struct database *); -retvalue trackedpackage_adddupfilekeys(trackingdb, struct trackedpackage *, enum filetype, const struct strlist *filekeys, bool used, struct database *); -retvalue trackedpackage_removefilekeys(trackingdb,struct trackedpackage *,const struct strlist *); -void trackedpackage_free(struct trackedpackage *pkg); - -retvalue tracking_get(trackingdb, const char *sourcename, const char *version, /*@out@*/struct trackedpackage **); -retvalue tracking_getornew(trackingdb,const char *name,const char *version,/*@out@*/struct trackedpackage **); -retvalue tracking_save(trackingdb,/*@only@*/struct trackedpackage *); -retvalue tracking_remove(trackingdb, const char *sourcename, const char *version, struct database *); -retvalue tracking_printall(trackingdb t); +retvalue trackedpackage_addfilekey(trackingdb, struct trackedpackage *, enum filetype, /*@only@*/char * /*filekey*/, bool /*used*/); +retvalue trackedpackage_adddupfilekeys(trackingdb, struct trackedpackage *, enum filetype, const struct strlist * /*filekeys*/, bool /*used*/); +retvalue trackedpackage_removefilekeys(trackingdb, struct trackedpackage *, const struct strlist *); +void trackedpackage_free(struct trackedpackage *); + +retvalue tracking_get(trackingdb, const char * /*sourcename*/, const char * /*version*/, /*@out@*/struct trackedpackage **); +retvalue tracking_getornew(trackingdb, const char * /*name*/, const char * /*version*/, /*@out@*/struct trackedpackage **); +retvalue tracking_save(trackingdb, /*@only@*/struct trackedpackage *); +retvalue tracking_remove(trackingdb, const char * /*sourcename*/, const char * /*version*/); +retvalue tracking_printall(trackingdb); -retvalue trackingdata_summon(trackingdb,const char *,const char *,struct trackingdata *); -retvalue trackingdata_new(trackingdb,struct trackingdata *); +retvalue trackingdata_summon(trackingdb, const char *, const char *, struct trackingdata *); +retvalue trackingdata_new(trackingdb, struct trackingdata *); retvalue trackingdata_switch(struct trackingdata *, const char *, const char *); -retvalue trackingdata_insert(struct trackingdata *,enum filetype,const struct strlist *filekeys,/*@null@*//*@only@*/char *oldsource,/*@null@*//*@only@*/char *oldversion,/*@null@*/const struct strlist *oldfilekeys,struct database *); -retvalue trackingdata_remove(struct trackingdata *,/*@only@*/char *oldsource,/*@only@*/char *oldversion,const struct strlist *filekeys); +retvalue trackingdata_insert(struct trackingdata *, enum filetype, const struct strlist * /*filekeys*/, /*@null@*//*@only@*/char * /*oldsource*/, /*@null@*//*@only@*/char * /*oldversion*/, /*@null@*/const struct strlist * /*oldfilekeys*/); +retvalue trackingdata_remove(struct trackingdata *, /*@only@*/char */*oldsource*/, /*@only@*/char * /*oldversion*/, const struct strlist * /*filekeys*/); void trackingdata_done(struct trackingdata *); /* like _done but actually do something */ -retvalue trackingdata_finish(trackingdb tracks, struct trackingdata *, struct database *); +retvalue trackingdata_finish(trackingdb, struct trackingdata *); /* look at all listed packages and remove everything not needed */ -retvalue tracking_tidyall(trackingdb, struct database *); +retvalue tracking_tidyall(trackingdb); -retvalue tracking_removepackages(trackingdb, struct database *, struct distribution *, const char *sourcename, /*@null@*/const char *version); +retvalue tracking_removepackages(trackingdb, struct distribution *, const char * /*sourcename*/, /*@null@*/const char * /*version*/); #endif /*REPREPRO_TRACKING_H*/ diff -Nru reprepro-4.5.0/trackingt.h reprepro-4.6.0/trackingt.h --- reprepro-4.5.0/trackingt.h 2010-10-24 08:59:11.000000000 +0000 +++ reprepro-4.6.0/trackingt.h 2011-05-05 14:42:55.000000000 +0000 @@ -32,7 +32,6 @@ }; struct distribution; -struct database; typedef retvalue tracking_foreach_ro_action(struct distribution *, const struct trackedpackage *); -retvalue tracking_foreach_ro(struct database *, struct distribution *, tracking_foreach_ro_action *); +retvalue tracking_foreach_ro(struct distribution *, tracking_foreach_ro_action *); #endif /*REPREPRO_TRACKINGT_H*/ diff -Nru reprepro-4.5.0/uncompression.c reprepro-4.6.0/uncompression.c --- reprepro-4.5.0/uncompression.c 2010-10-24 08:59:11.000000000 +0000 +++ reprepro-4.6.0/uncompression.c 2011-05-05 14:42:55.000000000 +0000 @@ -75,24 +75,24 @@ pid_t pid; pid = fork(); - if( pid < 0 ) { + if (pid < 0) { e = errno; fprintf(stderr, "Error %d forking: %s\n", e, strerror(e)); (void)close(stdinfd); (void)close(stdoutfd); return RET_ERRNO(e); } - if( pid == 0 ) { + if (pid == 0) { /* setup child */ i = dup2(stdoutfd, 1); - if( i < 0 ) { + if (i < 0) { e = errno; fprintf(stderr, "Error %d in dup(%d, 1): %s\n", e, stdoutfd, strerror(e)); raise(SIGUSR2); } i = dup2(stdinfd, 0); - if( i < 0 ) { + if (i < 0) { e = errno; fprintf(stderr, "Error %d in dup(%d, 0): %s\n", e, stdinfd, strerror(e)); @@ -118,7 +118,7 @@ retvalue r; i = pipe(filedes); - if( i < 0 ) { + if (i < 0) { e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); (void)close(fd); @@ -126,7 +126,7 @@ } markcloseonexec(filedes[0]); r = startchild(c, fd, filedes[1], pid_p); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) (void)close(filedes[0]); else *pipefd = filedes[0]; @@ -138,14 +138,14 @@ retvalue r; i = pipe(infiledes); - if( i < 0 ) { + if (i < 0) { e = errno; fprintf(stderr, "Error %d creating pipe: %s\n", e, strerror(e)); return RET_ERRNO(e); } markcloseonexec(infiledes[1]); r = startpipeoutchild(c, infiledes[0], outfd, pid_p); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) (void)close(infiledes[1]); else *infd = infiledes[1]; @@ -157,28 +157,28 @@ int running_count = 0; int e, stdinfd, stdoutfd; - for( t = tasks ; t != NULL ; t = t->next ) { - if( t->pid > 0 ) + for (t = tasks ; t != NULL ; t = t->next) { + if (t->pid > 0) running_count++; } // TODO: make the maximum number configurable, // until that 1 is the best guess... - if( running_count >= 1 ) + if (running_count >= 1) return; t = tasks; - while( t != NULL && t->pid > 0 ) + while (t != NULL && t->pid > 0) t = t->next; - if( t == NULL ) + if (t == NULL) /* nothing to do... */ return; - if( verbose > 1 ) { + if (verbose > 1) { fprintf(stderr, "Uncompress '%s' into '%s' using '%s'...\n", t->compressedfilename, t->uncompressedfilename, extern_uncompressors[t->compression]); } stdinfd = open(t->compressedfilename, O_RDONLY|O_NOCTTY); - if( stdinfd < 0 ) { + if (stdinfd < 0) { e = errno; fprintf(stderr, "Error %d opening %s: %s\n", e, t->compressedfilename, @@ -187,7 +187,7 @@ } stdoutfd = open(t->uncompressedfilename, O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, 0666); - if( stdoutfd < 0 ) { + if (stdoutfd < 0) { close(stdinfd); e = errno; fprintf(stderr, "Error %d creating %s: %s\n", @@ -207,26 +207,27 @@ retvalue r; bool error = false; - if( pid <= 0 ) + if (pid <= 0) return RET_NOTHING; t_p = &tasks; - while( (t = (*t_p)) != NULL && t->pid != pid ) + while ((t = (*t_p)) != NULL && t->pid != pid) t_p = &t->next; - if( t == NULL ) { + if (t == NULL) { /* not one we started */ return RET_NOTHING; } - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) != 0 ) { - fprintf(stderr, "'%s' < %s > %s exited with errorcode %d!\n", + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) { + fprintf(stderr, +"'%s' < %s > %s exited with errorcode %d!\n", extern_uncompressors[t->compression], t->compressedfilename, t->uncompressedfilename, (int)(WEXITSTATUS(status))); error = true; } - } else if( WIFSIGNALED(status) ) { - if( WTERMSIG(status) != SIGUSR2 ) + } else if (WIFSIGNALED(status)) { + if (WTERMSIG(status) != SIGUSR2) fprintf(stderr, "'%s' < %s > %s killed by signal %d!\n", extern_uncompressors[t->compression], t->compressedfilename, @@ -240,31 +241,31 @@ t->uncompressedfilename); error = true; } - if( error ) { + if (error) { /* no need to leave partial stuff around */ (void)unlink(t->uncompressedfilename); } - if( !error && verbose > 10 ) + if (!error && verbose > 10) printf("'%s' < %s > %s finished successfully!\n", extern_uncompressors[t->compression], t->compressedfilename, t->uncompressedfilename); - if( error && uncompression_builtin(t->compression) ) { + if (error && uncompression_builtin(t->compression)) { /* try builtin method instead */ r = builtin_uncompress(t->compressedfilename, t->uncompressedfilename, t->compression); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)unlink(t->uncompressedfilename); - } else if( RET_IS_OK(r) ) { + } else if (RET_IS_OK(r)) { error = false; } } /* call the notification, if asked for */ - if( t->callback != NULL ) { + if (t->callback != NULL) { r = t->callback(t->privdata, t->compressedfilename, error); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = RET_OK; - } else if( error ) + } else if (error) r = RET_ERROR; else r = RET_OK; @@ -289,51 +290,51 @@ const char *path, *colon; /* not set or empty means default */ - if( setting == NULL || setting[0] == '\0' ) + if (setting == NULL || setting[0] == '\0') setting = default_program; /* all-caps NONE means I do not want any... */ - if( strcmp(setting, "NONE") == 0 ) + if (strcmp(setting, "NONE") == 0) return; /* look for the file, look in $PATH if not qualified, * only check existance, if someone it putting files not executable * by us there it is their fault (as being executeable by us is hard * to check) */ - if( strchr(setting, '/') != NULL ) { - if( !isregularfile(setting) ) + if (strchr(setting, '/') != NULL) { + if (!isregularfile(setting)) return; - if( access(setting, X_OK) != 0 ) + if (access(setting, X_OK) != 0) return; program = strdup(setting); } else { path = getenv("PATH"); - if( path == NULL ) + if (path == NULL) return; program = NULL; - while( program == NULL && path[0] != '\0' ) { - if( path[0] == ':' ) { + while (program == NULL && path[0] != '\0') { + if (path[0] == ':') { path++; continue; } colon = strchr(path, ':'); - if( colon == NULL ) + if (colon == NULL) colon = path + strlen(path); - assert( colon > path ); + assert (colon > path); program = mprintf("%.*s/%s", (int)(colon - path), path, setting); - if( program == NULL ) + if (program == NULL) return; - if( !isregularfile(program) || - access(program, X_OK) != 0 ) { + if (!isregularfile(program) || + access(program, X_OK) != 0) { free(program); program = NULL; } - if( *colon == ':' ) + if (*colon == ':') path = colon + 1; else path = colon; } } - if( program == NULL ) + if (program == NULL) return; *program_p = program; @@ -357,10 +358,10 @@ retvalue r; r = uncompress_open(&f, compressed, compression); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; destfd = open(destination, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666); - if( destfd < 0 ) { + if (destfd < 0) { e = errno; fprintf(stderr, "Error %d creating '%s': %s\n", e, destination, strerror(e)); @@ -369,30 +370,31 @@ } do { bytes_read = uncompress_read(f, buffer, 4096); - if( bytes_read <= 0 ) + if (bytes_read <= 0) break; bytes_written = 0; - while( bytes_written < bytes_read ) { + while (bytes_written < bytes_read) { written = write(destfd, buffer + bytes_written, bytes_read - bytes_written); - if( written < 0 ) { + if (written < 0) { e = errno; fprintf(stderr, - "Error %d writing to '%s': %s\n", e, destination, strerror(e) ); +"Error %d writing to '%s': %s\n", + e, destination, strerror(e)); close(destfd); uncompress_abort(f); return RET_ERRNO(e); } bytes_written += written; } - } while( true ); + } while (true); r = uncompress_close(f); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)close(destfd); return r; } - if( close(destfd) != 0 ) { + if (close(destfd) != 0) { e = errno; fprintf(stderr, "Error %d writing to '%s': %s!\n", e, destination, strerror(e)); @@ -405,17 +407,17 @@ struct uncompress_task *t, **t_p; t_p = &tasks; - while( (t = (*t_p)) != NULL ) + while ((t = (*t_p)) != NULL) t_p = &t->next; - t = calloc(1, sizeof(struct uncompress_task)); - if( FAILEDTOALLOC(t) ) + t = zNEW(struct uncompress_task); + if (FAILEDTOALLOC(t)) return RET_ERROR_OOM; t->compressedfilename = strdup(compressed); t->uncompressedfilename = strdup(uncompressed); - if( FAILEDTOALLOC(t->compressedfilename) || - FAILEDTOALLOC(t->uncompressedfilename) ) { + if (FAILEDTOALLOC(t->compressedfilename) || + FAILEDTOALLOC(t->uncompressedfilename)) { uncompress_task_free(t); return RET_ERROR_OOM; } @@ -431,21 +433,22 @@ retvalue r; (void)unlink(destination); - if( extern_uncompressors[compression] != NULL ) { - r = uncompress_queue_external(compression, compressed, destination, action, privdata); - if( r != RET_NOTHING ) { + if (extern_uncompressors[compression] != NULL) { + r = uncompress_queue_external(compression, compressed, + destination, action, privdata); + if (r != RET_NOTHING) { return r; } - if( !uncompression_builtin(compression) ) + if (!uncompression_builtin(compression)) return RET_ERROR; } - if( verbose > 1 ) { + if (verbose > 1) { fprintf(stderr, "Uncompress '%s' into '%s'...\n", compressed, destination); } - assert( uncompression_builtin(compression) ); + assert (uncompression_builtin(compression)); r = builtin_uncompress(compressed, destination, compression); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)unlink(destination); return r; } @@ -456,23 +459,23 @@ retvalue r; /* not allowed within a aptmethod session */ - assert( tasks == NULL ); + assert (tasks == NULL); (void)unlink(destination); - if( uncompression_builtin(compression) ) { - if( verbose > 1 ) { + if (uncompression_builtin(compression)) { + if (verbose > 1) { fprintf(stderr, "Uncompress '%s' into '%s'...\n", compressed, destination); } r = builtin_uncompress(compressed, destination, compression); - } else if( extern_uncompressors[compression] != NULL ) { + } else if (extern_uncompressors[compression] != NULL) { r = uncompress_queue_external(compression, compressed, destination, NULL, NULL); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) r = RET_ERROR; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { /* wait for the child to finish... */ - assert( tasks != NULL && tasks->next == NULL ); + assert (tasks != NULL && tasks->next == NULL); do { int status; @@ -480,14 +483,14 @@ pid = wait(&status); - if( pid < 0 ) { + if (pid < 0) { int e = errno; - if( interrupted() ) { + if (interrupted()) { r = RET_ERROR_INTERRUPTED; break; } - if( e == EINTR ) + if (e == EINTR) continue; fprintf(stderr, "Error %d waiting for uncompression child %lu: %s\n", @@ -496,13 +499,13 @@ r = RET_ERRNO(e); } else r = uncompress_checkpid(pid, status); - } while( r == RET_NOTHING ); + } while (r == RET_NOTHING); } } else { - assert( "Impossible uncompress error" == NULL ); + assert ("Impossible uncompress error" == NULL); r = RET_ERROR; } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { (void)unlink(destination); return r; } @@ -534,11 +537,11 @@ int fd, e; retvalue r; - f = calloc(1, sizeof(struct compressedfile)); - if( FAILEDTOALLOC(f) ) + f = zNEW(struct compressedfile); + if (FAILEDTOALLOC(f)) return RET_ERROR_OOM; f->filename = strdup(filename); - if( FAILEDTOALLOC(f->filename) ) { + if (FAILEDTOALLOC(f->filename)) { free(f); return RET_ERROR_OOM; } @@ -548,14 +551,14 @@ f->pipeinfd = -1; f->len = -1; - switch( compression ) { + switch (compression) { case c_none: f->fd = open(filename, O_RDONLY|O_NOCTTY); - if( f->fd < 0 ) { + if (f->fd < 0) { e = errno; free(f->filename); free(f); - // if( e == || e == ) + // if (e == || e ==) // return RET_NOTHING; fprintf(stderr, "Error %d opening '%s': %s!\n", e, filename, strerror(e)); @@ -565,9 +568,10 @@ return RET_OK; case c_gzip: f->gz = gzopen(filename, "r"); - if( f->gz == NULL ) { + if (f->gz == NULL) { // TODO: better error message... - fprintf(stderr, "Could not read %s\n", filename); + fprintf(stderr, "Could not read %s\n", + filename); free(f->filename); free(f); return RET_ERROR; @@ -577,7 +581,7 @@ #ifdef HAVE_LIBBZ2 case c_bzip2: f->bz = BZ2_bzopen(filename, "r"); - if( f->bz == NULL ) { + if (f->bz == NULL) { // TODO: better error message... fprintf(stderr, "Could not read %s\n", filename); @@ -589,18 +593,18 @@ return RET_OK; #endif default: - assert( extern_uncompressors[compression] != NULL ); + assert (extern_uncompressors[compression] != NULL); } /* call external helper instead */ fd = open(f->filename, O_RDONLY|O_NOCTTY); - if( fd < 0 ) { + if (fd < 0) { e = errno; fprintf(stderr, "Error %d opening '%s': %s\n", e, f->filename, strerror(e)); return RET_ERRNO(e); } r = startpipeoutchild(compression, fd, &f->fd, &f->pid); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; *file_p = f; return RET_OK; @@ -612,8 +616,8 @@ struct compressedfile *f; retvalue r; - f = calloc(1, sizeof(struct compressedfile)); - if( FAILEDTOALLOC(f) ) { + f = zNEW(struct compressedfile); + if (FAILEDTOALLOC(f)) { *errno_p = ENOMEM; *msg_p = "Out of memory"; return RET_ERROR_OOM; @@ -625,7 +629,7 @@ f->pipeinfd = -1; f->len = len; - switch( compression ) { + switch (compression) { case c_none: f->fd = fd; f->infd = -1; @@ -634,11 +638,12 @@ // TODO: perhaps rather implement your own reading and // uncompression, this way length read cannot be controlled f->gz = gzdopen(dup(fd), "r"); - if( f->gz == NULL ) { + if (f->gz == NULL) { *errno_p = errno; *msg_p = strerror(errno); // TODO: better error message... - fprintf(stderr, "Error opening internal gz uncompression using zlib...\n"); + fprintf(stderr, +"Error opening internal gz uncompression using zlib...\n"); free(f); return RET_ERROR; } @@ -646,25 +651,26 @@ #ifdef HAVE_LIBBZ2 case c_bzip2: f->bz = BZ2_bzdopen(dup(fd), "r"); - if( f->bz == NULL ) { + if (f->bz == NULL) { *errno_p = errno; *msg_p = strerror(errno); // TODO: better error message... - fprintf(stderr, "Error opening internal bz2 uncompression using libbz2\n"); + fprintf(stderr, +"Error opening internal bz2 uncompression using libbz2\n"); free(f); return RET_ERROR; } break; #endif default: - if( intermediate_size == 0 ) { + if (intermediate_size == 0) { /* pipes are guaranteed to swallow a full * page without blocking if poll * tells you can write */ long l = sysconf(_SC_PAGESIZE); - if( l <= 0 ) + if (l <= 0) intermediate_size = 512; - else if( l > 4096 ) + else if (l > 4096) intermediate_size = 4096; else intermediate_size = l; @@ -672,7 +678,7 @@ f->intermediate.buffer = malloc(intermediate_size); f->intermediate.ready = 0; f->intermediate.ofs = 0; - if( FAILEDTOALLOC(f->intermediate.buffer) ) { + if (FAILEDTOALLOC(f->intermediate.buffer)) { *errno_p = ENOMEM; *msg_p = "Out of memory"; free(f); @@ -680,7 +686,7 @@ } r = startpipeinoutchild(f->compression, &f->pipeinfd, &f->fd, &f->pid); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { *errno_p = -EINVAL; *msg_p = "Error starting external uncompressor"; free(f->intermediate.buffer); @@ -697,8 +703,8 @@ * write when there is still space in the pipe, otherwise we can end up * in a because we are waiting for the output of a program that cannot * generate output because it needs more input from us first or because - * we wait for a program to accept input that waits for us to consume the - * output... */ + * we wait for a program to accept input that waits for us to consume + * the output... */ struct pollfd p[2]; ssize_t written; int i; @@ -712,20 +718,20 @@ /* wait till there is something to do */ i = poll(p, 2, -1); - if( i < 0 ) { - if( errno == EINTR ) + if (i < 0) { + if (errno == EINTR) continue; file->error = errno; return -1; } - if( (p[0].revents & POLLERR ) != 0 ) { + if ((p[0].revents & POLLERR) != 0) { file->error = EIO; return -1; } - if( (p[0].revents & POLLHUP ) != 0 ) { + if ((p[0].revents & POLLHUP) != 0) { /* not being able to send when we have something * is an error */ - if( file->len > 0 || file->intermediate.ready > 0 ) { + if (file->len > 0 || file->intermediate.ready > 0) { file->error = EIO; return -1; } @@ -735,31 +741,31 @@ return read(file->fd, buffer, size); } - if( (p[0].revents & POLLOUT) != 0 ) { + if ((p[0].revents & POLLOUT) != 0) { struct intermediate_buffer *im = &file->intermediate; - if( im->ready < 0 ) + if (im->ready < 0) return -1; - if( im->ready == 0 ) { + if (im->ready == 0) { // TODO: check if splice is safe or will create // dead-locks... int isize = intermediate_size; im->ofs = 0; - if( file->len >= 0 && isize > file->len ) + if (file->len >= 0 && isize > file->len) isize = file->len; - if( isize == 0 ) + if (isize == 0) im->ready = 0; else im->ready = read(file->infd, im->buffer + im->ofs, isize); - if( im->ready < 0 ) { + if (im->ready < 0) { file->error = errno; return -1; } - if( im->ready == 0 ) { + if (im->ready == 0) { (void)close(file->pipeinfd); file->pipeinfd = -1; /* wait for the rest */ @@ -769,7 +775,7 @@ } written = write(file->pipeinfd, im->buffer + im->ofs, im->ready); - if( written < 0 ) { + if (written < 0) { file->error = errno; return -1; } @@ -777,23 +783,23 @@ im->ready -= written; } - if( (p[1].revents & POLLIN) != 0 ) + if ((p[1].revents & POLLIN) != 0) return read(file->fd, buffer, size); - } while( true ); + } while (true); } int uncompress_read(struct compressedfile *file, void *buffer, int size) { ssize_t s; int i; - switch( file->compression ) { + switch (file->compression) { case c_none: - if( file->len == 0 ) + if (file->len == 0) return 0; - if( file->len > 0 && size > file->len ) + if (file->len > 0 && size > file->len) size = file->len; s = read(file->fd, buffer, size); - if( s < 0 ) + if (s < 0) file->error = errno; file->len -= s; return s; @@ -808,13 +814,13 @@ return i; #endif default: - if( file->pipeinfd != -1 ) { + if (file->pipeinfd != -1) { /* things more complicated, as perhaps something needs writing first... */ return pipebackforth(file, buffer, size); } s = read(file->fd, buffer, size); - if( s < 0 ) + if (s < 0) file->error = errno; return s; } @@ -829,13 +835,13 @@ #define ERRORBUFFERSIZE 100 static char errorbuffer[ERRORBUFFERSIZE]; - if( file == NULL ) + if (file == NULL) return RET_OK; free(file->intermediate.buffer); - switch( file->compression ) { + switch (file->compression) { case c_none: - if( file->error != 0 ) { + if (file->error != 0) { *errno_p = file->error; *msg_p = strerror(file->error); return RET_ERRNO(file->error); @@ -844,12 +850,12 @@ case c_gzip: file->fd = -1; msg = gzerror(file->gz, &zerror); - if( zerror == Z_ERRNO ) { + if (zerror == Z_ERRNO) { *errno_p = file->error; (void)gzclose(file->gz); *msg_p = strerror(file->error); return RET_ERRNO(file->error); - } else if( zerror < 0 ) { + } else if (zerror < 0) { *errno_p = -EINVAL; snprintf(errorbuffer, ERRORBUFFERSIZE, "Zlib error %d: %s", @@ -859,11 +865,11 @@ return RET_ERROR_Z; } zerror = gzclose(file->gz); - if( zerror == Z_ERRNO ) { + if (zerror == Z_ERRNO) { *errno_p = file->error; *msg_p = strerror(file->error); return RET_ERRNO(file->error); - } if( zerror < 0 ) { + } if (zerror < 0) { *errno_p = -EINVAL; snprintf(errorbuffer, ERRORBUFFERSIZE, "Zlib error %d", zerror); @@ -875,7 +881,7 @@ case c_bzip2: file->fd = -1; msg = BZ2_bzerror(file->bz, &zerror); - if( zerror < 0 ) { + if (zerror < 0) { *errno_p = -EINVAL; snprintf(errorbuffer, ERRORBUFFERSIZE, "libbz2 error %d: %s", @@ -890,29 +896,29 @@ #endif default: (void)close(file->fd); - if( file->pipeinfd != -1 ) + if (file->pipeinfd != -1) (void)close(file->pipeinfd); file->fd = file->infd; file->infd = -1; result = RET_OK; - if( file->pid <= 0 ) + if (file->pid <= 0) return RET_OK; do { pid = waitpid(file->pid, &status, 0); e = errno; - if( interrupted() ) { + if (interrupted()) { *errno_p = EINTR; *msg_p = "Interrupted"; result = RET_ERROR_INTERRUPTED; } - } while( pid == -1 && (e == EINTR || e == EAGAIN) ); - if( pid == -1 ) { + } while (pid == -1 && (e == EINTR || e == EAGAIN)); + if (pid == -1) { *errno_p = e; *msg_p = strerror(file->error); return RET_ERRNO(e); } - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0 ) + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) return result; else { *errno_p = -EINVAL; @@ -923,7 +929,7 @@ *msg_p = errorbuffer; return RET_ERROR; } - } else if( WIFSIGNALED(status) && WTERMSIG(status) != SIGUSR2 ) { + } else if (WIFSIGNALED(status) && WTERMSIG(status) != SIGUSR2) { *errno_p = -EINVAL; snprintf(errorbuffer, ERRORBUFFERSIZE, "%s killed by signal %d", @@ -950,20 +956,21 @@ const char *msg; pid_t pid; - if( file == NULL ) + if (file == NULL) return RET_NOTHING; - switch( file->compression ) { + switch (file->compression) { case c_none: - if( file->error == 0 ) + if (file->error == 0) return RET_OK; break; case c_gzip: msg = gzerror(file->gz, &zerror); - if( zerror >= 0 ) + if (zerror >= 0) return RET_OK; - if( zerror != Z_ERRNO ) { - fprintf(stderr, "Zlib error %d uncompressing file '%s': %s\n", + if (zerror != Z_ERRNO) { + fprintf(stderr, +"Zlib error %d uncompressing file '%s': %s\n", zerror, file->filename, msg); @@ -973,8 +980,9 @@ #ifdef HAVE_LIBBZ2 case c_bzip2: msg = BZ2_bzerror(file->bz, &zerror); - if( zerror < 0 ) { - fprintf(stderr, "libbz2 error %d uncompressing file '%s': %s\n", + if (zerror < 0) { + fprintf(stderr, +"libbz2 error %d uncompressing file '%s': %s\n", zerror, file->filename, msg); @@ -983,26 +991,27 @@ return RET_OK; #endif default: - if( file->error != 0 ) + if (file->error != 0) break; - if( file->pid <= 0 ) + if (file->pid <= 0) return RET_OK; pid = waitpid(file->pid, &status, WNOHANG); - if( pid < 0 ) { + if (pid < 0) { e = errno; - fprintf(stderr, "Error looking for child %lu (a '%s'): %s\n", + fprintf(stderr, +"Error looking for child %lu (a '%s'): %s\n", (long unsigned)file->pid, extern_uncompressors[file->compression], strerror(e)); return RET_ERRNO(e); } - if( pid != file->pid ) { + if (pid != file->pid) { /* still running */ return RET_OK; } file->pid = -1; - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0 ) + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) return RET_OK; else { fprintf(stderr, @@ -1011,7 +1020,7 @@ (int)(WEXITSTATUS(status))); return RET_ERROR; } - } else if( WIFSIGNALED(status) && WTERMSIG(status) != SIGUSR2 ) { + } else if (WIFSIGNALED(status) && WTERMSIG(status) != SIGUSR2) { fprintf(stderr, "%s killed by signal %d\n", extern_uncompressors[file->compression], @@ -1025,7 +1034,7 @@ } } /* an error, but which? */ - if( file->error != 0 ) { + if (file->error != 0) { fprintf(stderr, "Error %d uncompressing file '%s': %s\n", file->error, file->filename, strerror(file->error)); @@ -1040,12 +1049,12 @@ pid_t pid; int e, status; - if( file == NULL ) + if (file == NULL) return; - switch( file->compression ) { + switch (file->compression) { case c_none: - if( file->fd >= 0 ) + if (file->fd >= 0) (void)close(file->fd); break; case c_gzip: @@ -1059,28 +1068,28 @@ default: /* kill before closing, to avoid it getting * a sigpipe */ - if( file->pid > 0 ) + if (file->pid > 0) kill(file->pid, SIGTERM); - if( file->infd >= 0 ) + if (file->infd >= 0) (void)close(file->infd); - if( file->pipeinfd != -1 ) + if (file->pipeinfd != -1) (void)close(file->pipeinfd); do { pid = waitpid(file->pid, &status, 0); e = errno; - if( interrupted() ) { + if (interrupted()) { break; } - } while( pid == -1 && (e == EINTR || e == EAGAIN) ); - if( pid == -1 ) + } while (pid == -1 && (e == EINTR || e == EAGAIN)); + if (pid == -1) break; - if( file->fd >= 0 ) + if (file->fd >= 0) (void)close(file->fd); - if( WIFEXITED(status) ) { + if (WIFEXITED(status)) { break; - } else if( WIFSIGNALED(status) + } else if (WIFSIGNALED(status) && WTERMSIG(status) != SIGTERM - && WTERMSIG(status) != SIGUSR2 ) { + && WTERMSIG(status) != SIGUSR2) { fprintf(stderr, "%s killed by signal %d\n", extern_uncompressors[file->compression], (int)(WTERMSIG(status))); @@ -1093,10 +1102,10 @@ retvalue uncompress_fdclose(struct compressedfile *file, int *errno_p, const char **msg_p) { retvalue result; - if( file == NULL ) + if (file == NULL) return RET_OK; - assert( file->filename == NULL ); + assert (file->filename == NULL); result = uncompress_commonclose(file, errno_p, msg_p); @@ -1109,14 +1118,14 @@ retvalue r; int e; - if( file == NULL ) + if (file == NULL) return RET_OK; - assert( file->filename != NULL ); + assert (file->filename != NULL); r = uncompress_commonclose(file, &e, &msg); - if( RET_IS_OK(r) ) { - if( file->fd >= 0 && close(file->fd) != 0 ) { + if (RET_IS_OK(r)) { + if (file->fd >= 0 && close(file->fd) != 0) { e = errno; fprintf(stderr, "Error %d reading from %s: %s!\n", e, file->filename, strerror(e)); @@ -1125,9 +1134,9 @@ free(file); return r; } - if( file->fd >= 0 ) + if (file->fd >= 0) (void)close(file->fd); - if( e == -EINVAL ) { + if (e == -EINVAL) { fprintf(stderr, "Error reading from %s: %s!\n", file->filename, msg); } else { @@ -1143,12 +1152,12 @@ enum compression c; size_t len = *len_p; - for( c = c_COUNT - 1 ; c > c_none ; c-- ) { + for (c = c_COUNT - 1 ; c > c_none ; c--) { size_t l = strlen(uncompression_suffix[c]); - if( len <= l ) + if (len <= l) continue; - if( strncmp(name + len - l, uncompression_suffix[c], l) == 0 ) { + if (strncmp(name + len - l, uncompression_suffix[c], l) == 0) { *len_p -= l; return c; } diff -Nru reprepro-4.5.0/uncompression.h reprepro-4.6.0/uncompression.h --- reprepro-4.5.0/uncompression.h 2010-10-24 08:59:11.000000000 +0000 +++ reprepro-4.6.0/uncompression.h 2011-05-05 14:42:55.000000000 +0000 @@ -17,7 +17,7 @@ #else #define uncompression_builtin(c) ((c) == c_gzip) #endif -#define uncompression_supported(c) ( (c) == c_none || \ +#define uncompression_supported(c) ((c) == c_none || \ uncompression_builtin(c) || \ extern_uncompressors[c] != NULL) diff -Nru reprepro-4.5.0/updates.c reprepro-4.6.0/updates.c --- reprepro-4.5.0/updates.c 2010-07-11 10:16:04.000000000 +0000 +++ reprepro-4.6.0/updates.c 2011-05-05 14:42:55.000000000 +0000 @@ -159,6 +159,7 @@ // NULL means no condition /*@null@*/term *includecondition; struct filterlist filterlist; + struct filterlist filtersrclist; // NULL means nothing to execute after lists are downloaded... /*@null@*/char *listhook; /*@null@*/char *shellhook; @@ -242,7 +243,7 @@ }; static void update_pattern_free(/*@only@*/struct update_pattern *update) { - if( update == NULL ) + if (update == NULL) return; free(update->name); free(update->from); @@ -259,6 +260,7 @@ strlist_done(&update->udebcomponents_into); term_free(update->includecondition); filterlist_release(&update->filterlist); + filterlist_release(&update->filtersrclist); free(update->listhook); free(update->shellhook); remote_repository_free(update->repository); @@ -266,7 +268,7 @@ } void updates_freepatterns(struct update_pattern *p) { - while( p != NULL ) { + while (p != NULL) { struct update_pattern *pattern; pattern = p; @@ -276,7 +278,7 @@ } static void updates_freeorigins(/*@only@*/struct update_origin *o) { - while( o != NULL ) { + while (o != NULL) { struct update_origin *origin; origin = o; @@ -287,12 +289,12 @@ } static void updates_freetargets(/*@only@*/struct update_target *t) { - while( t != NULL ) { + while (t != NULL) { struct update_target *ut; ut = t; t = ut->next; - while( ut->indices != NULL ) { + while (ut->indices != NULL) { struct update_index_connector *ui; ui = ut->indices; @@ -305,7 +307,7 @@ } void updates_freeupdatedistributions(struct update_distribution *d) { - while( d != NULL ) { + while (d != NULL) { struct update_distribution *next; next = d->next; @@ -317,11 +319,11 @@ } } -static inline retvalue newupdatetarget(struct update_target **ts,/*@dependent@*/struct target *target) { +static inline retvalue newupdatetarget(struct update_target **ts, /*@dependent@*/struct target *target) { struct update_target *ut; ut = malloc(sizeof(struct update_target)); - if( ut == NULL ) + if (FAILEDTOALLOC(ut)) return RET_ERROR_OOM; ut->target = target; ut->next = *ts; @@ -352,6 +354,7 @@ CFscriptSETPROC(update_pattern, listhook) CFallSETPROC(update_pattern, shellhook) CFfilterlistSETPROC(update_pattern, filterlist) +CFfilterlistSETPROC(update_pattern, filtersrclist) CFtermSSETPROC(update_pattern, includecondition) CFUSETPROC(update_pattern, downloadlistsas) { @@ -364,9 +367,9 @@ this->downloadlistsas_set = true; r = config_getword(iter, &word); - while( RET_IS_OK(r) ) { + while (RET_IS_OK(r)) { bool force; - if( e >= ARRAYCOUNT(this->downloadlistsas.requested) ) { + if (e >= ARRAYCOUNT(this->downloadlistsas.requested)) { fprintf(stderr, "%s:%d:%d: Ignoring all but first %d entries...\n", config_filename(iter), @@ -377,20 +380,20 @@ free(word); break; } - if( strncmp(word, "force.", 6) == 0 ) { + if (strncmp(word, "force.", 6) == 0) { u = word + 5; force = true; } else { u = word; force = false; } - for( c = 0 ; c < c_COUNT ; c++ ) { - if( strcmp(uncompression_config[c], u) == 0 || - strcmp(uncompression_config[c]+1, u) == 0 ) { + for (c = 0 ; c < c_COUNT ; c++) { + if (strcmp(uncompression_config[c], u) == 0 || + strcmp(uncompression_config[c]+1, u) == 0) { break; } } - if( c < c_COUNT ) { + if (c < c_COUNT) { this->downloadlistsas.requested[e].compression = c; this->downloadlistsas.requested[e].diff = false; this->downloadlistsas.requested[e].force = force; @@ -399,7 +402,7 @@ r = config_getword(iter, &word); continue; } - if( strcmp(u, ".diff") == 0 || strcmp(u, "diff") == 0 ) { + if (strcmp(u, ".diff") == 0 || strcmp(u, "diff") == 0) { this->downloadlistsas.requested[e].compression = c_gzip; this->downloadlistsas.requested[e].diff = true; this->downloadlistsas.requested[e].force = force; @@ -417,7 +420,7 @@ free(word); return RET_ERROR; } - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; this->downloadlistsas.count = e; return RET_OK; @@ -432,12 +435,12 @@ r = config_getsplitwords(iter, "Components", &this->components_from, &this->components_into); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { // TODO: instead of this save numbers directly... - for( i = 0 ; i < this->components_into.count ; i++ ) { + for (i = 0 ; i < this->components_into.count ; i++) { component_t c; c = component_find(this->components_into.values[i]); - if( c == atom_unknown ) { + if (c == atom_unknown) { fprintf(stderr, "Warning parsing %s, line %u: unknown component '%s' will be ignored!\n", config_filename(iter), @@ -458,12 +461,12 @@ r = config_getsplitwords(iter, "UdebComponents", &this->udebcomponents_from, &this->udebcomponents_into); - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { // TODO: instead of this save numbers directly... - for( i = 0 ; i < this->udebcomponents_into.count ; i++ ) { + for (i = 0 ; i < this->udebcomponents_into.count ; i++) { component_t c; c = component_find(this->udebcomponents_into.values[i]); - if( c == atom_unknown ) { + if (c == atom_unknown) { fprintf(stderr, "Warning parsing %s, line %u: unknown udeb component '%s' will be ignored!\n", config_filename(iter), @@ -484,7 +487,7 @@ r = config_getsplitwords(iter, "Architectures", &this->architectures_from, &this->architectures_into); - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { strlist_init(&this->architectures_from); strlist_init(&this->architectures_into); fprintf(stderr, @@ -493,12 +496,12 @@ config_filename(iter), config_markerline(iter)); } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { // TODO: instead of this save numbers directly... - for( i = 0 ; i < this->architectures_into.count ; i++ ) { + for (i = 0 ; i < this->architectures_into.count ; i++) { architecture_t a; a = architecture_find(this->architectures_into.values[i]); - if( a == atom_unknown ) { + if (a == atom_unknown) { fprintf(stderr, "Warning parsing %s, line %u: unknown architecture '%s' will be ignored!\n", config_filename(iter), @@ -529,65 +532,66 @@ CF("ListShellHook", update_pattern, shellhook), CF("FilterFormula", update_pattern, includecondition), CF("FilterList", update_pattern, filterlist), + CF("FilterSrcList", update_pattern, filtersrclist), CF("DownloadListsAs", update_pattern, downloadlistsas) }; CFfinishparse(update_pattern) { CFUfinishparseVARS(update_pattern, n, last_p, mydata); - if( complete ) { - if( n->components_set && atom_defined(n->flat) ) { + if (complete) { + if (n->components_set && atom_defined(n->flat)) { fprintf(stderr, "%s:%u to %u: Update pattern may not contain Components and Flat fields ad the same time.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->udebcomponents_set && atom_defined(n->flat) ) { + if (n->udebcomponents_set && atom_defined(n->flat)) { fprintf(stderr, "%s:%u to %u: Update pattern may not contain UDebComponents and Flat fields ad the same time.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->from != NULL && n->method != NULL ) { + if (n->from != NULL && n->method != NULL) { fprintf(stderr, "%s:%u to %u: Update pattern may not contain From: and Method: fields ad the same time.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->from == NULL && n->method == NULL ) { + if (n->from == NULL && n->method == NULL) { fprintf(stderr, "%s:%u to %u: Update pattern must either contain a Methods: field or reference another one with a From: field.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->from != NULL && n->fallback != NULL ) { + if (n->from != NULL && n->fallback != NULL) { fprintf(stderr, "%s:%u to %u: Update pattern may not contain From: and Fallback: fields ad the same time.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->from != NULL && n->config_set ) { + if (n->from != NULL && n->config_set) { fprintf(stderr, "%s:%u to %u: Update pattern may not contain From: and Config: fields ad the same time.\n", config_filename(iter), config_firstline(iter), config_line(iter)); return RET_ERROR; } - if( n->suite_from != NULL && strcmp(n->suite_from, "*") != 0 && + if (n->suite_from != NULL && strcmp(n->suite_from, "*") != 0 && strncmp(n->suite_from, "*/", 2) != 0 && - strchr(n->suite_from, '*') != NULL ) { + strchr(n->suite_from, '*') != NULL) { fprintf(stderr, "%s:%u to %u: Unsupported suite pattern '%s'\n", config_filename(iter), config_firstline(iter), config_line(iter), n->suite_from); return RET_ERROR; } - if( n->listhook != NULL && n->shellhook != NULL ) { + if (n->listhook != NULL && n->shellhook != NULL) { fprintf(stderr, "%s:%u to %u: Only one of ListHook and ListShellHook allowed per update rule\n", config_filename(iter), config_firstline(iter), @@ -595,7 +599,8 @@ return RET_ERROR; } } - return linkedlistfinish(privdata_update_pattern, thisdata_update_pattern, + return linkedlistfinish(privdata_update_pattern, + thisdata_update_pattern, lastdata_p_update_pattern, complete, iter); } @@ -611,13 +616,13 @@ finishparseupdate_pattern, updateconfigfields, ARRAYCOUNT(updateconfigfields), &update); - if( RET_IS_OK(r) ) { - for( u = update ; u != NULL ; u = u->next ) { + if (RET_IS_OK(r)) { + for (u = update ; u != NULL ; u = u->next) { v = update; - while( v != NULL && - ( v == u || strcmp(v->name, u->name) != 0 ) ) + while (v != NULL && + (v == u || strcmp(v->name, u->name) != 0)) v = v->next; - if( v != NULL ) { + if (v != NULL) { // TODO: store line information... fprintf(stderr, "%s/updates: Multiple update patterns named '%s'!\n", @@ -625,12 +630,12 @@ updates_freepatterns(update); return RET_ERROR; } - if( u->from == NULL ) + if (u->from == NULL) continue; v = update; - while( v != NULL && strcmp(v->name, u->from) != 0 ) + while (v != NULL && strcmp(v->name, u->from) != 0) v = v->next; - if( v == NULL ) { + if (v == NULL) { fprintf(stderr, "%s/updates: Update pattern '%s' references unknown pattern '%s' via From!\n", global.confdir, u->name, u->from); @@ -642,41 +647,45 @@ /* check for circular references */ do { progress = false; - for( u = update ; u != NULL ; u = u->next ) { - if( u->visited ) + for (u = update ; u != NULL ; u = u->next) { + if (u->visited) continue; - if( u->pattern_from == NULL || - u->pattern_from->visited ) { + if (u->pattern_from == NULL || + u->pattern_from->visited) { u->visited = true; progress = true; } } - } while( progress ); + } while (progress); u = update; - while( u != NULL && u->visited ) + while (u != NULL && u->visited) u = u->next; - if( u != NULL ) { + if (u != NULL) { /* The actual error is more likely found later. * If someone creates a cycle and a chain into that * more than 1000 rules long, having a slightly * misleading error message will be the last of * their problems... */ - for( i = 0 ; i < 1000 ; i++ ) { + for (i = 0 ; i < 1000 ; i++) { u = u->pattern_from; - assert( u != NULL && !u->visited ); + assert (u != NULL && !u->visited); } - fprintf(stderr, "Error: Update rule '%s' part of circular From-referencing.\n", u->name); + fprintf(stderr, +"Error: Update rule '%s' part of circular From-referencing.\n", + u->name); updates_freepatterns(update); return RET_ERROR; } *patterns = update; - } else if( r == RET_NOTHING ) { - assert( update == NULL ); + } else if (r == RET_NOTHING) { + assert (update == NULL); *patterns = NULL; r = RET_OK; } else { - if( r == RET_ERROR_UNKNOWNFIELD ) - (void)fputs("To ignore unknown fields use --ignore=unknownfield\n", stderr); + if (r == RET_ERROR_UNKNOWNFIELD) + (void)fputs( +"To ignore unknown fields use --ignore=unknownfield\n", + stderr); updates_freepatterns(update); } return r; @@ -685,18 +694,18 @@ static inline void markfound(int count, struct update_pattern * const *patterns, const struct update_pattern *lookfor, const struct strlist *searched, const struct strlist *have, bool *found, bool (*hasattribute)(const struct update_pattern*)) { int i, j, o; - for( i = 0 ; i < count ; i++ ) { + for (i = 0 ; i < count ; i++) { const struct update_pattern *p = patterns[i]; /* check if this uses this attribute */ - while( p != NULL && !hasattribute(p) ) + while (p != NULL && !hasattribute(p)) p = p->pattern_from; - if( p != lookfor ) + if (p != lookfor) continue; - for( j = 0 ; j < have->count ; j++ ) { + for (j = 0 ; j < have->count ; j++) { o = strlist_ofs(searched, have->values[j]); - if( o >= 0 ) + if (o >= 0) found[o] = true; } break; @@ -721,8 +730,8 @@ struct update_origin *update; - update = calloc(1,sizeof(struct update_origin)); - if( update == NULL ) + update = zNEW(struct update_origin); + if (FAILEDTOALLOC(update)) return RET_ERROR_OOM; *origins = update; @@ -731,14 +740,14 @@ static inline char *translate_suite_pattern(const struct update_pattern *p, const char *codename) { /* look for first specified suite: */ - while( p != NULL && p->suite_from == NULL ) + while (p != NULL && p->suite_from == NULL) p = p->pattern_from; - if( p == NULL || strcmp(p->suite_from, "*") == 0) + if (p == NULL || strcmp(p->suite_from, "*") == 0) return strdup(codename); - if( p->suite_from[0] == '*' && p->suite_from[1] == '/' ) + if (p->suite_from[0] == '*' && p->suite_from[1] == '/') return calc_dirconcat(codename, p->suite_from + 2); - else if( strchr(p->suite_from, '*') == NULL ) + else if (strchr(p->suite_from, '*') == NULL) return strdup(p->suite_from); //TODO: implement this // but already checked in parsing... @@ -754,26 +763,26 @@ const char *verifyrelease; retvalue r; - update = calloc(1,sizeof(struct update_origin)); - if( update == NULL ) + update = zNEW(struct update_origin); + if (FAILEDTOALLOC(update)) return RET_ERROR_OOM; update->suite_from = translate_suite_pattern(pattern, distribution->codename); - if( FAILEDTOALLOC(update->suite_from) ) { + if (FAILEDTOALLOC(update->suite_from)) { free(update); return RET_ERROR_OOM; } - if( !pattern->used ) { + if (!pattern->used) { declaration = pattern; - while( declaration->pattern_from != NULL ) + while (declaration->pattern_from != NULL) declaration = declaration->pattern_from; - if( declaration->repository == NULL ) + if (declaration->repository == NULL) declaration->repository = remote_repository_prepare( declaration->name, declaration->method, declaration->fallback, &declaration->config); - if( FAILEDTOALLOC(declaration->repository) ) { + if (FAILEDTOALLOC(declaration->repository)) { free(update->suite_from); free(update); return RET_ERROR_OOM; @@ -781,9 +790,9 @@ pattern->used = true; } else { declaration = pattern; - while( declaration->pattern_from != NULL ) + while (declaration->pattern_from != NULL) declaration = declaration->pattern_from; - assert( declaration->repository != NULL ); + assert (declaration->repository != NULL); } update->distribution = distribution; @@ -791,21 +800,21 @@ update->failed = false; p = pattern; - while( p != NULL && !p->ignorerelease_set ) + while (p != NULL && !p->ignorerelease_set) p = p->pattern_from; - if( p == NULL ) + if (p == NULL) ignorerelease = false; else ignorerelease = p->ignorerelease; /* find the first set values: */ p = pattern; - while( p != NULL && p->verifyrelease == NULL ) + while (p != NULL && p->verifyrelease == NULL) p = p->pattern_from; - if( p == NULL ) + if (p == NULL) verifyrelease = NULL; else verifyrelease = p->verifyrelease; - if( !ignorerelease && verifyrelease == NULL && verbose >= 0 ) { + if (!ignorerelease && verifyrelease == NULL && verbose >= 0) { fprintf(stderr, "Warning: No VerifyRelease line in '%s' or any rule it includes via 'From:'.\n" "Release.gpg cannot be checked unless you tell which key to check with.\n" @@ -814,31 +823,31 @@ } p = pattern; - while( p != NULL && !p->ignorehashes_set ) + while (p != NULL && !p->ignorehashes_set) p = p->pattern_from; - if( p == NULL ) + if (p == NULL) memset(ignorehashes, 0, sizeof(ignorehashes)); else { - assert( sizeof(ignorehashes) == sizeof(p->ignorehashes)); + assert (sizeof(ignorehashes) == sizeof(p->ignorehashes)); memcpy(ignorehashes, p->ignorehashes, sizeof(ignorehashes)); } listscomponents = NULL; p = pattern; - while( p != NULL && !atom_defined(p->flat) ) { - if( p->components_set || p->udebcomponents_set ) + while (p != NULL && !atom_defined(p->flat)) { + if (p->components_set || p->udebcomponents_set) listscomponents = p; p = p->pattern_from; } update->flat = p != NULL; - if( update->flat && listscomponents != NULL ) { + if (update->flat && listscomponents != NULL) { fprintf(stderr, "WARNING: update pattern '%s' (first encountered via '%s' in '%s')\n" "sets components that are always ignored as '%s' sets Flat mode.\n", listscomponents->name, pattern->name, distribution->codename, p->name); } - if( p != NULL && !atomlist_in(&distribution->components, p->flat) ) { + if (p != NULL && !atomlist_in(&distribution->components, p->flat)) { fprintf(stderr, "Error: distribution '%s' uses flat update pattern '%s'\n" "with target component '%s' which it does not contain!\n", @@ -851,7 +860,7 @@ update->suite_from, ignorerelease, verifyrelease, update->flat, ignorehashes, &update->from); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { updates_freeorigins(update); return r; } @@ -864,29 +873,29 @@ int i; struct update_pattern **used_patterns; - if( distribution->updates.count == 0 ) + if (distribution->updates.count == 0) return RET_NOTHING; - used_patterns = calloc(distribution->updates.count, - sizeof(struct update_pattern)); - if( FAILEDTOALLOC(used_patterns) ) + used_patterns = nzNEW(distribution->updates.count, + struct update_pattern *); + if (FAILEDTOALLOC(used_patterns)) return RET_ERROR_OOM; - for( i = 0; i < distribution->updates.count ; i++ ) { + for (i = 0; i < distribution->updates.count ; i++) { const char *name = distribution->updates.values[i]; struct update_pattern *pattern; - if( strcmp(name, "-") == 0 ) + if (strcmp(name, "-") == 0) continue; pattern = patterns; - while( pattern != NULL && strcmp(name, pattern->name) != 0 ) + while (pattern != NULL && strcmp(name, pattern->name) != 0) pattern = pattern->next; - if( pattern == NULL ) { + if (pattern == NULL) { fprintf(stderr, "Cannot find definition of upgrade-rule '%s' for distribution '%s'!\n", name, distribution->codename); - if( distribution->selected ) { + if (distribution->selected) { free(used_patterns); return RET_ERROR; } else @@ -906,30 +915,30 @@ retvalue result; int i; - assert( d->patterns != NULL ); + assert (d->patterns != NULL); result = RET_NOTHING; - for( i = 0; i < distribution->updates.count ; i++ ) { + for (i = 0; i < distribution->updates.count ; i++) { struct update_pattern *pattern = d->patterns[i]; struct update_origin *update IFSTUPIDCC(=NULL); retvalue r; - if( pattern == NULL ) { - assert( strcmp(distribution->updates.values[i], "-") == 0); + if (pattern == NULL) { + assert (strcmp(distribution->updates.values[i], "-") == 0); r = new_deleterule(&update); } else { r = instance_pattern(pattern, distribution, &update); } - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { update->next = updates; updates = update; } } - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { updates_freeorigins(updates); } else { d->origins = updates; @@ -945,187 +954,183 @@ struct update_index_connector *uindex; const struct update_pattern *p; - uindex = calloc(1, sizeof(struct update_index_connector)); - if( FAILEDTOALLOC(uindex) ) + uindex = zNEW(struct update_index_connector); + if (FAILEDTOALLOC(uindex)) return false; p = origin->pattern; - while( p != NULL && !p->downloadlistsas_set ) + while (p != NULL && !p->downloadlistsas_set) p = p->pattern_from; uindex->origin = origin; uindex->remote = remote_index(origin->from, architecture, component, - target->packagetype_atom, + target->packagetype, (p == NULL)?NULL:&p->downloadlistsas); - if( FAILEDTOALLOC(uindex->remote) ) { + if (FAILEDTOALLOC(uindex->remote)) { free(uindex); return false; } - assert( !origin->flat ); + assert (!origin->flat); uindex->next = updatetargets->indices; uindex->ignorewrongarchitecture = strcmp(architecture, atoms_architectures[ - target->architecture_atom]) != 0; + target->architecture]) != 0; updatetargets->indices = uindex; return true; } -static retvalue addorigintotarget(struct update_origin *origin, struct target *target, struct distribution *distribution, struct update_target *updatetargets ) { +static retvalue addorigintotarget(struct update_origin *origin, struct target *target, struct distribution *distribution, struct update_target *updatetargets) { const struct update_pattern *p; const struct strlist *c_from = NULL, *c_into = NULL; const struct strlist *a_from = NULL, *a_into = NULL; - int ai,ci; + const char *architecture = atoms_architectures[target->architecture]; + const char *component = atoms_components[target->component]; + int ai, ci; - assert( origin != NULL && origin->pattern != NULL); + assert (origin != NULL && origin->pattern != NULL); p = origin->pattern; - while( p != NULL && !p->architectures_set ) + while (p != NULL && !p->architectures_set) p = p->pattern_from; - if( p != NULL ) { + if (p != NULL) { a_from = &p->architectures_from; a_into = &p->architectures_into; } p = origin->pattern; - if( target->packagetype_atom == pt_udeb ) { - while( p != NULL && !p->udebcomponents_set ) + if (target->packagetype == pt_udeb) { + while (p != NULL && !p->udebcomponents_set) p = p->pattern_from; - if( p != NULL ) { + if (p != NULL) { c_from = &p->udebcomponents_from; c_into = &p->udebcomponents_into; } } else { - while( p != NULL && !p->components_set ) + while (p != NULL && !p->components_set) p = p->pattern_from; - if( p != NULL ) { + if (p != NULL) { c_from = &p->components_from; c_into = &p->components_into; } } - if( a_into == NULL ) { - assert( atomlist_in(&distribution->architectures, - target->architecture_atom) ); - - if( c_into == NULL ) { - if( !addremoteindex(origin, target, updatetargets, - atoms_architectures[target->architecture_atom], - atoms_components[target->component_atom]) ) + if (a_into == NULL) { + assert (atomlist_in(&distribution->architectures, + target->architecture)); + + if (c_into == NULL) { + if (!addremoteindex(origin, target, updatetargets, + architecture, component)) return RET_ERROR_OOM; return RET_OK; } - for( ci = 0 ; ci < c_into->count ; ci++ ) { - if( strcmp(c_into->values[ci], - atoms_components[target->component_atom]) != 0 ) + for (ci = 0 ; ci < c_into->count ; ci++) { + if (strcmp(c_into->values[ci], component) != 0) continue; - if( !addremoteindex(origin, target, updatetargets, - atoms_architectures[target->architecture_atom], - c_from->values[ci]) ) + if (!addremoteindex(origin, target, updatetargets, + architecture, c_from->values[ci])) return RET_ERROR_OOM; } return RET_OK; } - for( ai = 0 ; ai < a_into->count ; ai++ ) { - if( strcmp(atoms_architectures[target->architecture_atom], - a_into->values[ai]) != 0 ) - continue; - if( c_into == NULL ) { - if( !addremoteindex(origin, target, updatetargets, - a_from->values[ai], - atoms_components[target->component_atom]) ) + for (ai = 0 ; ai < a_into->count ; ai++) { + if (strcmp(architecture, a_into->values[ai]) != 0) + continue; + if (c_into == NULL) { + if (!addremoteindex(origin, target, updatetargets, + a_from->values[ai], component)) return RET_ERROR_OOM; continue; } - for( ci = 0 ; ci < c_into->count ; ci++ ) { - if( strcmp(atoms_components[target->component_atom], - c_into->values[ci]) != 0 ) + for (ci = 0 ; ci < c_into->count ; ci++) { + if (strcmp(component, c_into->values[ci]) != 0) continue; - if( !addremoteindex(origin, target, updatetargets, - a_from->values[ai], c_from->values[ci]) ) + if (!addremoteindex(origin, target, updatetargets, + a_from->values[ai], c_from->values[ci])) return RET_ERROR_OOM; } } return RET_OK; } -static retvalue addflatorigintotarget(struct update_origin *origin, struct target *target, struct update_target *updatetargets ) { +static retvalue addflatorigintotarget(struct update_origin *origin, struct target *target, struct update_target *updatetargets) { const struct update_pattern *p; - const struct strlist *a_from, *a_into; + const struct strlist *a_into; const struct encoding_preferences *downloadlistsas; int ai; - assert( origin != NULL ); + assert (origin != NULL); - if( target->packagetype_atom == pt_udeb ) + if (target->packagetype == pt_udeb) return RET_NOTHING; p = origin->pattern; - while( p != NULL && !p->downloadlistsas_set ) + while (p != NULL && !p->downloadlistsas_set) p = p->pattern_from; - if( p == NULL ) + if (p == NULL) downloadlistsas = NULL; else downloadlistsas = &p->downloadlistsas; p = origin->pattern; - while( p != NULL && !atom_defined(p->flat) ) + while (p != NULL && !atom_defined(p->flat)) p = p->pattern_from; - assert( p != NULL ); - if( p->flat != target->component_atom ) + assert (p != NULL); + if (p->flat != target->component) return RET_NOTHING; p = origin->pattern; - while( p != NULL && !p->architectures_set ) + while (p != NULL && !p->architectures_set) p = p->pattern_from; - if( p == NULL ) { + if (p == NULL) { struct update_index_connector *uindex; - uindex = calloc(1, sizeof(struct update_index_connector)); - if( uindex == NULL ) + uindex = zNEW(struct update_index_connector); + if (FAILEDTOALLOC(uindex)) return RET_ERROR_OOM; uindex->origin = origin; uindex->remote = remote_flat_index(origin->from, - target->packagetype_atom, + target->packagetype, downloadlistsas); - if( FAILEDTOALLOC(uindex->remote) ) { + if (FAILEDTOALLOC(uindex->remote)) { free(uindex); return RET_ERROR_OOM; } uindex->next = updatetargets->indices; - assert( origin->flat ); + assert (origin->flat); uindex->ignorewrongarchitecture = true; updatetargets->indices = uindex; return RET_OK; } - a_from = &p->architectures_from; a_into = &p->architectures_into; - for( ai = 0 ; ai < a_into->count ; ai++ ) { + for (ai = 0 ; ai < a_into->count ; ai++) { struct update_index_connector *uindex; + const char *a = atoms_architectures[target->architecture]; - if( strcmp(a_into->values[ai], atoms_architectures[target->architecture_atom]) != 0 ) + if (strcmp(a_into->values[ai], a) != 0) continue; - uindex = calloc(1, sizeof(struct update_index_connector)); - if( uindex == NULL ) + uindex = zNEW(struct update_index_connector); + if (FAILEDTOALLOC(uindex)) return RET_ERROR_OOM; uindex->origin = origin; uindex->remote = remote_flat_index(origin->from, - target->packagetype_atom, + target->packagetype, downloadlistsas); - if( FAILEDTOALLOC(uindex->remote) ) { + if (FAILEDTOALLOC(uindex->remote)) { free(uindex); return RET_ERROR_OOM; } uindex->next = updatetargets->indices; - assert( origin->flat ); + assert (origin->flat); uindex->ignorewrongarchitecture = true; updatetargets->indices = uindex; } @@ -1135,8 +1140,8 @@ static retvalue adddeleteruletotarget(struct update_target *updatetargets) { struct update_index_connector *uindex; - uindex = calloc(1, sizeof(struct update_index_connector)); - if( FAILEDTOALLOC(uindex) ) + uindex = zNEW(struct update_index_connector); + if (FAILEDTOALLOC(uindex)) return RET_ERROR_OOM; uindex->next = updatetargets->indices; updatetargets->indices = uindex; @@ -1151,23 +1156,24 @@ updatetargets = NULL; - for( target = distribution->targets ; target != NULL ; target = target->next) { + for (target = distribution->targets ; target != NULL ; + target = target->next) { r = newupdatetarget(&updatetargets, target); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { updates_freetargets(updatetargets); return r; } - for( origin = origins ; origin != NULL ; origin=origin->next ) { - if( origin->pattern == NULL ) + for (origin = origins ; origin != NULL ; origin=origin->next) { + if (origin->pattern == NULL) r = adddeleteruletotarget(updatetargets); - else if( !origin->flat ) + else if (!origin->flat) r = addorigintotarget(origin, target, distribution, updatetargets); else r = addflatorigintotarget(origin, target, updatetargets); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { updates_freetargets(updatetargets); return r; } @@ -1183,36 +1189,40 @@ struct update_origin *last; int count; - assert( updates != NULL ); + assert (updates != NULL); last = updates; count = 1; - while( last->next != NULL ) { + while (last->next != NULL) { last = last->next; count++; } result = RET_OK; - if( count != distribution->updates.count ) { + if (count != distribution->updates.count) { int i; // TODO: why is this here? can this actually happen? - for( i=0;iupdates.count;i++ ){ + for (i=0; iupdates.count; i++){ const char *update = distribution->updates.values[i]; struct update_origin *u; u = updates; - while( u != NULL && strcmp(u->pattern->name,update) != 0 ) + while (u != NULL && strcmp(u->pattern->name, update) != 0) u = u->next; - if( u == NULL ) { - fprintf(stderr,"Update '%s' is listed in distribution '%s', but was not found!\n",update,distribution->codename); + if (u == NULL) { + fprintf(stderr, +"Update '%s' is listed in distribution '%s', but was not found!\n", + update, distribution->codename); result = RET_ERROR_MISSING; break; } } - if( RET_IS_OK(result) ) { - fprintf(stderr,"Did you write an update two times in the update-line of '%s'?\n",distribution->codename); + if (RET_IS_OK(result)) { + fprintf(stderr, +"Did you write an update two times in the update-line of '%s'?\n", + distribution->codename); result = RET_NOTHING; } } @@ -1228,24 +1238,24 @@ u_ds = NULL; result = RET_NOTHING; - for( distribution = distributions ; distribution != NULL ; - distribution = distribution->next ) { + for (distribution = distributions ; distribution != NULL ; + distribution = distribution->next) { struct update_distribution *u_d; struct update_pattern **translated_updates IFSTUPIDCC(= NULL); - if( !distribution->selected ) + if (!distribution->selected) continue; r = findpatterns(patterns, distribution, &translated_updates); - if( r == RET_NOTHING ) + if (r == RET_NOTHING) continue; - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - u_d = calloc(1,sizeof(struct update_distribution)); - if( FAILEDTOALLOC(u_d) ) { + u_d = zNEW(struct update_distribution); + if (FAILEDTOALLOC(u_d)) { free(translated_updates); result = RET_ERROR_OOM; break; @@ -1257,27 +1267,27 @@ u_ds = u_d; r = getorigins(u_d); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { /* Check if we got all: */ r = findmissingupdate(distribution, u_d->origins); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } r = gettargets(u_d->origins, distribution, &u_d->targets); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { result = r; break; } } result = RET_OK; } - if( RET_IS_OK(result) ) { + if (RET_IS_OK(result)) { *update_distributions = u_ds; } else updates_freeupdatedistributions(u_ds); @@ -1295,14 +1305,14 @@ retvalue r; struct update_distribution *d; - for( d=distributions ; d != NULL ; d=d->next) { - if( willwrite ) { + for (d=distributions ; d != NULL ; d=d->next) { + if (willwrite) { r = distribution_prepareforwriting(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } r = distribution_loadalloverrides(d->distribution); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return remote_startup(run); @@ -1334,20 +1344,20 @@ /* distribution, component, architecture and pattern specific... */ newfilename = genlistsfilename(oldbasefilename, 5, "", ut->target->distribution->codename, - atoms_components[ut->target->component_atom], - atoms_architectures[ut->target->architecture_atom], + atoms_components[ut->target->component], + atoms_architectures[ut->target->architecture], origin->pattern->name, ENDOFARGUMENTS); - if( FAILEDTOALLOC(newfilename) ) + if (FAILEDTOALLOC(newfilename)) return RET_ERROR_OOM; child = fork(); - if( child < 0 ) { + if (child < 0) { int e = errno; free(newfilename); fprintf(stderr, "Error %d while forking for listhook: %s\n", e, strerror(e)); return RET_ERRNO(e); } - if( child == 0 ) { + if (child == 0) { int e; (void)closefrom(3); setenv("REPREPRO_BASE_DIR", global.basedir, true); @@ -1358,13 +1368,13 @@ setenv("REPREPRO_FILTER_CODENAME", ut->target->distribution->codename, true); setenv("REPREPRO_FILTER_PACKAGETYPE", - atoms_architectures[ut->target->packagetype_atom], + atoms_architectures[ut->target->packagetype], true); setenv("REPREPRO_FILTER_COMPONENT", - atoms_components[ut->target->component_atom], + atoms_components[ut->target->component], true); setenv("REPREPRO_FILTER_ARCHITECTURE", - atoms_architectures[ut->target->architecture_atom], + atoms_architectures[ut->target->architecture], true); setenv("REPREPRO_FILTER_PATTERN", origin->pattern->name, true); execl(listhook, listhook, oldfilename, newfilename, @@ -1374,30 +1384,36 @@ e, listhook, strerror(e)); exit(255); } - if( verbose > 5 ) + if (verbose > 5) fprintf(stderr, "Called %s '%s' '%s'\n", listhook, oldfilename, newfilename); f->afterhookfilename = newfilename; do { c = waitpid(child, &status, WUNTRACED); - if( c < 0 ) { + if (c < 0) { int e = errno; - fprintf(stderr, "Error %d while waiting for hook '%s' to finish: %s\n", + fprintf(stderr, +"Error %d while waiting for hook '%s' to finish: %s\n", e, listhook, strerror(e)); return RET_ERRNO(e); } - } while( c != child ); - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0 ) { - if( verbose > 5 ) - fprintf(stderr,"Listhook successfully returned!\n"); + } while (c != child); + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) { + if (verbose > 5) + fprintf(stderr, +"Listhook successfully returned!\n"); return RET_OK; } else { - fprintf(stderr,"Listhook failed with exitcode %d!\n",(int)WEXITSTATUS(status)); + fprintf(stderr, +"Listhook failed with exitcode %d!\n", + (int)WEXITSTATUS(status)); return RET_ERROR; } } else { - fprintf(stderr,"Listhook terminated abnormally. (status is %x)!\n",status); + fprintf(stderr, +"Listhook terminated abnormally. (status is %x)!\n", + status); return RET_ERROR; } return RET_OK; @@ -1415,13 +1431,13 @@ /* distribution, component, architecture and pattern specific... */ newfilename = genlistsfilename(oldbasefilename, 5, "", ut->target->distribution->codename, - atoms_components[ut->target->component_atom], - atoms_architectures[ut->target->architecture_atom], + atoms_components[ut->target->component], + atoms_architectures[ut->target->architecture], origin->pattern->name, ENDOFARGUMENTS); - if( FAILEDTOALLOC(newfilename) ) + if (FAILEDTOALLOC(newfilename)) return RET_ERROR_OOM; infd = open(oldfilename, O_RDONLY|O_NOCTTY|O_NOFOLLOW); - if( infd < 0 ) { + if (infd < 0) { int e = errno; fprintf(stderr, @@ -1432,7 +1448,7 @@ (void)unlink(newfilename); outfd = open(newfilename, O_WRONLY|O_NOCTTY|O_NOFOLLOW|O_CREAT|O_EXCL, 0666); - if( outfd < 0 ) { + if (outfd < 0) { int e = errno; fprintf(stderr, "Error %d creating '%s': %s!\n", e, @@ -1441,7 +1457,7 @@ return RET_ERRNO(e); } child = fork(); - if( child < 0 ) { + if (child < 0) { int e = errno; free(newfilename); fprintf(stderr, "Error %d while forking for shell hook: %s\n", @@ -1451,11 +1467,11 @@ (void)unlink(newfilename); return RET_ERRNO(e); } - if( child == 0 ) { + if (child == 0) { int e; - assert( dup2(infd, 0) == 0 ); - assert( dup2(outfd, 1) == 1 ); + assert (dup2(infd, 0) == 0); + assert (dup2(outfd, 1) == 1); close(infd); close(outfd); (void)closefrom(3); @@ -1467,13 +1483,13 @@ setenv("REPREPRO_FILTER_CODENAME", ut->target->distribution->codename, true); setenv("REPREPRO_FILTER_PACKAGETYPE", - atoms_architectures[ut->target->packagetype_atom], + atoms_architectures[ut->target->packagetype], true); setenv("REPREPRO_FILTER_COMPONENT", - atoms_components[ut->target->component_atom], + atoms_components[ut->target->component], true); setenv("REPREPRO_FILTER_ARCHITECTURE", - atoms_architectures[ut->target->architecture_atom], + atoms_architectures[ut->target->architecture], true); setenv("REPREPRO_FILTER_PATTERN", origin->pattern->name, true); execlp("sh", "sh", "-c", shellhook, ENDOFARGUMENTS); @@ -1484,24 +1500,25 @@ } (void)close(infd); (void)close(outfd); - if( verbose > 5 ) + if (verbose > 5) fprintf(stderr, "Called sh -c '%s' <'%s' >'%s'\n", shellhook, oldfilename, newfilename); f->afterhookfilename = newfilename; do { c = waitpid(child, &status, WUNTRACED); - if( c < 0 ) { + if (c < 0) { int e = errno; fprintf(stderr, "Error %d while waiting for shell hook '%s' to finish: %s\n", e, shellhook, strerror(e)); return RET_ERRNO(e); } - } while( c != child ); - if( WIFEXITED(status) ) { - if( WEXITSTATUS(status) == 0 ) { - if( verbose > 5 ) - fprintf(stderr, "shell hook successfully returned!\n"); + } while (c != child); + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) { + if (verbose > 5) + fprintf(stderr, +"shell hook successfully returned!\n"); return RET_OK; } else { fprintf(stderr, @@ -1519,54 +1536,54 @@ } static retvalue calllisthooks(struct update_distribution *d) { - retvalue result,r; + retvalue result, r; struct update_target *target; struct update_index_connector *uindex; result = RET_NOTHING; - for( target = d->targets; target != NULL ; target = target->next ) { - if( target->nothingnew ) + for (target = d->targets; target != NULL ; target = target->next) { + if (target->nothingnew) continue; /* if anything is new, we will to need to look at * all (in case there are delete rules) */ - for( uindex = target->indices ; uindex != NULL ; - uindex = uindex->next ) { + for (uindex = target->indices ; uindex != NULL ; + uindex = uindex->next) { const struct update_pattern *p; - if( uindex->remote == NULL ) + if (uindex->remote == NULL) continue; - if( uindex->failed ) + if (uindex->failed) continue; p = uindex->origin->pattern; - while( p != NULL && p->listhook == NULL - && p->shellhook == NULL ) + while (p != NULL && p->listhook == NULL + && p->shellhook == NULL) p = p->pattern_from; - if( p == NULL ) + if (p == NULL) continue; - if( p->listhook != NULL ) + if (p->listhook != NULL) r = calllisthook(target, uindex, p->listhook); else { - assert( p->shellhook != NULL ); + assert (p->shellhook != NULL); r = callshellhook(target, uindex, p->shellhook); } - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uindex->failed = true; return r; } - RET_UPDATE(result,r); + RET_UPDATE(result, r); } } return result; } static retvalue updates_calllisthooks(struct update_distribution *distributions) { - retvalue result,r; + retvalue result, r; struct update_distribution *d; result = RET_NOTHING; - for( d=distributions ; d != NULL ; d=d->next) { + for (d=distributions ; d != NULL ; d=d->next) { r = calllisthooks(d); - RET_UPDATE(result,r); + RET_UPDATE(result, r); } return result; } @@ -1576,21 +1593,51 @@ * (all the logic in upgradelist.c, this is only clue code) * ****************************************************************************/ -static upgrade_decision ud_decide_by_pattern(void *privdata, const struct target *target, const char *package, /*@null@*/const char *old_version, UNUSED(const char *new_version), const char *newcontrolchunk) { +static upgrade_decision ud_decide_by_pattern(void *privdata, const struct target *target, const char *package, const char *source, /*@null@*/const char *old_version, const char *new_version, const char *new_src_version, const char *newcontrolchunk) { const struct update_pattern *pattern = privdata, *p; retvalue r; upgrade_decision decision = UD_UPGRADE; enum filterlisttype listdecision; + bool cmdline_still_undecided; - p = pattern; - while( p != NULL && !p->filterlist.set ) - p = p->pattern_from; - if( p == NULL ) - listdecision = flt_install; - else - listdecision = filterlist_find(package, &p->filterlist); + if (target->packagetype == pt_dsc) { + p = pattern; + while (p != NULL && !p->filtersrclist.set) + p = p->pattern_from; + if (p != NULL) + listdecision = filterlist_find(package, new_version, + &p->filtersrclist); + else { + p = pattern; + while (p != NULL && !p->filterlist.set) + p = p->pattern_from; + if (p == NULL) + listdecision = flt_install; + else + listdecision = filterlist_find(package, + new_version, &p->filterlist); + } + } else { + p = pattern; + while (p != NULL && !p->filterlist.set) + p = p->pattern_from; + if (p != NULL) + listdecision = filterlist_find(package, new_version, + &p->filterlist); + else { + p = pattern; + while (p != NULL && !p->filtersrclist.set) + p = p->pattern_from; + if (p == NULL) + listdecision = flt_install; + else + listdecision = filterlist_find(source, + new_src_version, + &p->filtersrclist); + } + } - switch( listdecision ) { + switch (listdecision) { case flt_deinstall: case flt_purge: return UD_NO; @@ -1605,22 +1652,90 @@ "Package name marked to be unexpected('error'): '%s'!\n", package); return UD_ERROR; case flt_upgradeonly: - if( old_version == NULL ) + if (old_version == NULL) return UD_NO; break; case flt_install: break; + case flt_unchanged: + case flt_auto_hold: + assert (listdecision != listdecision); + } + + cmdline_still_undecided = false; + switch (filterlist_find(source, new_src_version, &cmdline_src_filter)) { + case flt_deinstall: + case flt_purge: + return UD_NO; + case flt_warning: + return UD_LOUDNO; + case flt_auto_hold: + cmdline_still_undecided = true; + decision = UD_HOLD; + break; + case flt_hold: + decision = UD_HOLD; + break; + case flt_error: + /* cannot yet be handled! */ + fprintf(stderr, +"Package name marked to be unexpected('error'): '%s'!\n", package); + return UD_ERROR; + case flt_upgradeonly: + if (old_version == NULL) + return UD_NO; + break; + case flt_install: + decision = UD_UPGRADE; + break; + case flt_unchanged: + cmdline_still_undecided = true; + break; + } + + + if (target->packagetype != pt_dsc) { + switch (filterlist_find(package, new_version, + &cmdline_bin_filter)) { + case flt_deinstall: + case flt_purge: + return UD_NO; + case flt_warning: + return UD_LOUDNO; + case flt_hold: + decision = UD_HOLD; + break; + case flt_error: + /* cannot yet be handled! */ + fprintf(stderr, +"Package name marked to be unexpected('error'): '%s'!\n", package); + return UD_ERROR; + case flt_upgradeonly: + if (old_version == NULL) + return UD_NO; + break; + case flt_install: + decision = UD_UPGRADE; + break; + case flt_unchanged: + break; + case flt_auto_hold: + /* hold only if it was not in the src-filter */ + if (cmdline_still_undecided) + decision = UD_HOLD; + break; + } } p = pattern; - while( p != NULL && !p->includecondition_set ) + while (p != NULL && !p->includecondition_set) p = p->pattern_from; - if( p != NULL ) { + if (p != NULL) { r = term_decidechunktarget(p->includecondition, newcontrolchunk, target); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return UD_ERROR; - if( r == RET_NOTHING ) { + if (r == RET_NOTHING) { return UD_NO; } } @@ -1629,88 +1744,91 @@ } -static inline retvalue searchformissing(/*@null@*/FILE *out,struct database *database,struct update_target *u) { +static inline retvalue searchformissing(/*@null@*/FILE *out, struct update_target *u) { struct update_index_connector *uindex; - retvalue result,r; + retvalue result, r; - if( u->nothingnew ) { - if( u->indices == NULL && verbose >= 4 && out != NULL) + if (u->nothingnew) { + if (u->indices == NULL && verbose >= 4 && out != NULL) fprintf(out, " nothing to do for '%s'\n", u->target->identifier); - else if( u->indices != NULL && verbose >= 0 && out != NULL) + else if (u->indices != NULL && verbose >= 0 && out != NULL) fprintf(out, " nothing new for '%s' (use --noskipold to process anyway)\n", u->target->identifier); return RET_NOTHING; } - if( verbose > 2 && out != NULL) - fprintf(out," processing updates for '%s'\n",u->target->identifier); - r = upgradelist_initialize(&u->upgradelist, u->target, database); - if( RET_WAS_ERROR(r) ) + if (verbose > 2 && out != NULL) + fprintf(out, " processing updates for '%s'\n", + u->target->identifier); + r = upgradelist_initialize(&u->upgradelist, u->target); + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - for( uindex = u->indices ; uindex != NULL ; uindex = uindex->next ) { + for (uindex = u->indices ; uindex != NULL ; uindex = uindex->next) { const char *filename; - if( uindex->origin == NULL ) { - if( verbose > 4 && out != NULL) - fprintf(out," marking everything to be deleted\n"); + if (uindex->origin == NULL) { + if (verbose > 4 && out != NULL) + fprintf(out, +" marking everything to be deleted\n"); r = upgradelist_deleteall(u->upgradelist); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) u->incomplete = true; - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) return result; u->ignoredelete = false; continue; } - if( uindex->afterhookfilename != NULL ) + if (uindex->afterhookfilename != NULL) filename = uindex->afterhookfilename; else filename = remote_index_file(uindex->remote); - if( uindex->failed || uindex->origin->failed ) { - if( verbose >= 1 ) - fprintf(stderr," missing '%s'\n", filename); + if (uindex->failed || uindex->origin->failed) { + if (verbose >= 1) + fprintf(stderr, +" missing '%s'\n", filename); u->incomplete = true; u->ignoredelete = true; continue; } - if( verbose > 4 && out != NULL) - fprintf(out," reading '%s'\n", filename); + if (verbose > 4 && out != NULL) + fprintf(out, " reading '%s'\n", filename); r = upgradelist_update(u->upgradelist, uindex, filename, ud_decide_by_pattern, (void*)uindex->origin->pattern, uindex->ignorewrongarchitecture); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { u->incomplete = true; u->ignoredelete = true; } - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) return result; } return result; } -static retvalue updates_readindices(/*@null@*/FILE *out,struct database *database,struct update_distribution *d) { - retvalue result,r; +static retvalue updates_readindices(/*@null@*/FILE *out, struct update_distribution *d) { + retvalue result, r; struct update_target *u; result = RET_NOTHING; - for( u=d->targets ; u != NULL ; u=u->next ) { - r = searchformissing(out, database, u); - if( RET_WAS_ERROR(r) ) + for (u=d->targets ; u != NULL ; u=u->next) { + r = searchformissing(out, u); + if (RET_WAS_ERROR(r)) u->incomplete = true; - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } return result; @@ -1720,7 +1838,7 @@ * Step 10: enqueue downloading of missing packages * ****************************************************************************/ -static retvalue enqueue_upgrade_package(void *calldata, struct database *database, const struct checksumsarray *origfiles, const struct strlist *filekeys, void *privdata) { +static retvalue enqueue_upgrade_package(void *calldata, const struct checksumsarray *origfiles, const struct strlist *filekeys, void *privdata) { struct update_index_connector *uindex = privdata; struct aptmethod *aptmethod; struct downloadcache *cache = calldata; @@ -1728,23 +1846,23 @@ assert(privdata != NULL); aptmethod = remote_aptmethod(uindex->origin->from); assert(aptmethod != NULL); - return downloadcache_addfiles(cache, database, aptmethod, - origfiles, filekeys); + return downloadcache_addfiles(cache, aptmethod, origfiles, filekeys); } -static retvalue updates_enqueue(struct downloadcache *cache,struct database *database,struct update_distribution *distribution) { - retvalue result,r; +static retvalue updates_enqueue(struct downloadcache *cache, struct update_distribution *distribution) { + retvalue result, r; struct update_target *u; result = RET_NOTHING; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->nothingnew ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->nothingnew) continue; - r = upgradelist_enqueue(u->upgradelist, enqueue_upgrade_package, cache, database); - if( RET_WAS_ERROR(r) ) + r = upgradelist_enqueue(u->upgradelist, enqueue_upgrade_package, + cache); + if (RET_WAS_ERROR(r)) u->incomplete = true; - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } return result; @@ -1757,12 +1875,12 @@ static bool isbigdelete(struct update_distribution *d) { struct update_target *u, *v; - for( u = d->targets ; u != NULL ; u=u->next ) { - if( u->nothingnew || u->ignoredelete ) + for (u = d->targets ; u != NULL ; u=u->next) { + if (u->nothingnew || u->ignoredelete) continue; - if( upgradelist_isbigdelete(u->upgradelist) ) { + if (upgradelist_isbigdelete(u->upgradelist)) { d->distribution->omitted = true; - for( v = d->targets ; v != NULL ; v = v->next ) { + for (v = d->targets ; v != NULL ; v = v->next) { upgradelist_free(v->upgradelist); v->upgradelist = NULL; } @@ -1779,30 +1897,30 @@ *rule_p = uindex->origin->pattern->name; } -static retvalue updates_install(struct database *database, struct update_distribution *distribution) { - retvalue result,r; +static retvalue updates_install(struct update_distribution *distribution) { + retvalue result, r; struct update_target *u; struct distribution *d = distribution->distribution; - assert( logger_isprepared(d->logger) ); + assert (logger_isprepared(d->logger)); result = RET_NOTHING; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->nothingnew ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->nothingnew) continue; - r = upgradelist_install(u->upgradelist, d->logger, database, + r = upgradelist_install(u->upgradelist, d->logger, u->ignoredelete, updates_from_callback); RET_UPDATE(d->status, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) u->incomplete = true; - RET_UPDATE(result,r); + RET_UPDATE(result, r); upgradelist_free(u->upgradelist); u->upgradelist = NULL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) break; } - if( RET_IS_OK(result) && d->tracking != dt_NONE ) { - r = tracking_retrack(database, d, false); + if (RET_IS_OK(result) && d->tracking != dt_NONE) { + r = tracking_retrack(d, false); RET_ENDUPDATE(result, r); } return result; @@ -1820,15 +1938,15 @@ retvalue r; r = markdone_create(d->distribution->codename, &done); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return; - for( t = d->targets ; t != NULL ; t = t->next ) { - if( t->incomplete ) + for (t = d->targets ; t != NULL ; t = t->next) { + if (t->incomplete) continue; markdone_target(done, t->target->identifier); - for( i = t->indices ; i != NULL ; i = i->next ) - if( i->remote == NULL ) + for (i = t->indices ; i != NULL ; i = i->next) + if (i->remote == NULL) markdone_cleaner(done); else remote_index_markdone(i->remote, done); @@ -1850,30 +1968,30 @@ const char *identifier; r = donefile_open(ud->distribution->codename, &donefile); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - while( donefile_nexttarget(donefile, &identifier) ) { + while (donefile_nexttarget(donefile, &identifier)) { ut = ud->targets; - while( ut != NULL && strcmp(identifier, - ut->target->identifier) != 0 ) + while (ut != NULL && strcmp(identifier, + ut->target->identifier) != 0) ut = ut->next; - if( ut == NULL ) + if (ut == NULL) continue; ut->nothingnew = true; - for( ui = ut->indices ; ui != NULL ; ui = ui->next ) { + for (ui = ut->indices ; ui != NULL ; ui = ui->next) { /* if the order does not match, it does not matter * if they are new or not, they should be processed * anyway */ - if( ui->remote == NULL ) { - if( !donefile_iscleaner(donefile) ) { + if (ui->remote == NULL) { + if (!donefile_iscleaner(donefile)) { ut->nothingnew = false; break; } continue; } - if( remote_index_isnew(ui->remote, donefile) ) { + if (remote_index_isnew(ui->remote, donefile)) { ut->nothingnew = false; break; } @@ -1891,14 +2009,14 @@ retvalue r; r = remote_preparemetalists(run, nolistsdownload); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - for( d = distributions ; d != NULL ; d = d->next) { + for (d = distributions ; d != NULL ; d = d->next) { /* first check what is old */ - if( skipold ) { + if (skipold) { r = markold(d); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } /* we need anything that is needed in a target @@ -1906,15 +2024,15 @@ * a package is left hiding leftmore packages, * and everthing in rightmore packages is needed * to see what in the new takes effect) */ - for( ut = d->targets; ut != NULL ; ut = ut->next ) { - if( ut->nothingnew ) + for (ut = d->targets; ut != NULL ; ut = ut->next) { + if (ut->nothingnew) continue; - if( ut->indices == NULL ) { + if (ut->indices == NULL) { ut->nothingnew = true; continue; } - for( ui = ut->indices ; ui != NULL ; ui = ui->next ) { - if( ui->remote == NULL ) + for (ui = ut->indices ; ui != NULL ; ui = ui->next) { + if (ui->remote == NULL) continue; remote_index_needed(ui->remote); *anythingtodo = true; @@ -1923,39 +2041,42 @@ } r = remote_preparelists(run, nolistsdownload); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; return RET_OK; } static retvalue updates_prepare(struct update_distribution *distributions, bool willwrite, bool nolistsdownload, bool skipold, struct aptmethodrun **run_p) { - retvalue result,r; + retvalue result, r; struct aptmethodrun *run; bool anythingtodo = !skipold; r = aptmethod_initialize_run(&run); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; /* preperations */ result = updates_startup(run, distributions, willwrite); - if( RET_WAS_ERROR(result) ) { + if (RET_WAS_ERROR(result)) { aptmethod_shutdown(run); return result; } - r = updates_preparelists(run, distributions, nolistsdownload, skipold, &anythingtodo); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + r = updates_preparelists(run, distributions, nolistsdownload, skipold, + &anythingtodo); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) { aptmethod_shutdown(run); return result; } - if( !anythingtodo && skipold ) { - if( verbose >= 0 ) { - if( willwrite ) - printf("Nothing to do found. (Use --noskipold to force processing)\n"); + if (!anythingtodo && skipold) { + if (verbose >= 0) { + if (willwrite) + printf( +"Nothing to do found. (Use --noskipold to force processing)\n"); else - fprintf(stderr, "Nothing to do found. (Use --noskipold to force processing)\n"); + fprintf(stderr, +"Nothing to do found. (Use --noskipold to force processing)\n"); } aptmethod_shutdown(run); @@ -1966,8 +2087,8 @@ * (This is done even when nolistsdownload is given, as otherwise * the filename to look in is not calculated) */ r = updates_calllisthooks(distributions); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) { aptmethod_shutdown(run); return result; } @@ -1977,8 +2098,8 @@ } -retvalue updates_update(struct database *database, struct update_distribution *distributions, bool nolistsdownload, bool skipold, enum spacecheckmode mode, off_t reserveddb, off_t reservedother) { - retvalue result,r; +retvalue updates_update(struct update_distribution *distributions, bool nolistsdownload, bool skipold, enum spacecheckmode mode, off_t reserveddb, off_t reservedother) { + retvalue result, r; struct update_distribution *d; struct downloadcache *cache; struct aptmethodrun *run IFSTUPIDCC(=NULL); @@ -1986,97 +2107,99 @@ causingfile = NULL; - result = updates_prepare(distributions, true, nolistsdownload, skipold, &run); - if( !RET_IS_OK(result) ) + result = updates_prepare(distributions, true, nolistsdownload, skipold, + &run); + if (!RET_IS_OK(result)) return result; /* Then get all packages */ - if( verbose >= 0 ) + if (verbose >= 0) printf("Calculating packages to get...\n"); r = downloadcache_initialize(mode, reserveddb, reservedother, &cache); - if( !RET_IS_OK(r) ) { + if (!RET_IS_OK(r)) { aptmethod_shutdown(run); - RET_UPDATE(result,r); + RET_UPDATE(result, r); return result; } todo = false; - for( d=distributions ; d != NULL ; d=d->next) { - r = updates_readindices(stdout, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = updates_readindices(stdout, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; - if( global.onlysmalldeletes ) { - if( isbigdelete(d) ) + if (global.onlysmalldeletes) { + if (isbigdelete(d)) continue; } - r = updates_enqueue(cache, database, d); - if( RET_IS_OK(r) ) + r = updates_enqueue(cache, d); + if (RET_IS_OK(r)) todo = true; - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } - if( !RET_WAS_ERROR(result) ) { + if (!RET_WAS_ERROR(result)) { r = space_check(cache->devices); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); } - if( RET_WAS_ERROR(result) || !todo ) { - for( d=distributions ; d != NULL ; d=d->next) { + if (RET_WAS_ERROR(result) || !todo) { + for (d=distributions ; d != NULL ; d=d->next) { struct update_target *u; - if( d->distribution->omitted ) { + if (d->distribution->omitted) { fprintf(stderr, "Not processing updates for '%s' because of --onlysmalldeletes!\n", d->distribution->codename); - } else if( RET_IS_OK(result) ) + } else if (RET_IS_OK(result)) markdone(d); - for( u=d->targets ; u != NULL ; u=u->next ) { + for (u=d->targets ; u != NULL ; u=u->next) { upgradelist_free(u->upgradelist); u->upgradelist = NULL; } } r = downloadcache_free(cache); - RET_UPDATE(result,r); + RET_UPDATE(result, r); aptmethod_shutdown(run); return result; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Getting packages...\n"); r = aptmethod_download(run); - RET_UPDATE(result,r); + RET_UPDATE(result, r); r = downloadcache_free(cache); - RET_ENDUPDATE(result,r); - if( verbose > 0 ) + RET_ENDUPDATE(result, r); + if (verbose > 0) printf("Shutting down aptmethods...\n"); r = aptmethod_shutdown(run); - RET_UPDATE(result,r); + RET_UPDATE(result, r); - if( RET_WAS_ERROR(result) ) { - for( d=distributions ; d != NULL ; d=d->next) { + if (RET_WAS_ERROR(result)) { + for (d=distributions ; d != NULL ; d=d->next) { struct update_target *u; - for( u=d->targets ; u != NULL ; u=u->next ) { + for (u=d->targets ; u != NULL ; u=u->next) { upgradelist_free(u->upgradelist); u->upgradelist = NULL; } } return result; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Installing (and possibly deleting) packages...\n"); - for( d=distributions ; d != NULL ; d=d->next) { - if( d->distribution->omitted ) + for (d=distributions ; d != NULL ; d=d->next) { + if (d->distribution->omitted) continue; - r = updates_install(database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + r = updates_install(d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } - for( d=distributions ; d != NULL ; d=d->next) { - if( d->distribution->omitted ) { - fprintf(stderr, "Not processing updates for '%s' because of --onlysmalldeletes!\n", + for (d=distributions ; d != NULL ; d=d->next) { + if (d->distribution->omitted) { + fprintf(stderr, +"Not processing updates for '%s' because of --onlysmalldeletes!\n", d->distribution->codename); } else markdone(d); @@ -2094,12 +2217,12 @@ static void upgrade_dumppackage(const char *packagename, /*@null@*/const char *oldversion, /*@null@*/const char *newversion, /*@null@*/const char *bestcandidate, /*@null@*/const struct strlist *newfilekeys, /*@null@*/const char *newcontrol, void *privdata) { struct update_index_connector *uindex = privdata; - if( newversion == NULL ) { - if( oldversion != NULL && bestcandidate != NULL ) { + if (newversion == NULL) { + if (oldversion != NULL && bestcandidate != NULL) { printf("'%s': '%s' will be deleted" " (best new: '%s')\n", packagename, oldversion, bestcandidate); - } else if( oldversion != NULL ) { + } else if (oldversion != NULL) { printf("'%s': '%s' will be deleted" " (no longer available)\n", packagename, oldversion); @@ -2107,15 +2230,15 @@ printf("'%s': will NOT be added as '%s'\n", packagename, bestcandidate); } - } else if( newversion == oldversion ) { - if( bestcandidate != NULL ) { - if( verbose > 1 ) + } else if (newversion == oldversion) { + if (bestcandidate != NULL) { + if (verbose > 1) printf("'%s': '%s' will be kept" " (best new: '%s')\n", packagename, oldversion, bestcandidate); } else { - if( verbose > 0 ) + if (verbose > 0) printf("'%s': '%s' will be kept" " (unavailable for reload)\n", packagename, oldversion); @@ -2123,19 +2246,19 @@ } else { const char *via = uindex->origin->pattern->name; - assert( newfilekeys != NULL ); - assert( newcontrol != NULL ); - if( oldversion != NULL ) - (void)printf("'%s': '%s' will be upgraded" - " to '%s' (from '%s'):\n files needed: ", + assert (newfilekeys != NULL); + assert (newcontrol != NULL); + if (oldversion != NULL) + (void)printf( +"'%s': '%s' will be upgraded to '%s' (from '%s'):\n files needed: ", packagename, oldversion, newversion, via); else - (void)printf("'%s': newly installed" - " as '%s' (from '%s'):\n files needed: ", + (void)printf( +"'%s': newly installed as '%s' (from '%s'):\n files needed: ", packagename, newversion, via); (void)strlist_fprint(stdout, newfilekeys); - if( verbose > 2) + if (verbose > 2) (void)printf("\n installing as: '%s'\n", newcontrol); else @@ -2146,10 +2269,10 @@ static void updates_dump(struct update_distribution *distribution) { struct update_target *u; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->nothingnew ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->nothingnew) continue; - printf("Updates needed for '%s':\n",u->target->identifier); + printf("Updates needed for '%s':\n", u->target->identifier); upgradelist_dump(u->upgradelist, upgrade_dumppackage); upgradelist_free(u->upgradelist); u->upgradelist = NULL; @@ -2159,12 +2282,12 @@ static void upgrade_dumplistpackage(const char *packagename, /*@null@*/const char *oldversion, /*@null@*/const char *newversion, /*@null@*/const char *bestcandidate, /*@null@*/const struct strlist *newfilekeys, /*@null@*/const char *newcontrol, void *privdata) { struct update_index_connector *uindex = privdata; - if( newversion == NULL ) { - if( oldversion == NULL ) + if (newversion == NULL) { + if (oldversion == NULL) return; printf("delete '%s' '%s'\n", packagename, oldversion); - } else if( newversion == oldversion ) { - if( bestcandidate != NULL ) + } else if (newversion == oldversion) { + if (bestcandidate != NULL) printf("keep '%s' '%s' '%s'\n", packagename, oldversion, bestcandidate); else @@ -2173,9 +2296,9 @@ } else { const char *via = uindex->origin->pattern->name; - assert( newfilekeys != NULL ); - assert( newcontrol != NULL ); - if( oldversion != NULL ) + assert (newfilekeys != NULL); + assert (newcontrol != NULL); + if (oldversion != NULL) (void)printf("update '%s' '%s' '%s' '%s'\n", packagename, oldversion, newversion, via); @@ -2188,8 +2311,8 @@ static void updates_dumplist(struct update_distribution *distribution) { struct update_target *u; - for( u=distribution->targets ; u != NULL ; u=u->next ) { - if( u->nothingnew ) + for (u=distribution->targets ; u != NULL ; u=u->next) { + if (u->nothingnew) continue; printf("Updates needed for '%s':\n", u->target->identifier); upgradelist_dump(u->upgradelist, upgrade_dumplistpackage); @@ -2198,31 +2321,32 @@ } } -retvalue updates_checkupdate(struct database *database, struct update_distribution *distributions, bool nolistsdownload, bool skipold) { +retvalue updates_checkupdate(struct update_distribution *distributions, bool nolistsdownload, bool skipold) { struct update_distribution *d; - retvalue result,r; + retvalue result, r; struct aptmethodrun *run IFSTUPIDCC(=NULL); - result = updates_prepare(distributions, false, nolistsdownload, skipold, &run); - if( !RET_IS_OK(result) ) + result = updates_prepare(distributions, false, nolistsdownload, skipold, + &run); + if (!RET_IS_OK(result)) return result; - if( verbose > 0 ) - fprintf(stderr,"Shutting down aptmethods...\n"); + if (verbose > 0) + fprintf(stderr, "Shutting down aptmethods...\n"); r = aptmethod_shutdown(run); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) { return result; } /* Then look what packages to get */ - if( verbose >= 0 ) - fprintf(stderr,"Calculating packages to get...\n"); + if (verbose >= 0) + fprintf(stderr, "Calculating packages to get...\n"); - for( d=distributions ; d != NULL ; d=d->next) { - r = updates_readindices(stderr, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = updates_readindices(stderr, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; updates_dump(d); } @@ -2230,25 +2354,26 @@ return result; } -retvalue updates_dumpupdate(struct database *database, struct update_distribution *distributions, bool nolistsdownload, bool skipold) { +retvalue updates_dumpupdate(struct update_distribution *distributions, bool nolistsdownload, bool skipold) { struct update_distribution *d; - retvalue result,r; + retvalue result, r; struct aptmethodrun *run IFSTUPIDCC(=NULL); - result = updates_prepare(distributions, false, nolistsdownload, skipold, &run); - if( !RET_IS_OK(result) ) + result = updates_prepare(distributions, false, nolistsdownload, skipold, + &run); + if (!RET_IS_OK(result)) return result; r = aptmethod_shutdown(run); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) { return result; } - for( d=distributions ; d != NULL ; d=d->next) { - r = updates_readindices(NULL, database, d); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + for (d=distributions ; d != NULL ; d=d->next) { + r = updates_readindices(NULL, d); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; updates_dumplist(d); } @@ -2261,55 +2386,55 @@ * delete. (Assuming no unexpected errors occur, like a file missing upstream.* *****************************************************************************/ -retvalue updates_predelete(struct database *database, struct update_distribution *distributions, bool nolistsdownload, bool skipold) { - retvalue result,r; +retvalue updates_predelete(struct update_distribution *distributions, bool nolistsdownload, bool skipold) { + retvalue result, r; struct update_distribution *d; struct aptmethodrun *run IFSTUPIDCC(= NULL); causingfile = NULL; - result = updates_prepare(distributions, true, nolistsdownload, skipold, &run); - if( !RET_IS_OK(result) ) + result = updates_prepare(distributions, true, nolistsdownload, skipold, + &run); + if (!RET_IS_OK(result)) return result; - if( verbose > 0 ) + if (verbose > 0) printf("Shutting down aptmethods...\n"); r = aptmethod_shutdown(run); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(result) ) { + RET_UPDATE(result, r); + if (RET_WAS_ERROR(result)) { return result; } - if( verbose >= 0 ) + if (verbose >= 0) printf("Removing obsolete or to be replaced packages...\n"); - for( d=distributions ; d != NULL ; d=d->next) { + for (d=distributions ; d != NULL ; d=d->next) { struct distribution *dd = d->distribution; struct update_target *u; - for( u=d->targets ; u != NULL ; u=u->next ) { - r = searchformissing(stdout, database, u); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) { + for (u=d->targets ; u != NULL ; u=u->next) { + r = searchformissing(stdout, u); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) { u->incomplete = true; continue; } - if( u->nothingnew || u->ignoredelete ) { + if (u->nothingnew || u->ignoredelete) { upgradelist_free(u->upgradelist); u->upgradelist = NULL; continue; } - r = upgradelist_predelete(u->upgradelist, - dd->logger, database); + r = upgradelist_predelete(u->upgradelist, dd->logger); RET_UPDATE(dd->status, r); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) u->incomplete = true; - RET_UPDATE(result,r); + RET_UPDATE(result, r); upgradelist_free(u->upgradelist); u->upgradelist = NULL; - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( RET_IS_OK(result) && dd->tracking != dt_NONE ) { - r = tracking_retrack(database, dd, false); + if (RET_IS_OK(result) && dd->tracking != dt_NONE) { + r = tracking_retrack(dd, false); RET_ENDUPDATE(result, r); } } @@ -2327,43 +2452,43 @@ struct target *t; int i, ai; - if( atom_defined(flat) ) { + if (atom_defined(flat)) { bool deb_needed = false, dsc_needed = false; - for( t = d->targets ; t != NULL ; t = t->next) { - if( t->packagetype_atom == pt_udeb ) + for (t = d->targets ; t != NULL ; t = t->next) { + if (t->packagetype == pt_udeb) continue; - if( flat != t->architecture_atom ) + if (flat != t->architecture) continue; - if( a_into != NULL && + if (a_into != NULL && !strlist_in(a_into, atoms_architectures[ - t->architecture_atom]) ) + t->architecture])) continue; - if( t->packagetype_atom == pt_deb ) + if (t->packagetype == pt_deb) deb_needed = true; - else if( t->packagetype_atom == pt_dsc ) + else if (t->packagetype == pt_dsc) dsc_needed = true; } - if( deb_needed ) + if (deb_needed) cachedlistfile_need_flat_index(files, repository, suite, pt_deb); - if( dsc_needed ) + if (dsc_needed) cachedlistfile_need_flat_index(files, repository, suite, pt_dsc); return; } /* .dsc */ - if( (a_into != NULL && strlist_in(a_into, "source")) || + if ((a_into != NULL && strlist_in(a_into, "source")) || (a_into == NULL && atomlist_in(&d->architectures, - architecture_source)) ) { - if( c_from != NULL ) - for( i = 0 ; i < c_from->count ; i++ ) + architecture_source))) { + if (c_from != NULL) + for (i = 0 ; i < c_from->count ; i++) cachedlistfile_need_index(files, repository, suite, "source", c_from->values[i], pt_dsc); else - for( i = 0 ; i < d->components.count ; i++ ) + for (i = 0 ; i < d->components.count ; i++) cachedlistfile_need_index(files, repository, suite, "source", atoms_components[ @@ -2371,33 +2496,33 @@ pt_dsc); } /* .deb and .udeb */ - if( a_into != NULL ) { - for( ai = 0 ; ai < a_into->count ; ai++ ) { + if (a_into != NULL) { + for (ai = 0 ; ai < a_into->count ; ai++) { const char *a = a_from->values[ai]; - if( strcmp(a_into->values[ai], "source") == 0 ) + if (strcmp(a_into->values[ai], "source") == 0) continue; - if( c_from != NULL ) - for( i = 0 ; i < c_from->count ; i++ ) + if (c_from != NULL) + for (i = 0 ; i < c_from->count ; i++) cachedlistfile_need_index(files, repository, suite, a, c_from->values[i], pt_deb); else - for( i = 0 ; i < d->components.count ; i++ ) + for (i = 0 ; i < d->components.count ; i++) cachedlistfile_need_index(files, repository, suite, a, atoms_components[ d->components.atoms[i]], pt_deb); - if( uc_from != NULL ) - for( i = 0 ; i < uc_from->count ; i++ ) + if (uc_from != NULL) + for (i = 0 ; i < uc_from->count ; i++) cachedlistfile_need_index(files, repository, suite, a, uc_from->values[i], pt_udeb); else - for( i = 0 ; i < d->udebcomponents.count ; i++ ) + for (i = 0 ; i < d->udebcomponents.count ; i++) cachedlistfile_need_index(files, repository, suite, a, atoms_components[ @@ -2405,33 +2530,33 @@ pt_udeb); } } else { - for( ai = 0 ; ai < d->architectures.count ; ai++ ) { + for (ai = 0 ; ai < d->architectures.count ; ai++) { const char *a = atoms_architectures[ d->architectures.atoms[ai]]; - if( d->architectures.atoms[ai] == architecture_source ) + if (d->architectures.atoms[ai] == architecture_source) continue; - if( c_from != NULL ) - for( i = 0 ; i < c_from->count ; i++ ) + if (c_from != NULL) + for (i = 0 ; i < c_from->count ; i++) cachedlistfile_need_index(files, repository, suite, a, c_from->values[i], pt_deb); else - for( i = 0 ; i < d->components.count ; i++ ) + for (i = 0 ; i < d->components.count ; i++) cachedlistfile_need_index(files, repository, suite, a, atoms_components[ d->components.atoms[i]], pt_deb); - if( uc_from != NULL ) - for( i = 0 ; i < uc_from->count ; i++ ) + if (uc_from != NULL) + for (i = 0 ; i < uc_from->count ; i++) cachedlistfile_need_index(files, repository, suite, a, uc_from->values[i], pt_udeb); else - for( i = 0 ; i < d->udebcomponents.count ; i++ ) + for (i = 0 ; i < d->udebcomponents.count ; i++) cachedlistfile_need_index(files, repository, suite, a, atoms_components[ @@ -2455,24 +2580,24 @@ char *suite; result = cachedlists_scandir(&files); - if( !RET_IS_OK(result) ) + if (!RET_IS_OK(result)) return result; result = RET_OK; - for( d = distributions ; d != NULL ; d = d->next ) { - if( d->updates.count == 0 ) + for (d = distributions ; d != NULL ; d = d->next) { + if (d->updates.count == 0) continue; cachedlistfile_need(files, "lastseen", 2, "", d->codename, NULL); - for( i = 0; i < d->updates.count ; i++ ) { + for (i = 0; i < d->updates.count ; i++) { const char *name = d->updates.values[i]; - if( strcmp(name, "-") == 0 ) + if (strcmp(name, "-") == 0) continue; p = patterns; - while( p != NULL && strcmp(name, p->name) != 0 ) + while (p != NULL && strcmp(name, p->name) != 0) p = p->next; - if( p == NULL ) { + if (p == NULL) { fprintf(stderr, "Cannot find definition of upgrade-rule '%s' for distribution '%s'!\n", name, d->codename); @@ -2480,36 +2605,36 @@ continue; } q = p; - while( q != NULL && q->pattern_from != NULL ) + while (q != NULL && q->pattern_from != NULL) q = q->pattern_from; repository = q->name; q = p; - while( q != NULL && !atom_defined(q->flat) ) + while (q != NULL && !atom_defined(q->flat)) q = q->pattern_from; isflat = q != NULL; q = p; - while( q != NULL && !q->architectures_set ) + while (q != NULL && !q->architectures_set) q = q->pattern_from; - if( q != NULL ) { + if (q != NULL) { a_from = &q->architectures_from; a_into = &q->architectures_into; } q = p; - while( q != NULL && !q->components_set ) + while (q != NULL && !q->components_set) q = q->pattern_from; - if( q != NULL ) { + if (q != NULL) { c_from = &q->components_from; c_into = &q->components_into; } q = p; - while( q != NULL && !q->udebcomponents_set ) + while (q != NULL && !q->udebcomponents_set) q = q->pattern_from; - if( q != NULL ) { + if (q != NULL) { uc_from = &q->udebcomponents_from; uc_into = &q->udebcomponents_into; } suite = translate_suite_pattern(p, d->codename); - if( FAILEDTOALLOC(suite) ) { + if (FAILEDTOALLOC(suite)) { cachedlistfile_freelist(files); return RET_ERROR_OOM; } diff -Nru reprepro-4.5.0/updates.h reprepro-4.6.0/updates.h --- reprepro-4.5.0/updates.h 2009-01-03 21:48:37.000000000 +0000 +++ reprepro-4.6.0/updates.h 2011-05-05 14:42:55.000000000 +0000 @@ -31,10 +31,10 @@ retvalue updates_calcindices(struct update_pattern *, struct distribution *, /*@out@*/struct update_distribution **); -retvalue updates_update(struct database *, struct update_distribution *, bool nolistsdownload, bool skipold, enum spacecheckmode mode, off_t reserveddb, off_t reservedother); -retvalue updates_checkupdate(struct database *, struct update_distribution *, bool nolistsdownload, bool skipold); -retvalue updates_dumpupdate(struct database *, struct update_distribution *, bool nolistsdownload, bool skipold); -retvalue updates_predelete(struct database *, struct update_distribution *, bool nolistsdownload, bool skipold); +retvalue updates_update(struct update_distribution *, bool /*nolistsdownload*/, bool /*skipold*/, enum spacecheckmode, off_t /*reserveddb*/, off_t /*reservedother*/); +retvalue updates_checkupdate(struct update_distribution *, bool /*nolistsdownload*/, bool /*skipold*/); +retvalue updates_dumpupdate(struct update_distribution *, bool /*nolistsdownload*/, bool /*skipold*/); +retvalue updates_predelete(struct update_distribution *, bool /*nolistsdownload*/, bool /*skipold*/); retvalue updates_cleanlists(const struct distribution *, const struct update_pattern *); #endif diff -Nru reprepro-4.5.0/upgradelist.c reprepro-4.6.0/upgradelist.c --- reprepro-4.5.0/upgradelist.c 2011-02-21 15:34:29.000000000 +0000 +++ reprepro-4.6.0/upgradelist.c 2011-05-05 14:42:55.000000000 +0000 @@ -23,6 +23,7 @@ #include #include "error.h" +#include "ignore.h" #include "strlist.h" #include "indexfile.h" #include "dpkgversions.h" @@ -73,7 +74,7 @@ }; static void package_data_free(/*@only@*/struct package_data *data){ - if( data == NULL ) + if (data == NULL) return; free(data->name); free(data->version_in_use); @@ -94,18 +95,18 @@ struct package_data *package; r = upgrade->target->getversion(chunk, &version); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - package = calloc(1,sizeof(struct package_data)); - if( package == NULL ) { + package = zNEW(struct package_data); + if (FAILEDTOALLOC(package)) { free(version); return RET_ERROR_OOM; } package->privdata = NULL; package->name = strdup(packagename); - if( package->name == NULL ) { + if (FAILEDTOALLOC(package->name)) { free(package); free(version); return RET_ERROR_OOM; @@ -114,12 +115,12 @@ version = NULL; // just to be sure... package->version = package->version_in_use; - if( upgrade->list == NULL ) { + if (upgrade->list == NULL) { /* first chunk to add: */ upgrade->list = package; upgrade->last = package; } else { - if( strcmp(packagename,upgrade->last->name) > 0 ) { + if (strcmp(packagename, upgrade->last->name) > 0) { upgrade->last->next = package; upgrade->last = package; } else { @@ -135,35 +136,35 @@ return RET_OK; } -retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,struct database *database) { +retvalue upgradelist_initialize(struct upgradelist **ul, struct target *t) { struct upgradelist *upgrade; - retvalue r,r2; + retvalue r, r2; const char *packagename, *controlchunk; struct target_cursor iterator; - upgrade = calloc(1,sizeof(struct upgradelist)); - if( upgrade == NULL ) + upgrade = zNEW(struct upgradelist); + if (FAILEDTOALLOC(upgrade)) return RET_ERROR_OOM; upgrade->target = t; /* Beginn with the packages currently in the archive */ - r = target_openiterator(t, database, READONLY, &iterator); - if( RET_WAS_ERROR(r) ) { + r = target_openiterator(t, READONLY, &iterator); + if (RET_WAS_ERROR(r)) { upgradelist_free(upgrade); return r; } - while( target_nextpackage(&iterator, &packagename, &controlchunk) ) { + while (target_nextpackage(&iterator, &packagename, &controlchunk)) { r2 = save_package_version(upgrade, packagename, controlchunk); - RET_UPDATE(r,r2); - if( RET_WAS_ERROR(r2) ) + RET_UPDATE(r, r2); + if (RET_WAS_ERROR(r2)) break; } r2 = target_closeiterator(&iterator); - RET_UPDATE(r,r2); + RET_UPDATE(r, r2); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { upgradelist_free(upgrade); return r; } @@ -177,11 +178,11 @@ void upgradelist_free(struct upgradelist *upgrade) { struct package_data *l; - if( upgrade == NULL ) + if (upgrade == NULL) return; l = upgrade->list; - while( l != NULL ) { + while (l != NULL) { struct package_data *n = l->next; package_data_free(l); l = n; @@ -191,15 +192,24 @@ return; } -static retvalue upgradelist_trypackage(struct upgradelist *upgrade, void *privdata, upgrade_decide_function *predecide, void *predecide_data, const char *packagename_const, /*@null@*//*@only@*/char *packagename, /*@only@*/char *version, architecture_t architecture, const char *chunk) { +static retvalue upgradelist_trypackage(struct upgradelist *upgrade, void *privdata, upgrade_decide_function *predecide, void *predecide_data, const char *packagename_const, /*@null@*//*@only@*/char *packagename, const char *sourcename, /*@only@*/char *version, const char *sourceversion, architecture_t architecture, const char *chunk) { retvalue r; upgrade_decision decision; - struct package_data *current,*insertafter; + struct package_data *current, *insertafter; + + if (architecture == architecture_all) { + if (upgrade->target->packagetype == pt_dsc) { + fputs("Internal error: trying to put binary ('all')" + " package into source architecture!\n", + stderr); + return RET_ERROR_INTERNAL; + } + } /* insertafter = NULL will mean insert before list */ insertafter = upgrade->last; /* the next one to test, current = NULL will mean not found */ - if( insertafter != NULL ) + if (insertafter != NULL) current = insertafter->next; else current = upgrade->list; @@ -209,24 +219,24 @@ * after the last one. Otherwise we walk down the long list * again and again... and again... and even some more...*/ - while( true ) { + while (true) { int cmp; - assert( insertafter == NULL || insertafter->next == current ); - assert( insertafter != NULL || current == upgrade->list ); + assert (insertafter == NULL || insertafter->next == current); + assert (insertafter != NULL || current == upgrade->list); - if( current == NULL ) + if (current == NULL) cmp = -1; /* every package is before the end of list */ else cmp = strcmp(packagename_const, current->name); - if( cmp == 0 ) + if (cmp == 0) break; - if( cmp < 0 ) { + if (cmp < 0) { int precmp; - if( insertafter == NULL ) { + if (insertafter == NULL) { /* if we are before the first * package, add us there...*/ current = NULL; @@ -234,15 +244,15 @@ } // I only hope noone creates indices anti-sorted: precmp = strcmp(packagename_const, insertafter->name); - if( precmp == 0 ) { + if (precmp == 0) { current = insertafter; break; - } else if( precmp < 0 ) { + } else if (precmp < 0) { /* restart at the beginning: */ current = upgrade->list; insertafter = NULL; - if( verbose > 10 ) { - fprintf(stderr,"restarting search..."); + if (verbose > 10) { + fprintf(stderr, "restarting search..."); } continue; } else { // precmp > 0 @@ -250,45 +260,50 @@ current = NULL; break; } - assert( "This is not reached" == NULL ); + assert ("This is not reached" == NULL); } /* cmp > 0 : may come later... */ - assert( current != NULL ); + assert (current != NULL); insertafter = current; current = current->next; - if( current == NULL ) { + if (current == NULL) { /* add behind insertafter at end of list */ break; } /* otherwise repeat until place found */ } - if( current == NULL ) { + if (current == NULL) { /* adding a package not yet known */ struct package_data *new; char *newcontrol; decision = predecide(predecide_data, upgrade->target, - packagename_const, NULL, version, chunk); - if( decision != UD_UPGRADE ) { + packagename_const, sourcename, + NULL, version, sourceversion, + chunk); + if (decision != UD_UPGRADE) { upgrade->last = insertafter; - if( decision == UD_LOUDNO ) - fprintf(stderr, "Loudly rejecting '%s' '%s' to enter '%s'!\n", packagename, version, upgrade->target->identifier); + if (decision == UD_LOUDNO) + fprintf(stderr, +"Loudly rejecting '%s' '%s' to enter '%s'!\n", + packagename, version, + upgrade->target->identifier); free(packagename); free(version); return (decision==UD_ERROR)?RET_ERROR:RET_NOTHING; } - new = calloc(1,sizeof(struct package_data)); - if( new == NULL ) { + new = zNEW(struct package_data); + if (FAILEDTOALLOC(new)) { free(packagename); free(version); return RET_ERROR_OOM; } new->deleted = false; //to be sure... new->privdata = privdata; - if( packagename == NULL ) { + if (packagename == NULL) { new->name = strdup(packagename_const); - if( FAILEDTOALLOC(new->name) ) { + if (FAILEDTOALLOC(new->name)) { free(packagename); free(version); free(new); @@ -306,22 +321,22 @@ new->architecture, chunk, &new->new_control, &new->new_filekeys, &new->new_origfiles); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { package_data_free(new); return r; } /* apply override data */ r = upgrade->target->doreoverride(upgrade->target, new->name, new->new_control, &newcontrol); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { package_data_free(new); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(new->new_control); new->new_control = newcontrol; } - if( insertafter != NULL ) { + if (insertafter != NULL) { new->next = insertafter->next; insertafter->next = new; } else { @@ -338,27 +353,27 @@ upgrade->last = current; - r = dpkgversions_cmp(version,current->version,&versioncmp); - if( RET_WAS_ERROR(r) ) { + r = dpkgversions_cmp(version, current->version, &versioncmp); + if (RET_WAS_ERROR(r)) { free(packagename); free(version); return r; } - if( versioncmp <= 0 && !current->deleted ) { + if (versioncmp <= 0 && !current->deleted) { /* there already is a newer version, so * doing nothing but perhaps updating what * versions are around, when we are newer * than yet known candidates... */ int c = 0; - if( current->new_version == current->version ) + if (current->new_version == current->version) c =versioncmp; - else if( current->new_version == NULL ) + else if (current->new_version == NULL) c = 1; else (void)dpkgversions_cmp(version, - current->new_version,&c); + current->new_version, &c); - if( c > 0 ) { + if (c > 0) { free(current->new_version); current->new_version = version; } else @@ -367,29 +382,34 @@ free(packagename); return RET_NOTHING; } - if( versioncmp > 0 && verbose > 30 ) - fprintf(stderr,"'%s' from '%s' is newer than '%s' currently\n", + if (versioncmp > 0 && verbose > 30) + fprintf(stderr, +"'%s' from '%s' is newer than '%s' currently\n", version, packagename_const, current->version); decision = predecide(predecide_data, upgrade->target, - current->name, current->version, - version, chunk); - if( decision != UD_UPGRADE ) { - if( decision == UD_LOUDNO ) - fprintf(stderr, "Loudly rejecting '%s' '%s' to enter '%s'!\n", packagename, version, upgrade->target->identifier); + current->name, sourcename, + current->version, + version, sourceversion, chunk); + if (decision != UD_UPGRADE) { + if (decision == UD_LOUDNO) + fprintf(stderr, +"Loudly rejecting '%s' '%s' to enter '%s'!\n", + packagename, version, + upgrade->target->identifier); /* Even if we do not install it, setting it on hold * will keep it or even install from a mirror before * the delete was applied */ - if( decision == UD_HOLD ) + if (decision == UD_HOLD) current->deleted = false; free(version); free(packagename); return (decision==UD_ERROR)?RET_ERROR:RET_NOTHING; } - if( versioncmp == 0 ) { + if (versioncmp == 0) { /* we are replacing a package with the same version, * so we keep the old one for sake of speed. */ - if( current->deleted && + if (current->deleted && current->version != current->new_version) { /* remember the version for checkupdate/pull */ free(current->new_version); @@ -400,17 +420,18 @@ free(packagename); return RET_NOTHING; } - if( versioncmp != 0 && current->version == current->new_version - && current->version_in_use != NULL ) { + if (versioncmp != 0 && current->version == current->new_version + && current->version_in_use != NULL) { /* The version to include is not the newest after the * last deletion round), but maybe older, maybe newer. * So we get to the question: it is also not the same * like the version we already have? */ int vcmp = 1; - (void)dpkgversions_cmp(version,current->version_in_use,&vcmp); - if( vcmp == 0 ) { + (void)dpkgversions_cmp(version, + current->version_in_use, &vcmp); + if (vcmp == 0) { current->version = current->version_in_use; - if( current->deleted ) { + if (current->deleted) { free(current->new_version); current->new_version = version; } else @@ -423,8 +444,8 @@ // TODO: the following case might be worth considering, but sadly new_version // might have changed without the proper data set. -// if( versioncmp >= 0 && current->version == current->version_in_use -// && current->new_version != NULL ) { +// if (versioncmp >= 0 && current->version == current->version_in_use +// && current->new_version != NULL) { current->architecture = architecture; r = upgrade->target->getinstalldata(upgrade->target, @@ -432,21 +453,21 @@ architecture, chunk, &control, &files, &origfiles); free(packagename); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); return r; } /* apply override data */ r = upgrade->target->doreoverride(upgrade->target, packagename_const, control, &newcontrol); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(version); free(control); strlist_done(&files); checksumsarray_done(&origfiles); return r; } - if( RET_IS_OK(r) ) { + if (RET_IS_OK(r)) { free(control); control = newcontrol; } @@ -455,7 +476,7 @@ current->new_version = version; current->version = version; current->privdata = privdata; - strlist_move(¤t->new_filekeys,&files); + strlist_move(¤t->new_filekeys, &files); checksumsarray_move(¤t->new_origfiles, &origfiles); free(current->new_control); current->new_control = control; @@ -465,31 +486,39 @@ retvalue upgradelist_update(struct upgradelist *upgrade, void *privdata, const char *filename, upgrade_decide_function *decide, void *decide_data, bool ignorewrongarchitecture) { struct indexfile *i; - char *packagename, *version; + char *packagename, *version, *sourcename, *sourceversion; const char *control; retvalue result, r; architecture_t package_architecture; r = indexfile_open(&i, filename, c_none); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; result = RET_NOTHING; upgrade->last = NULL; - while( indexfile_getnext(i, &packagename, &version, &control, + while (indexfile_getnext(i, &packagename, &version, &control, &package_architecture, - upgrade->target, ignorewrongarchitecture) ) { - r = upgradelist_trypackage(upgrade, privdata, decide, decide_data, - packagename, packagename, version, - package_architecture, control); - RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) { - if( verbose > 0 ) + upgrade->target, ignorewrongarchitecture)) { + r = upgrade->target->getsourceandversion(control, packagename, + &sourcename, &sourceversion); + if (RET_IS_OK(r)) { + r = upgradelist_trypackage(upgrade, privdata, + decide, decide_data, + packagename, packagename, sourcename, + version, sourceversion, + package_architecture, control); + RET_UPDATE(result, r); + free(sourcename); + free(sourceversion); + } + if (RET_WAS_ERROR(r)) { + if (verbose > 0) fprintf(stderr, "Stop reading further chunks from '%s' due to previous errors.\n", filename); break; } - if( interrupted() ) { + if (interrupted()) { result = RET_ERROR_INTERRUPTED; break; } @@ -499,45 +528,81 @@ return result; } -retvalue upgradelist_pull(struct upgradelist *upgrade, struct target *source, upgrade_decide_function *predecide, void *decide_data, struct database *database, void *privdata) { +retvalue upgradelist_pull(struct upgradelist *upgrade, struct target *source, upgrade_decide_function *predecide, void *decide_data, void *privdata) { retvalue result, r; const char *package, *control; struct target_cursor iterator; upgrade->last = NULL; - r = target_openiterator(source, database, READONLY, &iterator); - if( RET_WAS_ERROR(r) ) + r = target_openiterator(source, READONLY, &iterator); + if (RET_WAS_ERROR(r)) return r; result = RET_NOTHING; - while( target_nextpackage(&iterator, &package, &control) ) { + while (target_nextpackage(&iterator, &package, &control)) { char *version; architecture_t package_architecture; + char *sourcename, *sourceversion; + + assert (source->packagetype == upgrade->target->packagetype); - r = upgrade->target->getversion(control, &version); - assert( r != RET_NOTHING ); - if( !RET_IS_OK(r) ) { + r = source->getversion(control, &version); + assert (r != RET_NOTHING); + if (!RET_IS_OK(r)) { RET_UPDATE(result, r); break; } - r = upgrade->target->getarchitecture(control, &package_architecture); - if( !RET_IS_OK(r) ) { + r = source->getarchitecture(control, &package_architecture); + if (!RET_IS_OK(r)) { RET_UPDATE(result, r); break; } - r = upgradelist_trypackage(upgrade, privdata, - predecide, decide_data, - package, NULL, version, - package_architecture, control); - RET_UPDATE(result, r); - if( RET_WAS_ERROR(r) ) + if (package_architecture != upgrade->target->architecture + && package_architecture != architecture_all) { + free(version); + continue; + if (source->architecture + == upgrade->target->architecture + && !ignore[IGN_wrongarchitecture]) { + fprintf(stderr, +"WARNING: architecture '%s' package '%s' in '%s'!\n", + atoms_architectures[ + package_architecture], + package, + source->identifier); + if (ignored[IGN_wrongarchitecture] == 0) { + fprintf(stderr, +"(expected 'all' or '%s', so ignoring this package, but\n" +"your database seems to be in a bad state. (Try running 'reprepro check')!)\n", + atoms_architectures[ + source->architecture]); + } + ignored[IGN_wrongarchitecture]++; + } + free(version); + continue; + } + + r = upgrade->target->getsourceandversion(control, package, + &sourcename, &sourceversion); + if (RET_IS_OK(r)) { + r = upgradelist_trypackage(upgrade, privdata, + predecide, decide_data, + package, NULL, sourcename, + version, sourceversion, + package_architecture, control); + RET_UPDATE(result, r); + free(sourcename); + free(sourceversion); + } + if (RET_WAS_ERROR(r)) break; - if( interrupted() ) { + if (interrupted()) { result = RET_ERROR_INTERRUPTED; break; } } r = target_closeiterator(&iterator); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } @@ -545,45 +610,25 @@ retvalue upgradelist_deleteall(struct upgradelist *upgrade) { struct package_data *pkg; - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { pkg->deleted = true; } return RET_OK; } -retvalue upgradelist_listmissing(struct upgradelist *upgrade,struct database *database){ - struct package_data *pkg; - - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->version == pkg->new_version ) { - retvalue r; - r = files_printmissing(database, - &pkg->new_filekeys, - &pkg->new_origfiles); - if( RET_WAS_ERROR(r) ) - return r; - - } - - } - return RET_OK; -} - - /* request all wanted files in the downloadlists given before */ -retvalue upgradelist_enqueue(struct upgradelist *upgrade, enqueueaction *action, void *calldata, struct database *database) { +retvalue upgradelist_enqueue(struct upgradelist *upgrade, enqueueaction *action, void *calldata) { struct package_data *pkg; - retvalue result,r; + retvalue result, r; result = RET_NOTHING; assert(upgrade != NULL); - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->version == pkg->new_version && !pkg->deleted) { - r = action(calldata, database, - &pkg->new_origfiles, + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { + if (pkg->version == pkg->new_version && !pkg->deleted) { + r = action(calldata, &pkg->new_origfiles, &pkg->new_filekeys, pkg->privdata); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } } @@ -591,31 +636,31 @@ } /* delete all packages that will not be kept (i.e. either deleted or upgraded) */ -retvalue upgradelist_predelete(struct upgradelist *upgrade, struct logger *logger, struct database *database) { +retvalue upgradelist_predelete(struct upgradelist *upgrade, struct logger *logger) { struct package_data *pkg; - retvalue result,r; + retvalue result, r; result = RET_NOTHING; assert(upgrade != NULL); - result = target_initpackagesdb(upgrade->target, database, READWRITE); - if( RET_WAS_ERROR(result) ) + result = target_initpackagesdb(upgrade->target, READWRITE); + if (RET_WAS_ERROR(result)) return result; - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->version_in_use != NULL && - (pkg->version == pkg->new_version || pkg->deleted)) { - if( interrupted() ) + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { + if (pkg->version_in_use != NULL && + (pkg->version == pkg->new_version + || pkg->deleted)) { + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_removepackage(upgrade->target, - logger, database, - pkg->name, NULL); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r)) + logger, pkg->name, NULL); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } } r = target_closepackagesdb(upgrade->target); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } @@ -623,37 +668,41 @@ struct package_data *pkg; long long deleted = 0, all = 0; - if( upgrade->list == NULL ) + if (upgrade->list == NULL) return false; - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->version_in_use == NULL ) + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { + if (pkg->version_in_use == NULL) continue; all++; - if( pkg->deleted ) + if (pkg->deleted) deleted++; } return deleted >= 10 && all/deleted < 5; } -retvalue upgradelist_install(struct upgradelist *upgrade, struct logger *logger, struct database *database, bool ignoredelete, void (*callback)(void *, const char **, const char **)){ +retvalue upgradelist_install(struct upgradelist *upgrade, struct logger *logger, bool ignoredelete, void (*callback)(void *, const char **, const char **)){ struct package_data *pkg; - retvalue result,r; + retvalue result, r; - if( upgrade->list == NULL ) + if (upgrade->list == NULL) return RET_NOTHING; - result = target_initpackagesdb(upgrade->target, database, READWRITE); - if( RET_WAS_ERROR(result) ) + result = target_initpackagesdb(upgrade->target, READWRITE); + if (RET_WAS_ERROR(result)) return result; result = RET_NOTHING; - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( pkg->version == pkg->new_version && !pkg->deleted ) { + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { + if (pkg->version == pkg->new_version && !pkg->deleted) { char *newcontrol; - r = files_checkorimprove(database, - &pkg->new_filekeys, + assert ((pkg->architecture == architecture_all && + upgrade->target->packagetype != pt_dsc) + || pkg->architecture == + upgrade->target->architecture); + + r = files_checkorimprove(&pkg->new_filekeys, pkg->new_origfiles.checksums); - if( ! RET_WAS_ERROR(r) ) { + if (! RET_WAS_ERROR(r)) { r = upgrade->target->completechecksums( pkg->new_control, @@ -661,45 +710,45 @@ pkg->new_origfiles.checksums, &newcontrol); } - if( ! RET_WAS_ERROR(r) ) { + if (! RET_WAS_ERROR(r)) { /* upgrade (or possibly downgrade) */ const char *causingrule = NULL, *suitefrom = NULL; free(pkg->new_control); pkg->new_control = newcontrol; - callback(pkg->privdata, &causingrule, &suitefrom); + callback(pkg->privdata, + &causingrule, &suitefrom); // TODO: trackingdata? - if( interrupted() ) + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_addpackage(upgrade->target, - logger, database, - pkg->name, + logger, pkg->name, pkg->new_version, pkg->new_control, &pkg->new_filekeys, true, NULL, pkg->architecture, causingrule, suitefrom); } - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } - if( pkg->deleted && pkg->version_in_use != NULL && !ignoredelete ) { - if( interrupted() ) + if (pkg->deleted && pkg->version_in_use != NULL + && !ignoredelete) { + if (interrupted()) r = RET_ERROR_INTERRUPTED; else r = target_removepackage(upgrade->target, - logger, database, - pkg->name, NULL); - RET_UPDATE(result,r); - if( RET_WAS_ERROR(r) ) + logger, pkg->name, NULL); + RET_UPDATE(result, r); + if (RET_WAS_ERROR(r)) break; } } r = target_closepackagesdb(upgrade->target); - RET_ENDUPDATE(result,r); + RET_ENDUPDATE(result, r); return result; } @@ -708,14 +757,14 @@ assert(upgrade != NULL); - for( pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next ) { - if( interrupted() ) + for (pkg = upgrade->list ; pkg != NULL ; pkg = pkg->next) { + if (interrupted()) return; - if( pkg->deleted ) + if (pkg->deleted) action(pkg->name, pkg->version_in_use, NULL, pkg->new_version, NULL, NULL, pkg->privdata); - else if( pkg->version == pkg->version_in_use ) + else if (pkg->version == pkg->version_in_use) action(pkg->name, pkg->version_in_use, pkg->version_in_use, pkg->new_version, NULL, NULL, pkg->privdata); @@ -726,8 +775,3 @@ pkg->privdata); } } - -/* standard answer function */ -upgrade_decision ud_always(UNUSED(void *privdata), UNUSED(const struct target *target), UNUSED(const char *package), UNUSED(const char *old_version), UNUSED(const char *new_version), UNUSED(const char *new_controlchunk)) { - return UD_UPGRADE; -} diff -Nru reprepro-4.5.0/upgradelist.h reprepro-4.6.0/upgradelist.h --- reprepro-4.5.0/upgradelist.h 2010-05-08 12:01:43.000000000 +0000 +++ reprepro-4.6.0/upgradelist.h 2011-05-05 14:42:55.000000000 +0000 @@ -5,9 +5,7 @@ typedef enum { UD_ERROR, UD_LOUDNO, UD_NO, UD_UPGRADE, UD_HOLD } upgrade_decision; -typedef upgrade_decision upgrade_decide_function(void *privdata, const struct target *, const char *package, const char *old_version, const char *new_version, const char *newcontrolchunk); - -upgrade_decision ud_always(void *, const struct target *, const char *, const char *, const char *, const char *); +typedef upgrade_decision upgrade_decide_function(void *privdata, const struct target *, const char *package, const char *source, const char *old_version, const char *new_version, const char *new_src_version, const char *newcontrolchunk); /* The main part: */ @@ -15,32 +13,31 @@ struct logger; struct upgradelist; -retvalue upgradelist_initialize(struct upgradelist **ul,/*@dependent@*/struct target *target,struct database *); -void upgradelist_free(/*@only@*/struct upgradelist *upgrade); +retvalue upgradelist_initialize(struct upgradelist **, /*@dependent@*/struct target *); +void upgradelist_free(/*@only@*/struct upgradelist *); typedef void dumpaction(const char */*packagename*/, /*@null@*/const char */*oldversion*/, /*@null@*/const char */*newversion*/, /*@null@*/const char */*bestcandidate*/, /*@null@*/const struct strlist */*newfilekeys*/, /*@null@*/const char */*newcontrol*/, void *); -void upgradelist_dump(struct upgradelist *upgrade, dumpaction *action); -retvalue upgradelist_listmissing(struct upgradelist *upgrade,struct database *); +void upgradelist_dump(struct upgradelist *, dumpaction *); /* Take all items in 'filename' into account, and remember them coming from 'method' */ -retvalue upgradelist_update(struct upgradelist *upgrade, /*@dependent@*/void *, const char *filename, upgrade_decide_function *predecide, void *decide_data, bool ignorewrongarchitecture); +retvalue upgradelist_update(struct upgradelist *, /*@dependent@*/void *, const char * /*filename*/, upgrade_decide_function *, void *, bool /*ignorewrongarchitecture*/); /* Take all items in source into account */ -retvalue upgradelist_pull(struct upgradelist *, struct target *, upgrade_decide_function *, void *, struct database *, void *); +retvalue upgradelist_pull(struct upgradelist *, struct target *, upgrade_decide_function *, void *, void *); /* mark all packages as deleted, so they will vanis unless readded or reholded */ -retvalue upgradelist_deleteall(struct upgradelist *upgrade); +retvalue upgradelist_deleteall(struct upgradelist *); -typedef retvalue enqueueaction(void *, struct database *, const struct checksumsarray *, const struct strlist *, void *); +typedef retvalue enqueueaction(void *, const struct checksumsarray *, const struct strlist *, void *); /* request all wanted files refering the methods given before */ -retvalue upgradelist_enqueue(struct upgradelist *, enqueueaction *, void *, struct database *); +retvalue upgradelist_enqueue(struct upgradelist *, enqueueaction *, void *); bool upgradelist_isbigdelete(const struct upgradelist *); -retvalue upgradelist_install(struct upgradelist *upgrade, /*@null@*/struct logger *, struct database *, bool ignoredelete, void (*callback)(void *, const char **, const char **)); +retvalue upgradelist_install(struct upgradelist *, /*@null@*/struct logger *, bool /*ignoredelete*/, void (*)(void *, const char **, const char **)); /* remove all packages that would either be removed or upgraded by an upgrade */ -retvalue upgradelist_predelete(struct upgradelist *, /*@null@*/struct logger *, struct database *); +retvalue upgradelist_predelete(struct upgradelist *, /*@null@*/struct logger *); #endif diff -Nru reprepro-4.5.0/uploaderslist.c reprepro-4.6.0/uploaderslist.c --- reprepro-4.5.0/uploaderslist.c 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/uploaderslist.c 2011-05-05 14:42:55.000000000 +0000 @@ -76,19 +76,19 @@ int newcount; struct upload_conditions *n; - if( a->type == uc_REJECTED ) { + if (a->type == uc_REJECTED) { /* due to groups, there can be empty conditions. * Don't include those in this list... */ return RET_OK; } - if( *c_p == NULL ) + if (*c_p == NULL) newcount = 1; else newcount = (*c_p)->count + 1; n = realloc(*c_p, sizeof(struct upload_conditions) + newcount * sizeof(const struct upload_condition*)); - if( n == NULL ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; n->current = NULL; n->count = newcount; @@ -134,11 +134,11 @@ static void uploadpermission_release(struct upload_condition *p) { struct upload_condition *h, *f = NULL; - assert( p != NULL ); + assert (p != NULL); do { h = p->next; - switch( p->type ) { + switch (p->type) { case uc_BINARIES: case uc_SECTIONS: case uc_SOURCENAME: @@ -160,11 +160,11 @@ f = h; /* and processed: */ p = h; - } while( p != NULL ); + } while (p != NULL); } static void uploadergroup_free(struct uploadergroup *u) { - if( u == NULL ) + if (u == NULL) return; free(u->name); free(u->memberof); @@ -173,7 +173,7 @@ } static void uploader_free(struct uploader *u) { - if( u == NULL ) + if (u == NULL) return; free(u->reversed_fingerprint); free(u->memberof); @@ -182,15 +182,15 @@ } static void uploaders_free(struct uploaders *u) { - if( u == NULL ) + if (u == NULL) return; - while( u->by_fingerprint != NULL ) { + while (u->by_fingerprint != NULL) { struct uploader *next = u->by_fingerprint->next; uploader_free(u->by_fingerprint); u->by_fingerprint = next; } - while( u->groups != NULL ) { + while (u->groups != NULL) { struct uploadergroup *next = u->groups->next; uploadergroup_free(u->groups); @@ -204,20 +204,20 @@ } void uploaders_unlock(struct uploaders *u) { - if( u->reference_count > 1 ) { + if (u->reference_count > 1) { u->reference_count--; } else { struct uploaders **p = &uploaderslists; - assert( u->reference_count == 1); + assert (u->reference_count == 1); /* avoid double free: */ - if( u->reference_count == 0 ) + if (u->reference_count == 0) return; - while( *p != NULL && *p != u ) + while (*p != NULL && *p != u) p = &(*p)->next; - assert( p != NULL && *p == u ); - if( *p == u ) { + assert (p != NULL && *p == u); + if (*p == u) { *p = u->next; uploaders_free(u); } @@ -228,11 +228,11 @@ const struct uploadergroup *group; retvalue r; - while( (group = *(groups++)) != NULL ) { + while ((group = *(groups++)) != NULL) { r = upload_conditions_add(c_p, &group->permissions); - if( !RET_WAS_ERROR(r) && group->memberof != NULL ) + if (!RET_WAS_ERROR(r) && group->memberof != NULL) r = upload_conditions_add_group(c_p, group->memberof); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; } return RET_OK; @@ -246,21 +246,21 @@ const struct uploader *uploader; retvalue r; - assert( u != NULL ); + assert (u != NULL); fingerprint = s->keyid; - assert( fingerprint != NULL ); + assert (fingerprint != NULL); len = strlen(fingerprint); reversed = alloca(len+1); - if( reversed == NULL ) + if (FAILEDTOALLOC(reversed)) return RET_ERROR_OOM; - for( i = 0 ; i < len ; i++ ) { + for (i = 0 ; i < len ; i++) { char c = fingerprint[len-i-1]; - if( c >= 'a' && c <= 'f' ) + if (c >= 'a' && c <= 'f') c -= 'a' - 'A'; - else if( c == 'x' && len-i-1 == 1 && fingerprint[0] == '0' ) + else if (c == 'x' && len-i-1 == 1 && fingerprint[0] == '0') break; - if( ( c < '0' || c > '9' ) && ( c <'A' && c > 'F') ) { + if ((c < '0' || c > '9') && (c <'A' && c > 'F')) { fprintf(stderr, "Strange character '%c'(=%hhu) in fingerprint '%s'.\n" "Search for appropriate rules in the uploaders file might fail.\n", @@ -276,17 +276,17 @@ primary_fingerprint = s->primary_keyid; primary_len = strlen(primary_fingerprint); reversed_primary_key = alloca(len+1); - if( FAILEDTOALLOC(reversed_primary_key) ) + if (FAILEDTOALLOC(reversed_primary_key)) return RET_ERROR_OOM; - for( i = 0 ; i < primary_len ; i++ ) { + for (i = 0 ; i < primary_len ; i++) { char c = primary_fingerprint[primary_len-i-1]; - if( c >= 'a' && c <= 'f' ) + if (c >= 'a' && c <= 'f') c -= 'a' - 'A'; - else if( c == 'x' && primary_len-i-1 == 1 && - primary_fingerprint[0] == '0' ) + else if (c == 'x' && primary_len-i-1 == 1 && + primary_fingerprint[0] == '0') break; - if( ( c < '0' || c > '9' ) && ( c <'A' && c > 'F') ) { + if ((c < '0' || c > '9') && (c <'A' && c > 'F')) { fprintf(stderr, "Strange character '%c'(=%hhu) in fingerprint/key-id '%s'.\n" "Search for appropriate rules in the uploaders file might fail.\n", @@ -298,28 +298,30 @@ primary_len = i; reversed_primary_key[primary_len] = '\0'; - for( uploader = u->by_fingerprint ; uploader != NULL ; uploader = uploader->next ) { + for (uploader = u->by_fingerprint ; uploader != NULL ; + uploader = uploader->next) { /* TODO: allow ignoring */ - if( s->state != sist_valid ) + if (s->state != sist_valid) continue; - if( uploader->allow_subkeys ) { - if( uploader->len > primary_len ) + if (uploader->allow_subkeys) { + if (uploader->len > primary_len) continue; - if( memcmp(uploader->reversed_fingerprint, + if (memcmp(uploader->reversed_fingerprint, reversed_primary_key, - uploader->len) != 0 ) + uploader->len) != 0) continue; } else { - if( uploader->len > len ) + if (uploader->len > len) continue; - if( memcmp(uploader->reversed_fingerprint, - reversed, uploader->len) != 0 ) + if (memcmp(uploader->reversed_fingerprint, + reversed, uploader->len) != 0) continue; } r = upload_conditions_add(c_p, &uploader->permissions); - if( !RET_WAS_ERROR(r) && uploader->memberof != NULL ) - r = upload_conditions_add_group(c_p, uploader->memberof); - if( RET_WAS_ERROR(r) ) + if (!RET_WAS_ERROR(r) && uploader->memberof != NULL) + r = upload_conditions_add_group(c_p, + uploader->memberof); + if (RET_WAS_ERROR(r)) return r; /* no break here, as a key might match * multiple specifications of different length */ @@ -334,33 +336,33 @@ r = upload_conditions_add(&conditions, &u->anybodypermissions); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - if( signatures == NULL ) { + if (signatures == NULL) { /* signatures.count might be 0 meaning there is * something lile a gpg header but we could not get * keys, because of a gpg error or because of being * compiling without libgpgme */ r = upload_conditions_add(&conditions, &u->unsignedpermissions); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(conditions); return r; } } - if( signatures != NULL && signatures->validcount > 0 ) { + if (signatures != NULL && signatures->validcount > 0) { r = upload_conditions_add(&conditions, &u->anyvalidkeypermissions); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(conditions); return r; } } - if( signatures != NULL ) { - for( j = 0 ; j < signatures->count ; j++ ) { + if (signatures != NULL) { + for (j = 0 ; j < signatures->count ; j++) { r = find_key_and_add(u, &conditions, &signatures->signatures[j]); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { free(conditions); return r; } @@ -373,30 +375,30 @@ /* uc_FAILED means rejected, uc_ACCEPTED means can go in */ enum upload_condition_type uploaders_nextcondition(struct upload_conditions *c) { - if( c->current != NULL ) { - if( c->matching && !c->needscandidate ) { - if( c->current->accept_if_true ) + if (c->current != NULL) { + if (c->matching && !c->needscandidate) { + if (c->current->accept_if_true) return uc_ACCEPTED; c->current = c->current->next_if_true; } else { - if( c->current->accept_if_false ) + if (c->current->accept_if_false) return uc_ACCEPTED; c->current = c->current->next_if_false; } } /* return the first non-trivial one left: */ - while( true ) { - while( c->current != NULL ) { - assert( c->current->type > uc_REJECTED ); - if( c->current->type == uc_ALWAYS ) { - if( c->current->accept_if_true ) + while (true) { + while (c->current != NULL) { + assert (c->current->type > uc_REJECTED); + if (c->current->type == uc_ALWAYS) { + if (c->current->accept_if_true) return uc_ACCEPTED; c->current = c->current->next_if_true; } else { /* empty set fullfills all conditions, but not an exists condition */ - switch( c->current->needs ) { + switch (c->current->needs) { case needs_any: c->matching = false; c->needscandidate = false; @@ -414,7 +416,7 @@ return c->current->type; } } - if( c->count == 0 ) + if (c->count == 0) return uc_REJECTED; c->count--; c->current = c->conditions[c->count]; @@ -425,8 +427,8 @@ static bool match_namecheck(const struct strlist *strings, const char *name) { int i; - for( i = 0 ; i < strings->count ; i++ ) { - if( globmatch(name, strings->values[i]) ) + for (i = 0 ; i < strings->count ; i++) { + if (globmatch(name, strings->values[i])) return true; } return false; @@ -435,26 +437,26 @@ bool uploaders_verifystring(struct upload_conditions *conditions, const char *name) { const struct upload_condition *c = conditions->current; - assert( c != NULL ); - assert( c->type == uc_BINARIES || c->type == uc_SECTIONS || + assert (c != NULL); + assert (c->type == uc_BINARIES || c->type == uc_SECTIONS || c->type == uc_CODENAME || - c->type == uc_SOURCENAME || c->type == uc_BYHAND ); + c->type == uc_SOURCENAME || c->type == uc_BYHAND); conditions->needscandidate = false; - switch( conditions->current->needs ) { + switch (conditions->current->needs) { case needs_all: case needs_existsall: /* once one condition is false, the case is settled */ - if( conditions->matching && - !match_namecheck(&c->strings, name) ) + if (conditions->matching && + !match_namecheck(&c->strings, name)) conditions->matching = false; /* but while it is true, more info is needed */ return conditions->matching; case needs_any: /* once one condition is true, the case is settled */ - if( !conditions->matching && - match_namecheck(&c->strings, name) ) + if (!conditions->matching && + match_namecheck(&c->strings, name)) conditions->matching = true; conditions->needscandidate = false; /* but while it is false, more info is needed */ @@ -464,30 +466,30 @@ return false; } /* NOT REACHED */ - assert( conditions->current->needs != conditions->current->needs ); + assert (conditions->current->needs != conditions->current->needs); } bool uploaders_verifyatom(struct upload_conditions *conditions, atom_t atom) { const struct upload_condition *c = conditions->current; - assert( c != NULL ); - assert( c->type == uc_ARCHITECTURES ); + assert (c != NULL); + assert (c->type == uc_ARCHITECTURES); conditions->needscandidate = false; - switch( conditions->current->needs ) { + switch (conditions->current->needs) { case needs_all: case needs_existsall: /* once one condition is false, the case is settled */ - if( conditions->matching && - !atomlist_in(&c->atoms, atom) ) + if (conditions->matching && + !atomlist_in(&c->atoms, atom)) conditions->matching = false; /* but while it is true, more info is needed */ return conditions->matching; case needs_any: /* once one condition is true, the case is settled */ - if( !conditions->matching && - atomlist_in(&c->atoms, atom) ) + if (!conditions->matching && + atomlist_in(&c->atoms, atom)) conditions->matching = true; /* but while it is false, more info is needed */ return !conditions->matching; @@ -496,7 +498,7 @@ return false; } /* NOT REACHED */ - assert( conditions->current->needs != conditions->current->needs ); + assert (conditions->current->needs != conditions->current->needs); } static struct uploader *addfingerprint(struct uploaders *u, const char *fingerprint, size_t len, bool allow_subkeys) { @@ -504,30 +506,32 @@ char *reversed = malloc(len+1); struct uploader *uploader, **last; - if( reversed == NULL ) + if (FAILEDTOALLOC(reversed)) return NULL; - for( i = 0 ; i < len ; i++ ) { + for (i = 0 ; i < len ; i++) { char c = fingerprint[len-i-1]; - if( c >= 'a' && c <= 'f' ) + if (c >= 'a' && c <= 'f') c -= 'a' - 'A'; - assert( ( c >= '0' && c <= '9' ) || ( c >= 'A' || c <= 'F') ); + assert ((c >= '0' && c <= '9') || (c >= 'A' || c <= 'F')); reversed[i] = c; } reversed[len] = '\0'; last = &u->by_fingerprint; - for( uploader = u->by_fingerprint ; uploader != NULL ; uploader = *(last = &uploader->next) ) { - if( uploader->len != len ) + for (uploader = u->by_fingerprint ; + uploader != NULL ; + uploader = *(last = &uploader->next)) { + if (uploader->len != len) continue; - if( memcmp(uploader->reversed_fingerprint, reversed, len) != 0 ) + if (memcmp(uploader->reversed_fingerprint, reversed, len) != 0) continue; - if( uploader->allow_subkeys != allow_subkeys ) + if (uploader->allow_subkeys != allow_subkeys) continue; free(reversed); return uploader; } - assert( *last == NULL ); - uploader = calloc(1,sizeof(struct uploader)); - if( uploader == NULL ) + assert (*last == NULL); + uploader = zNEW(struct uploader); + if (FAILEDTOALLOC(uploader)) return NULL; *last = uploader; uploader->reversed_fingerprint = reversed; @@ -540,20 +544,21 @@ struct uploadergroup *group, **last; last = &u->groups; - for( group = u->groups ; group != NULL ; group = *(last = &group->next) ) { - if( group->len != len ) + for (group = u->groups ; + group != NULL ; group = *(last = &group->next)) { + if (group->len != len) continue; - if( memcmp(group->name, name, len) != 0 ) + if (memcmp(group->name, name, len) != 0) continue; return group; } - assert( *last == NULL ); - group = calloc(1, sizeof(struct uploadergroup)); - if( FAILEDTOALLOC(group) ) + assert (*last == NULL); + group = zNEW(struct uploadergroup); + if (FAILEDTOALLOC(group)) return NULL; group->name = strndup(name, len); group->len = len; - if( FAILEDTOALLOC(group->name) ) { + if (FAILEDTOALLOC(group->name)) { free(group); return NULL; } @@ -562,8 +567,8 @@ } static inline const char *overkey(const char *p) { - while( (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F') ) { + while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) { p++; } return p; @@ -578,41 +583,43 @@ const char *startp, *endp; char *n; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( *p != '\'' ) { + if (*p != '\'') { fprintf(stderr, "%s:%lu:%u: starting \"'\" expected!\n", - filename, lineno, column + (int)(p-*pp)); + filename, lineno, + column + (int)(p - *pp)); return RET_ERROR; } p++; startp = p; - while( *p != '\0' && *p != '\'' ) + while (*p != '\0' && *p != '\'') p++; - if( *p == '\0' ) { + if (*p == '\0') { fprintf(stderr, "%s:%lu:%u: closing \"'\" expected!\n", - filename, lineno, column + (int)(p-*pp)); + filename, lineno, + column + (int)(p - *pp)); return RET_ERROR; } - assert( *p == '\'' ); + assert (*p == '\''); endp = p; p++; n = strndup(startp, endp - startp); - if( FAILEDTOALLOC(n) ) + if (FAILEDTOALLOC(n)) return RET_ERROR_OOM; r = strlist_adduniq(strings, n); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; column += (p - *pp); *pp = p; - if( **pp == '|' ) { + if (**pp == '|') { p++; } - } while ( **pp == '|' ); + } while (**pp == '|'); *pp = p; return RET_OK; } @@ -626,35 +633,38 @@ const char *startp, *endp; atom_t atom; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( *p != '\'' ) { + if (*p != '\'') { fprintf(stderr, "%s:%lu:%u: starting \"'\" expected!\n", - filename, lineno, column + (int)(p-*pp)); + filename, lineno, + column + (int)(p - *pp)); return RET_ERROR; } p++; startp = p; - while( *p != '\0' && *p != '\'' && *p != '*' && *p != '?' ) + while (*p != '\0' && *p != '\'' && *p != '*' && *p != '?') p++; - if( *p == '*' || *p == '?' ) { + if (*p == '*' || *p == '?') { fprintf(stderr, "%s:%lu:%u: Wildcards are not allowed in architectures!\n", - filename, lineno, column + (int)(p-*pp)); + filename, lineno, + column + (int)(p - *pp)); return RET_ERROR; } - if( *p == '\0' ) { + if (*p == '\0') { fprintf(stderr, "%s:%lu:%u: closing \"'\" expected!\n", - filename, lineno, column + (int)(p-*pp)); + filename, lineno, + column + (int)(p - *pp)); return RET_ERROR; } - assert( *p == '\'' ); + assert (*p == '\''); endp = p; p++; atom = architecture_find_l(startp, endp - startp); - if( !atom_defined(atom) ) { + if (!atom_defined(atom)) { fprintf(stderr, "%s:%lu:%u: Unknown architecture '%.*s'! (Did you mistype?)\n", filename, lineno, @@ -663,16 +673,16 @@ return RET_ERROR; } r = atomlist_add_uniq(atoms, atom); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; column += (p - *pp); *pp = p; - if( **pp == '|' ) { + if (**pp == '|') { p++; } - } while ( **pp == '|' ); + } while (**pp == '|'); *pp = p; return RET_OK; } @@ -681,14 +691,14 @@ const char *p = *pp; struct upload_condition *fallback, *last, *or_scope; - memset( condition, 0, sizeof(struct upload_condition)); + memset(condition, 0, sizeof(struct upload_condition)); /* allocate a new fallback-node: * (this one is used to make it easier to concatenate those decision * trees, especially it keeps open the possibility to have deny * decisions) */ - fallback = calloc(1, sizeof(struct upload_condition)); - if( FAILEDTOALLOC(fallback) ) + fallback = zNEW(struct upload_condition); + if (FAILEDTOALLOC(fallback)) return RET_ERROR_OOM; fallback->type = uc_ALWAYS; assert(!fallback->accept_if_true); @@ -701,11 +711,11 @@ last = condition; or_scope = condition; - while( true ) { - if( strncmp(p, "not", 3) == 0 && - xisspace(p[3]) ) { + while (true) { + if (strncmp(p, "not", 3) == 0 && + xisspace(p[3])) { p += 3; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; /* negate means false is good and true * is bad: */ @@ -719,20 +729,20 @@ last->next_if_false = fallback; last->next_if_true = NULL; } - if( p[0] == '*' && xisspace(p[1]) ) { + if (p[0] == '*' && xisspace(p[1])) { last->type = uc_ALWAYS; p++; - } else if( strncmp(p, "architectures", 13) == 0 && - strchr(" \t'", p[13]) != NULL ) { + } else if (strncmp(p, "architectures", 13) == 0 && + strchr(" \t'", p[13]) != NULL) { retvalue r; last->type = uc_ARCHITECTURES; last->needs = needs_all; p += 13; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "contain", 7) == 0 && - strchr(" \t'", p[7]) != NULL ) { + if (strncmp(p, "contain", 7) == 0 && + strchr(" \t'", p[7]) != NULL) { last->needs = needs_any; p += 7; } @@ -740,21 +750,21 @@ r = parse_architectures(&last->atoms, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } - } else if( strncmp(p, "binaries", 8) == 0 && - strchr(" \t'", p[8]) != NULL ) { + } else if (strncmp(p, "binaries", 8) == 0 && + strchr(" \t'", p[8]) != NULL) { retvalue r; last->type = uc_BINARIES; last->needs = needs_all; p += 8; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "contain", 7) == 0 && - strchr(" \t'", p[7]) != NULL ) { + if (strncmp(p, "contain", 7) == 0 && + strchr(" \t'", p[7]) != NULL) { last->needs = needs_any; p += 7; } @@ -762,41 +772,41 @@ r = parse_stringpart(&last->strings, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } - } else if( strncmp(p, "byhand", 6) == 0 && - strchr(" \t'", p[6]) != NULL ) { + } else if (strncmp(p, "byhand", 6) == 0 && + strchr(" \t'", p[6]) != NULL) { retvalue r; last->type = uc_BYHAND; last->needs = needs_existsall; p += 8; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( *p != '\'' ) { + if (*p != '\'') { strlist_init(&last->strings); r = RET_OK; } else r = parse_stringpart(&last->strings, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } - } else if( strncmp(p, "sections", 8) == 0 && - strchr(" \t'", p[8]) != NULL ) { + } else if (strncmp(p, "sections", 8) == 0 && + strchr(" \t'", p[8]) != NULL) { retvalue r; last->type = uc_SECTIONS; last->needs = needs_all; p += 8; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "contain", 7) == 0 && - strchr(" \t'", p[7]) != NULL ) { + if (strncmp(p, "contain", 7) == 0 && + strchr(" \t'", p[7]) != NULL) { last->needs = needs_any; p += 7; } @@ -804,12 +814,12 @@ r = parse_stringpart(&last->strings, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } - } else if( strncmp(p, "source", 6) == 0 && - strchr(" \t'", p[6]) != NULL ) { + } else if (strncmp(p, "source", 6) == 0 && + strchr(" \t'", p[6]) != NULL) { retvalue r; last->type = uc_SOURCENAME; @@ -818,13 +828,13 @@ r = parse_stringpart(&last->strings, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } - } else if( strncmp(p, "distribution", 12) == 0 && - strchr(" \t'", p[12]) != NULL ) { + } else if (strncmp(p, "distribution", 12) == 0 && + strchr(" \t'", p[12]) != NULL) { retvalue r; last->type = uc_CODENAME; @@ -833,36 +843,39 @@ r = parse_stringpart(&last->strings, &p, filename, lineno, column + (p-*pp)); - if( RET_WAS_ERROR(r) ) { + if (RET_WAS_ERROR(r)) { uploadpermission_release(condition); return r; } } else { - fprintf(stderr, "%s:%lu:%u: condition expected after 'allow' keyword!\n", filename, lineno, column + (int)(p-*pp)); + fprintf(stderr, +"%s:%lu:%u: condition expected after 'allow' keyword!\n", + filename, lineno, + column + (int)(p - *pp)); uploadpermission_release(condition); return RET_ERROR; } - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "and", 3) == 0 && xisspace(p[3]) ) { + if (strncmp(p, "and", 3) == 0 && xisspace(p[3])) { struct upload_condition *n, *c; p += 3; - n = calloc(1, sizeof(struct upload_condition)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct upload_condition); + if (FAILEDTOALLOC(n)) { uploadpermission_release(condition); return RET_ERROR_OOM; } /* everything that yet made it succeed makes it need * to check this condition: */ - for( c = condition ; c != NULL ; c = c->next ) { - if( c->accept_if_true ) { + for (c = condition ; c != NULL ; c = c->next) { + if (c->accept_if_true) { c->next_if_true = n; c->accept_if_true = false; } - if( c->accept_if_false ) { + if (c->accept_if_false) { c->next_if_false = n; c->accept_if_false = false; } @@ -871,17 +884,17 @@ or_scope = n; /* add it to queue: */ - assert( last->next == fallback ); + assert (last->next == fallback); n->next = fallback; last->next = n; last = n; - } else if( strncmp(p, "or", 2) == 0 && xisspace(p[2]) ) { + } else if (strncmp(p, "or", 2) == 0 && xisspace(p[2])) { struct upload_condition *n, *c; p += 2; - n = calloc(1, sizeof(struct upload_condition)); - if( FAILEDTOALLOC(n) ) { + n = zNEW(struct upload_condition); + if (FAILEDTOALLOC(n)) { uploadpermission_release(condition); return RET_ERROR_OOM; } @@ -889,27 +902,30 @@ * now makes it check this: (currently that will * only be true at most for c == last, but with * parantheses this all will be needed) */ - for( c = or_scope ; c != NULL ; c = c->next ) { - if( c->next_if_true == fallback ) + for (c = or_scope ; c != NULL ; c = c->next) { + if (c->next_if_true == fallback) c->next_if_true = n; - if( c->next_if_false == fallback ) + if (c->next_if_false == fallback) c->next_if_false = n; } /* add it to queue: */ - assert( last->next == fallback ); + assert (last->next == fallback); n->next = fallback; last->next = n; last = n; - } else if( strncmp(p, "by", 2) == 0 && xisspace(p[2]) ) { + } else if (strncmp(p, "by", 2) == 0 && xisspace(p[2])) { p += 2; break; } else { - fprintf(stderr, "%s:%lu:%u: 'by','and' or 'or' keyword expected!\n", filename, (long)lineno, column + (int)(p-*pp)); + fprintf(stderr, +"%s:%lu:%u: 'by','and' or 'or' keyword expected!\n", + filename, (long)lineno, + column + (int)(p - *pp)); uploadpermission_release(condition); - memset( condition, 0, sizeof(struct upload_condition)); + memset(condition, 0, sizeof(struct upload_condition)); return RET_ERROR; } - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; } *pp = p; @@ -917,7 +933,7 @@ } static void condition_add(struct upload_condition *permissions, struct upload_condition *c) { - if( permissions->next == NULL ) { + if (permissions->next == NULL) { /* first condition, as no fallback yet allocated */ *permissions = *c; memset(c, 0, sizeof(struct upload_condition)); @@ -925,8 +941,8 @@ struct upload_condition *last; last = permissions->next; - assert( last != NULL ); - while( last->next != NULL ) + assert (last != NULL); + while (last->next != NULL) last = last->next; /* the very last is always the fallback-node to which all @@ -945,24 +961,26 @@ p = *pp; q = p; - while( (*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || + while ((*q >= 'a' && *q <= 'z') || (*q >= 'A' && *q <= 'Z') || (*q >= '0' && *q <= '9') || *q == '-' - || *q == '_' || *q == '.' ) + || *q == '_' || *q == '.') q++; - if( *p == '\0' || ( q-p == 3 && memcmp(p, "add", 3) == 0 ) - || ( q-p == 5 && memcmp(p, "empty", 5) == 0 ) - || ( q-p == 6 && memcmp(p, "unused", 6) == 0 ) - || ( q-p == 8 && memcmp(p, "contains", 8) == 0 ) ) { - fprintf(stderr, "%s:%lu:%u: group name expected!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*p == '\0' || (q-p == 3 && memcmp(p, "add", 3) == 0) + || (q-p == 5 && memcmp(p, "empty", 5) == 0) + || (q-p == 6 && memcmp(p, "unused", 6) == 0) + || (q-p == 8 && memcmp(p, "contains", 8) == 0)) { + fprintf(stderr, "%s:%lu:%u: group name expected!\n", filename, + (long)lineno, (int)(1 + p - buffer)); return RET_ERROR; } - if( *q != '\0' && *q != ' ' && *q != '\t' ) { - fprintf(stderr, "%s:%lu:%u: invalid group name!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*q != '\0' && *q != ' ' && *q != '\t') { + fprintf(stderr, "%s:%lu:%u: invalid group name!\n", + filename, (long)lineno, (int)(1 +p -buffer)); return RET_ERROR; } *pp = q; group = addgroup(u, p, q-p); - if( FAILEDTOALLOC(group) ) + if (FAILEDTOALLOC(group)) return RET_ERROR_OOM; *g = group; return RET_OK; @@ -973,30 +991,34 @@ bool allow_subkeys = false; const char *q, *qq; - if( p[0] == '0' && p[1] == 'x' ) + if (p[0] == '0' && p[1] == 'x') p += 2; q = overkey(p); - if( *p == '\0' || (*q !='\0' && !xisspace(*q) && *q != '+') || q==p ) { - fprintf(stderr, "%s:%lu:%u: key id or fingerprint expected!\n", filename, (long)lineno, (int)(1+q-buffer)); + if (*p == '\0' || (*q !='\0' && !xisspace(*q) && *q != '+') || q==p) { + fprintf(stderr, "%s:%lu:%u: key id or fingerprint expected!\n", + filename, (long)lineno, (int)(1 + q - buffer)); return RET_ERROR; } qq = q; - while( xisspace(*qq) ) + while (xisspace(*qq)) qq++; - if( *qq == '+' ) { + if (*qq == '+') { qq++; allow_subkeys = true; } - while( xisspace(*qq) ) + while (xisspace(*qq)) qq++; - if( *qq != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data after 'key ' statement!\n\n", filename, (long)lineno, (int)(1+qq-buffer)); - if( *q == ' ' ) - fprintf(stderr, " Hint: no spaces allowed in fingerprint specification.\n"); + if (*qq != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data after 'key ' statement!\n\n", + filename, (long)lineno, (int)(1 +qq - buffer)); + if (*q == ' ') + fprintf(stderr, +" Hint: no spaces allowed in fingerprint specification.\n"); return RET_ERROR; } uploader = addfingerprint(u, p, q-p, allow_subkeys); - if( FAILEDTOALLOC(uploader) ) + if (FAILEDTOALLOC(uploader)) return RET_ERROR_OOM; *u_p = uploader; return RET_OK; @@ -1007,28 +1029,33 @@ const struct uploadergroup **memberof = *memberof_p; n = 0; - if( memberof != NULL ) { - while( memberof[n] != NULL ) { - if( memberof[n] == group ) { - fprintf(stderr, "%s:%lu: member added to group %s a second time!\n", filename, lineno, group->name); + if (memberof != NULL) { + while (memberof[n] != NULL) { + if (memberof[n] == group) { + fprintf(stderr, +"%s:%lu: member added to group %s a second time!\n", + filename, lineno, group->name); return RET_ERROR; } n++; } } - if( n == 0 || (n & 15) == 15 ) { + if (n == 0 || (n & 15) == 15) { /* let's hope no static checker is confused here ;-> */ - memberof = realloc(memberof, ((n+16)&~15) * sizeof(struct uploadergroup*)); - if( memberof == NULL ) + memberof = realloc(memberof, + ((n+16)&~15) * sizeof(struct uploadergroup*)); + if (FAILEDTOALLOC(memberof)) return RET_ERROR_OOM; *memberof_p = memberof; } memberof[n] = group; memberof[n+1] = NULL; - if( group->firstmemberat == 0 ) + if (group->firstmemberat == 0) group->firstmemberat = lineno; - if( group->emptyat != 0 ) { - fprintf(stderr, "%s:%lu: cannot add members to group '%s' marked empty in line %lu\n", filename, lineno, group->name, group->emptyat); + if (group->emptyat != 0) { + fprintf(stderr, +"%s:%lu: cannot add members to group '%s' marked empty in line %lu\n", + filename, lineno, group->name, group->emptyat); return RET_ERROR; } return RET_OK; @@ -1037,12 +1064,12 @@ static bool is_included_in(const struct uploadergroup *needle, const struct uploadergroup *chair) { const struct uploadergroup **g; - if( needle->memberof == NULL ) + if (needle->memberof == NULL) return false; - for( g = needle->memberof ; *g != NULL ; g++ ) { - if( *g == chair ) + for (g = needle->memberof ; *g != NULL ; g++) { + if (*g == chair) return true; - if( is_included_in(*g, chair) ) + if (is_included_in(*g, chair)) return true; } return false; @@ -1055,198 +1082,262 @@ struct upload_condition condition; l = strlen(buffer); - if( l == 0 ) + if (l == 0) return RET_NOTHING; - if( buffer[l-1] != '\n' ) { - if( l >= 1024 ) - fprintf(stderr, "%s:%lu:1024: Overlong line!\n", filename, (long)lineno); + if (buffer[l-1] != '\n') { + if (l >= 1024) + fprintf(stderr, "%s:%lu:1024: Overlong line!\n", + filename, (long)lineno); else - fprintf(stderr, "%s:%lu:%lu: Unterminated line!\n", filename, (long)lineno,(long)l); + fprintf(stderr, "%s:%lu:%lu: Unterminated line!\n", + filename, (long)lineno, (long)l); return RET_ERROR; } do { buffer[--l] = '\0'; - } while( l > 0 && xisspace(buffer[l-1]) ); + } while (l > 0 && xisspace(buffer[l-1])); p = buffer; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( *p == '\0' || *p == '#' ) + if (*p == '\0' || *p == '#') return RET_NOTHING; - if( strncmp(p, "group", 5) == 0 && (*p == '\0' || xisspace(p[5])) ) { + if (strncmp(p, "group", 5) == 0 && (*p == '\0' || xisspace(p[5]))) { struct uploadergroup *group; p += 5; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; r = find_group(&group, u, &p, filename, lineno, buffer); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "add", 3) == 0) { + if (strncmp(p, "add", 3) == 0) { struct uploader *uploader; p += 3; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - r = find_uploader(&uploader, u, p, filename, lineno, buffer); - if( RET_WAS_ERROR(r) ) + r = find_uploader(&uploader, u, p, filename, + lineno, buffer); + if (RET_WAS_ERROR(r)) return r; - r = include_group(group, &uploader->memberof, filename, lineno); - if( RET_WAS_ERROR(r) ) + r = include_group(group, &uploader->memberof, + filename, lineno); + if (RET_WAS_ERROR(r)) return r; return RET_OK; - } else if( strncmp(p, "contains", 8) == 0 ) { + } else if (strncmp(p, "contains", 8) == 0) { struct uploadergroup *member; p += 8; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; q = p; - r = find_group(&member, u, &q, filename, lineno, buffer); - if( RET_WAS_ERROR(r) ) + r = find_group(&member, u, &q, filename, + lineno, buffer); + if (RET_WAS_ERROR(r)) return r; - if( group == member ) { - fprintf(stderr, "%s:%lu: cannot add group '%s' to itself!\n", filename, (unsigned long)lineno, member->name); + if (group == member) { + fprintf(stderr, +"%s:%lu: cannot add group '%s' to itself!\n", + filename, (unsigned long)lineno, + member->name); return RET_ERROR; } - if( is_included_in(group, member) ) { - /* perhaps offer a winning coupon for the first one triggering this? */ - fprintf(stderr, "%s:%lu: cannot add group '%s' to group '%s' as the later is already member of the former!\n", filename, (unsigned long)lineno, member->name, group->name); + if (is_included_in(group, member)) { + /* perhaps offer a winning coupon for the first + * one triggering this? */ + fprintf(stderr, +"%s:%lu: cannot add group '%s' to group '%s' as the later is already member of the former!\n", + filename, (unsigned long)lineno, + member->name, group->name); return RET_ERROR; } - r = include_group(group, &member->memberof, filename, lineno); - if( RET_WAS_ERROR(r) ) + r = include_group(group, &member->memberof, + filename, lineno); + if (RET_WAS_ERROR(r)) return r; - if( member->firstusedat == 0 ) + if (member->firstusedat == 0) member->firstusedat = lineno; - if( member->unusedat != 0 ) { - fprintf(stderr, "%s:%lu: cannot use group '%s' marked as unused in line %lu.\n", filename, (unsigned long)lineno, member->name, member->unusedat); + if (member->unusedat != 0) { + fprintf(stderr, +"%s:%lu: cannot use group '%s' marked as unused in line %lu.\n", + filename, (unsigned long)lineno, + member->name, member->unusedat); return RET_ERROR; } - } else if( strncmp(p, "empty", 5) == 0 ) { + } else if (strncmp(p, "empty", 5) == 0) { q = p + 5; - if( group->emptyat != 0 ) { - fprintf(stderr, "%s:%lu: group '%s' marked as empty again (already happened in line %lu).\n", filename, (unsigned long)lineno, group->name, group->emptyat); - } - if( group->firstmemberat != 0 ) { - fprintf(stderr, "%s:%lu: group '%s' cannot be marked empty as it already has members (first in line %lu).\n", filename, (unsigned long)lineno, group->name, group->firstmemberat); + if (group->emptyat != 0) { + fprintf(stderr, +"%s:%lu: group '%s' marked as empty again (already happened in line %lu).\n", + filename, (unsigned long)lineno, + group->name, group->emptyat); + } + if (group->firstmemberat != 0) { + fprintf(stderr, +"%s:%lu: group '%s' cannot be marked empty as it already has members (first in line %lu).\n", + filename, (unsigned long)lineno, + group->name, + group->firstmemberat); return RET_ERROR; } group->emptyat = lineno; - } else if( strncmp(p, "unused", 6) == 0 ) { + } else if (strncmp(p, "unused", 6) == 0) { q = p + 6; - if( group->unusedat != 0 ) { - fprintf(stderr, "%s:%lu: group '%s' marked as unused again (already happened in line %lu).\n", filename, (unsigned long)lineno, group->name, group->unusedat); - } - if( group->firstusedat != 0 ) { - fprintf(stderr, "%s:%lu: group '%s' cannot be marked unused as it was already used (first in line %lu).\n", filename, (unsigned long)lineno, group->name, group->firstusedat); + if (group->unusedat != 0) { + fprintf(stderr, +"%s:%lu: group '%s' marked as unused again (already happened in line %lu).\n", + filename, (unsigned long)lineno, + group->name, group->unusedat); + } + if (group->firstusedat != 0) { + fprintf(stderr, +"%s:%lu: group '%s' cannot be marked unused as it was already used (first in line %lu).\n", + filename, (unsigned long)lineno, + group->name, + group->firstusedat); return RET_ERROR; } group->unusedat = lineno; } else { - fprintf(stderr, "%s:%lu:%u: missing 'add', 'contains', 'unused' or 'empty' keyword.\n", filename, (long)lineno, (int)(1+p-buffer)); + fprintf(stderr, +"%s:%lu:%u: missing 'add', 'contains', 'unused' or 'empty' keyword.\n", + filename, (long)lineno, + (int)(1 + p - buffer)); return RET_ERROR; } - while( *q != '\0' && xisspace(*q) ) + while (*q != '\0' && xisspace(*q)) q++; - if( *q != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data at end of group statement!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*q != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data at end of group statement!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); return RET_ERROR; } return RET_OK; } - if( strncmp(p,"allow",5) != 0 || !xisspace(p[5]) ) { - fprintf(stderr, "%s:%lu:%u: 'allow' or 'group' keyword expected! (no other statement has yet been implemented)\n", filename, (long)lineno, (int)(1+p-buffer)); + if (strncmp(p, "allow", 5) != 0 || !xisspace(p[5])) { + fprintf(stderr, +"%s:%lu:%u: 'allow' or 'group' keyword expected! (no other statement has yet been implemented)\n", + filename, (long)lineno, + (int)(1 +p - buffer)); return RET_ERROR; } p+=5; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; r = parse_condition(filename, lineno, (1+p-buffer), &p, &condition); - if( RET_WAS_ERROR(r) ) + if (RET_WAS_ERROR(r)) return r; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p,"key",3) == 0 && (p[3] == '\0' || xisspace(p[3])) ) { + if (strncmp(p, "key", 3) == 0 && (p[3] == '\0' || xisspace(p[3]))) { struct uploader *uploader; p += 3; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; r = find_uploader(&uploader, u, p, filename, lineno, buffer); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { uploadpermission_release(&condition); return r; } condition_add(&uploader->permissions, &condition); - } else if( strncmp(p, "group", 5) == 0 && (p[5] == '\0' || xisspace(p[5])) ) { + } else if (strncmp(p, "group", 5) == 0 + && (p[5] == '\0' || xisspace(p[5]))) { struct uploadergroup *group; p += 5; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; r = find_group(&group, u, &p, filename, lineno, buffer); - assert( r != RET_NOTHING ); - if( RET_WAS_ERROR(r) ) { + assert (r != RET_NOTHING); + if (RET_WAS_ERROR(r)) { uploadpermission_release(&condition); return r; } - assert( group != NULL ); - while( *p != '\0' && xisspace(*p) ) + assert (group != NULL); + while (*p != '\0' && xisspace(*p)) p++; - if( *p != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data at end of group statement!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*p != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data at end of group statement!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } - if( group->firstusedat == 0 ) + if (group->firstusedat == 0) group->firstusedat = lineno; - if( group->unusedat != 0 ) { - fprintf(stderr, "%s:%lu: cannot use group '%s' marked as unused in line %lu.\n", filename, (unsigned long)lineno, group->name, group->unusedat); + if (group->unusedat != 0) { + fprintf(stderr, +"%s:%lu: cannot use group '%s' marked as unused in line %lu.\n", + filename, (unsigned long)lineno, + group->name, group->unusedat); uploadpermission_release(&condition); return RET_ERROR; } condition_add(&group->permissions, &condition); - } else if( strncmp(p, "unsigned",8) == 0 && (p[8]=='\0' || xisspace(p[8])) ) { + } else if (strncmp(p, "unsigned", 8) == 0 + && (p[8]=='\0' || xisspace(p[8]))) { p+=8; - if( *p != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data after 'unsigned' statement!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*p != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data after 'unsigned' statement!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } condition_add(&u->unsignedpermissions, &condition); - } else if( strncmp(p, "any",3) == 0 && xisspace(p[3]) ) { + } else if (strncmp(p, "any", 3) == 0 && xisspace(p[3])) { p+=3; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( strncmp(p, "key", 3) != 0 || (p[3]!='\0' && !xisspace(p[3])) ) { - fprintf(stderr, "%s:%lu:%u: 'key' keyword expected after 'any' keyword!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (strncmp(p, "key", 3) != 0 + || (p[3]!='\0' && !xisspace(p[3]))) { + fprintf(stderr, +"%s:%lu:%u: 'key' keyword expected after 'any' keyword!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } p += 3; - if( *p != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data after 'any key' statement!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*p != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data after 'any key' statement!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } condition_add(&u->anyvalidkeypermissions, &condition); - } else if( strncmp(p, "anybody", 7) == 0 && (p[7] == '\0' || xisspace(p[7])) ) { + } else if (strncmp(p, "anybody", 7) == 0 + && (p[7] == '\0' || xisspace(p[7]))) { p+=7; - while( *p != '\0' && xisspace(*p) ) + while (*p != '\0' && xisspace(*p)) p++; - if( *p != '\0' ) { - fprintf(stderr, "%s:%lu:%u: unexpected data after 'anybody' statement!\n", filename, (long)lineno, (int)(1+p-buffer)); + if (*p != '\0') { + fprintf(stderr, +"%s:%lu:%u: unexpected data after 'anybody' statement!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } condition_add(&u->anybodypermissions, &condition); } else { - fprintf(stderr, "%s:%lu:%u: 'key', 'unsigned', 'anybody' or 'any key' expected!\n", filename, (long)lineno, (int)(1+p-buffer)); + fprintf(stderr, +"%s:%lu:%u: 'key', 'unsigned', 'anybody' or 'any key' expected!\n", + filename, (long)lineno, + (int)(1 + p - buffer)); uploadpermission_release(&condition); return RET_ERROR; } @@ -1262,21 +1353,22 @@ struct uploadergroup *g; retvalue r; - if( filename[0] != '/' ) { + if (filename[0] != '/') { fullfilename = calc_conffile(filename); - if( fullfilename == NULL ) + if (FAILEDTOALLOC(fullfilename)) return RET_ERROR_OOM; filename = fullfilename; } f = fopen(filename, "r"); - if( f == NULL ) { + if (f == NULL) { int e = errno; - fprintf(stderr, "Error opening '%s': %s\n", filename, strerror(e)); + fprintf(stderr, "Error opening '%s': %s\n", + filename, strerror(e)); free(fullfilename); return RET_ERRNO(e); } - u = calloc(1,sizeof(struct uploaders)); - if( FAILEDTOALLOC(u) ) { + u = zNEW(struct uploaders); + if (FAILEDTOALLOC(u)) { (void)fclose(f); free(fullfilename); return RET_ERROR_OOM; @@ -1286,30 +1378,35 @@ u->anyvalidkeypermissions.type = uc_ALWAYS; u->anybodypermissions.type = uc_ALWAYS; - while( fgets(buffer,1024,f) != NULL ) { + while (fgets(buffer, 1024, f) != NULL) { lineno++; - r = parseuploaderline(buffer,filename,lineno,u); - if( RET_WAS_ERROR(r) ) { + r = parseuploaderline(buffer, filename, lineno, u); + if (RET_WAS_ERROR(r)) { (void)fclose(f); free(fullfilename); uploaders_free(u); return r; } } - if( fclose(f) != 0 ) { + if (fclose(f) != 0) { int e = errno; - fprintf(stderr, "Error reading '%s': %s\n", filename, strerror(e)); + fprintf(stderr, "Error reading '%s': %s\n", + filename, strerror(e)); free(fullfilename); uploaders_free(u); return RET_ERRNO(e); } - for( g = u->groups ; g != NULL ; g = g->next ) { - if( (g->firstmemberat == 0 && g->emptyat == 0) && - g->firstusedat != 0 ) - fprintf(stderr, "%s:%lu: Warning: group '%s' gets used but never gets any members\n", filename, g->firstusedat, g->name); - if( (g->firstusedat == 0 && g->unusedat == 0) && - g->firstmemberat != 0 ) - fprintf(stderr, "%s:%lu: Warning: group '%s' gets members but is not used in any rule\n", filename, g->firstmemberat, g->name); + for (g = u->groups ; g != NULL ; g = g->next) { + if ((g->firstmemberat == 0 && g->emptyat == 0) && + g->firstusedat != 0) + fprintf(stderr, +"%s:%lu: Warning: group '%s' gets used but never gets any members\n", + filename, g->firstusedat, g->name); + if ((g->firstusedat == 0 && g->unusedat == 0) && + g->firstmemberat != 0) + fprintf(stderr, +"%s:%lu: Warning: group '%s' gets members but is not used in any rule\n", + filename, g->firstmemberat, g->name); } free(fullfilename); *list = u; @@ -1321,20 +1418,20 @@ struct uploaders *u; size_t len; - assert( filename != NULL ); + assert (filename != NULL); len = strlen(filename); u = uploaderslists; - while( u != NULL && ( u->filename_len != len || - memcmp(u->filename,filename,len) != 0 ) ) + while (u != NULL && (u->filename_len != len || + memcmp(u->filename, filename, len) != 0)) u = u->next; - if( u == NULL ) { + if (u == NULL) { r = uploaders_load(&u, filename); - if( !RET_IS_OK(r) ) + if (!RET_IS_OK(r)) return r; - assert( u != NULL ); + assert (u != NULL); u->filename = strdup(filename); - if( u->filename == NULL ) { + if (FAILEDTOALLOC(u->filename)) { uploaders_free(u); return RET_ERROR_OOM; } diff -Nru reprepro-4.5.0/uploaderslist.h reprepro-4.6.0/uploaderslist.h --- reprepro-4.5.0/uploaderslist.h 2011-02-09 14:20:23.000000000 +0000 +++ reprepro-4.6.0/uploaderslist.h 2011-05-05 14:42:55.000000000 +0000 @@ -2,7 +2,6 @@ #define REPREPRO_UPLOADERSLIST_H -struct upload_condition; struct upload_conditions; struct uploaders; @@ -24,6 +23,4 @@ bool uploaders_verifystring(struct upload_conditions *, const char *); bool uploaders_verifyatom(struct upload_conditions *, atom_t); -void upload_conditions_free(/*@only@*/struct upload_conditions *); - #endif