2004-03-27 16:07:20 +00:00
|
|
|
/*
|
|
|
|
* mbsync - mailbox synchronizer
|
2002-12-28 15:31:20 +00:00
|
|
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
|
2013-04-20 14:57:16 +00:00
|
|
|
* Copyright (C) 2002-2006,2010-2013 Oswald Buddenhagen <ossi@users.sf.net>
|
2000-12-20 21:41:21 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-04-10 17:34:36 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-10-30 02:31:20 +00:00
|
|
|
*
|
2004-03-27 16:07:20 +00:00
|
|
|
* As a special exception, mbsync may be linked with the OpenSSL library,
|
2002-10-30 02:31:20 +00:00
|
|
|
* despite that library's more restrictive license.
|
2000-12-20 21:41:21 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
#include "sync.h"
|
2003-05-07 00:06:37 +00:00
|
|
|
|
2013-11-02 22:32:42 +00:00
|
|
|
#include <assert.h>
|
2000-12-20 21:41:21 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
2006-03-21 20:03:21 +00:00
|
|
|
#include <stddef.h>
|
2000-12-20 21:41:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
2013-11-16 12:25:31 +00:00
|
|
|
#include <ctype.h>
|
2000-12-20 21:41:21 +00:00
|
|
|
#include <string.h>
|
2000-12-21 18:16:44 +00:00
|
|
|
#include <errno.h>
|
2001-01-11 10:13:47 +00:00
|
|
|
#include <sys/stat.h>
|
2000-12-20 21:41:21 +00:00
|
|
|
|
2014-01-02 18:36:45 +00:00
|
|
|
#if !defined(_POSIX_SYNCHRONIZED_IO) || _POSIX_SYNCHRONIZED_IO <= 0
|
2012-09-15 11:25:50 +00:00
|
|
|
# define fdatasync fsync
|
|
|
|
#endif
|
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
#define JOURNAL_VERSION "4"
|
|
|
|
|
2013-12-08 19:46:40 +00:00
|
|
|
channel_conf_t global_conf;
|
|
|
|
channel_conf_t *channels;
|
|
|
|
group_conf_t *groups;
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
|
2005-12-28 10:02:22 +00:00
|
|
|
|
2015-03-23 07:42:51 +00:00
|
|
|
static void ATTR_PRINTFLIKE(1, 2)
|
|
|
|
debug( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start( va, msg );
|
|
|
|
vdebug( DEBUG_SYNC, msg, va );
|
|
|
|
va_end( va );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ATTR_PRINTFLIKE(1, 2)
|
|
|
|
debugn( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start( va, msg );
|
|
|
|
vdebugn( DEBUG_SYNC, msg, va );
|
|
|
|
va_end( va );
|
|
|
|
}
|
|
|
|
|
2019-07-28 18:54:01 +00:00
|
|
|
static void
|
2012-09-15 11:25:50 +00:00
|
|
|
Fclose( FILE *f, int safe )
|
2006-02-11 19:52:53 +00:00
|
|
|
{
|
2013-11-02 20:42:34 +00:00
|
|
|
if ((safe && (fflush( f ) || (UseFSync && fdatasync( fileno( f ) )))) || fclose( f ) == EOF) {
|
2014-04-12 16:28:21 +00:00
|
|
|
sys_error( "Error: cannot close file" );
|
2006-02-11 19:52:53 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-28 18:54:01 +00:00
|
|
|
static void ATTR_PRINTFLIKE(2, 0)
|
2017-04-02 13:24:03 +00:00
|
|
|
vFprintf( FILE *f, const char *msg, va_list va )
|
2004-11-13 09:19:36 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = vfprintf( f, msg, va );
|
|
|
|
if (r < 0) {
|
2014-04-12 16:28:21 +00:00
|
|
|
sys_error( "Error: cannot write file" );
|
2004-11-13 09:19:36 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-28 18:54:01 +00:00
|
|
|
static void ATTR_PRINTFLIKE(2, 3)
|
2017-04-02 13:24:03 +00:00
|
|
|
Fprintf( FILE *f, const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start( va, msg );
|
|
|
|
vFprintf( f, msg, va );
|
|
|
|
va_end( va );
|
|
|
|
}
|
|
|
|
|
2004-11-13 09:19:36 +00:00
|
|
|
|
2018-06-21 14:52:00 +00:00
|
|
|
/* Keep the mailbox driver flag definitions in sync: */
|
|
|
|
/* grep for MAILBOX_DRIVER_FLAG */
|
|
|
|
/* The order is according to alphabetical maildir flag sort */
|
2018-06-21 14:52:01 +00:00
|
|
|
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
|
2000-12-20 21:41:21 +00:00
|
|
|
|
2020-07-08 15:27:37 +00:00
|
|
|
static uchar
|
2004-03-27 16:07:20 +00:00
|
|
|
parse_flags( const char *buf )
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2020-07-08 15:27:37 +00:00
|
|
|
uint i, d;
|
|
|
|
uchar flags;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
|
|
|
for (flags = i = d = 0; i < as(Flags); i++)
|
|
|
|
if (buf[d] == Flags[i]) {
|
|
|
|
flags |= (1 << i);
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
return flags;
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 15:27:37 +00:00
|
|
|
static uint
|
|
|
|
make_flags( uchar flags, char *buf )
|
2002-01-16 19:47:28 +00:00
|
|
|
{
|
2014-12-07 12:19:30 +00:00
|
|
|
uint i, d;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
|
|
|
for (i = d = 0; i < as(Flags); i++)
|
|
|
|
if (flags & (1 << i))
|
|
|
|
buf[d++] = Flags[i];
|
|
|
|
buf[d] = 0;
|
|
|
|
return d;
|
2002-01-16 19:47:28 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 18:45:00 +00:00
|
|
|
// This is the (mostly) persistent status of the sync record.
|
2017-04-01 15:02:22 +00:00
|
|
|
// Most of these bits are actually mutually exclusive. It is a
|
|
|
|
// bitfield to allow for easy testing for multiple states.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
#define S_EXPIRE (1<<0) // the entry is being expired (near side message removal scheduled)
|
|
|
|
#define S_EXPIRED (1<<1) // the entry is expired (near side message removal confirmed)
|
2017-03-11 12:20:53 +00:00
|
|
|
#define S_PENDING (1<<2) // the entry is new and awaits propagation (possibly a retry)
|
2019-12-29 13:37:53 +00:00
|
|
|
#define S_DUMMY(fn) (1<<(3+(fn))) // f/n message is only a placeholder
|
|
|
|
#define S_SKIPPED (1<<5) // pre-1.4 legacy: the entry was not propagated (message is too big)
|
2017-04-01 15:02:22 +00:00
|
|
|
#define S_DEAD (1<<7) // ephemeral: the entry was killed and should be ignored
|
|
|
|
|
|
|
|
// Ephemeral working set.
|
|
|
|
#define W_NEXPIRE (1<<0) // temporary: new expiration state
|
|
|
|
#define W_DELETE (1<<1) // ephemeral: flags propagation is a deletion
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
#define W_DEL(fn) (1<<(2+(fn))) // ephemeral: f/n message would be subject to expunge
|
2019-12-29 13:37:53 +00:00
|
|
|
#define W_UPGRADE (1<<4) // ephemeral: upgrading placeholder, do not apply MaxSize
|
|
|
|
#define W_PURGE (1<<5) // ephemeral: placeholder is being nuked
|
2006-02-02 17:03:01 +00:00
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
typedef struct sync_rec {
|
|
|
|
struct sync_rec *next;
|
|
|
|
/* string_list_t *keywords; */
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid[2];
|
2005-12-28 19:17:40 +00:00
|
|
|
message_t *msg[2];
|
2019-12-29 13:37:53 +00:00
|
|
|
uchar status, wstate, flags, pflags, aflags[2], dflags[2];
|
2006-02-03 21:33:43 +00:00
|
|
|
char tuid[TUIDL];
|
2004-03-27 16:07:20 +00:00
|
|
|
} sync_rec_t;
|
|
|
|
|
2006-03-21 15:53:43 +00:00
|
|
|
typedef struct {
|
2006-03-21 20:03:21 +00:00
|
|
|
int t[2];
|
|
|
|
void (*cb)( int sts, void *aux ), *aux;
|
2014-10-04 16:26:10 +00:00
|
|
|
char *dname, *jname, *nname, *lname, *box_name[2];
|
2006-03-21 15:53:43 +00:00
|
|
|
FILE *jfp, *nfp;
|
2013-11-24 17:26:11 +00:00
|
|
|
sync_rec_t *srecs, **srecadd;
|
2006-03-21 15:53:43 +00:00
|
|
|
channel_conf_t *chan;
|
|
|
|
store_t *ctx[2];
|
|
|
|
driver_t *drv[2];
|
2014-10-25 13:06:50 +00:00
|
|
|
const char *orig_name[2];
|
2017-03-24 17:09:40 +00:00
|
|
|
message_t *msgs[2], *new_msgs[2];
|
2017-03-21 19:05:29 +00:00
|
|
|
uint_array_alloc_t trashed_msgs[2];
|
2020-07-08 15:27:37 +00:00
|
|
|
int state[2], lfd, ret, existing, replayed;
|
|
|
|
uint ref_count, nsrecs, opts[2];
|
|
|
|
uint new_pending[2], flags_pending[2], trash_pending[2];
|
2017-03-21 19:05:29 +00:00
|
|
|
uint maxuid[2]; // highest UID that was already propagated
|
2019-11-25 19:55:41 +00:00
|
|
|
uint oldmaxuid[2]; // highest UID that was already propagated before this run
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uidval[2]; // UID validity value
|
|
|
|
uint newuidval[2]; // UID validity obtained from driver
|
2019-12-29 10:52:26 +00:00
|
|
|
uint finduid[2]; // TUID lookup makes sense only for UIDs >= this
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
uint maxxfuid; // highest expired UID on far side
|
2019-11-25 19:55:41 +00:00
|
|
|
uint oldmaxxfuid; // highest expired UID on far side before this run
|
2020-01-08 17:22:48 +00:00
|
|
|
uchar good_flags[2], bad_flags[2];
|
2006-03-21 15:53:43 +00:00
|
|
|
} sync_vars_t;
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void sync_ref( sync_vars_t *svars ) { ++svars->ref_count; }
|
2013-12-11 15:13:49 +00:00
|
|
|
static void sync_deref( sync_vars_t *svars );
|
2012-07-29 21:14:48 +00:00
|
|
|
static int check_cancel( sync_vars_t *svars );
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
#define AUX &svars->t[t]
|
2012-09-22 15:35:39 +00:00
|
|
|
#define INV_AUX &svars->t[1-t]
|
2012-06-17 12:52:46 +00:00
|
|
|
#define DECL_SVARS \
|
|
|
|
int t; \
|
|
|
|
sync_vars_t *svars
|
|
|
|
#define INIT_SVARS(aux) \
|
|
|
|
t = *(int *)aux; \
|
|
|
|
svars = (sync_vars_t *)(((char *)(&((int *)aux)[-t])) - offsetof(sync_vars_t, t))
|
|
|
|
#define DECL_INIT_SVARS(aux) \
|
2006-03-21 20:03:21 +00:00
|
|
|
int t = *(int *)aux; \
|
2012-06-17 12:52:46 +00:00
|
|
|
sync_vars_t *svars = (sync_vars_t *)(((char *)(&((int *)aux)[-t])) - offsetof(sync_vars_t, t))
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
/* operation dependencies:
|
2013-12-11 15:29:02 +00:00
|
|
|
select(x): -
|
|
|
|
load(x): select(x)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
new(F), new(N), flags(F), flags(N): load(F) & load(N)
|
2006-03-21 20:03:21 +00:00
|
|
|
find_new(x): new(x)
|
|
|
|
trash(x): flags(x)
|
2013-12-11 15:29:02 +00:00
|
|
|
close(x): trash(x) & find_new(x) & new(!x) // with expunge
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
cleanup: close(F) & close(N)
|
2006-03-21 20:03:21 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
#define ST_LOADED (1<<0)
|
2013-11-02 11:57:39 +00:00
|
|
|
#define ST_FIND_OLD (1<<1)
|
|
|
|
#define ST_SENT_NEW (1<<2)
|
|
|
|
#define ST_FIND_NEW (1<<3)
|
|
|
|
#define ST_FOUND_NEW (1<<4)
|
|
|
|
#define ST_SENT_FLAGS (1<<5)
|
|
|
|
#define ST_SENT_TRASH (1<<6)
|
|
|
|
#define ST_CLOSED (1<<7)
|
|
|
|
#define ST_SENT_CANCEL (1<<8)
|
|
|
|
#define ST_CANCELED (1<<9)
|
|
|
|
#define ST_SELECTED (1<<10)
|
|
|
|
#define ST_DID_EXPUNGE (1<<11)
|
2013-12-11 15:25:30 +00:00
|
|
|
#define ST_CLOSING (1<<12)
|
2014-12-29 01:08:48 +00:00
|
|
|
#define ST_CONFIRMED (1<<13)
|
|
|
|
#define ST_PRESENT (1<<14)
|
2015-02-15 17:13:05 +00:00
|
|
|
#define ST_SENDING_NEW (1<<15)
|
2006-03-21 15:53:43 +00:00
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
static void
|
|
|
|
create_state( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
if (!(svars->nfp = fopen( svars->nname, "w" ))) {
|
|
|
|
sys_error( "Error: cannot create new sync state %s", svars->nname );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-28 18:54:01 +00:00
|
|
|
static void ATTR_PRINTFLIKE(2, 3)
|
2017-04-02 13:24:03 +00:00
|
|
|
jFprintf( sync_vars_t *svars, const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
2017-03-19 10:53:16 +00:00
|
|
|
if (JLimit && !--JLimit)
|
|
|
|
exit( 101 );
|
2019-11-25 19:55:41 +00:00
|
|
|
if (!svars->jfp) {
|
|
|
|
create_state( svars );
|
|
|
|
if (!(svars->jfp = fopen( svars->jname, svars->replayed ? "a" : "w" ))) {
|
|
|
|
sys_error( "Error: cannot create journal %s", svars->jname );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
setlinebuf( svars->jfp );
|
|
|
|
if (!svars->replayed)
|
|
|
|
Fprintf( svars->jfp, JOURNAL_VERSION "\n" );
|
|
|
|
}
|
2017-04-02 13:24:03 +00:00
|
|
|
va_start( va, msg );
|
|
|
|
vFprintf( svars->jfp, msg, va );
|
|
|
|
va_end( va );
|
2017-03-19 10:53:16 +00:00
|
|
|
if (JLimit && !--JLimit)
|
|
|
|
exit( 100 );
|
2017-04-02 13:24:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 20:16:47 +00:00
|
|
|
#define JLOG_(log_fmt, log_args, dbg_fmt, ...) \
|
|
|
|
do { \
|
|
|
|
debug( "-> log: " log_fmt " (" dbg_fmt ")\n", __VA_ARGS__ ); \
|
|
|
|
jFprintf( svars, log_fmt "\n", deparen(log_args) ); \
|
|
|
|
} while (0)
|
|
|
|
#define JLOG3(log_fmt, log_args, dbg_fmt) \
|
|
|
|
JLOG_(log_fmt, log_args, dbg_fmt, deparen(log_args))
|
|
|
|
#define JLOG4(log_fmt, log_args, dbg_fmt, dbg_args) \
|
|
|
|
JLOG_(log_fmt, log_args, dbg_fmt, deparen(log_args), deparen(dbg_args))
|
|
|
|
#define JLOG_SEL(_1, _2, _3, _4, x, ...) x
|
|
|
|
#define JLOG(...) JLOG_SEL(__VA_ARGS__, JLOG4, JLOG3, NO_JLOG2, NO_JLOG1)(__VA_ARGS__)
|
|
|
|
|
2019-12-29 13:41:45 +00:00
|
|
|
static void
|
|
|
|
assign_uid( sync_vars_t *svars, sync_rec_t *srec, int t, uint uid )
|
|
|
|
{
|
|
|
|
srec->uid[t] = uid;
|
|
|
|
if (uid == svars->maxuid[t] + 1)
|
|
|
|
svars->maxuid[t] = uid;
|
|
|
|
srec->status &= ~S_PENDING;
|
2019-12-29 13:37:53 +00:00
|
|
|
srec->wstate &= ~W_UPGRADE;
|
2019-12-29 13:41:45 +00:00
|
|
|
srec->tuid[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ASSIGN_UID(srec, t, nuid, ...) \
|
|
|
|
do { \
|
|
|
|
JLOG( "%c %u %u %u", ("<>"[t], srec->uid[F], srec->uid[N], nuid), __VA_ARGS__ ); \
|
|
|
|
assign_uid( svars, srec, t, nuid ); \
|
|
|
|
} while (0)
|
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
static void
|
2017-03-26 16:44:43 +00:00
|
|
|
match_tuids( sync_vars_t *svars, int t, message_t *msgs )
|
2011-04-10 11:06:07 +00:00
|
|
|
{
|
|
|
|
sync_rec_t *srec;
|
2019-07-28 18:50:31 +00:00
|
|
|
message_t *tmsg, *ntmsg = NULL;
|
2011-04-10 11:06:07 +00:00
|
|
|
const char *diag;
|
2013-07-27 18:17:07 +00:00
|
|
|
int num_lost = 0;
|
2011-04-10 11:06:07 +00:00
|
|
|
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!srec->uid[t] && srec->tuid[0]) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "pair(%u,%u) TUID %." stringify(TUIDL) "s\n", srec->uid[F], srec->uid[N], srec->tuid );
|
2011-04-10 11:06:07 +00:00
|
|
|
for (tmsg = ntmsg; tmsg; tmsg = tmsg->next) {
|
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
|
|
|
if (tmsg->tuid[0] && !memcmp( tmsg->tuid, srec->tuid, TUIDL )) {
|
|
|
|
diag = (tmsg == ntmsg) ? "adjacently" : "after gap";
|
|
|
|
goto mfound;
|
|
|
|
}
|
|
|
|
}
|
2017-03-26 16:44:43 +00:00
|
|
|
for (tmsg = msgs; tmsg != ntmsg; tmsg = tmsg->next) {
|
2011-04-10 11:06:07 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
|
|
|
if (tmsg->tuid[0] && !memcmp( tmsg->tuid, srec->tuid, TUIDL )) {
|
|
|
|
diag = "after reset";
|
|
|
|
goto mfound;
|
|
|
|
}
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "& %u %u", (srec->uid[F], srec->uid[N]), "TUID lost" );
|
2017-03-11 12:20:53 +00:00
|
|
|
// Note: status remains S_PENDING.
|
2011-04-10 11:06:07 +00:00
|
|
|
srec->tuid[0] = 0;
|
2013-07-27 18:17:07 +00:00
|
|
|
num_lost++;
|
2011-04-10 11:06:07 +00:00
|
|
|
continue;
|
|
|
|
mfound:
|
|
|
|
tmsg->srec = srec;
|
2013-11-09 10:42:09 +00:00
|
|
|
srec->msg[t] = tmsg;
|
2011-04-10 11:06:07 +00:00
|
|
|
ntmsg = tmsg->next;
|
2019-12-29 13:41:45 +00:00
|
|
|
ASSIGN_UID( srec, t, tmsg->uid, "TUID matched %s", diag );
|
2011-04-10 11:06:07 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-27 18:17:07 +00:00
|
|
|
if (num_lost)
|
|
|
|
warn( "Warning: lost track of %d %sed message(s)\n", num_lost, str_hl[t] );
|
2011-04-10 11:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-08 17:22:48 +00:00
|
|
|
static uchar
|
|
|
|
sanitize_flags( uchar tflags, sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
if (!(DFlags & QUIET)) {
|
|
|
|
// We complain only once per flag per store - even though _theoretically_
|
|
|
|
// each mailbox can support different flags according to the IMAP spec.
|
|
|
|
uchar bflags = tflags & ~(svars->good_flags[t] | svars->bad_flags[t]);
|
|
|
|
if (bflags) {
|
|
|
|
char bfbuf[16];
|
|
|
|
make_flags( bflags, bfbuf );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
notice( "Notice: %s store does not support flag(s) '%s'; not propagating.\n", str_fn[t], bfbuf );
|
2020-01-08 17:22:48 +00:00
|
|
|
svars->bad_flags[t] |= bflags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tflags & svars->good_flags[t];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
typedef struct copy_vars {
|
2017-03-21 19:05:29 +00:00
|
|
|
void (*cb)( int sts, uint uid, struct copy_vars *vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
void *aux;
|
|
|
|
sync_rec_t *srec; /* also ->tuid */
|
|
|
|
message_t *msg;
|
|
|
|
msg_data_t data;
|
2019-12-29 13:37:53 +00:00
|
|
|
int minimal;
|
2006-03-21 20:03:21 +00:00
|
|
|
} copy_vars_t;
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msg_fetched( int sts, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
copy_msg( copy_vars_t *vars )
|
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_INIT_SVARS(vars->aux);
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
t ^= 1;
|
2006-03-21 20:03:21 +00:00
|
|
|
vars->data.flags = vars->msg->flags;
|
2013-07-28 13:55:13 +00:00
|
|
|
vars->data.date = svars->chan->use_internal_date ? -1 : 0;
|
2019-12-29 13:37:53 +00:00
|
|
|
svars->drv[t]->fetch_msg( svars->ctx[t], vars->msg, &vars->data, vars->minimal, msg_fetched, vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_stored( int sts, uint uid, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2016-11-05 17:32:49 +00:00
|
|
|
static void
|
2020-07-08 15:27:37 +00:00
|
|
|
copy_msg_bytes( char **out_ptr, const char *in_buf, uint *in_idx, uint in_len, int in_cr, int out_cr )
|
2016-11-05 17:32:49 +00:00
|
|
|
{
|
|
|
|
char *out = *out_ptr;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint idx = *in_idx;
|
2016-11-05 17:32:49 +00:00
|
|
|
if (out_cr != in_cr) {
|
|
|
|
char c;
|
|
|
|
if (out_cr) {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
if ((c = in_buf[idx]) != '\r') {
|
|
|
|
if (c == '\n')
|
|
|
|
*out++ = '\r';
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
if ((c = in_buf[idx]) != '\r')
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy( out, in_buf + idx, in_len - idx );
|
|
|
|
out += in_len - idx;
|
|
|
|
idx = in_len;
|
|
|
|
}
|
|
|
|
*out_ptr = out;
|
|
|
|
*in_idx = idx;
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
static int
|
|
|
|
copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars )
|
|
|
|
{
|
|
|
|
char *in_buf = vars->data.data;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint in_len = vars->data.len;
|
2019-12-29 13:37:53 +00:00
|
|
|
uint idx = 0, sbreak = 0, ebreak = 0, break2 = 0;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0;
|
2019-12-29 13:37:53 +00:00
|
|
|
uint add_subj = 0;
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
if (vars->srec) {
|
|
|
|
nloop: ;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint start = idx;
|
|
|
|
uint line_crs = 0;
|
2016-11-05 17:33:16 +00:00
|
|
|
while (idx < in_len) {
|
|
|
|
char c = in_buf[idx++];
|
|
|
|
if (c == '\r') {
|
|
|
|
line_crs++;
|
|
|
|
} else if (c == '\n') {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!ebreak && starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) {
|
2016-11-05 17:33:16 +00:00
|
|
|
extra = (sbreak = start) - (ebreak = idx);
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!vars->minimal)
|
|
|
|
goto oke;
|
|
|
|
} else {
|
|
|
|
if (!break2 && vars->minimal && !strncasecmp( in_buf + start, "Subject:", 8 )) {
|
|
|
|
break2 = start + 8;
|
|
|
|
if (in_buf[break2] == ' ')
|
|
|
|
break2++;
|
|
|
|
}
|
|
|
|
lines++;
|
|
|
|
hdr_crs += line_crs;
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
if (idx - line_crs - 1 == start) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!ebreak)
|
|
|
|
sbreak = ebreak = start;
|
|
|
|
if (vars->minimal) {
|
|
|
|
in_len = idx;
|
|
|
|
if (!break2) {
|
|
|
|
break2 = start;
|
|
|
|
add_subj = 1;
|
|
|
|
}
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
goto oke;
|
|
|
|
}
|
|
|
|
goto nloop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* invalid message */
|
|
|
|
free( in_buf );
|
|
|
|
return 0;
|
|
|
|
oke:
|
2016-11-05 17:33:47 +00:00
|
|
|
app_cr = out_cr && (!in_cr || hdr_crs);
|
|
|
|
extra += 8 + TUIDL + app_cr + 1;
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
if (out_cr != in_cr) {
|
|
|
|
for (; idx < in_len; idx++) {
|
|
|
|
char c = in_buf[idx];
|
|
|
|
if (c == '\r')
|
|
|
|
bdy_crs++;
|
|
|
|
else if (c == '\n')
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
extra -= hdr_crs + bdy_crs;
|
|
|
|
if (out_cr)
|
|
|
|
extra += lines;
|
|
|
|
}
|
|
|
|
|
2019-12-29 13:37:53 +00:00
|
|
|
uint dummy_msg_len = 0;
|
|
|
|
char dummy_msg_buf[180];
|
|
|
|
static const char dummy_pfx[] = "[placeholder] ";
|
|
|
|
static const char dummy_subj[] = "Subject: [placeholder] (No Subject)";
|
|
|
|
static const char dummy_msg[] =
|
|
|
|
"Having a size of %s, this message is over the MaxSize limit.%s"
|
|
|
|
"Flag it and sync again (Sync mode ReNew) to fetch its real contents.%s";
|
|
|
|
|
|
|
|
if (vars->minimal) {
|
|
|
|
char sz[32];
|
|
|
|
|
|
|
|
if (vars->msg->size < 1024000)
|
|
|
|
sprintf( sz, "%dKiB", (int)(vars->msg->size >> 10) );
|
|
|
|
else
|
|
|
|
sprintf( sz, "%.1fMiB", vars->msg->size / 1048576. );
|
|
|
|
const char *nl = app_cr ? "\r\n" : "\n";
|
|
|
|
dummy_msg_len = (uint)sprintf( dummy_msg_buf, dummy_msg, sz, nl, nl );
|
|
|
|
extra += dummy_msg_len;
|
|
|
|
extra += add_subj ? strlen(dummy_subj) + app_cr + 1 : strlen(dummy_pfx);
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
vars->data.len = in_len + extra;
|
|
|
|
char *out_buf = vars->data.data = nfmalloc( vars->data.len );
|
|
|
|
idx = 0;
|
|
|
|
if (vars->srec) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (break2 && break2 < sbreak) {
|
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, break2, in_cr, out_cr );
|
|
|
|
memcpy( out_buf, dummy_pfx, strlen(dummy_pfx) );
|
|
|
|
out_buf += strlen(dummy_pfx);
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, sbreak, in_cr, out_cr );
|
|
|
|
|
|
|
|
memcpy( out_buf, "X-TUID: ", 8 );
|
|
|
|
out_buf += 8;
|
|
|
|
memcpy( out_buf, vars->srec->tuid, TUIDL );
|
|
|
|
out_buf += TUIDL;
|
2016-11-05 17:33:47 +00:00
|
|
|
if (app_cr)
|
2016-11-05 17:33:16 +00:00
|
|
|
*out_buf++ = '\r';
|
|
|
|
*out_buf++ = '\n';
|
|
|
|
idx = ebreak;
|
2019-12-29 13:37:53 +00:00
|
|
|
|
|
|
|
if (break2 >= sbreak) {
|
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, break2, in_cr, out_cr );
|
|
|
|
if (!add_subj) {
|
|
|
|
memcpy( out_buf, dummy_pfx, strlen(dummy_pfx) );
|
|
|
|
out_buf += strlen(dummy_pfx);
|
|
|
|
} else {
|
|
|
|
memcpy( out_buf, dummy_subj, strlen(dummy_subj) );
|
|
|
|
out_buf += strlen(dummy_subj);
|
|
|
|
if (app_cr)
|
|
|
|
*out_buf++ = '\r';
|
|
|
|
*out_buf++ = '\n';
|
|
|
|
}
|
|
|
|
}
|
2016-11-05 17:33:16 +00:00
|
|
|
}
|
|
|
|
copy_msg_bytes( &out_buf, in_buf, &idx, in_len, in_cr, out_cr );
|
|
|
|
|
2019-12-29 13:37:53 +00:00
|
|
|
if (vars->minimal)
|
|
|
|
memcpy( out_buf, dummy_msg_buf, dummy_msg_len );
|
|
|
|
|
2016-11-05 17:33:16 +00:00
|
|
|
free( in_buf );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msg_fetched( int sts, void *aux )
|
|
|
|
{
|
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2016-11-05 17:33:16 +00:00
|
|
|
int scr, tcr;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
2012-07-29 21:15:12 +00:00
|
|
|
if (check_cancel( svars )) {
|
|
|
|
free( vars->data.data );
|
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
return;
|
|
|
|
}
|
2012-06-17 12:52:46 +00:00
|
|
|
|
2020-01-08 17:22:48 +00:00
|
|
|
vars->msg->flags = vars->data.flags = sanitize_flags( vars->data.flags, svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2017-03-19 12:50:41 +00:00
|
|
|
scr = (svars->drv[1-t]->get_caps( svars->ctx[1-t] ) / DRV_CRLF) & 1;
|
|
|
|
tcr = (svars->drv[t]->get_caps( svars->ctx[t] ) / DRV_CRLF) & 1;
|
2006-03-21 20:03:21 +00:00
|
|
|
if (vars->srec || scr != tcr) {
|
2016-11-05 17:33:16 +00:00
|
|
|
if (!copy_msg_convert( scr, tcr, vars )) {
|
2017-03-21 19:05:29 +00:00
|
|
|
warn( "Warning: message %u from %s has incomplete header.\n",
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
vars->msg->uid, str_fn[1-t] );
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
svars->drv[t]->store_msg( svars->ctx[t], &vars->data, !vars->srec, msg_stored, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_CANCELED:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_MSG_BAD:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
default:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_FAIL, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_stored( int sts, uint uid, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
|
|
|
copy_vars_t *vars = (copy_vars_t *)aux;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_OK, uid, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
case DRV_CANCELED:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_CANCELED, 0, vars );
|
|
|
|
break;
|
2010-02-06 09:32:10 +00:00
|
|
|
case DRV_MSG_BAD:
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
|
|
|
(void)svars;
|
2017-03-21 19:05:29 +00:00
|
|
|
warn( "Warning: %s refuses to store message %u from %s.\n",
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
str_fn[t], vars->msg->uid, str_fn[1-t] );
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_NOGOOD, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
default:
|
2012-07-29 21:14:48 +00:00
|
|
|
vars->cb( SYNC_FAIL, 0, vars );
|
|
|
|
break;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sync_bail( sync_vars_t *svars );
|
|
|
|
static void sync_bail2( sync_vars_t *svars );
|
2012-08-18 11:58:14 +00:00
|
|
|
static void sync_bail3( sync_vars_t *svars );
|
2012-07-22 15:32:32 +00:00
|
|
|
static void cancel_done( void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
cancel_sync( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
2012-07-22 15:46:54 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
int other_state = svars->state[1-t];
|
2012-07-22 15:32:32 +00:00
|
|
|
if (svars->ret & SYNC_BAD(t)) {
|
|
|
|
cancel_done( AUX );
|
2011-04-03 14:29:18 +00:00
|
|
|
} else if (!(svars->state[t] & ST_SENT_CANCEL)) {
|
|
|
|
/* ignore subsequent failures from in-flight commands */
|
|
|
|
svars->state[t] |= ST_SENT_CANCEL;
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->cancel_cmds( svars->ctx[t], cancel_done, AUX );
|
2012-07-22 15:32:32 +00:00
|
|
|
}
|
2012-07-22 15:46:54 +00:00
|
|
|
if (other_state & ST_CANCELED)
|
|
|
|
break;
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-22 15:32:32 +00:00
|
|
|
cancel_done( void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_INIT_SVARS(aux);
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
svars->state[t] |= ST_CANCELED;
|
|
|
|
if (svars->state[1-t] & ST_CANCELED) {
|
2014-12-27 22:50:31 +00:00
|
|
|
if (svars->nfp) {
|
2012-09-15 11:25:50 +00:00
|
|
|
Fclose( svars->nfp, 0 );
|
|
|
|
Fclose( svars->jfp, 0 );
|
2011-07-23 14:06:32 +00:00
|
|
|
}
|
2014-12-27 22:50:31 +00:00
|
|
|
sync_bail( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-15 10:55:04 +00:00
|
|
|
static void
|
|
|
|
store_bad( void *aux )
|
|
|
|
{
|
|
|
|
DECL_INIT_SVARS(aux);
|
|
|
|
|
|
|
|
svars->drv[t]->cancel_store( svars->ctx[t] );
|
|
|
|
svars->ret |= SYNC_BAD(t);
|
|
|
|
cancel_sync( svars );
|
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static int
|
|
|
|
check_cancel( sync_vars_t *svars )
|
|
|
|
{
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
return (svars->state[F] | svars->state[N]) & (ST_SENT_CANCEL | ST_CANCELED);
|
2012-07-29 21:14:48 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
static int
|
2012-06-17 12:52:46 +00:00
|
|
|
check_ret( int sts, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
|
|
|
|
2012-07-29 21:15:12 +00:00
|
|
|
if (sts == DRV_CANCELED)
|
2006-03-21 20:03:21 +00:00
|
|
|
return 1;
|
2012-07-29 21:15:12 +00:00
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (sts == DRV_BOX_BAD) {
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-29 21:15:12 +00:00
|
|
|
return check_cancel( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:52:46 +00:00
|
|
|
#define SVARS_CHECK_RET \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (check_ret( sts, aux )) \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
INIT_SVARS(aux)
|
|
|
|
|
|
|
|
#define SVARS_CHECK_RET_VARS(type) \
|
|
|
|
type *vars = (type *)aux; \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (check_ret( sts, vars->aux )) { \
|
|
|
|
free( vars ); \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
} \
|
|
|
|
INIT_SVARS(vars->aux)
|
|
|
|
|
|
|
|
#define SVARS_CHECK_CANCEL_RET \
|
|
|
|
DECL_SVARS; \
|
|
|
|
if (sts == SYNC_CANCELED) { \
|
|
|
|
free( vars ); \
|
2012-07-29 21:14:48 +00:00
|
|
|
return; \
|
2012-06-17 12:52:46 +00:00
|
|
|
} \
|
|
|
|
INIT_SVARS(vars->aux)
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
static char *
|
|
|
|
clean_strdup( const char *s )
|
|
|
|
{
|
|
|
|
char *cs;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint i;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
|
|
|
cs = nfstrdup( s );
|
|
|
|
for (i = 0; cs[i]; i++)
|
|
|
|
if (cs[i] == '/')
|
|
|
|
cs[i] = '!';
|
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2019-12-29 13:37:53 +00:00
|
|
|
static sync_rec_t *
|
|
|
|
upgrade_srec( sync_vars_t *svars, sync_rec_t *srec )
|
|
|
|
{
|
|
|
|
// Create an entry and append it to the current one.
|
|
|
|
sync_rec_t *nsrec = nfcalloc( sizeof(*nsrec) );
|
|
|
|
nsrec->next = srec->next;
|
|
|
|
srec->next = nsrec;
|
|
|
|
if (svars->srecadd == &srec->next)
|
|
|
|
svars->srecadd = &nsrec->next;
|
|
|
|
// Move the placeholder to the new entry.
|
|
|
|
int t = (srec->status & S_DUMMY(F)) ? F : N;
|
|
|
|
nsrec->uid[t] = srec->uid[t];
|
|
|
|
srec->uid[t] = 0;
|
|
|
|
if (srec->msg[t]) { // NULL during journal replay; is assigned later.
|
|
|
|
nsrec->msg[t] = srec->msg[t];
|
|
|
|
nsrec->msg[t]->srec = nsrec;
|
|
|
|
srec->msg[t] = NULL;
|
|
|
|
}
|
|
|
|
// Mark the original entry for upgrade.
|
|
|
|
srec->status = (srec->status & ~(S_DUMMY(F)|S_DUMMY(N))) | S_PENDING;
|
|
|
|
srec->wstate |= W_UPGRADE;
|
|
|
|
// Mark the placeholder for nuking.
|
|
|
|
nsrec->wstate = W_PURGE;
|
|
|
|
nsrec->aflags[t] = F_DELETED;
|
|
|
|
return nsrec;
|
|
|
|
}
|
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
static int
|
|
|
|
prepare_state( sync_vars_t *svars )
|
2011-07-23 14:06:32 +00:00
|
|
|
{
|
|
|
|
char *s, *cmname, *csname;
|
|
|
|
channel_conf_t *chan;
|
|
|
|
|
|
|
|
chan = svars->chan;
|
2013-11-24 18:32:42 +00:00
|
|
|
if (!strcmp( chan->sync_state ? chan->sync_state : global_conf.sync_state, "*" )) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
const char *path = svars->drv[N]->get_box_path( svars->ctx[N] );
|
2017-03-24 13:06:19 +00:00
|
|
|
if (!path) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: store '%s' does not support in-box sync state\n", chan->stores[N]->name );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2017-03-24 13:06:19 +00:00
|
|
|
nfasprintf( &svars->dname, "%s/." EXE "state", path );
|
2004-03-27 16:07:20 +00:00
|
|
|
} else {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
csname = clean_strdup( svars->box_name[N] );
|
2004-03-27 16:07:20 +00:00
|
|
|
if (chan->sync_state)
|
2006-03-21 15:53:43 +00:00
|
|
|
nfasprintf( &svars->dname, "%s%s", chan->sync_state, csname );
|
2004-03-27 16:07:20 +00:00
|
|
|
else {
|
2014-10-25 15:30:57 +00:00
|
|
|
char c = FieldDelimiter;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
cmname = clean_strdup( svars->box_name[F] );
|
2014-10-25 15:30:57 +00:00
|
|
|
nfasprintf( &svars->dname, "%s%c%s%c%s_%c%s%c%s", global_conf.sync_state,
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
c, chan->stores[F]->name, c, cmname, c, chan->stores[N]->name, c, csname );
|
2004-03-27 16:07:20 +00:00
|
|
|
free( cmname );
|
|
|
|
}
|
|
|
|
free( csname );
|
2011-07-24 18:27:09 +00:00
|
|
|
if (!(s = strrchr( svars->dname, '/' ))) {
|
2011-04-10 13:32:25 +00:00
|
|
|
error( "Error: invalid SyncState location '%s'\n", svars->dname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2011-07-24 18:27:09 +00:00
|
|
|
}
|
|
|
|
*s = 0;
|
|
|
|
if (mkdir( svars->dname, 0700 ) && errno != EEXIST) {
|
2011-04-10 13:32:25 +00:00
|
|
|
sys_error( "Error: cannot create SyncState directory '%s'", svars->dname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2011-07-24 18:27:09 +00:00
|
|
|
}
|
|
|
|
*s = '/';
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
nfasprintf( &svars->jname, "%s.journal", svars->dname );
|
|
|
|
nfasprintf( &svars->nname, "%s.new", svars->dname );
|
|
|
|
nfasprintf( &svars->lname, "%s.lock", svars->dname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lock_state( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
struct flock lck;
|
|
|
|
|
2014-12-27 22:50:31 +00:00
|
|
|
if (svars->lfd >= 0)
|
|
|
|
return 1;
|
2004-03-27 16:07:20 +00:00
|
|
|
memset( &lck, 0, sizeof(lck) );
|
|
|
|
#if SEEK_SET != 0
|
|
|
|
lck.l_whence = SEEK_SET;
|
|
|
|
#endif
|
|
|
|
#if F_WRLCK != 0
|
|
|
|
lck.l_type = F_WRLCK;
|
|
|
|
#endif
|
2006-03-21 15:53:43 +00:00
|
|
|
if ((svars->lfd = open( svars->lname, O_WRONLY|O_CREAT, 0666 )) < 0) {
|
2011-04-10 13:32:25 +00:00
|
|
|
sys_error( "Error: cannot create lock file %s", svars->lname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
if (fcntl( svars->lfd, F_SETLK, &lck )) {
|
2006-03-19 11:29:12 +00:00
|
|
|
error( "Error: channel :%s:%s-:%s:%s is locked\n",
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->chan->stores[F]->name, svars->orig_name[F], svars->chan->stores[N]->name, svars->orig_name[N] );
|
2014-12-27 22:13:45 +00:00
|
|
|
close( svars->lfd );
|
2014-12-27 22:50:31 +00:00
|
|
|
svars->lfd = -1;
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2014-12-27 22:13:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_state( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec;
|
|
|
|
char fbuf[16]; /* enlarge when support for keywords is added */
|
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
// If no change was made, the state is also unmodified.
|
|
|
|
if (!svars->jfp && !svars->replayed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!svars->nfp)
|
|
|
|
create_state( svars );
|
2014-12-27 22:13:45 +00:00
|
|
|
Fprintf( svars->nfp,
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
"FarUidValidity %u\nNearUidValidity %u\nMaxPulledUid %u\nMaxPushedUid %u\n",
|
|
|
|
svars->uidval[F], svars->uidval[N], svars->maxuid[F], svars->maxuid[N] );
|
|
|
|
if (svars->maxxfuid)
|
|
|
|
Fprintf( svars->nfp, "MaxExpiredFarUid %u\n", svars->maxxfuid );
|
2014-12-27 22:13:45 +00:00
|
|
|
Fprintf( svars->nfp, "\n" );
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
|
|
|
make_flags( srec->flags, fbuf );
|
2019-12-29 13:37:53 +00:00
|
|
|
Fprintf( svars->nfp, "%u %u %s%s%s\n", srec->uid[F], srec->uid[N],
|
|
|
|
(srec->status & S_DUMMY(F)) ? "<" : (srec->status & S_DUMMY(N)) ? ">" : "",
|
2020-07-04 14:13:50 +00:00
|
|
|
(srec->status & S_SKIPPED) ? "^" : (srec->status & S_EXPIRED) ? "~" : "", fbuf );
|
2014-12-27 22:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Fclose( svars->nfp, 1 );
|
2019-11-25 19:55:41 +00:00
|
|
|
if (svars->jfp)
|
|
|
|
Fclose( svars->jfp, 0 );
|
2014-12-27 22:13:45 +00:00
|
|
|
if (!(DFlags & KEEPJOURNAL)) {
|
|
|
|
/* order is important! */
|
|
|
|
if (rename( svars->nname, svars->dname ))
|
|
|
|
warn( "Warning: cannot commit sync state %s\n", svars->dname );
|
|
|
|
else if (unlink( svars->jname ))
|
|
|
|
warn( "Warning: cannot delete journal %s\n", svars->jname );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
load_state( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec, *nsrec;
|
|
|
|
char *s;
|
|
|
|
FILE *jfp;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint ll;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
uint maxxnuid = 0;
|
2016-11-05 17:16:43 +00:00
|
|
|
char c;
|
2014-12-27 22:13:45 +00:00
|
|
|
struct stat st;
|
|
|
|
char fbuf[16]; /* enlarge when support for keywords is added */
|
|
|
|
char buf[128], buf1[64], buf2[64];
|
|
|
|
|
2006-03-21 15:53:43 +00:00
|
|
|
if ((jfp = fopen( svars->dname, "r" ))) {
|
2014-12-27 22:50:31 +00:00
|
|
|
if (!lock_state( svars ))
|
|
|
|
goto jbail;
|
2006-03-21 15:53:43 +00:00
|
|
|
debug( "reading sync state %s ...\n", svars->dname );
|
2017-03-21 19:05:29 +00:00
|
|
|
int line = 0;
|
2013-11-16 12:25:31 +00:00
|
|
|
while (fgets( buf, sizeof(buf), jfp )) {
|
|
|
|
line++;
|
2017-03-21 19:05:29 +00:00
|
|
|
if (!(ll = strlen( buf )) || buf[ll - 1] != '\n') {
|
2013-11-16 12:25:31 +00:00
|
|
|
error( "Error: incomplete sync state header entry at %s:%d\n", svars->dname, line );
|
|
|
|
jbail:
|
|
|
|
fclose( jfp );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2013-11-16 12:25:31 +00:00
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
if (ll == 1)
|
2013-11-16 12:25:31 +00:00
|
|
|
goto gothdr;
|
2019-11-17 18:45:00 +00:00
|
|
|
if (line == 1 && isdigit( buf[0] )) { // Pre-1.1 legacy
|
2013-11-16 12:25:31 +00:00
|
|
|
if (sscanf( buf, "%63s %63s", buf1, buf2 ) != 2 ||
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
sscanf( buf1, "%u:%u", &svars->uidval[F], &svars->maxuid[F] ) < 2 ||
|
|
|
|
sscanf( buf2, "%u:%u:%u", &svars->uidval[N], &maxxnuid, &svars->maxuid[N] ) < 3) {
|
2013-11-16 12:25:31 +00:00
|
|
|
error( "Error: invalid sync state header in %s\n", svars->dname );
|
|
|
|
goto jbail;
|
|
|
|
}
|
|
|
|
goto gothdr;
|
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid;
|
|
|
|
if (sscanf( buf, "%63s %u", buf1, &uid ) != 2) {
|
2013-11-16 12:25:31 +00:00
|
|
|
error( "Error: malformed sync state header entry at %s:%d\n", svars->dname, line );
|
|
|
|
goto jbail;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!strcmp( buf1, "FarUidValidity" ) || !strcmp( buf1, "MasterUidValidity" ) /* Pre-1.4 legacy */)
|
|
|
|
svars->uidval[F] = uid;
|
|
|
|
else if (!strcmp( buf1, "NearUidValidity" ) || !strcmp( buf1, "SlaveUidValidity" ) /* Pre-1.4 legacy */)
|
|
|
|
svars->uidval[N] = uid;
|
2013-11-16 12:25:31 +00:00
|
|
|
else if (!strcmp( buf1, "MaxPulledUid" ))
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->maxuid[F] = uid;
|
2013-11-16 12:25:31 +00:00
|
|
|
else if (!strcmp( buf1, "MaxPushedUid" ))
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->maxuid[N] = uid;
|
|
|
|
else if (!strcmp( buf1, "MaxExpiredFarUid" ) || !strcmp( buf1, "MaxExpiredMasterUid" ) /* Pre-1.4 legacy */)
|
|
|
|
svars->maxxfuid = uid;
|
2019-11-17 18:45:00 +00:00
|
|
|
else if (!strcmp( buf1, "MaxExpiredSlaveUid" )) // Pre-1.3 legacy
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
maxxnuid = uid;
|
2013-11-16 12:25:31 +00:00
|
|
|
else {
|
|
|
|
error( "Error: unrecognized sync state header entry at %s:%d\n", svars->dname, line );
|
|
|
|
goto jbail;
|
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2013-11-16 12:25:31 +00:00
|
|
|
error( "Error: unterminated sync state header in %s\n", svars->dname );
|
|
|
|
goto jbail;
|
|
|
|
gothdr:
|
2006-03-21 15:53:43 +00:00
|
|
|
while (fgets( buf, sizeof(buf), jfp )) {
|
|
|
|
line++;
|
2017-03-21 19:05:29 +00:00
|
|
|
if (!(ll = strlen( buf )) || buf[--ll] != '\n') {
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: incomplete sync state entry at %s:%d\n", svars->dname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2004-11-13 09:19:36 +00:00
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
buf[ll] = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
fbuf[0] = 0;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint t1, t2;
|
|
|
|
if (sscanf( buf, "%u %u %15s", &t1, &t2, fbuf ) < 2) {
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: invalid sync state entry at %s:%d\n", svars->dname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2019-12-03 12:06:12 +00:00
|
|
|
srec = nfcalloc( sizeof(*srec) );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
srec->uid[F] = t1;
|
|
|
|
srec->uid[N] = t2;
|
2004-03-27 16:07:20 +00:00
|
|
|
s = fbuf;
|
2019-12-29 13:37:53 +00:00
|
|
|
if (*s == '<') {
|
|
|
|
s++;
|
|
|
|
srec->status = S_DUMMY(F);
|
|
|
|
} else if (*s == '>') {
|
|
|
|
s++;
|
|
|
|
srec->status = S_DUMMY(N);
|
|
|
|
}
|
|
|
|
if (*s == '^') { // Pre-1.4 legacy
|
2017-03-11 12:20:53 +00:00
|
|
|
s++;
|
|
|
|
srec->status = S_SKIPPED;
|
|
|
|
} else if (*s == '~' || *s == 'X' /* Pre-1.3 legacy */) {
|
2004-03-27 16:07:20 +00:00
|
|
|
s++;
|
2006-02-02 17:03:01 +00:00
|
|
|
srec->status = S_EXPIRE | S_EXPIRED;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
} else if (srec->uid[F] == (uint)-1) { // Pre-1.3 legacy
|
|
|
|
srec->uid[F] = 0;
|
2017-03-11 12:20:53 +00:00
|
|
|
srec->status = S_SKIPPED;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
} else if (srec->uid[N] == (uint)-1) {
|
|
|
|
srec->uid[N] = 0;
|
2017-03-11 12:20:53 +00:00
|
|
|
srec->status = S_SKIPPED;
|
2019-12-03 12:06:12 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
srec->flags = parse_flags( s );
|
2019-12-29 13:37:53 +00:00
|
|
|
debug( " entry (%u,%u,%u,%s%s)\n", srec->uid[F], srec->uid[N], srec->flags,
|
|
|
|
(srec->status & S_SKIPPED) ? "SKIP" : (srec->status & S_EXPIRED) ? "XPIRE" : "",
|
|
|
|
(srec->status & S_DUMMY(F)) ? ",F-DUMMY" : (srec->status & S_DUMMY(N)) ? ",N-DUMMY" : "" );
|
2006-03-21 15:53:43 +00:00
|
|
|
*svars->srecadd = srec;
|
|
|
|
svars->srecadd = &srec->next;
|
2012-08-26 11:36:12 +00:00
|
|
|
svars->nsrecs++;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
fclose( jfp );
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->existing = 1;
|
2004-03-27 16:07:20 +00:00
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
2014-04-12 16:30:09 +00:00
|
|
|
sys_error( "Error: cannot read sync state %s", svars->dname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->existing = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2017-04-02 12:04:43 +00:00
|
|
|
|
|
|
|
// This is legacy support for pre-1.3 sync states.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (maxxnuid) {
|
2017-03-21 19:05:29 +00:00
|
|
|
uint minwuid = UINT_MAX;
|
2017-04-02 12:04:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((srec->status & (S_DEAD | S_SKIPPED | S_PENDING)) || !srec->uid[F])
|
2017-04-02 12:04:43 +00:00
|
|
|
continue;
|
|
|
|
if (srec->status & S_EXPIRED) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->uid[N]) {
|
2017-04-02 12:04:43 +00:00
|
|
|
// The expired message was already gone.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The expired message was not expunged yet, so re-examine it.
|
|
|
|
// This will happen en masse, so just extend the bulk fetch.
|
|
|
|
} else {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (srec->uid[N] && maxxnuid >= srec->uid[N]) {
|
2017-04-02 12:04:43 +00:00
|
|
|
// The non-expired message is in the generally expired range,
|
|
|
|
// so don't make it contribute to the bulk fetch.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Usual non-expired message.
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (minwuid > srec->uid[F])
|
|
|
|
minwuid = srec->uid[F];
|
2017-04-02 12:04:43 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->maxxfuid = minwuid - 1;
|
2017-04-02 12:04:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 19:05:29 +00:00
|
|
|
int line = 0;
|
2006-03-21 15:53:43 +00:00
|
|
|
if ((jfp = fopen( svars->jname, "r" ))) {
|
2014-12-27 22:50:31 +00:00
|
|
|
if (!lock_state( svars ))
|
|
|
|
goto jbail;
|
2006-03-21 15:53:43 +00:00
|
|
|
if (!stat( svars->nname, &st ) && fgets( buf, sizeof(buf), jfp )) {
|
2004-03-27 16:07:20 +00:00
|
|
|
debug( "recovering journal ...\n" );
|
2017-03-21 19:05:29 +00:00
|
|
|
if (!(ll = strlen( buf )) || buf[--ll] != '\n') {
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: incomplete journal header in %s\n", svars->jname );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2006-02-02 11:07:54 +00:00
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
buf[ll] = 0;
|
2020-07-08 15:27:37 +00:00
|
|
|
if (!equals( buf, (int)ll, JOURNAL_VERSION, strlen(JOURNAL_VERSION) )) {
|
2006-03-19 11:29:12 +00:00
|
|
|
error( "Error: incompatible journal version "
|
2016-11-13 21:19:40 +00:00
|
|
|
"(got %s, expected " JOURNAL_VERSION ")\n", buf );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2006-02-02 11:07:54 +00:00
|
|
|
}
|
2019-07-28 18:50:31 +00:00
|
|
|
srec = NULL;
|
2006-02-02 11:07:54 +00:00
|
|
|
line = 1;
|
2004-03-27 16:07:20 +00:00
|
|
|
while (fgets( buf, sizeof(buf), jfp )) {
|
|
|
|
line++;
|
2017-03-21 19:05:29 +00:00
|
|
|
if (!(ll = strlen( buf )) || buf[--ll] != '\n') {
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: incomplete journal entry at %s:%d\n", svars->jname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2004-11-13 09:19:36 +00:00
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
buf[ll] = 0;
|
|
|
|
int tn;
|
2019-12-29 13:37:53 +00:00
|
|
|
uint t1, t2, t3, t4;
|
2016-11-05 17:16:43 +00:00
|
|
|
if ((c = buf[0]) == '#' ?
|
2020-07-08 15:27:37 +00:00
|
|
|
(tn = 0, (sscanf( buf + 2, "%u %u %n", &t1, &t2, &tn ) < 2) || !tn || (ll - (uint)tn != TUIDL + 2)) :
|
2020-07-20 18:53:21 +00:00
|
|
|
c == '!' ?
|
2017-03-21 19:05:29 +00:00
|
|
|
(sscanf( buf + 2, "%u", &t1 ) != 1) :
|
2019-12-29 13:37:53 +00:00
|
|
|
c == 'N' || c == 'F' || c == 'T' || c == '+' || c == '&' || c == '-' || c == '=' || c == '_' || c == '|' ?
|
2017-03-21 19:05:29 +00:00
|
|
|
(sscanf( buf + 2, "%u %u", &t1, &t2 ) != 2) :
|
2019-12-29 13:37:53 +00:00
|
|
|
c != '^' ?
|
|
|
|
(sscanf( buf + 2, "%u %u %u", &t1, &t2, &t3 ) != 3) :
|
|
|
|
(sscanf( buf + 2, "%u %u %u %u", &t1, &t2, &t3, &t4 ) != 4))
|
2006-02-02 10:44:19 +00:00
|
|
|
{
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: malformed journal entry at %s:%d\n", svars->jname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2006-02-02 10:44:19 +00:00
|
|
|
}
|
2020-07-20 18:53:21 +00:00
|
|
|
if (c == 'N')
|
|
|
|
svars->maxuid[t1] = t2;
|
2017-03-31 10:39:12 +00:00
|
|
|
else if (c == 'F')
|
2019-12-29 10:52:26 +00:00
|
|
|
svars->finduid[t1] = t2;
|
2017-03-31 10:39:12 +00:00
|
|
|
else if (c == 'T')
|
2017-03-21 19:05:29 +00:00
|
|
|
*uint_array_append( &svars->trashed_msgs[t1] ) = t2;
|
2016-11-05 17:16:43 +00:00
|
|
|
else if (c == '!')
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->maxxfuid = t1;
|
2016-11-05 17:16:43 +00:00
|
|
|
else if (c == '|') {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->uidval[F] = t1;
|
|
|
|
svars->uidval[N] = t2;
|
2016-11-05 17:16:43 +00:00
|
|
|
} else if (c == '+') {
|
2019-12-03 12:06:12 +00:00
|
|
|
srec = nfcalloc( sizeof(*srec) );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
srec->uid[F] = t1;
|
|
|
|
srec->uid[N] = t2;
|
2017-03-21 19:05:29 +00:00
|
|
|
debug( " new entry(%u,%u)\n", t1, t2 );
|
2017-03-11 12:20:53 +00:00
|
|
|
srec->status = S_PENDING;
|
2006-03-21 15:53:43 +00:00
|
|
|
*svars->srecadd = srec;
|
|
|
|
svars->srecadd = &srec->next;
|
2012-08-26 11:36:12 +00:00
|
|
|
svars->nsrecs++;
|
2006-02-02 10:44:19 +00:00
|
|
|
} else {
|
|
|
|
for (nsrec = srec; srec; srec = srec->next)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (srec->uid[F] == t1 && srec->uid[N] == t2)
|
2006-02-02 10:44:19 +00:00
|
|
|
goto syncfnd;
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec != nsrec; srec = srec->next)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (srec->uid[F] == t1 && srec->uid[N] == t2)
|
2006-02-02 10:44:19 +00:00
|
|
|
goto syncfnd;
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: journal entry at %s:%d refers to non-existing sync state entry\n", svars->jname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2006-02-02 10:44:19 +00:00
|
|
|
syncfnd:
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debugn( " entry(%u,%u,%u) ", srec->uid[F], srec->uid[N], srec->flags );
|
2016-11-05 17:16:43 +00:00
|
|
|
switch (c) {
|
2006-02-02 10:44:19 +00:00
|
|
|
case '-':
|
|
|
|
debug( "killed\n" );
|
|
|
|
srec->status = S_DEAD;
|
|
|
|
break;
|
2017-03-30 18:04:02 +00:00
|
|
|
case '=':
|
|
|
|
debug( "aborted\n" );
|
2020-07-20 18:53:21 +00:00
|
|
|
if (svars->maxxfuid < srec->uid[F])
|
|
|
|
svars->maxxfuid = srec->uid[F];
|
2017-03-30 18:04:02 +00:00
|
|
|
srec->status = S_DEAD;
|
|
|
|
break;
|
2006-02-03 21:33:43 +00:00
|
|
|
case '#':
|
2017-03-21 19:05:29 +00:00
|
|
|
memcpy( srec->tuid, buf + tn + 2, TUIDL );
|
2016-11-13 21:20:55 +00:00
|
|
|
debug( "TUID now %." stringify(TUIDL) "s\n", srec->tuid );
|
2006-02-03 21:33:43 +00:00
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
debug( "TUID %." stringify(TUIDL) "s lost\n", srec->tuid );
|
|
|
|
srec->tuid[0] = 0;
|
|
|
|
break;
|
2006-02-02 10:44:19 +00:00
|
|
|
case '<':
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "far side now %u\n", t3 );
|
2019-12-29 13:41:45 +00:00
|
|
|
assign_uid( svars, srec, F, t3 );
|
2006-02-02 10:44:19 +00:00
|
|
|
break;
|
|
|
|
case '>':
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "near side now %u\n", t3 );
|
2019-12-29 13:41:45 +00:00
|
|
|
assign_uid( svars, srec, N, t3 );
|
2006-02-02 10:44:19 +00:00
|
|
|
break;
|
|
|
|
case '*':
|
2017-03-21 19:05:29 +00:00
|
|
|
debug( "flags now %u\n", t3 );
|
2019-07-28 20:10:21 +00:00
|
|
|
srec->flags = (uchar)t3;
|
2019-12-29 13:37:53 +00:00
|
|
|
srec->aflags[F] = srec->aflags[N] = 0;
|
|
|
|
srec->wstate &= ~W_PURGE;
|
2006-02-02 10:44:19 +00:00
|
|
|
break;
|
|
|
|
case '~':
|
2017-04-01 15:02:22 +00:00
|
|
|
debug( "status now %#x\n", t3 );
|
2019-07-28 20:10:21 +00:00
|
|
|
srec->status = (uchar)t3;
|
2006-02-02 10:44:19 +00:00
|
|
|
break;
|
2019-12-29 13:37:53 +00:00
|
|
|
case '_':
|
|
|
|
debug( "has placeholder now\n" );
|
|
|
|
srec->status = S_PENDING; // Pre-1.4 legacy only
|
|
|
|
srec->status |= !srec->uid[F] ? S_DUMMY(F) : S_DUMMY(N);
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
debug( "is being upgraded, flags %u, srec flags %u\n", t3, t4 );
|
|
|
|
srec->pflags = (uchar)t3;
|
|
|
|
srec->flags = (uchar)t4;
|
|
|
|
srec = upgrade_srec( svars, srec );
|
|
|
|
break;
|
2006-02-02 10:44:19 +00:00
|
|
|
default:
|
2006-03-21 15:53:43 +00:00
|
|
|
error( "Error: unrecognized journal entry at %s:%d\n", svars->jname, line );
|
2011-04-10 07:58:41 +00:00
|
|
|
goto jbail;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose( jfp );
|
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
2014-04-12 16:30:09 +00:00
|
|
|
sys_error( "Error: cannot read journal %s", svars->jname );
|
2014-12-27 22:13:45 +00:00
|
|
|
return 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->replayed = line;
|
2017-04-02 12:04:43 +00:00
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-29 01:08:48 +00:00
|
|
|
static void
|
|
|
|
delete_state( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
unlink( svars->nname );
|
|
|
|
unlink( svars->jname );
|
|
|
|
if (unlink( svars->dname ) || unlink( svars->lname )) {
|
|
|
|
sys_error( "Error: channel %s: sync state cannot be deleted", svars->chan->name );
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:45:06 +00:00
|
|
|
static void box_confirmed( int sts, uint uidvalidity, void *aux );
|
2014-12-29 01:08:48 +00:00
|
|
|
static void box_confirmed2( sync_vars_t *svars, int t );
|
|
|
|
static void box_deleted( int sts, void *aux );
|
2014-12-29 00:42:17 +00:00
|
|
|
static void box_created( int sts, void *aux );
|
2020-07-08 11:45:06 +00:00
|
|
|
static void box_opened( int sts, uint uidvalidity, void *aux );
|
2014-12-29 00:42:17 +00:00
|
|
|
static void box_opened2( sync_vars_t *svars, int t );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void load_box( sync_vars_t *svars, int t, uint minwuid, uint_array_t mexcs );
|
2014-12-27 22:13:45 +00:00
|
|
|
|
|
|
|
void
|
2019-07-28 19:13:28 +00:00
|
|
|
sync_boxes( store_t *ctx[], const char * const names[], int present[], channel_conf_t *chan,
|
2014-12-27 22:13:45 +00:00
|
|
|
void (*cb)( int sts, void *aux ), void *aux )
|
|
|
|
{
|
|
|
|
sync_vars_t *svars;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
svars = nfcalloc( sizeof(*svars) );
|
|
|
|
svars->t[1] = 1;
|
|
|
|
svars->ref_count = 1;
|
|
|
|
svars->cb = cb;
|
|
|
|
svars->aux = aux;
|
|
|
|
svars->ctx[0] = ctx[0];
|
|
|
|
svars->ctx[1] = ctx[1];
|
|
|
|
svars->chan = chan;
|
2014-12-27 22:50:31 +00:00
|
|
|
svars->lfd = -1;
|
2017-01-29 14:39:36 +00:00
|
|
|
svars->uidval[0] = svars->uidval[1] = UIDVAL_BAD;
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->srecadd = &svars->srecs;
|
|
|
|
|
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
svars->orig_name[t] =
|
|
|
|
(!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ?
|
|
|
|
"INBOX" : names[t];
|
2017-10-15 14:14:20 +00:00
|
|
|
if (!ctx[t]->conf->flat_delim[0]) {
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->box_name[t] = nfstrdup( svars->orig_name[t] );
|
|
|
|
} else if (map_name( svars->orig_name[t], &svars->box_name[t], 0, "/", ctx[t]->conf->flat_delim ) < 0) {
|
|
|
|
error( "Error: canonical mailbox name '%s' contains flattened hierarchy delimiter\n", svars->orig_name[t] );
|
2015-05-01 17:16:23 +00:00
|
|
|
bail3:
|
2014-12-27 22:13:45 +00:00
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail3( svars );
|
|
|
|
return;
|
|
|
|
}
|
2017-04-02 12:57:17 +00:00
|
|
|
svars->drv[t] = ctx[t]->driver;
|
2017-03-21 18:27:04 +00:00
|
|
|
svars->drv[t]->set_bad_callback( ctx[t], store_bad, AUX );
|
2014-12-27 22:13:45 +00:00
|
|
|
}
|
|
|
|
/* Both boxes must be fully set up at this point, so that error exit paths
|
|
|
|
* don't run into uninitialized variables. */
|
2014-12-27 22:39:55 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2015-05-01 17:16:23 +00:00
|
|
|
switch (svars->drv[t]->select_box( ctx[t], svars->box_name[t] )) {
|
2020-08-03 22:23:33 +00:00
|
|
|
case DRV_STORE_BAD:
|
2014-12-27 22:39:55 +00:00
|
|
|
store_bad( AUX );
|
|
|
|
return;
|
2015-05-01 17:16:23 +00:00
|
|
|
case DRV_BOX_BAD:
|
|
|
|
goto bail3;
|
2014-12-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 22:16:20 +00:00
|
|
|
|
|
|
|
if (!prepare_state( svars )) {
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail2( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!load_state( svars )) {
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
sync_ref( svars );
|
2015-01-03 22:16:20 +00:00
|
|
|
for (t = 0; ; t++) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Opening %s box %s...\n", str_fn[t], svars->orig_name[t] );
|
2014-12-30 14:16:38 +00:00
|
|
|
if (present[t] == BOX_ABSENT)
|
2014-12-29 01:08:48 +00:00
|
|
|
box_confirmed2( svars, t );
|
2014-12-30 14:16:38 +00:00
|
|
|
else
|
|
|
|
svars->drv[t]->open_box( ctx[t], box_confirmed, AUX );
|
2015-01-03 22:16:20 +00:00
|
|
|
if (t || check_cancel( svars ))
|
2014-12-27 22:13:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sync_deref( svars );
|
|
|
|
}
|
|
|
|
|
2014-12-29 00:42:17 +00:00
|
|
|
static void
|
2020-07-08 11:45:06 +00:00
|
|
|
box_confirmed( int sts, uint uidvalidity, void *aux )
|
2014-12-29 00:42:17 +00:00
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (sts == DRV_CANCELED)
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
return;
|
|
|
|
|
2017-03-24 18:24:30 +00:00
|
|
|
if (sts == DRV_OK) {
|
2014-12-29 01:08:48 +00:00
|
|
|
svars->state[t] |= ST_PRESENT;
|
2017-03-24 18:24:30 +00:00
|
|
|
svars->newuidval[t] = uidvalidity;
|
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
box_confirmed2( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_confirmed2( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
svars->state[t] |= ST_CONFIRMED;
|
|
|
|
if (!(svars->state[1-t] & ST_CONFIRMED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sync_ref( svars );
|
|
|
|
for (t = 0; ; t++) {
|
|
|
|
if (!(svars->state[t] & ST_PRESENT)) {
|
|
|
|
if (!(svars->state[1-t] & ST_PRESENT)) {
|
|
|
|
if (!svars->existing) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: both far side %s and near side %s cannot be opened.\n",
|
|
|
|
svars->chan->name, svars->orig_name[F], svars->orig_name[N] );
|
2014-12-29 01:08:48 +00:00
|
|
|
bail:
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
} else {
|
|
|
|
/* This can legitimately happen if a deletion propagation was interrupted.
|
|
|
|
* We have no place to record this transaction, so we just assume it.
|
|
|
|
* Of course this bears the danger of clearing the state if both mailboxes
|
|
|
|
* temorarily cannot be opened for some weird reason (while the stores can). */
|
|
|
|
delete_state( svars );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
sync_bail( svars );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (svars->existing) {
|
|
|
|
if (!(svars->chan->ops[1-t] & OP_REMOVE)) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: %s box %s cannot be opened.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
if (svars->drv[1-t]->confirm_box_empty( svars->ctx[1-t] ) != DRV_OK) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
warn( "Warning: channel %s: %s box %s cannot be opened and %s box %s is not empty.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t], str_fn[1-t], svars->orig_name[1-t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
goto done;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Deleting %s box %s...\n", str_fn[1-t], svars->orig_name[1-t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
svars->drv[1-t]->delete_box( svars->ctx[1-t], box_deleted, INV_AUX );
|
|
|
|
} else {
|
|
|
|
if (!(svars->chan->ops[t] & OP_CREATE)) {
|
2017-03-24 18:24:30 +00:00
|
|
|
box_opened( DRV_BOX_BAD, UIDVAL_BAD, AUX );
|
2014-12-29 01:08:48 +00:00
|
|
|
} else {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Creating %s box %s...\n", str_fn[t], svars->orig_name[t] );
|
2014-12-29 01:08:48 +00:00
|
|
|
svars->drv[t]->create_box( svars->ctx[t], box_created, AUX );
|
|
|
|
}
|
|
|
|
}
|
2014-12-29 00:42:17 +00:00
|
|
|
} else {
|
2014-12-29 01:08:48 +00:00
|
|
|
box_opened2( svars, t );
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
if (t || check_cancel( svars ))
|
|
|
|
break;
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
2014-12-29 01:08:48 +00:00
|
|
|
sync_deref( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_deleted( int sts, void *aux )
|
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (check_ret( sts, aux ))
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
|
|
|
|
delete_state( svars );
|
|
|
|
svars->drv[t]->finish_delete_box( svars->ctx[t] );
|
|
|
|
sync_bail( svars );
|
2014-12-29 00:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_created( int sts, void *aux )
|
|
|
|
{
|
|
|
|
DECL_SVARS;
|
|
|
|
|
|
|
|
if (check_ret( sts, aux ))
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
|
|
|
|
svars->drv[t]->open_box( svars->ctx[t], box_opened, AUX );
|
|
|
|
}
|
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
static void
|
2020-07-08 11:45:06 +00:00
|
|
|
box_opened( int sts, uint uidvalidity, void *aux )
|
2014-12-27 22:13:45 +00:00
|
|
|
{
|
|
|
|
DECL_SVARS;
|
2014-12-29 00:42:17 +00:00
|
|
|
|
|
|
|
if (sts == DRV_CANCELED)
|
|
|
|
return;
|
|
|
|
INIT_SVARS(aux);
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sts == DRV_BOX_BAD) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
error( "Error: channel %s: %s box %s cannot be opened.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2014-12-29 00:42:17 +00:00
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
} else {
|
2017-03-24 18:24:30 +00:00
|
|
|
svars->newuidval[t] = uidvalidity;
|
2014-12-29 00:42:17 +00:00
|
|
|
box_opened2( svars, t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_opened2( sync_vars_t *svars, int t )
|
|
|
|
{
|
2014-12-27 22:13:45 +00:00
|
|
|
store_t *ctx[2];
|
|
|
|
channel_conf_t *chan;
|
2015-01-03 22:16:20 +00:00
|
|
|
sync_rec_t *srec;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint_array_alloc_t mexcs;
|
2020-07-08 15:27:37 +00:00
|
|
|
uint opts[2], fails, minwuid;
|
2014-12-27 22:13:45 +00:00
|
|
|
|
|
|
|
svars->state[t] |= ST_SELECTED;
|
|
|
|
if (!(svars->state[1-t] & ST_SELECTED))
|
|
|
|
return;
|
2015-01-03 22:16:20 +00:00
|
|
|
ctx[0] = svars->ctx[0];
|
|
|
|
ctx[1] = svars->ctx[1];
|
|
|
|
chan = svars->chan;
|
2011-07-23 14:06:32 +00:00
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
fails = 0;
|
2011-07-23 14:06:32 +00:00
|
|
|
for (t = 0; t < 2; t++)
|
2017-03-24 18:24:30 +00:00
|
|
|
if (svars->uidval[t] != UIDVAL_BAD && svars->uidval[t] != svars->newuidval[t])
|
2014-12-27 22:13:45 +00:00
|
|
|
fails++;
|
2021-02-20 21:52:49 +00:00
|
|
|
// If only one side changed UIDVALIDITY, we will try to re-approve it further down.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (fails == 2) {
|
2021-02-20 21:52:01 +00:00
|
|
|
error( "Error: channel %s: UIDVALIDITY of both far side %s and near side %s changed.\n",
|
|
|
|
svars->chan->name, svars->orig_name[F], svars->orig_name[N]);
|
2014-12-27 22:13:45 +00:00
|
|
|
bail:
|
|
|
|
svars->ret = SYNC_FAIL;
|
|
|
|
sync_bail( svars );
|
|
|
|
return;
|
|
|
|
}
|
2011-07-23 14:06:32 +00:00
|
|
|
|
2014-12-27 22:50:31 +00:00
|
|
|
if (!lock_state( svars ))
|
|
|
|
goto bail;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
opts[F] = opts[N] = 0;
|
2016-12-18 19:50:20 +00:00
|
|
|
if (fails)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
opts[F] = opts[N] = OPEN_OLD|OPEN_OLD_IDS;
|
2006-01-29 11:35:22 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
if (chan->ops[t] & (OP_DELETE|OP_FLAGS)) {
|
|
|
|
opts[t] |= OPEN_SETFLAGS;
|
|
|
|
opts[1-t] |= OPEN_OLD;
|
|
|
|
if (chan->ops[t] & OP_FLAGS)
|
|
|
|
opts[1-t] |= OPEN_FLAGS;
|
|
|
|
}
|
|
|
|
if (chan->ops[t] & (OP_NEW|OP_RENEW)) {
|
|
|
|
opts[t] |= OPEN_APPEND;
|
2019-12-29 13:37:53 +00:00
|
|
|
if (chan->ops[t] & OP_NEW) {
|
2006-01-29 11:35:22 +00:00
|
|
|
opts[1-t] |= OPEN_NEW;
|
2019-12-29 13:37:53 +00:00
|
|
|
if (chan->stores[t]->max_size != UINT_MAX)
|
2019-12-29 11:59:40 +00:00
|
|
|
opts[1-t] |= OPEN_FLAGS|OPEN_NEW_SIZE;
|
2016-12-18 20:22:52 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
if (chan->ops[t] & OP_RENEW) {
|
|
|
|
opts[t] |= OPEN_OLD|OPEN_FLAGS|OPEN_SETFLAGS;
|
|
|
|
opts[1-t] |= OPEN_OLD|OPEN_FLAGS;
|
|
|
|
}
|
|
|
|
if (chan->ops[t] & OP_EXPUNGE) // Don't propagate doomed msgs
|
|
|
|
opts[1-t] |= OPEN_FLAGS;
|
2006-01-29 11:35:22 +00:00
|
|
|
}
|
|
|
|
if (chan->ops[t] & OP_EXPUNGE) {
|
|
|
|
opts[t] |= OPEN_EXPUNGE;
|
|
|
|
if (chan->stores[t]->trash) {
|
|
|
|
if (!chan->stores[t]->trash_only_new)
|
|
|
|
opts[t] |= OPEN_OLD;
|
|
|
|
opts[t] |= OPEN_NEW|OPEN_FLAGS;
|
|
|
|
} else if (chan->stores[1-t]->trash && chan->stores[1-t]->trash_remote_new)
|
|
|
|
opts[t] |= OPEN_NEW|OPEN_FLAGS;
|
|
|
|
}
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((chan->ops[N] & (OP_NEW|OP_RENEW|OP_FLAGS)) && chan->max_messages)
|
|
|
|
opts[N] |= OPEN_OLD|OPEN_NEW|OPEN_FLAGS;
|
2014-12-27 22:13:45 +00:00
|
|
|
if (svars->replayed)
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
2006-02-03 21:33:43 +00:00
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
|
|
|
if (srec->tuid[0]) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->uid[F])
|
|
|
|
opts[F] |= OPEN_NEW|OPEN_FIND, svars->state[F] |= ST_FIND_OLD;
|
|
|
|
else if (!srec->uid[N])
|
|
|
|
opts[N] |= OPEN_NEW|OPEN_FIND, svars->state[N] |= ST_FIND_OLD;
|
2013-11-02 22:32:42 +00:00
|
|
|
else
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
warn( "Warning: sync record (%u,%u) has stray TUID. Ignoring.\n", srec->uid[F], srec->uid[N] );
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
if (srec->wstate & W_PURGE) {
|
|
|
|
t = srec->uid[F] ? F : N;
|
|
|
|
opts[t] |= OPEN_SETFLAGS;
|
|
|
|
}
|
|
|
|
if (srec->wstate & W_UPGRADE) {
|
|
|
|
t = !srec->uid[F] ? F : N;
|
|
|
|
opts[t] |= OPEN_APPEND;
|
|
|
|
opts[1-t] |= OPEN_OLD;
|
|
|
|
}
|
2006-02-03 21:33:43 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->opts[F] = svars->drv[F]->prepare_load_box( ctx[F], opts[F] );
|
|
|
|
svars->opts[N] = svars->drv[N]->prepare_load_box( ctx[N], opts[N] );
|
2006-01-29 11:35:22 +00:00
|
|
|
|
2016-11-04 20:48:58 +00:00
|
|
|
ARRAY_INIT( &mexcs );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (svars->opts[F] & OPEN_OLD) {
|
2013-11-30 12:03:12 +00:00
|
|
|
if (chan->max_messages) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
/* When messages have been expired on the near side, the far side fetch is split into
|
2013-11-17 10:23:44 +00:00
|
|
|
* two ranges: The bulk fetch which corresponds with the most recent messages, and an
|
|
|
|
* exception list of messages which would have been expired if they weren't important. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "preparing far side selection - max expired far uid is %u\n", svars->maxxfuid );
|
2013-11-17 10:23:44 +00:00
|
|
|
/* First, find out the lower bound for the bulk fetch. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
minwuid = svars->maxxfuid + 1;
|
2013-11-17 10:23:44 +00:00
|
|
|
/* Next, calculate the exception fetch. */
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->uid[F])
|
2020-07-07 19:14:59 +00:00
|
|
|
continue; // No message; other state is irrelevant
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (srec->uid[F] >= minwuid)
|
2020-07-07 19:14:59 +00:00
|
|
|
continue; // Message is in non-expired range
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((svars->opts[F] & OPEN_NEW) && srec->uid[F] >= svars->maxuid[F])
|
2020-07-07 19:14:59 +00:00
|
|
|
continue; // Message is in expired range, but new range overlaps that
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->uid[N] && !(srec->status & S_PENDING))
|
2020-07-07 19:14:59 +00:00
|
|
|
continue; // Only actually paired up messages matter
|
|
|
|
// The pair is alive, but outside the bulk range
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
*uint_array_append( &mexcs ) = srec->uid[F];
|
2013-11-17 10:23:44 +00:00
|
|
|
}
|
2017-03-21 19:05:29 +00:00
|
|
|
sort_uint_array( mexcs.array );
|
2013-11-17 10:23:44 +00:00
|
|
|
} else {
|
|
|
|
minwuid = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-21 19:05:29 +00:00
|
|
|
minwuid = UINT_MAX;
|
2013-11-17 10:23:44 +00:00
|
|
|
}
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_ref( svars );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
load_box( svars, F, minwuid, mexcs.array );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (!check_cancel( svars ))
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
load_box( svars, N, (svars->opts[N] & OPEN_OLD) ? 1 : UINT_MAX, (uint_array_t){ NULL, 0 } );
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:45:06 +00:00
|
|
|
static uint
|
2016-12-18 20:22:52 +00:00
|
|
|
get_seenuid( sync_vars_t *svars, int t )
|
|
|
|
{
|
2017-03-21 19:05:29 +00:00
|
|
|
uint seenuid = 0;
|
2016-12-18 20:22:52 +00:00
|
|
|
for (sync_rec_t *srec = svars->srecs; srec; srec = srec->next)
|
|
|
|
if (!(srec->status & S_DEAD) && seenuid < srec->uid[t])
|
|
|
|
seenuid = srec->uid[t];
|
|
|
|
return seenuid;
|
|
|
|
}
|
|
|
|
|
2017-03-24 17:09:40 +00:00
|
|
|
static void box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
load_box( sync_vars_t *svars, int t, uint minwuid, uint_array_t mexcs )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2019-12-29 10:52:26 +00:00
|
|
|
uint maxwuid = 0, pairuid = UINT_MAX;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2017-03-24 13:18:41 +00:00
|
|
|
if (svars->opts[t] & OPEN_NEW) {
|
2006-03-21 20:03:21 +00:00
|
|
|
if (minwuid > svars->maxuid[t] + 1)
|
|
|
|
minwuid = svars->maxuid[t] + 1;
|
2017-03-21 19:05:29 +00:00
|
|
|
maxwuid = UINT_MAX;
|
2019-12-29 10:52:26 +00:00
|
|
|
if (svars->opts[t] & OPEN_OLD_IDS) // Implies OPEN_OLD
|
|
|
|
pairuid = get_seenuid( svars, t );
|
2017-03-24 13:18:41 +00:00
|
|
|
} else if (svars->opts[t] & OPEN_OLD) {
|
2019-12-29 10:52:26 +00:00
|
|
|
maxwuid = get_seenuid( svars, t );
|
2016-12-18 20:22:52 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "Loading %s box...\n", str_fn[t] );
|
2019-12-29 10:52:26 +00:00
|
|
|
svars->drv[t]->load_box( svars->ctx[t], minwuid, maxwuid, svars->finduid[t], pairuid, svars->maxuid[t], mexcs, box_loaded, AUX );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
void *aux;
|
|
|
|
sync_rec_t *srec;
|
|
|
|
int aflags, dflags;
|
|
|
|
} flag_vars_t;
|
|
|
|
|
2012-08-26 11:36:12 +00:00
|
|
|
typedef struct {
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid;
|
2012-08-26 11:36:12 +00:00
|
|
|
sync_rec_t *srec;
|
|
|
|
} sync_rec_map_t;
|
|
|
|
|
2013-11-24 14:58:32 +00:00
|
|
|
static void flags_set( int sts, void *aux );
|
|
|
|
static void flags_set_p2( sync_vars_t *svars, sync_rec_t *srec, int t );
|
2013-12-11 15:13:49 +00:00
|
|
|
static void msgs_flags_set( sync_vars_t *svars, int t );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_copied( int sts, uint uid, copy_vars_t *vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msgs_copied( sync_vars_t *svars, int t );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-24 17:09:40 +00:00
|
|
|
box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2011-04-10 11:06:07 +00:00
|
|
|
DECL_SVARS;
|
2012-08-26 11:36:12 +00:00
|
|
|
sync_rec_t *srec;
|
|
|
|
sync_rec_map_t *srecmap;
|
2006-03-21 20:03:21 +00:00
|
|
|
message_t *tmsg;
|
|
|
|
flag_vars_t *fv;
|
2017-03-21 19:05:29 +00:00
|
|
|
int no[2], del[2], alive, todel;
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar sflags, nflags, aflags, dflags;
|
2014-12-07 12:19:30 +00:00
|
|
|
uint hashsz, idx;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
if (check_ret( sts, aux ))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2011-04-10 11:06:07 +00:00
|
|
|
INIT_SVARS(aux);
|
|
|
|
svars->state[t] |= ST_LOADED;
|
2017-03-24 17:09:40 +00:00
|
|
|
svars->msgs[t] = msgs;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
info( "%s: %d messages, %d recent\n", str_fn[t], total_msgs, recent_msgs );
|
2011-04-10 11:06:07 +00:00
|
|
|
|
2013-11-02 11:57:39 +00:00
|
|
|
if (svars->state[t] & ST_FIND_OLD) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "matching previously copied messages on %s\n", str_fn[t] );
|
2017-03-26 16:44:43 +00:00
|
|
|
match_tuids( svars, t, msgs );
|
2011-04-10 11:06:07 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "matching messages on %s against sync records\n", str_fn[t] );
|
2012-08-26 11:36:12 +00:00
|
|
|
hashsz = bucketsForSize( svars->nsrecs * 3 );
|
|
|
|
srecmap = nfcalloc( hashsz * sizeof(*srecmap) );
|
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid = srec->uid[t];
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!uid)
|
2017-03-11 12:27:53 +00:00
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
idx = (uint)(uid * 1103515245U) % hashsz;
|
2012-08-26 11:36:12 +00:00
|
|
|
while (srecmap[idx].uid)
|
|
|
|
if (++idx == hashsz)
|
|
|
|
idx = 0;
|
|
|
|
srecmap[idx].uid = uid;
|
|
|
|
srecmap[idx].srec = srec;
|
|
|
|
}
|
2017-03-24 17:09:40 +00:00
|
|
|
for (tmsg = svars->msgs[t]; tmsg; tmsg = tmsg->next) {
|
2011-04-10 11:06:07 +00:00
|
|
|
if (tmsg->srec) /* found by TUID */
|
|
|
|
continue;
|
2017-03-21 19:05:29 +00:00
|
|
|
uint uid = tmsg->uid;
|
|
|
|
idx = (uint)(uid * 1103515245U) % hashsz;
|
2012-08-26 11:36:12 +00:00
|
|
|
while (srecmap[idx].uid) {
|
|
|
|
if (srecmap[idx].uid == uid) {
|
|
|
|
srec = srecmap[idx].srec;
|
2006-03-21 20:03:21 +00:00
|
|
|
goto found;
|
|
|
|
}
|
2012-08-26 11:36:12 +00:00
|
|
|
if (++idx == hashsz)
|
|
|
|
idx = 0;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
found:
|
|
|
|
tmsg->srec = srec;
|
|
|
|
srec->msg[t] = tmsg;
|
|
|
|
}
|
2012-08-26 11:36:12 +00:00
|
|
|
free( srecmap );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2011-04-10 11:06:07 +00:00
|
|
|
if (!(svars->state[1-t] & ST_LOADED))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2016-12-18 19:50:20 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2017-03-24 18:24:30 +00:00
|
|
|
if (svars->uidval[t] != UIDVAL_BAD && svars->uidval[t] != svars->newuidval[t]) {
|
2021-02-20 21:52:49 +00:00
|
|
|
// This code checks whether the messages with known UIDs are actually the
|
|
|
|
// same messages, as recognized by their Message-IDs.
|
2016-12-18 19:50:20 +00:00
|
|
|
unsigned need = 0, got = 0;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "trying to re-approve uid validity of %s\n", str_fn[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
2021-02-20 21:52:49 +00:00
|
|
|
need++;
|
2016-12-18 19:50:20 +00:00
|
|
|
if (!srec->msg[t])
|
|
|
|
continue; // Message disappeared.
|
2021-02-20 21:52:49 +00:00
|
|
|
// Present paired messages require re-validation.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (!srec->msg[t]->msgid)
|
|
|
|
continue; // Messages without ID are useless for re-validation.
|
|
|
|
if (!srec->msg[1-t])
|
|
|
|
continue; // Partner disappeared.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->msg[1-t]->msgid || strcmp( srec->msg[F]->msgid, srec->msg[N]->msgid )) {
|
|
|
|
error( "Error: channel %s, %s box %s: UIDVALIDITY genuinely changed (at UID %u).\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t], srec->uid[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
uvchg:
|
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2021-02-20 21:52:49 +00:00
|
|
|
// We encountered no messages that contradict the hypothesis that the
|
|
|
|
// UIDVALIDITY change was spurious.
|
|
|
|
// If we got enough messages confirming the hypothesis, we just accept it.
|
|
|
|
// If there aren't quite enough messages, we check that at least 80% of
|
|
|
|
// those previously present are still there and confirm the hypothesis;
|
|
|
|
// this also covers the case of a box that was already empty.
|
2016-12-18 19:50:20 +00:00
|
|
|
if (got < 20 && got * 5 < need * 4) {
|
|
|
|
// Too few confirmed messages. This is very likely in the drafts folder.
|
|
|
|
// A proper fallback would be fetching more headers (which potentially need
|
|
|
|
// normalization) or the message body (which should be truncated for sanity)
|
|
|
|
// and comparing.
|
2021-02-20 21:52:01 +00:00
|
|
|
error( "Error: channel %s, %s box %s: Unable to recover from UIDVALIDITY change.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2016-12-18 19:50:20 +00:00
|
|
|
goto uvchg;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
notice( "Notice: channel %s, %s box %s: Recovered from change of UIDVALIDITY.\n",
|
|
|
|
svars->chan->name, str_fn[t], svars->orig_name[t] );
|
2017-01-29 14:39:36 +00:00
|
|
|
svars->uidval[t] = UIDVAL_BAD;
|
2016-12-18 19:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (svars->uidval[F] == UIDVAL_BAD || svars->uidval[N] == UIDVAL_BAD) {
|
|
|
|
svars->uidval[F] = svars->newuidval[F];
|
|
|
|
svars->uidval[N] = svars->newuidval[N];
|
|
|
|
JLOG( "| %u %u", (svars->uidval[F], svars->uidval[N]), "new UIDVALIDITYs" );
|
2001-11-15 23:59:27 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
svars->oldmaxuid[F] = svars->maxuid[F];
|
|
|
|
svars->oldmaxuid[N] = svars->maxuid[N];
|
|
|
|
svars->oldmaxxfuid = svars->maxxfuid;
|
|
|
|
|
2005-12-28 10:02:22 +00:00
|
|
|
info( "Synchronizing...\n" );
|
2020-01-08 17:22:48 +00:00
|
|
|
for (t = 0; t < 2; t++)
|
|
|
|
svars->good_flags[t] = (uchar)svars->drv[t]->get_supported_flags( svars->ctx[t] );
|
2006-01-29 15:52:49 +00:00
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
int any_new[2] = { 0, 0 };
|
|
|
|
|
2004-03-27 16:07:20 +00:00
|
|
|
debug( "synchronizing old entries\n" );
|
2013-11-24 17:26:11 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
|
|
|
if (srec->status & S_DEAD)
|
2004-03-27 16:07:20 +00:00
|
|
|
continue;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "pair (%u,%u)\n", srec->uid[F], srec->uid[N] );
|
2017-04-02 15:21:39 +00:00
|
|
|
assert( !srec->tuid[0] );
|
2017-03-10 16:40:54 +00:00
|
|
|
// no[] means that a message is known to be not there.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
no[F] = !srec->msg[F] && (svars->opts[F] & OPEN_OLD);
|
|
|
|
no[N] = !srec->msg[N] && (svars->opts[N] & OPEN_OLD);
|
|
|
|
if (no[F] && no[N]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// It does not matter whether one side was already known to be missing
|
|
|
|
// (never stored [skipped or failed] or expunged [possibly expired]) -
|
|
|
|
// now both are missing, so the entry is superfluous.
|
2004-03-27 16:07:20 +00:00
|
|
|
srec->status = S_DEAD;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "both missing" );
|
2004-03-27 16:07:20 +00:00
|
|
|
} else {
|
2017-03-10 16:40:54 +00:00
|
|
|
// del[] means that a message becomes known to have been expunged.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
del[F] = no[F] && srec->uid[F];
|
|
|
|
del[N] = no[N] && srec->uid[N];
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2005-12-28 10:02:22 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2006-02-02 17:03:01 +00:00
|
|
|
if (srec->msg[t] && (srec->msg[t]->flags & F_DELETED))
|
2017-04-01 15:02:22 +00:00
|
|
|
srec->wstate |= W_DEL(t);
|
2017-03-10 16:40:54 +00:00
|
|
|
if (del[t]) {
|
|
|
|
// The target was newly expunged, so there is nothing to update.
|
|
|
|
// The deletion is propagated in the opposite iteration.
|
2017-03-11 12:20:53 +00:00
|
|
|
} else if (!srec->uid[t]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// The target was never stored, or was previously expunged, so there
|
|
|
|
// is nothing to update.
|
|
|
|
// Note: the opposite UID must be valid, as otherwise the entry would
|
|
|
|
// have been pruned already.
|
2005-12-28 10:02:22 +00:00
|
|
|
} else if (del[1-t]) {
|
2017-03-10 16:40:54 +00:00
|
|
|
// The source was newly expunged, so possibly propagate the deletion.
|
|
|
|
// The target may be in an unknown state (not fetched).
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == F) && (srec->status & (S_EXPIRE|S_EXPIRED))) {
|
2013-11-17 08:06:20 +00:00
|
|
|
/* Don't propagate deletion resulting from expiration. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "near side expired, orphaning far side" );
|
|
|
|
srec->uid[N] = 0;
|
2013-11-17 08:06:20 +00:00
|
|
|
} else {
|
|
|
|
if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS) && srec->msg[t]->flags != srec->flags)
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
notice( "Notice: conflicting changes in (%u,%u)\n", srec->uid[F], srec->uid[N] );
|
2013-11-17 08:06:20 +00:00
|
|
|
if (svars->chan->ops[t] & OP_DELETE) {
|
|
|
|
debug( " %sing delete\n", str_hl[t] );
|
2013-11-24 14:58:32 +00:00
|
|
|
srec->aflags[t] = F_DELETED;
|
2017-04-01 15:02:22 +00:00
|
|
|
srec->wstate |= W_DELETE;
|
2013-11-17 08:06:20 +00:00
|
|
|
} else {
|
|
|
|
debug( " not %sing delete\n", str_hl[t] );
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 16:40:54 +00:00
|
|
|
} else if (!srec->msg[1-t]) {
|
|
|
|
// We have no source to work with, because it was never stored,
|
|
|
|
// it was previously expunged, or we did not fetch it.
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( " no %s\n", str_fn[1-t] );
|
2017-03-10 16:40:54 +00:00
|
|
|
} else {
|
|
|
|
// We have a source. The target may be in an unknown state.
|
2006-03-21 15:53:43 +00:00
|
|
|
if (svars->chan->ops[t] & OP_FLAGS) {
|
2020-01-08 17:22:48 +00:00
|
|
|
sflags = sanitize_flags( srec->msg[1-t]->flags, svars, t );
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == F) && (srec->status & (S_EXPIRE|S_EXPIRED))) {
|
2013-11-02 19:06:08 +00:00
|
|
|
/* Don't propagate deletion resulting from expiration. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( " near side expiring\n" );
|
2006-02-02 17:03:01 +00:00
|
|
|
sflags &= ~F_DELETED;
|
2013-11-02 19:06:08 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
if (srec->status & S_DUMMY(1-t)) {
|
|
|
|
// For placeholders, don't propagate:
|
|
|
|
// - Seen, because the real contents were obviously not seen yet
|
|
|
|
// - Flagged, because it's just a request to upgrade
|
|
|
|
sflags &= ~(F_SEEN|F_FLAGGED);
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
srec->aflags[t] = sflags & ~srec->flags;
|
|
|
|
srec->dflags[t] = ~sflags & srec->flags;
|
2017-03-10 16:40:54 +00:00
|
|
|
if ((DFlags & DEBUG_SYNC) && (srec->aflags[t] || srec->dflags[t])) {
|
2006-02-02 11:23:57 +00:00
|
|
|
char afbuf[16], dfbuf[16]; /* enlarge when support for keywords is added */
|
2006-02-02 17:03:01 +00:00
|
|
|
make_flags( srec->aflags[t], afbuf );
|
|
|
|
make_flags( srec->dflags[t], dfbuf );
|
2006-02-02 11:23:57 +00:00
|
|
|
debug( " %sing flags: +%s -%s\n", str_hl[t], afbuf, dfbuf );
|
|
|
|
}
|
2017-03-10 16:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-28 10:02:22 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
|
|
|
|
sync_rec_t *nsrec = srec;
|
|
|
|
if (((srec->status & S_DUMMY(F)) && (svars->chan->ops[F] & OP_RENEW)) ||
|
|
|
|
((srec->status & S_DUMMY(N)) && (svars->chan->ops[N] & OP_RENEW))) {
|
|
|
|
// Flagging the message on either side causes an upgrade of the dummy.
|
|
|
|
// We ignore flag resets, because that corner case is not worth it.
|
|
|
|
ushort muflags = srec->msg[F] ? srec->msg[F]->flags : 0;
|
|
|
|
ushort suflags = srec->msg[N] ? srec->msg[N]->flags : 0;
|
|
|
|
if ((muflags | suflags) & F_FLAGGED) {
|
|
|
|
t = (srec->status & S_DUMMY(F)) ? F : N;
|
|
|
|
// We calculate the flags for the replicated message already now,
|
|
|
|
// because after an interruption the dummy may be already gone.
|
|
|
|
srec->pflags = ((srec->msg[t]->flags & ~(F_SEEN|F_FLAGGED)) | srec->aflags[t]) & ~srec->dflags[t];
|
|
|
|
// Consequently, the srec's flags are committed right away as well.
|
|
|
|
srec->flags = (srec->flags | srec->aflags[t]) & ~srec->dflags[t];
|
|
|
|
JLOG( "^ %u %u %u %u", (srec->uid[F], srec->uid[N], srec->pflags, srec->flags), "upgrading placeholder" );
|
|
|
|
nsrec = upgrade_srec( svars, srec );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This is separated, because the upgrade can come from the journal.
|
|
|
|
if (srec->wstate & W_UPGRADE) {
|
|
|
|
t = !srec->uid[F] ? F : N;
|
|
|
|
tmsg = srec->msg[1-t];
|
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && (srec->pflags & F_DELETED)) {
|
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing upgrade - would be expunged anyway" );
|
|
|
|
tmsg->srec = NULL;
|
|
|
|
srec->status = S_DEAD;
|
|
|
|
} else {
|
|
|
|
// Pretend that the source message has the adjusted flags of the dummy.
|
|
|
|
tmsg->flags = srec->pflags;
|
|
|
|
tmsg->status = M_FLAGS;
|
|
|
|
any_new[t] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srec = nsrec;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2001-11-15 23:59:27 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2013-11-24 17:26:11 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2020-07-08 12:37:57 +00:00
|
|
|
debug( "synchronizing new messages on %s\n", str_fn[1-t] );
|
2017-03-24 17:09:40 +00:00
|
|
|
for (tmsg = svars->msgs[1-t]; tmsg; tmsg = tmsg->next) {
|
2013-11-24 17:26:11 +00:00
|
|
|
srec = tmsg->srec;
|
2020-07-08 12:37:57 +00:00
|
|
|
if (srec) {
|
|
|
|
if (srec->status & S_SKIPPED) {
|
2019-12-29 13:37:53 +00:00
|
|
|
// Pre-1.4 legacy only: The message was skipped due to being too big.
|
2020-07-20 18:53:21 +00:00
|
|
|
// We must have already seen the UID, but we might have been interrupted.
|
|
|
|
if (svars->maxuid[1-t] < tmsg->uid)
|
|
|
|
svars->maxuid[1-t] = tmsg->uid;
|
2020-07-08 12:37:57 +00:00
|
|
|
if (!(svars->chan->ops[t] & OP_RENEW))
|
|
|
|
continue;
|
2019-12-29 13:37:53 +00:00
|
|
|
srec->status = S_PENDING;
|
|
|
|
// The message size was not queried, so this won't be dummified below.
|
|
|
|
if (!(tmsg->flags & F_FLAGGED)) {
|
|
|
|
srec->status |= S_DUMMY(t);
|
|
|
|
JLOG( "_ %u %u", (srec->uid[F], srec->uid[N]), "placeholder only - was previously skipped" );
|
|
|
|
} else {
|
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "was previously skipped" );
|
|
|
|
}
|
2020-07-08 12:37:57 +00:00
|
|
|
} else {
|
|
|
|
if (!(svars->chan->ops[t] & OP_NEW))
|
|
|
|
continue;
|
2020-07-20 18:53:21 +00:00
|
|
|
// This catches messages:
|
|
|
|
// - that are actually new
|
|
|
|
// - whose propagation got interrupted
|
|
|
|
// - whose propagation was completed, but not logged yet
|
|
|
|
// - that aren't actually new, but a result of syncing, and the instant
|
|
|
|
// maxuid upping was prevented by the presence of actually new messages
|
|
|
|
if (svars->maxuid[1-t] < tmsg->uid)
|
|
|
|
svars->maxuid[1-t] = tmsg->uid;
|
2020-07-08 12:37:57 +00:00
|
|
|
if (!(srec->status & S_PENDING))
|
|
|
|
continue; // Nothing to do - the message is paired or expired
|
|
|
|
// Propagation was scheduled, but we got interrupted
|
2019-12-29 13:37:53 +00:00
|
|
|
debug( "unpropagated old message %u\n", tmsg->uid );
|
2020-07-08 12:37:57 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:26:11 +00:00
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && (tmsg->flags & F_DELETED)) {
|
2020-07-08 12:37:57 +00:00
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing - would be expunged anyway" );
|
|
|
|
tmsg->srec = NULL;
|
|
|
|
srec->status = S_DEAD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(svars->chan->ops[t] & OP_NEW))
|
|
|
|
continue;
|
2020-07-20 18:53:21 +00:00
|
|
|
if (tmsg->uid <= svars->maxuid[1-t]) {
|
2020-07-08 12:37:57 +00:00
|
|
|
// The message should be already paired. It's not, so it was:
|
|
|
|
// - previously paired, but the entry was expired and pruned => ignore
|
|
|
|
// - attempted, but failed => ignore (the wisdom of this is debatable)
|
|
|
|
// - ignored, as it would have been expunged anyway => ignore (even if undeleted)
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-20 18:53:21 +00:00
|
|
|
svars->maxuid[1-t] = tmsg->uid;
|
2020-07-08 12:37:57 +00:00
|
|
|
debug( "new message %u\n", tmsg->uid );
|
|
|
|
|
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && (tmsg->flags & F_DELETED)) {
|
|
|
|
debug( "-> ignoring - would be expunged anyway\n" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
srec = nfcalloc( sizeof(*srec) );
|
|
|
|
*svars->srecadd = srec;
|
|
|
|
svars->srecadd = &srec->next;
|
|
|
|
svars->nsrecs++;
|
|
|
|
srec->status = S_PENDING;
|
|
|
|
srec->uid[1-t] = tmsg->uid;
|
|
|
|
srec->msg[1-t] = tmsg;
|
|
|
|
tmsg->srec = srec;
|
|
|
|
JLOG( "+ %u %u", (srec->uid[F], srec->uid[N]), "fresh" );
|
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!(tmsg->flags & F_FLAGGED) && tmsg->size > svars->chan->stores[t]->max_size &&
|
|
|
|
!(srec->wstate & W_UPGRADE) && !(srec->status & (S_DUMMY(F)|S_DUMMY(N)))) {
|
|
|
|
srec->status |= S_DUMMY(t);
|
|
|
|
JLOG( "_ %u %u", (srec->uid[F], srec->uid[N]), "placeholder only - too big" );
|
2013-11-24 17:26:11 +00:00
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
any_new[t] = 1;
|
2013-11-24 17:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((svars->chan->ops[N] & (OP_NEW|OP_RENEW|OP_FLAGS)) && svars->chan->max_messages) {
|
|
|
|
// Note: When this branch is entered, we have loaded all near side messages.
|
2013-11-10 18:57:08 +00:00
|
|
|
/* Expire excess messages. Important (flagged, unread, or unpropagated) messages
|
|
|
|
* older than the first not expired message are not counted towards the total. */
|
2013-11-23 11:01:23 +00:00
|
|
|
debug( "preparing message expiration\n" );
|
2020-07-16 12:47:30 +00:00
|
|
|
// Due to looping only over the far side, we completely ignore unpaired
|
|
|
|
// near-side messages. This is correct, as we cannot expire them without
|
|
|
|
// data loss anyway; consequently, we also don't count them.
|
|
|
|
// Note that we also ignore near-side messages we're currently propagating,
|
|
|
|
// which delays expiration of some messages by one cycle. Otherwise, we'd have
|
|
|
|
// to sequence flag propagation after message propagation to avoid a race
|
|
|
|
// with 3rd-party expunging, and that seems unreasonably expensive.
|
2013-11-23 11:01:23 +00:00
|
|
|
alive = 0;
|
2020-07-16 12:47:30 +00:00
|
|
|
for (tmsg = svars->msgs[F]; tmsg; tmsg = tmsg->next) {
|
2013-05-20 16:53:22 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
2020-07-16 12:47:30 +00:00
|
|
|
// We ignore unpaired far-side messages, as there is obviously nothing
|
|
|
|
// to expire in the first place.
|
|
|
|
if (!(srec = tmsg->srec))
|
|
|
|
continue;
|
|
|
|
if (!(srec->status & S_PENDING)) {
|
|
|
|
if (!srec->msg[N])
|
|
|
|
continue; // Already expired or skipped.
|
|
|
|
nflags = (srec->msg[N]->flags | srec->aflags[N]) & ~srec->dflags[N];
|
2013-11-23 11:01:23 +00:00
|
|
|
} else {
|
2020-07-16 12:47:30 +00:00
|
|
|
nflags = tmsg->flags;
|
2013-11-23 11:01:23 +00:00
|
|
|
}
|
2020-07-16 12:47:30 +00:00
|
|
|
if (!(nflags & F_DELETED) || (srec->status & (S_EXPIRE|S_EXPIRED)))
|
|
|
|
// The message is not deleted, or it is, but only due to being expired.
|
2013-11-30 12:03:12 +00:00
|
|
|
alive++;
|
|
|
|
}
|
2013-11-23 11:01:23 +00:00
|
|
|
todel = alive - svars->chan->max_messages;
|
|
|
|
debug( "%d alive messages, %d excess - expiring\n", alive, todel );
|
2013-11-24 19:26:33 +00:00
|
|
|
alive = 0;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
for (tmsg = svars->msgs[F]; tmsg; tmsg = tmsg->next) {
|
2020-07-16 11:08:29 +00:00
|
|
|
if (tmsg->status & M_DEAD)
|
|
|
|
continue;
|
2020-07-16 12:47:30 +00:00
|
|
|
if (!(srec = tmsg->srec))
|
|
|
|
continue;
|
|
|
|
if (!(srec->status & S_PENDING)) {
|
|
|
|
if (!srec->msg[N])
|
|
|
|
continue;
|
|
|
|
nflags = (srec->msg[N]->flags | srec->aflags[N]) & ~srec->dflags[N];
|
|
|
|
} else {
|
2013-11-30 12:03:12 +00:00
|
|
|
nflags = tmsg->flags;
|
2020-07-16 12:47:30 +00:00
|
|
|
}
|
|
|
|
if (!(nflags & F_DELETED) || (srec->status & (S_EXPIRE|S_EXPIRED))) {
|
|
|
|
if ((nflags & F_FLAGGED) ||
|
|
|
|
!((nflags & F_SEEN) || ((void)(todel > 0 && alive++), svars->chan->expire_unread > 0))) {
|
|
|
|
// Important messages are always fetched/kept.
|
|
|
|
debug( " pair(%u,%u) is important\n", srec->uid[F], srec->uid[N] );
|
|
|
|
todel--;
|
|
|
|
} else if (todel > 0 ||
|
|
|
|
((srec->status & (S_EXPIRE|S_EXPIRED)) == (S_EXPIRE|S_EXPIRED)) ||
|
|
|
|
((srec->status & (S_EXPIRE|S_EXPIRED)) && (srec->msg[N]->flags & F_DELETED))) {
|
|
|
|
/* The message is excess or was already (being) expired. */
|
|
|
|
srec->wstate |= W_NEXPIRE;
|
|
|
|
debug( " pair(%u,%u) expired\n", srec->uid[F], srec->uid[N] );
|
|
|
|
if (svars->maxxfuid < srec->uid[F])
|
|
|
|
svars->maxxfuid = srec->uid[F];
|
|
|
|
todel--;
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
debug( "%d excess messages remain\n", todel );
|
2020-07-08 15:27:37 +00:00
|
|
|
if (svars->chan->expire_unread < 0 && alive * 2 > svars->chan->max_messages) {
|
2013-11-24 19:26:33 +00:00
|
|
|
error( "%s: %d unread messages in excess of MaxMessages (%d).\n"
|
|
|
|
"Please set ExpireUnread to decide outcome. Skipping mailbox.\n",
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
svars->orig_name[N], alive, svars->chan->max_messages );
|
2013-11-24 19:26:33 +00:00
|
|
|
svars->ret |= SYNC_FAIL;
|
|
|
|
cancel_sync( svars );
|
|
|
|
return;
|
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
2013-11-30 12:03:12 +00:00
|
|
|
if (srec->status & S_DEAD)
|
2006-02-02 17:03:01 +00:00
|
|
|
continue;
|
2017-04-02 15:21:39 +00:00
|
|
|
if (!(srec->status & S_PENDING)) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->msg[N])
|
2013-11-30 12:03:12 +00:00
|
|
|
continue;
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar nex = (srec->wstate / W_NEXPIRE) & 1;
|
2013-11-30 12:03:12 +00:00
|
|
|
if (nex != ((srec->status / S_EXPIRED) & 1)) {
|
|
|
|
/* The record needs a state change ... */
|
|
|
|
if (nex != ((srec->status / S_EXPIRE) & 1)) {
|
|
|
|
/* ... and we need to start a transaction. */
|
|
|
|
srec->status = (srec->status & ~S_EXPIRE) | (nex * S_EXPIRE);
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "expire %u - begin", nex );
|
2013-11-30 12:03:12 +00:00
|
|
|
} else {
|
|
|
|
/* ... but the "right" transaction is already pending. */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "-> pair(%u,%u): expire %u (pending)\n", srec->uid[F], srec->uid[N], nex );
|
2013-11-30 12:03:12 +00:00
|
|
|
}
|
2013-11-17 16:36:08 +00:00
|
|
|
} else {
|
2013-11-30 12:03:12 +00:00
|
|
|
/* Note: the "wrong" transaction may be pending here,
|
2017-04-01 15:02:22 +00:00
|
|
|
* e.g.: W_NEXPIRE = 0, S_EXPIRE = 1, S_EXPIRED = 0. */
|
2013-11-17 16:36:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-04-01 15:02:22 +00:00
|
|
|
if (srec->wstate & W_NEXPIRE) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "= %u %u", (srec->uid[F], srec->uid[N]), "expire unborn" );
|
2017-04-02 12:04:43 +00:00
|
|
|
// If we have so many new messages that some of them are instantly expired,
|
|
|
|
// but some are still propagated because they are important, we need to
|
|
|
|
// ensure explicitly that the bulk fetch limit is upped.
|
2020-07-20 18:53:21 +00:00
|
|
|
if (svars->maxxfuid < srec->uid[F])
|
|
|
|
svars->maxxfuid = srec->uid[F];
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
srec->msg[F]->srec = NULL;
|
2013-11-30 12:03:12 +00:00
|
|
|
srec->status = S_DEAD;
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
sync_ref( svars );
|
|
|
|
|
2006-02-02 17:03:01 +00:00
|
|
|
debug( "synchronizing flags\n" );
|
2013-11-24 17:26:11 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (srec->status & S_DEAD)
|
2006-02-02 17:03:01 +00:00
|
|
|
continue;
|
|
|
|
for (t = 0; t < 2; t++) {
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!srec->uid[t])
|
|
|
|
continue;
|
2006-02-02 17:03:01 +00:00
|
|
|
aflags = srec->aflags[t];
|
|
|
|
dflags = srec->dflags[t];
|
2019-12-29 13:37:53 +00:00
|
|
|
if (srec->wstate & (W_DELETE|W_PURGE)) {
|
2013-11-24 14:58:32 +00:00
|
|
|
if (!aflags) {
|
2019-12-29 13:37:53 +00:00
|
|
|
// This deletion propagation goes the other way round, or
|
|
|
|
// this deletion of a dummy happens on the other side.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!srec->msg[t] && (svars->opts[t] & OPEN_OLD)) {
|
|
|
|
// The message disappeared. This can happen, because the wstate may
|
|
|
|
// come from the journal, and things could have happened meanwhile.
|
2013-11-24 14:58:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-17 16:36:08 +00:00
|
|
|
/* The trigger is an expiration transaction being ongoing ... */
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if ((t == N) && ((shifted_bit(srec->status, S_EXPIRE, S_EXPIRED) ^ srec->status) & S_EXPIRED)) {
|
2013-11-17 16:36:08 +00:00
|
|
|
/* ... but the actual action derives from the wanted state. */
|
2017-04-01 15:02:22 +00:00
|
|
|
if (srec->wstate & W_NEXPIRE)
|
2013-11-24 14:58:32 +00:00
|
|
|
aflags |= F_DELETED;
|
|
|
|
else
|
|
|
|
dflags |= F_DELETED;
|
|
|
|
}
|
2006-02-02 17:03:01 +00:00
|
|
|
}
|
2006-03-21 15:53:43 +00:00
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) && (((srec->msg[t] ? srec->msg[t]->flags : 0) | aflags) & ~dflags & F_DELETED) &&
|
|
|
|
(!svars->ctx[t]->conf->trash || svars->ctx[t]->conf->trash_only_new))
|
2006-02-02 17:03:01 +00:00
|
|
|
{
|
2013-11-02 19:06:08 +00:00
|
|
|
/* If the message is going to be expunged, don't propagate anything but the deletion. */
|
2006-02-02 17:03:01 +00:00
|
|
|
srec->aflags[t] &= F_DELETED;
|
|
|
|
aflags &= F_DELETED;
|
|
|
|
srec->dflags[t] = dflags = 0;
|
|
|
|
}
|
|
|
|
if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS)) {
|
2013-11-02 19:06:08 +00:00
|
|
|
/* If we know the target message's state, optimize away non-changes. */
|
2006-02-02 17:03:01 +00:00
|
|
|
aflags &= ~srec->msg[t]->flags;
|
|
|
|
dflags &= srec->msg[t]->flags;
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
if (aflags | dflags) {
|
2015-03-28 16:26:08 +00:00
|
|
|
flags_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->flags_pending[t]++;
|
2006-03-21 20:03:21 +00:00
|
|
|
fv = nfmalloc( sizeof(*fv) );
|
|
|
|
fv->aux = AUX;
|
|
|
|
fv->srec = srec;
|
|
|
|
fv->aflags = aflags;
|
|
|
|
fv->dflags = dflags;
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->set_msg_flags( svars->ctx[t], srec->msg[t], srec->uid[t], aflags, dflags, flags_set, fv );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
} else
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set_p2( svars, srec, t );
|
2000-12-21 18:16:44 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
for (t = 0; t < 2; t++) {
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->commit_cmds( svars->ctx[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->state[t] |= ST_SENT_FLAGS;
|
2013-12-11 15:13:49 +00:00
|
|
|
msgs_flags_set( svars, t );
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
2013-11-23 14:55:02 +00:00
|
|
|
|
|
|
|
debug( "propagating new messages\n" );
|
2019-11-25 19:55:41 +00:00
|
|
|
if (UseFSync && svars->jfp)
|
2013-11-02 20:41:48 +00:00
|
|
|
fdatasync( fileno( svars->jfp ) );
|
2013-11-23 14:55:02 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
2019-11-25 19:55:41 +00:00
|
|
|
if (any_new[t]) {
|
|
|
|
svars->finduid[t] = svars->drv[t]->get_uidnext( svars->ctx[t] );
|
|
|
|
JLOG( "F %d %u", (t, svars->finduid[t]), "save UIDNEXT of %s", str_fn[t] );
|
|
|
|
svars->new_msgs[t] = svars->msgs[1-t];
|
|
|
|
} else {
|
|
|
|
svars->state[t] |= ST_SENT_NEW;
|
|
|
|
}
|
2013-11-23 14:55:02 +00:00
|
|
|
msgs_copied( svars, t );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2013-11-23 14:55:02 +00:00
|
|
|
}
|
2013-12-11 15:13:49 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_copied( int sts, uint uid, copy_vars_t *vars )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_CANCEL_RET;
|
2019-12-29 11:31:10 +00:00
|
|
|
sync_rec_t *srec = vars->srec;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case SYNC_OK:
|
2019-12-29 13:37:53 +00:00
|
|
|
if (!(srec->wstate & W_UPGRADE) && vars->msg->flags != srec->flags) {
|
2019-12-29 11:34:36 +00:00
|
|
|
srec->flags = vars->msg->flags;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "* %u %u %u", (srec->uid[F], srec->uid[N], srec->flags), "%sed with flags", str_hl[t] );
|
2019-12-29 11:34:36 +00:00
|
|
|
}
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!uid) { // Stored to a non-UIDPLUS mailbox
|
2013-11-02 11:57:39 +00:00
|
|
|
svars->state[t] |= ST_FIND_NEW;
|
2017-03-11 12:20:53 +00:00
|
|
|
} else {
|
2019-12-29 13:41:45 +00:00
|
|
|
ASSIGN_UID( srec, t, uid, "%sed message", str_hl[t] );
|
2017-03-11 12:20:53 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
case SYNC_NOGOOD:
|
2019-12-29 11:31:10 +00:00
|
|
|
srec->status = S_DEAD;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "%s failed", str_hl[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cancel_sync( svars );
|
|
|
|
free( vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
new_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->new_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
msgs_copied( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 16:44:43 +00:00
|
|
|
static void msgs_found_new( int sts, message_t *msgs, void *aux );
|
2011-04-10 11:06:07 +00:00
|
|
|
static void msgs_new_done( sync_vars_t *svars, int t );
|
2012-07-29 21:14:48 +00:00
|
|
|
static void sync_close( sync_vars_t *svars, int t );
|
2005-12-28 10:02:22 +00:00
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msgs_copied( sync_vars_t *svars, int t )
|
|
|
|
{
|
2015-02-15 17:13:05 +00:00
|
|
|
message_t *tmsg;
|
|
|
|
sync_rec_t *srec;
|
|
|
|
copy_vars_t *cv;
|
|
|
|
|
|
|
|
if (svars->state[t] & ST_SENDING_NEW)
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:25:30 +00:00
|
|
|
sync_ref( svars );
|
|
|
|
|
2015-02-15 17:13:05 +00:00
|
|
|
if (!(svars->state[t] & ST_SENT_NEW)) {
|
|
|
|
for (tmsg = svars->new_msgs[t]; tmsg; tmsg = tmsg->next) {
|
2017-04-02 15:21:39 +00:00
|
|
|
if ((srec = tmsg->srec) && (srec->status & S_PENDING)) {
|
2017-03-19 12:46:03 +00:00
|
|
|
if (svars->drv[t]->get_memory_usage( svars->ctx[t] ) >= BufferLimit) {
|
2015-02-15 17:13:05 +00:00
|
|
|
svars->new_msgs[t] = tmsg;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-04-02 15:21:39 +00:00
|
|
|
for (uint i = 0; i < TUIDL; i++) {
|
|
|
|
uchar c = arc4_getbyte() & 0x3f;
|
2019-07-28 20:10:21 +00:00
|
|
|
srec->tuid[i] = (char)(c < 26 ? c + 'A' : c < 52 ? c + 'a' - 26 : c < 62 ? c + '0' - 52 : c == 62 ? '+' : '/');
|
2017-04-02 15:21:39 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "# %u %u %." stringify(TUIDL) "s", (srec->uid[F], srec->uid[N], srec->tuid), "%sing message", str_hl[t] );
|
2015-03-28 16:26:08 +00:00
|
|
|
new_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->new_pending[t]++;
|
2015-02-15 17:13:05 +00:00
|
|
|
svars->state[t] |= ST_SENDING_NEW;
|
|
|
|
cv = nfmalloc( sizeof(*cv) );
|
|
|
|
cv->cb = msg_copied;
|
|
|
|
cv->aux = AUX;
|
|
|
|
cv->srec = srec;
|
|
|
|
cv->msg = tmsg;
|
2019-12-29 13:37:53 +00:00
|
|
|
cv->minimal = (srec->status & S_DUMMY(t));
|
2015-02-15 17:13:05 +00:00
|
|
|
copy_msg( cv );
|
|
|
|
svars->state[t] &= ~ST_SENDING_NEW;
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svars->state[t] |= ST_SENT_NEW;
|
|
|
|
}
|
|
|
|
|
2015-03-28 16:26:08 +00:00
|
|
|
if (svars->new_pending[t])
|
2015-02-15 17:13:05 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-12-11 15:25:30 +00:00
|
|
|
sync_close( svars, 1-t );
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2013-11-02 19:47:20 +00:00
|
|
|
|
2013-11-02 11:57:39 +00:00
|
|
|
if (svars->state[t] & ST_FIND_NEW) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "finding just copied messages on %s\n", str_fn[t] );
|
2019-12-29 10:52:26 +00:00
|
|
|
svars->drv[t]->find_new_msgs( svars->ctx[t], svars->finduid[t], msgs_found_new, AUX );
|
2011-04-10 11:06:07 +00:00
|
|
|
} else {
|
|
|
|
msgs_new_done( svars, t );
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
2013-12-11 15:25:30 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-26 16:44:43 +00:00
|
|
|
msgs_found_new( int sts, message_t *msgs, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2011-04-10 11:06:07 +00:00
|
|
|
SVARS_CHECK_RET;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "matching just copied messages on %s\n", str_fn[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
warn( "Warning: cannot find newly stored messages on %s.\n", str_fn[t] );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-26 16:44:43 +00:00
|
|
|
match_tuids( svars, t, msgs );
|
2011-04-10 11:06:07 +00:00
|
|
|
msgs_new_done( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
msgs_new_done( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
svars->state[t] |= ST_FOUND_NEW;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set( int sts, void *aux )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_RET_VARS(flag_vars_t);
|
2019-12-29 11:31:10 +00:00
|
|
|
sync_rec_t *srec = vars->srec;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case DRV_OK:
|
|
|
|
if (vars->aflags & F_DELETED)
|
2019-12-29 11:31:10 +00:00
|
|
|
srec->wstate |= W_DEL(t);
|
2006-03-21 20:03:21 +00:00
|
|
|
else if (vars->dflags & F_DELETED)
|
2019-12-29 11:31:10 +00:00
|
|
|
srec->wstate &= ~W_DEL(t);
|
|
|
|
flags_set_p2( svars, srec, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
flags_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->flags_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
msgs_flags_set( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-24 14:58:32 +00:00
|
|
|
flags_set_p2( sync_vars_t *svars, sync_rec_t *srec, int t )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2017-04-01 15:02:22 +00:00
|
|
|
if (srec->wstate & W_DELETE) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "%c %u %u 0", ("><"[t], srec->uid[F], srec->uid[N]), "%sed deletion", str_hl[t] );
|
2013-11-24 14:58:32 +00:00
|
|
|
srec->uid[1-t] = 0;
|
|
|
|
} else {
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar nflags = (srec->flags | srec->aflags[t]) & ~srec->dflags[t];
|
2013-11-24 14:58:32 +00:00
|
|
|
if (srec->flags != nflags) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "* %u %u %u", (srec->uid[F], srec->uid[N], nflags), "%sed flags; were %u", (str_hl[t], srec->flags) );
|
2013-11-24 14:58:32 +00:00
|
|
|
srec->flags = nflags;
|
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (t == N) {
|
2019-07-28 19:24:17 +00:00
|
|
|
uchar nex = (srec->wstate / W_NEXPIRE) & 1;
|
2013-11-24 14:58:32 +00:00
|
|
|
if (nex != ((srec->status / S_EXPIRED) & 1)) {
|
|
|
|
srec->status = (srec->status & ~S_EXPIRED) | (nex * S_EXPIRED);
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "expired %d - commit", nex );
|
2013-11-24 14:58:32 +00:00
|
|
|
} else if (nex != ((srec->status / S_EXPIRE) & 1)) {
|
|
|
|
srec->status = (srec->status & ~S_EXPIRE) | (nex * S_EXPIRE);
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "~ %u %u %u", (srec->uid[F], srec->uid[N], srec->status), "expire %d - cancel", nex );
|
2013-11-24 14:58:32 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 20:23:39 +00:00
|
|
|
typedef struct {
|
|
|
|
void *aux;
|
|
|
|
message_t *msg;
|
|
|
|
} trash_vars_t;
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void msg_trashed( int sts, void *aux );
|
2017-03-21 19:05:29 +00:00
|
|
|
static void msg_rtrashed( int sts, uint uid, copy_vars_t *vars );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msgs_flags_set( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
message_t *tmsg;
|
2016-11-04 20:23:39 +00:00
|
|
|
trash_vars_t *tv;
|
2006-03-21 20:03:21 +00:00
|
|
|
copy_vars_t *cv;
|
|
|
|
|
2015-03-28 16:26:08 +00:00
|
|
|
if (!(svars->state[t] & ST_SENT_FLAGS) || svars->flags_pending[t])
|
2013-12-11 15:13:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sync_ref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) &&
|
|
|
|
(svars->ctx[t]->conf->trash || (svars->ctx[1-t]->conf->trash && svars->ctx[1-t]->conf->trash_remote_new))) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "trashing on %s\n", str_fn[t] );
|
2017-03-24 17:09:40 +00:00
|
|
|
for (tmsg = svars->msgs[t]; tmsg; tmsg = tmsg->next)
|
2017-03-21 19:05:29 +00:00
|
|
|
if ((tmsg->flags & F_DELETED) && !find_uint_array( svars->trashed_msgs[t].array, tmsg->uid ) &&
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
(t == F || !tmsg->srec || !(tmsg->srec->status & (S_EXPIRE|S_EXPIRED)))) {
|
2006-03-21 20:03:21 +00:00
|
|
|
if (svars->ctx[t]->conf->trash) {
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!svars->ctx[t]->conf->trash_only_new || !tmsg->srec || (tmsg->srec->status & (S_PENDING | S_SKIPPED))) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "%s: trashing message %u\n", str_fn[t], tmsg->uid );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]++;
|
2016-11-04 20:23:39 +00:00
|
|
|
tv = nfmalloc( sizeof(*tv) );
|
|
|
|
tv->aux = AUX;
|
|
|
|
tv->msg = tmsg;
|
|
|
|
svars->drv[t]->trash_msg( svars->ctx[t], tmsg, msg_trashed, tv );
|
2013-12-11 15:13:49 +00:00
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
} else
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "%s: not trashing message %u - not new\n", str_fn[t], tmsg->uid );
|
2006-03-21 20:03:21 +00:00
|
|
|
} else {
|
2017-03-11 12:20:53 +00:00
|
|
|
if (!tmsg->srec || (tmsg->srec->status & (S_PENDING | S_SKIPPED))) {
|
2013-05-11 08:12:33 +00:00
|
|
|
if (tmsg->size <= svars->ctx[1-t]->conf->max_size) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "%s: remote trashing message %u\n", str_fn[t], tmsg->uid );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_total[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]++;
|
2006-03-21 20:03:21 +00:00
|
|
|
cv = nfmalloc( sizeof(*cv) );
|
|
|
|
cv->cb = msg_rtrashed;
|
2012-09-22 15:35:39 +00:00
|
|
|
cv->aux = INV_AUX;
|
2019-07-28 18:50:31 +00:00
|
|
|
cv->srec = NULL;
|
2006-03-21 20:03:21 +00:00
|
|
|
cv->msg = tmsg;
|
2019-12-29 13:37:53 +00:00
|
|
|
cv->minimal = 0;
|
2013-12-11 15:13:49 +00:00
|
|
|
copy_msg( cv );
|
|
|
|
if (check_cancel( svars ))
|
|
|
|
goto out;
|
2006-03-21 20:03:21 +00:00
|
|
|
} else
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "%s: not remote trashing message %u - too big\n", str_fn[t], tmsg->uid );
|
2006-03-21 20:03:21 +00:00
|
|
|
} else
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "%s: not remote trashing message %u - not new\n", str_fn[t], tmsg->uid );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svars->state[t] |= ST_SENT_TRASH;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2013-12-11 15:13:49 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
sync_deref( svars );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
msg_trashed( int sts, void *aux )
|
|
|
|
{
|
2016-11-04 20:23:39 +00:00
|
|
|
trash_vars_t *vars = (trash_vars_t *)aux;
|
2012-06-17 12:52:46 +00:00
|
|
|
DECL_SVARS;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
if (sts == DRV_MSG_BAD)
|
|
|
|
sts = DRV_BOX_BAD;
|
2016-11-04 20:23:39 +00:00
|
|
|
if (check_ret( sts, vars->aux ))
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2016-11-04 20:23:39 +00:00
|
|
|
INIT_SVARS(vars->aux);
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "T %d %u", (t, vars->msg->uid), "trashed on %s", str_fn[t] );
|
2016-11-04 20:23:39 +00:00
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2017-03-21 19:05:29 +00:00
|
|
|
msg_rtrashed( int sts, uint uid ATTR_UNUSED, copy_vars_t *vars )
|
2006-03-21 20:03:21 +00:00
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_CANCEL_RET;
|
2006-03-21 20:03:21 +00:00
|
|
|
switch (sts) {
|
|
|
|
case SYNC_OK:
|
|
|
|
case SYNC_NOGOOD: /* the message is gone or heavily busted */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cancel_sync( svars );
|
|
|
|
free( vars );
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
2012-09-22 15:35:39 +00:00
|
|
|
t ^= 1;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
JLOG( "T %d %u", (t, vars->msg->uid), "trashed remotely on %s", str_fn[1-t] );
|
2016-11-04 20:23:39 +00:00
|
|
|
free( vars );
|
2015-03-28 16:26:08 +00:00
|
|
|
trash_done[t]++;
|
|
|
|
stats();
|
|
|
|
svars->trash_pending[t]--;
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_close( svars, t );
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void box_closed( int sts, void *aux );
|
2006-03-21 20:03:21 +00:00
|
|
|
static void box_closed_p2( sync_vars_t *svars, int t );
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_close( sync_vars_t *svars, int t )
|
|
|
|
{
|
2015-03-28 16:26:08 +00:00
|
|
|
if ((~svars->state[t] & (ST_FOUND_NEW|ST_SENT_TRASH)) || svars->trash_pending[t] ||
|
|
|
|
!(svars->state[1-t] & ST_SENT_NEW) || svars->new_pending[1-t])
|
2013-12-11 15:25:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (svars->state[t] & ST_CLOSING)
|
2012-07-29 21:14:48 +00:00
|
|
|
return;
|
2013-12-11 15:25:30 +00:00
|
|
|
svars->state[t] |= ST_CLOSING;
|
2006-03-21 20:03:21 +00:00
|
|
|
|
|
|
|
if ((svars->chan->ops[t] & OP_EXPUNGE) /*&& !(svars->state[t] & ST_TRASH_BAD)*/) {
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
debug( "expunging %s\n", str_fn[t] );
|
2014-12-27 21:13:24 +00:00
|
|
|
svars->drv[t]->close_box( svars->ctx[t], box_closed, AUX );
|
2012-07-29 21:14:48 +00:00
|
|
|
} else {
|
|
|
|
box_closed_p2( svars, t );
|
2006-12-09 10:39:30 +00:00
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 21:14:48 +00:00
|
|
|
static void
|
2006-03-21 20:03:21 +00:00
|
|
|
box_closed( int sts, void *aux )
|
|
|
|
{
|
2012-06-17 12:52:46 +00:00
|
|
|
SVARS_CHECK_RET;
|
2006-03-21 20:03:21 +00:00
|
|
|
svars->state[t] |= ST_DID_EXPUNGE;
|
|
|
|
box_closed_p2( svars, t );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
box_closed_p2( sync_vars_t *svars, int t )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec;
|
|
|
|
|
|
|
|
svars->state[t] |= ST_CLOSED;
|
|
|
|
if (!(svars->state[1-t] & ST_CLOSED))
|
|
|
|
return;
|
|
|
|
|
2017-04-02 12:04:43 +00:00
|
|
|
// All the journalling done in this function is merely for the autotest -
|
|
|
|
// the operations are idempotent, and we're about to commit the new state
|
|
|
|
// right afterwards anyway.
|
|
|
|
|
2020-07-20 18:53:21 +00:00
|
|
|
for (t = 0; t < 2; t++) {
|
|
|
|
// Committing maxuid is delayed until all messages were propagated, to
|
|
|
|
// ensure that all pending messages are still loaded next time in case
|
|
|
|
// of interruption - in particular skipping big messages would otherwise
|
|
|
|
// up the limit too early.
|
2019-11-25 19:55:41 +00:00
|
|
|
if (svars->maxuid[t] != svars->oldmaxuid[t])
|
|
|
|
JLOG( "N %d %u", (t, svars->maxuid[t]), "up maxuid of %s", str_fn[t] );
|
2020-07-20 18:53:21 +00:00
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (((svars->state[F] | svars->state[N]) & ST_DID_EXPUNGE) || svars->chan->max_messages) {
|
2013-11-30 12:03:12 +00:00
|
|
|
debug( "purging obsolete entries\n" );
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = srec->next) {
|
2004-03-27 16:07:20 +00:00
|
|
|
if (srec->status & S_DEAD)
|
|
|
|
continue;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
if (!srec->uid[N] || ((srec->wstate & W_DEL(N)) && (svars->state[N] & ST_DID_EXPUNGE))) {
|
|
|
|
if (!srec->uid[F] || ((srec->wstate & W_DEL(F)) && (svars->state[F] & ST_DID_EXPUNGE)) ||
|
|
|
|
((srec->status & S_EXPIRED) && svars->maxuid[F] >= srec->uid[F] && svars->maxxfuid >= srec->uid[F])) {
|
|
|
|
JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing" );
|
2004-03-27 16:07:20 +00:00
|
|
|
srec->status = S_DEAD;
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
} else if (srec->uid[N]) {
|
|
|
|
JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" );
|
|
|
|
srec->uid[N] = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
} else if (srec->uid[F] && ((srec->wstate & W_DEL(F)) && (svars->state[F] & ST_DID_EXPUNGE))) {
|
|
|
|
JLOG( "< %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" );
|
|
|
|
srec->uid[F] = 0;
|
2004-03-27 16:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2001-10-31 19:50:01 +00:00
|
|
|
|
2017-04-02 12:04:43 +00:00
|
|
|
// This is just an optimization, so it needs no journaling of intermediate states.
|
|
|
|
// However, doing it before the entry purge would require ensuring that the
|
|
|
|
// exception list includes all relevant messages.
|
2019-11-25 19:55:41 +00:00
|
|
|
if (svars->maxxfuid != svars->oldmaxxfuid)
|
|
|
|
JLOG( "! %u", svars->maxxfuid, "max expired UID on far side" );
|
2017-04-02 12:04:43 +00:00
|
|
|
|
2014-12-27 22:13:45 +00:00
|
|
|
save_state( svars );
|
2002-12-28 04:12:07 +00:00
|
|
|
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_bail( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail( sync_vars_t *svars )
|
|
|
|
{
|
|
|
|
sync_rec_t *srec, *nsrec;
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
free( svars->trashed_msgs[F].array.data );
|
|
|
|
free( svars->trashed_msgs[N].array.data );
|
2006-03-21 15:53:43 +00:00
|
|
|
for (srec = svars->srecs; srec; srec = nsrec) {
|
2004-03-27 16:07:20 +00:00
|
|
|
nsrec = srec->next;
|
|
|
|
free( srec );
|
|
|
|
}
|
2014-12-27 22:50:31 +00:00
|
|
|
if (svars->lfd >= 0) {
|
|
|
|
unlink( svars->lname );
|
|
|
|
close( svars->lfd );
|
|
|
|
}
|
2006-03-21 20:03:21 +00:00
|
|
|
sync_bail2( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail2( sync_vars_t *svars )
|
|
|
|
{
|
2006-03-21 15:53:43 +00:00
|
|
|
free( svars->lname );
|
|
|
|
free( svars->nname );
|
|
|
|
free( svars->jname );
|
|
|
|
free( svars->dname );
|
2012-08-18 11:58:14 +00:00
|
|
|
sync_bail3( svars );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_bail3( sync_vars_t *svars )
|
|
|
|
{
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
free( svars->box_name[F] );
|
|
|
|
free( svars->box_name[N] );
|
2012-07-29 21:14:48 +00:00
|
|
|
sync_deref( svars );
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2004-03-27 16:07:20 +00:00
|
|
|
|
2013-12-11 15:13:49 +00:00
|
|
|
static void
|
|
|
|
sync_deref( sync_vars_t *svars )
|
2012-07-29 21:14:48 +00:00
|
|
|
{
|
|
|
|
if (!--svars->ref_count) {
|
|
|
|
void (*cb)( int sts, void *aux ) = svars->cb;
|
|
|
|
void *aux = svars->aux;
|
|
|
|
int ret = svars->ret;
|
|
|
|
free( svars );
|
|
|
|
cb( ret, aux );
|
|
|
|
}
|
|
|
|
}
|