CVS commit by ossi: 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.
M +25 -7 sync.c 1.66 --- isync/src/sync.c #1.65:1.66 @@ -176,4 +176,6 @@ clean_strdup( const char *s ) } +#define JOURNAL_VERSION "1" + int sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan ) @@ -188,5 +190,5 @@ sync_boxes( store_t *ctx[], const char * int muidval, suidval, smaxxuid, maxuid[2], minwuid, maxwuid; 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; msg_data_t msgdata; @@ -237,4 +239,5 @@ sync_boxes( store_t *ctx[], const char * lck.l_type = F_WRLCK; #endif + line = 0; if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) { if (errno != ENOENT) { @@ -267,9 +270,9 @@ sync_boxes( store_t *ctx[], const char * goto bail; } - line = 1; + sline = 1; while (fgets( buf, sizeof(buf), dfp )) { - line++; + sline++; 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 ); ret = SYNC_FAIL; @@ -278,5 +281,5 @@ sync_boxes( store_t *ctx[], const char * fbuf[0] = 0; 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 ); ret = SYNC_FAIL; @@ -308,8 +311,21 @@ sync_boxes( store_t *ctx[], const char * } if ((jfp = fopen( jname, "r" ))) { - if (!stat( nname, &st )) { + if (!stat( nname, &st ) && fgets( buf, sizeof(buf), jfp )) { 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; - line = 0; + line = 1; while (fgets( buf, sizeof(buf), jfp )) { line++; @@ -489,4 +505,6 @@ sync_boxes( store_t *ctx[], const char * } setlinebuf( jfp ); + if (!line) + Fprintf( jfp, JOURNAL_VERSION "\n" ); mexcs = 0; ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel