diff --git a/src/mbsync.1 b/src/mbsync.1 index 8a8b01f..ffd6188 100644 --- a/src/mbsync.1 +++ b/src/mbsync.1 @@ -726,7 +726,7 @@ you want to specify a directory. .br This option can be used outside any section for a global effect. In this case the appended string is made up according to the pattern -\fB:\fIfar-store\fB:\fIfar-box\fB_:\fInear-store\fB:\fInear-box\fR +far-store\fB:\fIfar-box\fB_\fInear-store\fB:\fInear-box\fR (see also \fBFieldDelimiter\fR below). .br (Global default: \fI$XDG_STATE_HOME/isync/\fR, with a fallback to diff --git a/src/sync_state.c b/src/sync_state.c index 5567f10..c4c4175 100644 --- a/src/sync_state.c +++ b/src/sync_state.c @@ -45,11 +45,26 @@ prepare_state( sync_vars_t *svars ) if (chan->sync_state) { nfasprintf( &svars->dname, "%s%s", chan->sync_state, cnname ); } else { + char *dname, *dname2; char c = FieldDelimiter; char *cfname = clean_strdup( svars->box_name[F] ); - nfasprintf( &svars->dname, "%s%c%s%c%s_%c%s%c%s", global_conf.sync_state, + nfasprintf( &dname, "%s%s%c%s_%s%c%s", global_conf.sync_state, + chan->stores[F]->name, c, cfname, chan->stores[N]->name, c, cnname ); + nfasprintf( &dname2, "%s%c%s%c%s_%c%s%c%s", global_conf.sync_state, c, chan->stores[F]->name, c, cfname, c, chan->stores[N]->name, c, cnname ); free( cfname ); + struct stat st; + int ex = !lstat( dname, &st ); + int ex2 = !lstat( dname2, &st ); + if (ex2 && !ex) { + svars->dname = dname2; + free( dname ); + } else { + if (ex && ex2) + warn( "Warning: both %s and %s exist; using the former.\n", dname, dname2 ); + svars->dname = dname; + free( dname2 ); + } } free( cnname ); char *s;