make the sync entry search in the journal replay wrap around at the end

of the list. the "always forward" assumption is violated in some cases.
This commit is contained in:
Oswald Buddenhagen 2006-02-02 10:44:19 +00:00
parent 5e01034aee
commit 8728dfdf21

View File

@ -309,8 +309,8 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
if ((jfp = fopen( jname, "r" ))) {
if (!stat( nname, &st )) {
debug( "recovering journal ...\n" );
srec = 0;
line = 0;
srec = recs;
while (fgets( buf, sizeof(buf), jfp )) {
line++;
if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
@ -319,9 +319,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
ret = SYNC_FAIL;
goto bail;
}
if (buf[0] == '^')
srec = recs;
else {
if (buf[0] == '(' || buf[0] == ')' ?
(sscanf( buf + 2, "%d", &t1 ) != 1) :
buf[0] == '-' || buf[0] == '|' ?
@ -352,7 +349,10 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
*srecadd = srec;
srecadd = &srec->next;
} else {
for (; srec; srec = srec->next)
for (nsrec = srec; srec; srec = srec->next)
if (srec->uid[M] == t1 && srec->uid[S] == t2)
goto syncfnd;
for (srec = recs; srec != nsrec; srec = srec->next)
if (srec->uid[M] == t1 && srec->uid[S] == t2)
goto syncfnd;
fprintf( stderr, "Error: journal entry at %s:%d refers to non-existing sync state entry\n", jname, line );
@ -396,7 +396,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
}
}
}
}
fclose( jfp );
} else {
if (errno != ENOENT) {
@ -511,7 +510,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
minwuid = srec->uid[M];
}
debug( " min non-orphaned master uid is %d\n", minwuid );
Fprintf( jfp, "^\n" ); /* if any S_EXP_S */
for (srec = recs; srec; srec = srec->next) {
if (srec->status & S_DEAD)
continue;
@ -650,7 +648,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
}
debug( "synchronizing old entries\n" );
Fprintf( jfp, "^\n" );
for (srec = recs; srec != *osrecadd; srec = srec->next) {
if (srec->status & (S_DEAD|S_DONE))
continue;
@ -778,7 +775,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
}
}
if (delt) {
Fprintf( jfp, "^\n" );
for (srec = recs; srec; srec = srec->next) {
if (srec->status & (S_DEAD|S_EXPIRED))
continue;
@ -868,7 +864,6 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
debug( " min non-orphaned master uid is %d\n", minwuid );
}
Fprintf( jfp, "^\n" );
for (srec = recs; srec; srec = srec->next) {
if (srec->status & S_DEAD)
continue;