versioned journal. the commands and their meanings change all the time,
so better handle that case. ps: yes, i think not upgrading mbsync between interrupting and resuming a run is a reasonable requirement.
This commit is contained in:
parent
8728dfdf21
commit
905ded175f
32
src/sync.c
32
src/sync.c
|
@ -175,6 +175,8 @@ clean_strdup( const char *s )
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define JOURNAL_VERSION "1"
|
||||||
|
|
||||||
int
|
int
|
||||||
sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
||||||
{
|
{
|
||||||
|
@ -187,7 +189,7 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
||||||
int nom, nos, del[2], ex[2];
|
int nom, nos, del[2], ex[2];
|
||||||
int muidval, suidval, smaxxuid, maxuid[2], minwuid, maxwuid;
|
int muidval, suidval, smaxxuid, maxuid[2], minwuid, maxwuid;
|
||||||
int t1, t2, t3, t;
|
int t1, t2, t3, t;
|
||||||
int lfd, ret, line, todel, delt, *mexcs, nmexcs, rmexcs;
|
int lfd, ret, line, sline, todel, delt, *mexcs, nmexcs, rmexcs;
|
||||||
unsigned char nflags;
|
unsigned char nflags;
|
||||||
msg_data_t msgdata;
|
msg_data_t msgdata;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -236,6 +238,7 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
||||||
#if F_WRLCK != 0
|
#if F_WRLCK != 0
|
||||||
lck.l_type = F_WRLCK;
|
lck.l_type = F_WRLCK;
|
||||||
#endif
|
#endif
|
||||||
|
line = 0;
|
||||||
if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) {
|
if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
lferr:
|
lferr:
|
||||||
|
@ -266,18 +269,18 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
||||||
ret = SYNC_FAIL;
|
ret = SYNC_FAIL;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
line = 1;
|
sline = 1;
|
||||||
while (fgets( buf, sizeof(buf), dfp )) {
|
while (fgets( buf, sizeof(buf), dfp )) {
|
||||||
line++;
|
sline++;
|
||||||
if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
|
if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
|
||||||
fprintf( stderr, "Error: incomplete sync state entry at %s:%d\n", dname, line );
|
fprintf( stderr, "Error: incomplete sync state entry at %s:%d\n", dname, sline );
|
||||||
fclose( dfp );
|
fclose( dfp );
|
||||||
ret = SYNC_FAIL;
|
ret = SYNC_FAIL;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
fbuf[0] = 0;
|
fbuf[0] = 0;
|
||||||
if (sscanf( buf, "%d %d %15s", &t1, &t2, fbuf ) < 2) {
|
if (sscanf( buf, "%d %d %15s", &t1, &t2, fbuf ) < 2) {
|
||||||
fprintf( stderr, "Error: invalid sync state entry at %s:%d\n", dname, line );
|
fprintf( stderr, "Error: invalid sync state entry at %s:%d\n", dname, sline );
|
||||||
fclose( dfp );
|
fclose( dfp );
|
||||||
ret = SYNC_FAIL;
|
ret = SYNC_FAIL;
|
||||||
goto bail;
|
goto bail;
|
||||||
|
@ -307,10 +310,23 @@ 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 ) && fgets( buf, sizeof(buf), jfp )) {
|
||||||
debug( "recovering journal ...\n" );
|
debug( "recovering journal ...\n" );
|
||||||
|
if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
|
||||||
|
fprintf( stderr, "Error: incomplete journal header in %s\n", jname );
|
||||||
|
fclose( jfp );
|
||||||
|
ret = SYNC_FAIL;
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
|
if (memcmp( buf, JOURNAL_VERSION "\n", strlen(JOURNAL_VERSION) + 1 )) {
|
||||||
|
fprintf( stderr, "Error: incompatible journal version "
|
||||||
|
"(got %.*s, expected " JOURNAL_VERSION ")\n", t - 1, buf );
|
||||||
|
fclose( jfp );
|
||||||
|
ret = SYNC_FAIL;
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
srec = 0;
|
srec = 0;
|
||||||
line = 0;
|
line = 1;
|
||||||
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') {
|
||||||
|
@ -488,6 +504,8 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan )
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
setlinebuf( jfp );
|
setlinebuf( jfp );
|
||||||
|
if (!line)
|
||||||
|
Fprintf( jfp, JOURNAL_VERSION "\n" );
|
||||||
|
|
||||||
mexcs = 0;
|
mexcs = 0;
|
||||||
nmexcs = rmexcs = 0;
|
nmexcs = rmexcs = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user