Skip to content

Commit

Permalink
dsync: Fix syncing attributes with large values.
Browse files Browse the repository at this point in the history
This mainly meant that large Sieve scripts weren't synced properly, because
their last_change field was never deserialized, so it was set to 0.
  • Loading branch information
sirainen committed Feb 26, 2017
1 parent 39f751d commit 4d884cb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/doveadm/dsync/dsync-ibc-stream.c
Expand Up @@ -1557,16 +1557,6 @@ dsync_ibc_stream_recv_mailbox_attribute(struct dsync_ibc *_ibc,
value = dsync_deserializer_decode_get(decoder, "key");
attr->key = p_strdup(pool, value);

if (dsync_deserializer_decode_try(decoder, "stream", &value)) {
attr->value_stream = dsync_ibc_stream_input_stream(ibc);
if (dsync_ibc_stream_read_mail_stream(ibc) <= 0) {
ibc->cur_attr = attr;
return DSYNC_IBC_RECV_RET_TRYAGAIN;
}
/* already finished reading the stream */
i_assert(ibc->value_input == NULL);
} else if (dsync_deserializer_decode_try(decoder, "value", &value))
attr->value = p_strdup(pool, value);
if (dsync_deserializer_decode_try(decoder, "deleted", &value))
attr->deleted = TRUE;
if (dsync_deserializer_decode_try(decoder, "last_change", &value) &&
Expand All @@ -1580,6 +1570,20 @@ dsync_ibc_stream_recv_mailbox_attribute(struct dsync_ibc *_ibc,
return DSYNC_IBC_RECV_RET_TRYAGAIN;
}

/* NOTE: stream reading must be the last here, because reading a large
stream will be finished later by return TRYAGAIN. We need to
deserialize all the other fields before that or they'll get lost. */
if (dsync_deserializer_decode_try(decoder, "stream", &value)) {
attr->value_stream = dsync_ibc_stream_input_stream(ibc);
if (dsync_ibc_stream_read_mail_stream(ibc) <= 0) {
ibc->cur_attr = attr;
return DSYNC_IBC_RECV_RET_TRYAGAIN;
}
/* already finished reading the stream */
i_assert(ibc->value_input == NULL);
} else if (dsync_deserializer_decode_try(decoder, "value", &value))
attr->value = p_strdup(pool, value);

*attr_r = attr;
return DSYNC_IBC_RECV_RET_OK;
}
Expand Down

0 comments on commit 4d884cb

Please sign in to comment.