Skip to content

Commit

Permalink
reconstruct: -M option to prefer mailboxes.db acl and uniqueid
Browse files Browse the repository at this point in the history
  • Loading branch information
brong committed Jun 22, 2015
1 parent 981c5f6 commit df06a03
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
33 changes: 24 additions & 9 deletions imap/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,16 +770,21 @@ mailbox_notifyproc_t *mailbox_get_updatenotifier(void)
return updatenotifier;
}

static void mailbox_set_uniqueid(struct mailbox *mailbox, const char *uniqueid)
{
free(mailbox->uniqueid);
mailbox->uniqueid = xstrdup(uniqueid);
mailbox->header_dirty = 1;
}

/*
* Create the unique identifier for a mailbox named 'name' with
* uidvalidity 'uidvalidity'. We use Ted Ts'o's libuuid if available,
* otherwise we use some random bits.
*/
EXPORTED void mailbox_make_uniqueid(struct mailbox *mailbox)
{
free(mailbox->uniqueid);
mailbox->uniqueid = xstrdup(makeuuid());
mailbox->header_dirty = 1;
mailbox_set_uniqueid(mailbox, makeuuid());
}

EXPORTED int mailbox_map_record(struct mailbox *mailbox, const struct index_record *record, struct buf *buf)
Expand Down Expand Up @@ -5565,9 +5570,14 @@ static int mailbox_reconstruct_uniqueid(struct mailbox *mailbox, int flags)
printf("%s: update uniqueid from header %s => %s\n", mailbox->name,
mbentry->uniqueid, mailbox->uniqueid);
if (make_changes) {
free(mbentry->uniqueid);
mbentry->uniqueid = xstrdup(mailbox->uniqueid);
r = mboxlist_update(mbentry, 0);
if ((flags & RECONSTRUCT_PREFER_MBOXLIST) && mbentry->uniqueid) {
mailbox_set_uniqueid(mailbox, mbentry->uniqueid);
}
else {
free(mbentry->uniqueid);
mbentry->uniqueid = xstrdup(mailbox->uniqueid);
r = mboxlist_update(mbentry, 0);
}
}
}

Expand All @@ -5590,9 +5600,14 @@ static int mailbox_reconstruct_acl(struct mailbox *mailbox, int flags)
mbentry_t *mbentry = NULL;
r = mboxlist_lookup(mailbox->name, &mbentry, NULL);
if (!r) {
free(mbentry->acl);
mbentry->acl = xstrdup(acl);
r = mboxlist_update(mbentry, 0);
if ((flags & RECONSTRUCT_PREFER_MBOXLIST) && mbentry->acl) {
mailbox_set_acl(mailbox, mbentry->acl, /*dirty_modseq*/0);
}
else {
free(mbentry->acl);
mbentry->acl = xstrdup(acl);
r = mboxlist_update(mbentry, 0);
}
}
mboxlist_entry_free(&mbentry);
}
Expand Down
1 change: 1 addition & 0 deletions imap/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ struct mailbox_iter {
#define RECONSTRUCT_GUID_UNLINK (1<<6)
#define RECONSTRUCT_REMOVE_ODDFILES (1<<7)
#define RECONSTRUCT_IGNORE_ODDFILES (1<<8)
#define RECONSTRUCT_PREFER_MBOXLIST (1<<9)

struct mailbox_header_cache {
const char *name; /* Name of header */
Expand Down
6 changes: 5 additions & 1 deletion imap/reconstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char **argv)

construct_hash_table(&unqid_table, 2047, 1);

while ((opt = getopt(argc, argv, "C:kp:rmfsxgGqRUoOnV:u")) != EOF) {
while ((opt = getopt(argc, argv, "C:kp:rmfsxgGqRUMoOnV:u")) != EOF) {
switch (opt) {
case 'C': /* alt config file */
alt_config = optarg;
Expand Down Expand Up @@ -213,6 +213,10 @@ int main(int argc, char **argv)
reconstruct_flags |= RECONSTRUCT_REMOVE_ODDFILES;
break;

case 'M':
reconstruct_flags |= RECONSTRUCT_PREFER_MBOXLIST;
break;

case 'V':
if (!strcasecmp(optarg, "max"))
setversion = MAILBOX_MINOR_VERSION;
Expand Down
4 changes: 4 additions & 0 deletions man/reconstruct.8
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ are using some tool which adds additional tracking files.
.B -O
Delete odd files. This is the opposite of '-o'.
.TP
.B -M
Prefer mailboxes.db over cyrus.header - will rewrite ACL or uniqueid from
the mailboxes.db into the header file rather than the other way around.
.TP
.BI \-V " version"
Change the cyrus.index minor version to a specific version. This can be
useful for upgrades or downgrades. Use a magical version of \fImax\fR to
Expand Down

0 comments on commit df06a03

Please sign in to comment.