"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/server/resume.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.

resume.c  (burp-2.3.14.tar.bz2):resume.c  (burp-2.3.20.tar.bz2)
skipping to change at line 79 skipping to change at line 79
if(!(*pos=manio_tell(manio))) if(!(*pos=manio_tell(manio)))
{ {
logp("Could not manio_tell first pos in %s(): %s\n", logp("Could not manio_tell first pos in %s(): %s\n",
__func__, strerror(errno)); __func__, strerror(errno));
goto error; goto error;
} }
while(1) while(1)
{ {
sbuf_free_content(sb); sbuf_free_content(sb);
man_off_t_free(pos);
if(!(*pos=manio_tell(manio)))
{
logp("Could not manio_tell top pos in %s(): %s\n",
__func__, strerror(errno));
goto error;
}
switch(manio_read(manio, sb)) switch(manio_read(manio, sb))
{ {
case 0: break; case 0:
case 1: logp("End of file in %s()\n", __func__); break;
case 1:
logp("End of file in %s()\n", __func__);
goto error; goto error;
default: default:
logp("Error in %s()\n", __func__); logp("Error in %s()\n", __func__);
// Treat error in unchanged manio as not OK.
goto error; goto error;
} }
if(target->cmd==sb->path.cmd switch(iobuf_pathcmp(target, &sb->path))
&& !pathcmp(target->buf, sb->path.buf))
{ {
man_off_t_free(pos); case 0:
if(!(*pos=manio_tell(manio))) // Exact match, we want to be past here.
{ if(protocol==PROTO_2
logp("Could not get pos in %s(): %s\n", && manio->phase==0
__func__, strerror(errno)); && !sb->endfile.buf)
goto error; {
} // This is the current manio, and we
sbuf_free(&sb); // need one more read to get us past
return 0; // endfile.
sbuf_free_content(sb);
switch(manio_read(manio, sb))
{
case 0:
break;
case 1:
logp("End of file finishi
ng up in %s()\n", __func__);
goto error;
default:
logp("Error finishing up
in %s()\n", __func__);
goto error;
}
if(sb->path.buf)
{
logp("Not expecting %s in %s()\n"
,
iobuf_to_printable(&sb->p
ath),
__func__);
goto error;
}
if(!sb->endfile.buf)
{
logp("Was expecting endfile in %s
()\n",
__func__);
goto error;
}
// Drop through to tell the position.
}
man_off_t_free(pos);
if(!(*pos=manio_tell(manio)))
{
logp("Could not manio_tell pos in %s(): "
"%s\n", __func__, strerror(errno)
);
goto error;
}
sbuf_free(&sb);
return 0;
case -1:
// Gone past the match, we want to return to
// the previous tell.
sbuf_free(&sb);
return 0;
default:
// Not gone far enough yet, continue.
break;
} }
} }
error: error:
sbuf_free(&sb); sbuf_free(&sb);
man_off_t_free(pos); man_off_t_free(pos);
return -1; return -1;
} }
#ifndef UTEST #ifndef UTEST
skipping to change at line 173 skipping to change at line 225
} }
if(iobuf_pathcmp(target, &sb->path)<=0) if(iobuf_pathcmp(target, &sb->path)<=0)
{ {
sbuf_free(&sb); sbuf_free(&sb);
return 0; return 0;
} }
if(cntr) if(cntr)
{ {
cntr_add_same(cntr, sb->path.cmd);
if(sb->endfile.buf) if(sb->endfile.buf)
{ {
uint64_t e=strtoull(sb->endfile.buf, NULL, 10); uint64_t e=strtoull(sb->endfile.buf, NULL, 10);
cntr_add_bytes(cntr, e); cntr_add_bytes(cntr, e);
} }
} }
} }
error: error:
sbuf_free(&sb); sbuf_free(&sb);
skipping to change at line 292 skipping to change at line 343
case CMD_ENC_FILE: case CMD_ENC_FILE:
if(S_ISDIR(sb->statp.st_mode)) if(S_ISDIR(sb->statp.st_mode))
got_vss_start=0; got_vss_start=0;
break; break;
default: default:
break; break;
} }
if(cntr) if(cntr)
{ {
// FIX THIS: cannot distinguish between new and
// changed files.
cntr_add_changed(cntr, sb->path.cmd);
if(sb->endfile.buf) if(sb->endfile.buf)
{ {
uint64_t e=strtoull(sb->endfile.buf, NULL, 10); uint64_t e=strtoull(sb->endfile.buf, NULL, 10);
cntr_add_bytes(cntr, e); cntr_add_bytes(cntr, e);
} }
} }
} }
error: error:
iobuf_free_content(&lastpath); iobuf_free_content(&lastpath);
sbuf_free(&sb); sbuf_free(&sb);
man_off_t_free(pos); man_off_t_free(pos);
return -1; return -1;
} }
// Return p1manio position. static int add_to_cntr(
static man_off_t *do_resume_work(struct sdirs *sdirs, struct cntr *cntr,
struct dpth *dpth, struct conf **cconfs) enum cmd cmd,
enum cntr_manio cntr_manio
) {
switch(cntr_manio)
{
case CNTR_MANIO_NEW:
cntr_add(cntr, cmd, 0);
break;
case CNTR_MANIO_CHANGED:
cntr_add_changed(cntr, cmd);
break;
case CNTR_MANIO_SAME:
cntr_add_same(cntr, cmd);
break;
case CNTR_MANIO_DELETED:
cntr_add_deleted(cntr, cmd);
break;
default:
logp("Unknown counter in %s(): %c\n",
__func__, cntr_manio);
return -1;
}
return 0;
}
static int forward_past_entry_counter(
struct manio *manio,
struct iobuf *target,
struct cntr *cntr,
man_off_t **pos
) {
char what[1];
struct iobuf rbuf;
iobuf_init(&rbuf);
while(1)
{
iobuf_free_content(&rbuf);
man_off_t_free(pos);
if(!(*pos=manio_tell(manio)))
{
logp("Could not manio_tell top pos in %s(): %s\n",
__func__, strerror(errno));
goto error;
}
switch(fzp_read_ensure(manio->fzp, what, sizeof(what), __func__))
{
case 0: break;
case 1: return 0;
default:
logp("Error read in %s(), but continuing\n",
__func__);
// Treat error in unchanged manio as
// OK - could have been a short write.
iobuf_free_content(&rbuf);
return 0;
}
switch(iobuf_fill_from_fzp(&rbuf, manio->fzp))
{
case 0: break;
case 1:
iobuf_free_content(&rbuf);
return 0;
default:
logp("Error in %s(), but continuing\n",
__func__);
// Treat error in unchanged manio as
// OK - could have been a short write.
iobuf_free_content(&rbuf);
return 0;
}
switch(iobuf_pathcmp(target, &rbuf))
{
case 0:
add_to_cntr(cntr, rbuf.cmd, what[0]);
// Exact match, we want to be past here.
man_off_t_free(pos);
if(!(*pos=manio_tell(manio)))
{
logp("Could not manio_tell pos in %s(): "
"%s\n", __func__, strerror(errno)
);
goto error;
}
iobuf_free_content(&rbuf);
return 0;
case -1:
// Gone past the match, we want to return to
// the previous tell. Do not add_to_cntr,
// or we will have one too many.
iobuf_free_content(&rbuf);
return 0;
default:
// Not gone far enough yet, continue.
add_to_cntr(cntr, rbuf.cmd, what[0]);
break;
}
}
error:
iobuf_free_content(&rbuf);
man_off_t_free(pos);
return -1;
}
static int tell_and_truncate(struct manio **manio, int compression)
{ {
int ret=-1;
man_off_t *pos=NULL;
if(!(pos=manio_tell(*manio))) {
logp("Could not get pos in %s\n", __func__);
goto end;
}
if(manio_close_and_truncate(manio, pos, compression))
goto end;
ret=0;
end:
man_off_t_free(&pos);
return ret;
}
// Return p1manio position.
static int do_resume_work(
man_off_t **pos_phase1,
man_off_t **pos_current,
struct sdirs *sdirs,
struct dpth *dpth, struct conf **cconfs
) {
int ret=-1;
man_off_t *pos=NULL; man_off_t *pos=NULL;
man_off_t *p1pos=NULL;
struct iobuf *chb=NULL; struct iobuf *chb=NULL;
struct manio *cmanio=NULL; struct manio *cmanio=NULL;
struct manio *umanio=NULL; struct manio *chmanio=NULL;
struct manio *unmanio=NULL;
struct manio *p1manio=NULL; struct manio *p1manio=NULL;
struct manio *counters_d=NULL;
struct manio *counters_n=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);
int compression=get_int(cconfs[OPT_COMPRESSION]); int compression=get_int(cconfs[OPT_COMPRESSION]);
if(!(p1manio=manio_open_phase1(sdirs->phase1data, if(!(cmanio=manio_open(sdirs->cmanifest,
MANIO_MODE_READ, protocol))
|| !(p1manio=manio_open_phase1(sdirs->phase1data,
MANIO_MODE_READ, protocol))
|| !(chmanio=manio_open_phase2(sdirs->changed,
MANIO_MODE_READ, protocol)) MANIO_MODE_READ, protocol))
|| !(cmanio=manio_open_phase2(sdirs->changed, || !(unmanio=manio_open_phase2(sdirs->unchanged,
MANIO_MODE_READ, protocol)) MANIO_MODE_READ, protocol))
|| !(umanio=manio_open_phase2(sdirs->unchanged, // The counters are always flat files, which is given by PROTO_1.
MANIO_MODE_READ, protocol))) || !(counters_d=manio_open_phase2(sdirs->counters_d,
MANIO_MODE_READ, PROTO_1))
|| !(counters_n=manio_open_phase2(sdirs->counters_n,
MANIO_MODE_READ, PROTO_1)))
goto end; goto end;
if(!(chb=iobuf_alloc())) if(!(chb=iobuf_alloc()))
return NULL; goto error;
logp("Setting up resume positions...\n"); logp("Setting up resume positions...\n");
if(get_last_good_entry(cmanio, chb, cntr, dpth, protocol, &pos)) if(get_last_good_entry(chmanio, chb, cntr, dpth, protocol, &pos)
|| manio_close_and_truncate(&chmanio, pos, compression))
goto error; goto error;
if(manio_close_and_truncate(&cmanio, pos, compression)) goto error;
man_off_t_free(&pos); man_off_t_free(&pos);
if(chb->buf) if(chb->buf)
{ {
logp(" last good entry: %s\n", logp(" last good entry: %s\n",
iobuf_to_printable(chb)); iobuf_to_printable(chb));
// Now need to go to the appropriate places in p1manio and // Now need to go to the appropriate places in p1manio, cmanio
// unchanged. // and unmanio.
if(forward_past_entry(p1manio, chb, protocol, &p1pos))
// This sets pos_phase1.
if(forward_past_entry(p1manio, chb, protocol, pos_phase1))
goto error; goto error;
// The unchanged file needs to be positioned just before the // This sets pos_current. This manifest may not exist.
if(cmanio->fzp && forward_past_entry(cmanio,
chb, protocol, pos_current))
goto error;
// The unchanged manio needs to be positioned just before the
// found entry, otherwise it ends up having a duplicated entry. // found entry, otherwise it ends up having a duplicated entry.
if(forward_before_entry(umanio, if(forward_before_entry(unmanio,
chb, cntr, dpth, protocol, &pos)) chb, cntr, dpth, protocol, &pos))
goto error; goto error;
if(manio_close_and_truncate(&umanio, pos, compression)) if(manio_close_and_truncate(&unmanio, pos, compression))
goto error;
man_off_t_free(&pos);
if(forward_past_entry_counter(counters_d, chb, cntr, &pos))
goto error;
if(manio_close_and_truncate(&counters_d, pos, 0))
goto error;
man_off_t_free(&pos);
if(forward_past_entry_counter(counters_n, chb, cntr, &pos))
goto error;
if(manio_close_and_truncate(&counters_n, pos, 0))
goto error; goto error;
man_off_t_free(&pos); man_off_t_free(&pos);
} }
else else
{ {
logp(" nothing previously transferred\n"); logp(" nothing previously transferred\n");
if(!(p1pos=manio_tell(p1manio))) if(!(*pos_phase1=manio_tell(p1manio))) {
{ logp("Could not get pos_phase1 in %s\n", __func__);
logp("Could not get p1pos in %s\n", __func__);
goto error;
}
if(!(pos=manio_tell(umanio)))
{
logp("Could not get pos in %s\n", __func__);
goto error; goto error;
} }
if(manio_close_and_truncate(&umanio, pos, compression)) if(tell_and_truncate(&unmanio, compression)
|| tell_and_truncate(&counters_d, 0)
|| tell_and_truncate(&counters_n, 0))
goto error; goto error;
} }
// Now should have all file pointers in the right places to resume. // Now should have all manios truncated correctly, with pos_phase1 and
// pos_current set correctly in order to resume.
ret=0;
goto end; goto end;
error: error:
man_off_t_free(&p1pos); man_off_t_free(pos_phase1);
man_off_t_free(pos_current);
end: end:
iobuf_free(&chb); iobuf_free(&chb);
man_off_t_free(&pos); man_off_t_free(&pos);
manio_close(&p1manio); manio_close(&p1manio);
manio_close(&cmanio); manio_close(&cmanio);
manio_close(&umanio); manio_close(&chmanio);
return p1pos; manio_close(&unmanio);
manio_close(&counters_d);
manio_close(&counters_n);
return ret;
} }
man_off_t *do_resume(struct sdirs *sdirs, int do_resume(
struct dpth *dpth, struct conf **cconfs) man_off_t **pos_phase1,
{ man_off_t **pos_current,
man_off_t *p1pos=NULL; struct sdirs *sdirs,
struct manio *cmanio=NULL; struct dpth *dpth,
struct manio *umanio=NULL; struct conf **cconfs
) {
int ret=-1;
struct manio *chmanio=NULL;
struct manio *unmanio=NULL;
struct manio *p1manio=NULL; struct manio *p1manio=NULL;
struct manio *counters_d=NULL;
struct manio *counters_n=NULL;
enum protocol protocol=get_protocol(cconfs); enum protocol protocol=get_protocol(cconfs);
logp("Begin phase1 (read previous file system scan)\n"); logp("Begin phase1 (read previous file system scan)\n");
if(!(p1manio=manio_open_phase1(sdirs->phase1data, "rb", protocol)) if(!(p1manio=manio_open_phase1(sdirs->phase1data, "rb", protocol))
|| read_phase1(p1manio, cconfs)) || read_phase1(p1manio, cconfs))
goto end; goto end;
manio_close(&p1manio); manio_close(&p1manio);
// First, open them in append mode, so that they will be created if // First, open them in append mode, so that they will be created if
// they do not exist. // they do not exist.
if(!(cmanio=manio_open_phase2(sdirs->changed, "ab", protocol)) if(!(chmanio=manio_open_phase2(sdirs->changed, "ab", protocol))
|| !(umanio=manio_open_phase2(sdirs->unchanged, "ab", protocol))) || !(unmanio=manio_open_phase2(sdirs->unchanged, "ab", protocol))
|| !(counters_d=manio_open_phase2(sdirs->counters_d, "ab", PROTO_1))
|| !(counters_n=manio_open_phase2(sdirs->counters_n, "ab", PROTO_1)))
goto end; goto end;
manio_close(&cmanio); manio_close(&chmanio);
manio_close(&umanio); manio_close(&unmanio);
manio_close(&counters_d);
manio_close(&counters_n);
if(!(p1pos=do_resume_work(sdirs, dpth, cconfs))) goto end; if(do_resume_work(pos_phase1, pos_current, sdirs, dpth, cconfs))
goto end;
if(dpth_incr(dpth)) goto end; if(dpth_incr(dpth)) goto end;
logp("End phase1 (read previous file system scan)\n"); logp("End phase1 (read previous file system scan)\n");
ret=0;
end: end:
manio_close(&p1manio); manio_close(&p1manio);
manio_close(&cmanio); manio_close(&chmanio);
manio_close(&umanio); manio_close(&unmanio);
return p1pos; manio_close(&counters_d);
manio_close(&counters_n);
return ret;
} }
 End of changes. 35 change blocks. 
64 lines changed or deleted 294 lines changed or added

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