"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/server/restore.c" between
burp-2.3.14.tar.bz2 and burp-2.3.20.tar.bz2

About: Burp is a backup and restore program using librsync and also VSS (for Windows clients). Latest version.

restore.c  (burp-2.3.14.tar.bz2):restore.c  (burp-2.3.20.tar.bz2)
skipping to change at line 63 skipping to change at line 63
int r=0; int r=0;
if(!s->flag) return 0; // Do not know how to do excludes yet. if(!s->flag) return 0; // Do not know how to do excludes yet.
if((r=strncmp_w(path, s->path))) return 0; // no match if((r=strncmp_w(path, s->path))) return 0; // no match
if(!r) return 1; // exact match if(!r) return 1; // exact match
if(*(path+strlen(s->path)+1)=='/') if(*(path+strlen(s->path)+1)=='/')
return 1; // matched directory contents return 1; // matched directory contents
return 0; // no match return 0; // no match
} }
// Used when restore is initiated from the server. // Used when restore is initiated from the server.
static int check_srestore(struct conf **confs, const char *path) static int srestore_check(struct conf **confs, const char *path)
{ {
struct strlist *l=get_strlist(confs[OPT_INCEXCDIR]); struct strlist *l=get_strlist(confs[OPT_INCEXCDIR]);
// If no includes specified, restore everything. // If no includes specified, restore everything.
if(!l) return 1; if(!l) return 1;
for(; l; l=l->next) for(; l; l=l->next)
if(srestore_matches(l, path)) if(srestore_matches(l, path))
return 1; return 1;
return 0; return 0;
} }
static int want_to_restore(int srestore, struct sbuf *sb, static int restore_list_check(
regex_t *regex, enum action act , struct conf **cconfs) struct asfd *asfd,
struct cntr *cntr,
struct fzp *rl_fzp,
struct iobuf *rl_iobuf,
const char *path
)
{ {
char *last=NULL;
do {
if(!rl_iobuf->buf)
{
switch(iobuf_fill_from_fzp(rl_iobuf, rl_fzp))
{
case 0: break; // OK, read something.
case 1: return 0; // Finished, no match.
default: return -1; // Error.
}
}
if(last && pathcmp(rl_iobuf->buf, last)!=1)
{
logw(asfd, cntr,
"Input file ordering problem: '%s' '%s'",
last, rl_iobuf->buf);
}
switch(pathcmp(rl_iobuf->buf, path))
{
case 0: return 1; // Successful match.
case 1: return 0; // Ahead in input, no match.
default:
// Behind, need to read more from input.
free_w(&last);
last=rl_iobuf->buf;
rl_iobuf->buf=NULL;
}
} while (1);
return 0;
}
static int want_to_restore(
struct asfd *asfd,
int srestore,
struct fzp *input_fzp,
struct iobuf *input_iobuf,
struct sbuf *sb,
regex_t *regex,
enum action act,
struct conf **cconfs
) {
if(act==ACTION_RESTORE) if(act==ACTION_RESTORE)
{ {
// Do not send VSS data to non-windows, or to windows client // Do not send VSS data to non-windows, or to windows client
// that asked us not to send it. // that asked us not to send it.
if(!get_int(cconfs[OPT_CLIENT_IS_WINDOWS]) if(!get_int(cconfs[OPT_CLIENT_IS_WINDOWS])
|| get_int(cconfs[OPT_VSS_RESTORE])!=VSS_RESTORE_ON) || get_int(cconfs[OPT_VSS_RESTORE])!=VSS_RESTORE_ON)
{ {
if(sbuf_is_vssdata(sb)) if(sbuf_is_vssdata(sb))
return 0; return 0;
// Do not send VSS directory data to non-windows. // Do not send VSS directory data to non-windows.
if(S_ISDIR(sb->statp.st_mode) if(S_ISDIR(sb->statp.st_mode)
&& sbuf_is_filedata(sb) && sbuf_is_filedata(sb)
&& !sbuf_is_metadata(sb)) && !sbuf_is_metadata(sb))
return 0; return 0;
} }
} }
return (!srestore || check_srestore(cconfs, sb->path.buf)) return
&& (!regex || regex_check(regex, sb->path.buf)); (!input_fzp
|| restore_list_check(asfd, get_cntr(cconfs),
input_fzp, input_iobuf, sb->path.buf))
&& (!srestore
|| srestore_check(cconfs, sb->path.buf))
&& (!regex
|| regex_check(regex, sb->path.buf));
}
static int maybe_open_restore_list(
struct conf **cconfs,
struct fzp **rl_fzp,
struct iobuf **rl_iobuf,
struct sdirs *sdirs
) {
if(!get_string(cconfs[OPT_RESTORE_LIST]))
return 0;
if(!(*rl_fzp=fzp_open(sdirs->restore_list, "rb"))
|| !(*rl_iobuf=iobuf_alloc()))
return -1;
return 0;
} }
static int setup_cntr(struct asfd *asfd, const char *manifest, static int setup_cntr(struct asfd *asfd, const char *manifest,
regex_t *regex, int srestore, struct conf **cconfs, enum action act, regex_t *regex, int srestore, struct conf **cconfs, enum action act,
struct bu *bu) struct bu *bu, struct sdirs *sdirs)
{ {
int ars=0; int ars=0;
int ret=-1; int ret=-1;
struct fzp *fzp=NULL; struct fzp *fzp=NULL;
struct sbuf *sb=NULL; struct sbuf *sb=NULL;
struct cntr *cntr=NULL; struct cntr *cntr=NULL;
struct fzp *rl_fzp=NULL;
struct iobuf *rl_iobuf=NULL;
cntr=get_cntr(cconfs); cntr=get_cntr(cconfs);
if(!cntr) return 0; if(!cntr) return 0;
cntr->bno=(int)bu->bno; cntr->bno=(int)bu->bno;
// FIX THIS: this is only trying to work for protocol1. // FIX THIS: this is only trying to work for protocol1.
if(get_protocol(cconfs)!=PROTO_1) return 0; if(get_protocol(cconfs)!=PROTO_1) return 0;
if(maybe_open_restore_list(cconfs, &rl_fzp, &rl_iobuf, sdirs))
goto end;
if(!(sb=sbuf_alloc(PROTO_1))) goto end; if(!(sb=sbuf_alloc(PROTO_1))) goto end;
if(!(fzp=fzp_gzopen(manifest, "rb"))) if(!(fzp=fzp_gzopen(manifest, "rb")))
{ {
log_and_send(asfd, "could not open manifest"); log_and_send(asfd, "could not open manifest");
goto end; goto end;
} }
while(1) while(1)
{ {
if((ars=sbuf_fill_from_file(sb, fzp, NULL))) if((ars=sbuf_fill_from_file(sb, fzp, NULL)))
{ {
if(ars<0) goto end; if(ars<0) goto end;
// ars==1 means end ok // ars==1 means end ok
break; break;
} }
else else
{ {
if(want_to_restore(srestore, sb, regex, act, cconfs)) if(want_to_restore(asfd, srestore,
rl_fzp, rl_iobuf,
sb, regex, act, cconfs))
{ {
cntr_add_phase1(cntr, sb->path.cmd, 0); cntr_add_phase1(cntr, sb->path.cmd, 0);
if(sb->endfile.buf) if(sb->endfile.buf)
cntr_add_val(cntr, cntr_add_val(cntr,
CMD_BYTES_ESTIMATED, CMD_BYTES_ESTIMATED,
strtoull(sb->endfile.buf, strtoull(sb->endfile.buf,
NULL, 10)); NULL, 10));
} }
} }
sbuf_free_content(sb); sbuf_free_content(sb);
} }
ret=0; ret=0;
end: end:
iobuf_free(&rl_iobuf);
fzp_close(&rl_fzp);
sbuf_free(&sb); sbuf_free(&sb);
fzp_close(&fzp); fzp_close(&fzp);
return ret; return ret;
} }
static int restore_sbuf(struct asfd *asfd, struct sbuf *sb, struct bu *bu, static int restore_sbuf(struct asfd *asfd, struct sbuf *sb, struct bu *bu,
enum action act, struct sdirs *sdirs, enum cntr_status cntr_status, enum action act, struct sdirs *sdirs, enum cntr_status cntr_status,
struct conf **cconfs, struct sbuf *need_data, const char *manifest, struct conf **cconfs, struct sbuf *need_data, const char *manifest,
struct slist *slist); struct slist *slist);
skipping to change at line 445 skipping to change at line 526
int last_ent_was_dir=0; int last_ent_was_dir=0;
int last_ent_was_skipped=0; int last_ent_was_skipped=0;
struct sbuf *sb=NULL; struct sbuf *sb=NULL;
struct iobuf *rbuf=asfd->rbuf; struct iobuf *rbuf=asfd->rbuf;
struct manio *manio=NULL; struct manio *manio=NULL;
struct blk *blk=NULL; struct blk *blk=NULL;
struct sbuf *need_data=NULL; struct sbuf *need_data=NULL;
enum protocol protocol=get_protocol(cconfs); enum protocol protocol=get_protocol(cconfs);
struct cntr *cntr=get_cntr(cconfs); struct cntr *cntr=get_cntr(cconfs);
struct iobuf interrupt; struct iobuf interrupt;
struct fzp *rl_fzp=NULL;
struct iobuf *rl_iobuf=NULL;
iobuf_init(&interrupt); iobuf_init(&interrupt);
if(protocol==PROTO_2) if(protocol==PROTO_2)
{ {
static int rs_sent=0; static int rs_sent=0;
if(!(blk=blk_alloc())) if(!(blk=blk_alloc()))
goto end; goto end;
if(!rs_sent) if(!rs_sent)
{ {
rs_sent=1; rs_sent=1;
if(asfd->write_str(asfd, if(asfd->write_str(asfd,
CMD_GEN, "restore_stream") CMD_GEN, "restore_stream")
|| asfd_read_expect(asfd, || asfd_read_expect(asfd,
CMD_GEN, "restore_stream_ok")) CMD_GEN, "restore_stream_ok"))
goto end; goto end;
} }
} }
if(maybe_open_restore_list(cconfs, &rl_fzp, &rl_iobuf, sdirs))
goto end;
if(!(manio=manio_open(manifest, "rb", protocol)) if(!(manio=manio_open(manifest, "rb", protocol))
|| !(need_data=sbuf_alloc(protocol)) || !(need_data=sbuf_alloc(protocol))
|| !(sb=sbuf_alloc(protocol))) || !(sb=sbuf_alloc(protocol)))
goto end; goto end;
while(1) while(1)
{ {
iobuf_free_content(rbuf); iobuf_free_content(rbuf);
if(asfd->as->read_quick(asfd->as)) if(asfd->as->read_quick(asfd->as))
{ {
skipping to change at line 572 skipping to change at line 658
if(blk->data) if(blk->data)
{ {
if(protocol2_extra_restore_stream_bits(asfd, if(protocol2_extra_restore_stream_bits(asfd,
blk, slist, act, need_data, blk, slist, act, need_data,
last_ent_was_dir, cntr)) goto end; last_ent_was_dir, cntr)) goto end;
continue; continue;
} }
sbuf_free_content(need_data); sbuf_free_content(need_data);
} }
if(want_to_restore(srestore, sb, regex, act, cconfs)) if(want_to_restore(asfd, srestore, rl_fzp, rl_iobuf,
sb, regex, act, cconfs))
{ {
last_ent_was_skipped=0; last_ent_was_skipped=0;
if(restore_ent(asfd, &sb, slist, if(restore_ent(asfd, &sb, slist,
bu, act, sdirs, cntr_status, cconfs, bu, act, sdirs, cntr_status, cconfs,
need_data, &last_ent_was_dir, manifest)) need_data, &last_ent_was_dir, manifest))
goto end; goto end;
} }
else else
{ {
last_ent_was_skipped=1; last_ent_was_skipped=1;
skipping to change at line 597 skipping to change at line 684
struct f_link **bucket=NULL; struct f_link **bucket=NULL;
if(!linkhash_search(&sb->statp, &bucket) if(!linkhash_search(&sb->statp, &bucket)
&& linkhash_add(sb->path.buf, &sb->statp, bucke t)) && linkhash_add(sb->path.buf, &sb->statp, bucke t))
goto end; goto end;
} }
} }
sbuf_free_content(sb); sbuf_free_content(sb);
} }
end: end:
iobuf_free(&rl_iobuf);
fzp_close(&rl_fzp);
blk_free(&blk); blk_free(&blk);
sbuf_free(&sb); sbuf_free(&sb);
sbuf_free(&need_data); sbuf_free(&need_data);
iobuf_free_content(rbuf); iobuf_free_content(rbuf);
iobuf_free_content(&interrupt); iobuf_free_content(&interrupt);
manio_close(&manio); manio_close(&manio);
return ret; return ret;
} }
static int actual_restore(struct asfd *asfd, struct bu *bu, static int actual_restore(struct asfd *asfd, struct bu *bu,
skipping to change at line 747 skipping to change at line 836
} }
*dir_for_notify=strdup_w(bu->path, __func__); *dir_for_notify=strdup_w(bu->path, __func__);
log_restore_settings(cconfs, srestore); log_restore_settings(cconfs, srestore);
// First, do a pass through the manifest to set up cntr. // First, do a pass through the manifest to set up cntr.
// This is the equivalent of a phase1 scan during backup. // This is the equivalent of a phase1 scan during backup.
if(setup_cntr(asfd, manifest, if(setup_cntr(asfd, manifest,
regex, srestore, cconfs, act, bu)) regex, srestore, cconfs, act, bu, sdirs))
goto end; goto end;
if(!manifest_count) if(!manifest_count)
{ {
// FIX THIS: Only send the counters once, otherwise the // FIX THIS: Only send the counters once, otherwise the
// client will break on '-b a' because it does not expect // client will break on '-b a' because it does not expect
// multiple sets of counters to turn up. // multiple sets of counters to turn up.
// This means that the client side 'expected' counter will be // This means that the client side 'expected' counter will be
// confusing in that case. Live with it for now. // confusing in that case. Live with it for now.
// However, the server side log will be OK. // However, the server side log will be OK.
 End of changes. 14 change blocks. 
9 lines changed or deleted 98 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)