#!perl
use Cassandane::Tiny;

sub test_sync_reset_nolegacy
    :DelayedDelete :min_version_3_5 :NoMailboxLegacyDirs
    :needs_component_replication
{
    my ($self) = @_;

    my $adminstore = $self->{adminstore};
    my $admintalk = $adminstore->get_client();

    my $inbox = "user.magicuser";
    my $subfolder = "$inbox.foo";

    $admintalk->create($inbox);
    $admintalk->setacl($inbox, admin => 'lrswipkxtecdan');
    $admintalk->create($subfolder);
    $self->assert_str_equals('ok', $admintalk->get_last_completion_response());

    $adminstore->set_folder($subfolder);
    $self->make_message("Email", store => $adminstore) or die;

    # Create the search database.
    xlog $self, "Run squatter";
    $self->{instance}->run_command({cyrus => 1}, 'squatter');

    my $res = $admintalk->status($inbox, ['mailboxid']);
    my $inboxid = $res->{mailboxid}[0];
    $res = $admintalk->status($subfolder, ['mailboxid']);
    my $subid = $res->{mailboxid}[0];

    my $basedir = $self->{instance}{basedir};
    open(FH, "-|", "find", $basedir);
    my @files = grep { m{/uuid/} } <FH>;
    close(FH);

    xlog $self, "files exists";
    $self->assert(scalar grep { m{$inboxid} } @files);
    $self->assert(scalar grep { m{$subid} } @files);

    $self->{instance}->run_command({ cyrus => 1 }, 'sync_reset', '-f' => 'magicuser' );

    open(FH, "-|", "find", $basedir);
    @files = grep { m{/uuid/} } <FH>;
    close(FH);

    xlog $self, "ensure there's no files left matching either uuid!";
    $self->assert(not scalar grep { m{$inboxid} } @files);
    $self->assert(not scalar grep { m{$subid} } @files);
}
