static int do_restore_file_or_get_meta(struct asfd *asfd, BFILE *bfd, struct sbuf *sb, const char *fname, char **metadata, size_t *metalen, struct cntr *cntr, const char *rpath, const char *encryption_password) { int ret=-1; int enccompressed=0; uint64_t rcvdbytes=0; uint64_t sentbytes=0; const char *encpassword=NULL; if(sbuf_is_encrypted(sb)) encpassword=encryption_password; enccompressed=dpth_protocol1_is_compressed(sb->compression, sb->protocol1->datapth.buf); /* printf("%s \n", fname); if(encpassword && !enccompressed) printf("encrypted and not compressed\n"); else if(!encpassword && enccompressed) printf("not encrypted and compressed\n"); else if(!encpassword && !enccompressed) printf("not encrypted and not compressed\n"); else if(encpassword && enccompressed) printf("encrypted and compressed\n"); */ if(metadata) { ret=transfer_gzfile_inl(asfd, sb, fname, NULL, &rcvdbytes, &sentbytes, encpassword, enccompressed, cntr, metadata); *metalen=sentbytes; // skip setting cntr, as we do not actually // restore until a bit later goto end; } else { ret=transfer_gzfile_inl(asfd, sb, fname, bfd, &rcvdbytes, &sentbytes, encpassword, enccompressed, cntr, NULL); #ifndef HAVE_WIN32 if(bfd && bfd->close(bfd, asfd)) { logp("error closing %s in %s\n", fname, __func__); goto end; } #endif if(!ret) attribs_set(asfd, rpath, &sb->statp, sb->winattr, cntr); } ret=0; end: if(ret) { char msg[256]=""; snprintf(msg, sizeof(msg), "Could not transfer file in: %s", rpath); if(restore_interrupt(asfd, sb, msg, cntr, PROTO_1)) ret=-1; } return ret; }
static int restore_file_or_get_meta(struct asfd *asfd, BFILE *bfd, struct sbuf *sb, const char *fname, enum action act, const char *encpassword, char **metadata, size_t *metalen, int vss_restore, struct conf *conf) { int ret=0; char *rpath=NULL; FILE *fp=NULL; if(act==ACTION_VERIFY) { cntr_add(conf->cntr, sb->path.cmd, 1); return 0; } if(build_path(fname, "", &rpath, NULL)) { char msg[256]=""; // failed - do a warning snprintf(msg, sizeof(msg), "build path failed: %s", fname); if(restore_interrupt(asfd, sb, msg, conf)) ret=-1; goto end; } #ifndef HAVE_WIN32 // We always want to open the file if it is on Windows. Otherwise, // only open it if we are not doing metadata. if(!metadata) { #endif if(open_for_restore(asfd, bfd, &fp, rpath, sb, vss_restore, conf)) { ret=-1; goto end; } #ifndef HAVE_WIN32 } #endif if(!ret) { int enccompressed=0; unsigned long long rcvdbytes=0; unsigned long long sentbytes=0; enccompressed=dpthl_is_compressed(sb->compression, sb->burp1->datapth.buf); /* printf("%s \n", fname); if(encpassword && !enccompressed) printf("encrypted and not compressed\n"); else if(!encpassword && enccompressed) printf("not encrypted and compressed\n"); else if(!encpassword && !enccompressed) printf("not encrypted and not compressed\n"); else if(encpassword && enccompressed) printf("encrypted and compressed\n"); */ if(metadata) { ret=transfer_gzfile_inl(asfd, sb, fname, NULL, NULL, &rcvdbytes, &sentbytes, encpassword, enccompressed, conf->cntr, metadata); *metalen=sentbytes; // skip setting cntr, as we do not actually // restore until a bit later goto end; } else { int c=0; #ifdef HAVE_WIN32 ret=transfer_gzfile_inl(asfd, sb, fname, bfd, NULL, &rcvdbytes, &sentbytes, encpassword, enccompressed, conf->cntr, NULL); //c=bclose(bfd); #else ret=transfer_gzfile_inl(asfd, sb, fname, NULL, fp, &rcvdbytes, &sentbytes, encpassword, enccompressed, conf->cntr, NULL); c=close_fp(&fp); #endif if(c) { logp("error closing %s in restore_file_or_get_meta\n", fname); ret=-1; } if(!ret) attribs_set(asfd, rpath, &(sb->statp), sb->winattr, conf); } if(ret) { char msg[256]=""; snprintf(msg, sizeof(msg), "Could not transfer file in: %s", rpath); if(restore_interrupt(asfd, sb, msg, conf)) ret=-1; goto end; } } if(!ret) cntr_add(conf->cntr, sb->path.cmd, 1); end: if(rpath) free(rpath); return ret; }