END_TEST static void do_md5sum_test(const char *endfile, int warnings, void setup_callback(struct asfd *asfd, struct sbuf *sb)) { struct asfd *asfd; struct cntr *cntr; struct sbuf *sb; const char *path="somepath"; const char *datapth="/datapth"; const char *best=BASE "/existent"; clean(); cntr=setup_cntr(); sb=setup_sbuf(path, datapth, endfile, 0/*compression*/); build_file(best, "blah"); asfd=asfd_mock_setup(&areads, &awrites); setup_callback(asfd, sb); // Returns 0 so that the parent process continues. fail_unless(!verify_file(asfd, sb, 0 /*patches*/, best, cntr)); fail_unless(cntr->ent[CMD_WARNING]->count==warnings); tear_down(&sb, &cntr, NULL, &asfd); }
END_TEST START_TEST(test_protocol1_verify_file_gzip_read_failure) { struct asfd *asfd; struct cntr *cntr; struct sbuf *sb; const char *path="somepath"; const char *datapth="/datapth"; const char *endfile="0:0"; const char *best=BASE "/existent"; const char *plain_text="some plain text"; size_t s; struct fzp *fzp; s=strlen(plain_text); clean(); cntr=setup_cntr(); sb=setup_sbuf(path, datapth, endfile, 1/*compression*/); // Make a corrupt gzipped file. build_path_w(best); fail_unless((fzp=fzp_gzopen(best, "wb"))!=NULL); fail_unless(fzp_write(fzp, plain_text, s)==s); fail_unless(!fzp_close(&fzp)); fail_unless((fzp=fzp_open(best, "r+b"))!=NULL); fail_unless(!fzp_seek(fzp, 10, SEEK_SET)); fail_unless(fzp_write(fzp, "aa", 2)==2); fail_unless(!fzp_close(&fzp)); asfd=asfd_mock_setup(&areads, &awrites); setup_error_while_reading(asfd, best); // Returns 0 so that the parent process continues. fail_unless(!verify_file(asfd, sb, 0 /*patches*/, best, cntr)); fail_unless(cntr->ent[CMD_WARNING]->count==1); tear_down(&sb, &cntr, NULL, &asfd); }
static int restore_manifest(struct asfd *asfd, struct bu *bu, regex_t *regex, int srestore, enum action act, struct sdirs *sdirs, char **dir_for_notify, struct conf **cconfs) { int ret=-1; char *manifest=NULL; char *logpath=NULL; char *logpathz=NULL; // For sending status information up to the server. enum cntr_status cntr_status=CNTR_STATUS_RESTORING; if(act==ACTION_RESTORE) cntr_status=CNTR_STATUS_RESTORING; else if(act==ACTION_VERIFY) cntr_status=CNTR_STATUS_VERIFYING; if((act==ACTION_RESTORE && get_logpaths(bu, "restorelog", &logpath, &logpathz)) || (act==ACTION_VERIFY && get_logpaths(bu, "verifylog", &logpath, &logpathz)) || !(manifest=prepend_s(bu->path, get_protocol(cconfs)==PROTO_1? "manifest.gz":"manifest"))) { log_and_send_oom(asfd, __func__); goto end; } if(log_fzp_set(logpath, cconfs)) { char msg[256]=""; snprintf(msg, sizeof(msg), "could not open log file: %s", logpath); log_and_send(asfd, msg); goto end; } *dir_for_notify=strdup_w(bu->path, __func__); log_restore_settings(cconfs, srestore); // First, do a pass through the manifest to set up cntr. // This is the equivalent of a phase1 scan during backup. if(setup_cntr(asfd, manifest, regex, srestore, act, cntr_status, cconfs)) goto end; if(get_int(cconfs[OPT_SEND_CLIENT_CNTR]) && cntr_send(get_cntr(cconfs))) goto end; // Now, do the actual restore. ret=actual_restore(asfd, bu, manifest, regex, srestore, act, sdirs, cntr_status, cconfs); end: log_fzp_set(NULL, cconfs); compress_file(logpath, logpathz, get_int(cconfs[OPT_COMPRESSION])); if(manifest) free(manifest); if(logpath) free(logpath); if(logpathz) free(logpathz); return ret; }