int do_list_server(struct asfd *asfd, struct sdirs *sdirs, struct conf *conf, const char *backup, const char *listregex, const char *browsedir) { int ret=-1; uint8_t found=0; unsigned long bno=0; regex_t *regex=NULL; struct bu *bu=NULL; struct bu *bu_list=NULL; printf("in do_list_server\n"); if(compile_regex(®ex, listregex) || bu_list_get(sdirs, &bu_list) || write_status(STATUS_LISTING, NULL, conf)) goto end; if(backup && *backup) bno=strtoul(backup, NULL, 10); for(bu=bu_list; bu; bu=bu->next) { // Search all backups for things matching the regex. if(listregex && backup && *backup=='a') { found=1; if(write_wrapper_str(asfd, CMD_TIMESTAMP, bu->timestamp) || list_manifest(asfd, bu->path, regex, browsedir, conf)) goto end; } // Search or list a particular backup. else if(backup && *backup) { if(!found && (!strcmp(bu->timestamp, backup) || bu->bno==bno)) { found=1; if(send_backup_name_to_client(asfd, bu, conf) || list_manifest(asfd, bu->path, regex, browsedir, conf)) goto end; } } // List the backups. else { found=1; if(send_backup_name_to_client(asfd, bu, conf)) goto end; } } if(backup && *backup && !found) { write_wrapper_str(asfd, CMD_ERROR, "backup not found"); goto end; } if(flush_asio(asfd)) goto end; ret=0; end: if(regex) { regfree(regex); free(regex); } bu_list_free(&bu); return ret; }
int do_list_server(const char *basedir, const char *backup, const char *listregex, const char *browsedir, const char *client, struct cntr *p1cntr, struct cntr *cntr) { int a=0; int i=0; int ret=0; int found=0; struct bu *arr=NULL; unsigned long index=0; regex_t *regex=NULL; logp("in do_list\n"); if(compile_regex(®ex, listregex)) return -1; if(get_current_backups(basedir, &arr, &a, 1)) { if(regex) { regfree(regex); free(regex); } return -1; } write_status(client, STATUS_LISTING, NULL, p1cntr, cntr); if(backup && *backup) index=strtoul(backup, NULL, 10); for(i=0; i<a; i++) { // Search all backups for things matching the regex. if(listregex && backup && *backup=='a') { found=TRUE; async_write(CMD_TIMESTAMP, arr[i].timestamp, strlen(arr[i].timestamp)); ret+=list_manifest(arr[i].path, regex, browsedir, client, p1cntr, cntr); } // Search or list a particular backup. else if(backup && *backup) { if(!found && (!strcmp(arr[i].timestamp, backup) || arr[i].index==index)) { found=TRUE; async_write(CMD_TIMESTAMP, arr[i].timestamp, strlen(arr[i].timestamp)); ret=list_manifest(arr[i].path, regex, browsedir, client, p1cntr, cntr); } } // List the backups. else { found=TRUE; async_write(CMD_TIMESTAMP, arr[i].timestamp, strlen(arr[i].timestamp)); } } free_current_backups(&arr, a); if(backup && *backup && !found) { async_write_str(CMD_ERROR, "backup not found"); ret=-1; } if(regex) { regfree(regex); free(regex); } return ret; }