Skip to content

Commit

Permalink
Merge pull request #4731 from cyrusimap/mailbox-locking-refcount
Browse files Browse the repository at this point in the history
Mailbox locking refcount
  • Loading branch information
brong authored Feb 12, 2024
2 parents da14a17 + 9255220 commit 67f1d69
Show file tree
Hide file tree
Showing 37 changed files with 802 additions and 768 deletions.
9 changes: 9 additions & 0 deletions cassandane/Cassandane/Cyrus/JMAPMailbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,15 @@ sub test_mailbox_query_filteroperator
]);
$self->assert(exists $res->[0][1]{updated}{$mboxids{'Ham'}});

xlog $self, "make sure subscribing changed state";
$self->assert_not_equals($res->[0][1]{oldState}, $res->[0][1]{newState});

my $state = $res->[0][1]{oldState};
$res = $jmap->CallMethods([['Mailbox/changes', { sinceState => $state }, "R1"]]);
$self->assert_num_equals(1, scalar @{$res->[0][1]{updated}});
$self->assert_equals($res->[0][1]{updated}[0], $mboxids{'Ham'});
$self->assert_null($res->[0][1]{updatedProperties});

xlog $self, "list mailboxes filtered by parentId OR role";
$res = $jmap->CallMethods([['Mailbox/query', {
filter => {
Expand Down
51 changes: 51 additions & 0 deletions cassandane/Cassandane/Cyrus/Reconstruct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,55 @@ sub test_reconstruct_uniqueid_from_header_uuidmb
$self->assert_str_equals("user\x1fcassandane", $hash->{N});
}

sub test_downgrade_upgrade
{
my ($self) = @_;

my $talk = $self->{store}->get_client();
$self->{store}->_select();
$self->assert_num_equals(1, $talk->uid());
$self->{store}->set_fetch_attributes(qw(uid flags));

xlog $self, "Add two messages";
my %msg;
$msg{A} = $self->make_message('Message A');
$msg{A}->set_attributes(id => 1,
uid => 1,
flags => []);
$msg{B} = $self->make_message('Message B');
$msg{B}->set_attributes(id => 2,
uid => 2,
flags => []);
$self->check_messages(\%msg);

xlog $self, "Set \\Seen on message A";
my $res = $talk->store('1', '+flags', '(\\Seen)');
$self->assert_deep_equals({ '1' => { 'flags' => [ '\\Seen' ] }}, $res);
$msg{A}->set_attribute(flags => ['\\Seen']);
$self->check_messages(\%msg);

xlog $self, "Clear \\Seen on message A";
$res = $talk->store('1', '-flags', '(\\Seen)');
$self->assert_deep_equals({ '1' => { 'flags' => [] }}, $res);
$msg{A}->set_attribute(flags => []);
$self->check_messages(\%msg);

xlog $self, "Set \\Seen on message A again";
$res = $talk->store('1', '+flags', '(\\Seen)');
$self->assert_deep_equals({ '1' => { 'flags' => [ '\\Seen' ] }}, $res);
$msg{A}->set_attribute(flags => ['\\Seen']);
$self->check_messages(\%msg);

for my $version (12, 14, 16, 'max') {
xlog $self, "Set to version $version";
$self->{instance}->run_command({ cyrus => 1 }, 'reconstruct', '-V', $version);

xlog $self, "Reconnect, \\Seen should still be on message A";
$self->{store}->disconnect();
$self->{store}->connect();
$self->{store}->_select();
$self->check_messages(\%msg);
}
}

1;
2 changes: 2 additions & 0 deletions cassandane/Cassandane/Cyrus/Replication.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@ sub assert_user_sub_exists
my ($self, $instance, $user) = @_;

my $subs = $instance->get_conf_user_file($user, 'sub');
$self->assert_not_null($subs);

xlog $self, "Looking for subscriptions file $subs";

Expand All @@ -1540,6 +1541,7 @@ sub assert_user_sub_not_exists
my ($self, $instance, $user) = @_;

my $subs = $instance->get_conf_user_file($user, 'sub');
return unless $subs; # user might not exist

xlog $self, "Looking for subscriptions file $subs";

Expand Down
6 changes: 5 additions & 1 deletion cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,11 @@ sub _check_cores
my $prog = _detect_core_program($core);

xlog "Found core file $core";
xlog " from program $prog" if defined $prog;
if (defined $prog) {
xlog " from program $prog";
my ($bin) = $prog =~ m/^(\S+)/; # binary only
xlog " debug: sudo gdb $bin $core";
}
}
closedir CORES;

Expand Down
3 changes: 2 additions & 1 deletion cassandane/doc/README.deps
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ Debian/Ubuntu copypasta:
libdbd-sqlite3-perl libdigest-crc-perl libxml-simple-perl

sudo cpan Math::Int64 Mail::JMAPTalk Mail::IMAPTalk \
Net::CalDAVTalk Net::CardDAVTalk String::CRC32
Net::CalDAVTalk Net::CardDAVTalk String::CRC32 \
IO::File::Lockable

Fedora copypasta:
# there's heaps more to add here... needs to be tested
Expand Down
13 changes: 9 additions & 4 deletions cassandane/tiny-tests/JMAPCalendars/calendar-set-sharewith-acl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ sub test_calendar_set_sharewith_acl
my $jmap = $self->{jmap};
my $admin = $self->{adminstore}->get_client();

$admin->create("user.test1");
$admin->create("user.aatester");
$admin->create("user.zztester");

my $res = $jmap->CallMethods([
['Calendar/set', {
Expand Down Expand Up @@ -79,7 +80,8 @@ sub test_calendar_set_sharewith_acl
update => {
$calendarId => {
shareWith => {
test1 => $_->{rights},
aatester => $_->{rights},
zztester => $_->{rights},
},
},
},
Expand All @@ -104,8 +106,11 @@ sub test_calendar_set_sharewith_acl
), %{$_->{wantRights}});

$self->assert_deep_equals(\%mergedrights,
$res->[1][1]{list}[0]{shareWith}{test1});
$res->[1][1]{list}[0]{shareWith}{aatester});
$self->assert_deep_equals(\%mergedrights,
$res->[1][1]{list}[0]{shareWith}{zztester});
my %acl = @{$admin->getacl("user.cassandane.#calendars.$calendarId")};
$self->assert_str_equals($_->{acl}, $acl{test1});
$self->assert_str_equals($_->{acl}, $acl{aatester});
$self->assert_str_equals($_->{acl}, $acl{zztester});
}
}
6 changes: 3 additions & 3 deletions imap/autocreate.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ static int autochangesub(struct findall_data *data, void *rock)
/* ignore all user mailboxes, we only want shared */
if (mboxname_isusermailbox(name, 0)) return 0;

r = mboxlist_changesub(name, userid, auth_state, 1, 0, 1);
r = mboxlist_changesub(name, userid, auth_state, 1, 0, 1, 1);

/* unless this name was explicitly chosen, ignore the failure */
if (!was_explicit) return 0;
Expand Down Expand Up @@ -777,7 +777,7 @@ int autocreate_user(struct namespace *namespace, const char *userid)
1/*isadmin*/, userid, auth_state,
MBOXLIST_CREATE_NOTIFY, NULL/*mailboxptr*/);

if (!r) r = mboxlist_changesub(inboxname, userid, auth_state, 1, 1, 1);
if (!r) r = mboxlist_changesub(inboxname, userid, auth_state, 1, 1, 1, 1);
if (r) {
syslog(LOG_ERR, "autocreateinbox: User %s, INBOX failed. %s",
userid, error_message(r));
Expand Down Expand Up @@ -839,7 +839,7 @@ int autocreate_user(struct namespace *namespace, const char *userid)

/* subscribe if requested */
if (strarray_find(subscribe, name, 0) >= 0) {
r = mboxlist_changesub(foldername, userid, auth_state, 1, 1, 1);
r = mboxlist_changesub(foldername, userid, auth_state, 1, 1, 1, 1);
if (!r) {
numsub++;
syslog(LOG_NOTICE,"autocreateinbox: User %s, subscription to %s succeeded",
Expand Down
11 changes: 11 additions & 0 deletions imap/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,3 +1722,14 @@ EXPORTED void dlist_rename(struct dlist *dl, const char *name)
free(dl->name);
dl->name = xstrdup(name);
}

EXPORTED struct dlist *dlist_copy(const struct dlist *dl)
{
if (!dl) return NULL;
struct buf buf = BUF_INITIALIZER;
struct dlist *new = NULL;
dlist_printbuf(dl, 1, &buf);
dlist_parsemap(&new, 1, 0, buf_base(&buf), buf_len(&buf));
buf_free(&buf);
return new;
}
2 changes: 2 additions & 0 deletions imap/dlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ struct dlist *dlist_getkvchild_bykey(struct dlist *dl,

void dlist_rename(struct dlist *dl, const char *name);

struct dlist *dlist_copy(const struct dlist *dl);

const char *dlist_lastkey(void);

/* print a dlist iteratively rather than recursively */
Expand Down
2 changes: 1 addition & 1 deletion imap/http_dav.c
Original file line number Diff line number Diff line change
Expand Up @@ -4943,7 +4943,7 @@ static int meth_delete_collection(struct transaction_t *txn,
/* Unsubscribe */
r = mboxlist_changesub(txn->req_tgt.mbentry->name,
txn->req_tgt.userid,
httpd_authstate, 0 /* remove */, 0, 0);
httpd_authstate, 0 /* remove */, 0, 0, 0);
if (r) {
syslog(LOG_ERR, "mboxlist_changesub(%s, %s) failed: %s",
txn->req_tgt.mbentry->name, txn->req_tgt.userid,
Expand Down
Loading

0 comments on commit 67f1d69

Please sign in to comment.