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