summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5fb44bf)
This will make transparently upgrading from 1.7.0 -> 1.8.x
easier. Only a single user has access to mail_sync.sqlite3,
and R/W at the kernel-level is required for WAL, anyways.
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Backend for `lei' (local email interface). Unlike the C10K-oriented
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Backend for `lei' (local email interface). Unlike the C10K-oriented
+ my ($lei, $creat) = @_;
my $sto = $lei->{sto} // _lei_store($lei) // return;
require PublicInbox::LeiMailSync;
my $f = "$sto->{priv_eidx}->{topdir}/mail_sync.sqlite3";
my $sto = $lei->{sto} // _lei_store($lei) // return;
require PublicInbox::LeiMailSync;
my $f = "$sto->{priv_eidx}->{topdir}/mail_sync.sqlite3";
- (-f $f || $rw) ? PublicInbox::LeiMailSync->new($f) : undef;
+ (-f $f || $creat) ? PublicInbox::LeiMailSync->new($f) : undef;
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# front-end for the "lei import" sub-command
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# front-end for the "lei import" sub-command
my $kw = PublicInbox::MdirReader::flags2kw($fl);
substr($folder, 0, 0) = 'maildir:'; # add prefix
my $lse = $self->{lse} //= $self->{lei}->{sto}->search;
my $kw = PublicInbox::MdirReader::flags2kw($fl);
substr($folder, 0, 0) = 'maildir:'; # add prefix
my $lse = $self->{lse} //= $self->{lei}->{sto}->search;
- my $lms = $self->{-lms_ro} //= $self->{lei}->lms; # may be 0 or undef
+ my $lms = $self->{-lms_rw} //= $self->{lei}->lms; # may be 0 or undef
my @oidbin = $lms ? $lms->name_oidbin($folder, $bn) : ();
@oidbin > 1 and warn("W: $folder/*/$$bn not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
my @oidbin = $lms ? $lms->name_oidbin($folder, $bn) : ();
@oidbin > 1 and warn("W: $folder/*/$$bn not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
# $j = $net->net_concurrency($j); TODO
if ($lei->{opt}->{incremental} // 1) {
$net->{incremental} = 1;
# $j = $net->net_concurrency($j); TODO
if ($lei->{opt}->{incremental} // 1) {
$net->{incremental} = 1;
- $net->{-lms_ro} = $lei->lms // 0;
- if ($self->{-import_kw} && $net->{-lms_ro} &&
+ $net->{-lms_rw} = $lei->lms // 0;
+ if ($self->{-import_kw} && $net->{-lms_rw} &&
!$lei->{opt}->{'new-only'} &&
$net->{imap_order}) {
require PublicInbox::LeiImportKw;
!$lei->{opt}->{'new-only'} &&
$net->{imap_order}) {
require PublicInbox::LeiImportKw;
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# WQ worker for dealing with LeiImport IMAP flags on already-imported messages
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# WQ worker for dealing with LeiImport IMAP flags on already-imported messages
$self->{verbose} = $lei->{opt}->{verbose};
$self->{lse} = $self->{sto}->search;
$self->{over} = $self->{lse}->over;
$self->{verbose} = $lei->{opt}->{verbose};
$self->{lse} = $self->{sto}->search;
$self->{over} = $self->{lse}->over;
- $self->{-lms_ro} = $net->{-lms_ro} || die 'BUG: net->{-lms_ro} FALSE';
+ $self->{-lms_rw} = $net->{-lms_rw} || die 'BUG: net->{-lms_rw} FALSE';
$self->SUPER::ipc_atfork_child;
}
sub ck_update_kw { # via wq_io_do
my ($self, $url, $uid, $kw) = @_;
$self->SUPER::ipc_atfork_child;
}
sub ck_update_kw { # via wq_io_do
my ($self, $url, $uid, $kw) = @_;
- my @oidbin = $self->{-lms_ro}->num_oidbin($url, $uid);
+ my @oidbin = $self->{-lms_rw}->num_oidbin($url, $uid);
my $uid_url = "$url/;UID=$uid";
@oidbin > 1 and warn("W: $uid_url not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
my $uid_url = "$url/;UID=$uid";
@oidbin > 1 and warn("W: $uid_url not unique:\n",
map { "\t".unpack('H*', $_)."\n" } @oidbin);
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# lcat: local cat, display a local message by Message-ID or blob,
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# lcat: local cat, display a local message by Message-ID or blob,
sub lcat_folder ($$;$$) {
my ($lei, $folder, $beg, $end) = @_;
sub lcat_folder ($$;$$) {
my ($lei, $folder, $beg, $end) = @_;
- my $lms = $lei->{-lms_ro} //= $lei->lms // return;
+ my $lms = $lei->{-lms_rw} //= $lei->lms // return;
my $folders = [ $folder ];
eval { $lms->arg2folder($lei, $folders) };
return $lei->child_error(0, "# unknown folder: $folder") if $@;
my $folders = [ $folder ];
eval { $lms->arg2folder($lei, $folders) };
return $lei->child_error(0, "# unknown folder: $folder") if $@;
sub lcat_imap_uri ($$) {
my ($lei, $uri) = @_;
# cf. LeiXSearch->lcat_dump
sub lcat_imap_uri ($$) {
my ($lei, $uri) = @_;
# cf. LeiXSearch->lcat_dump
- my $lms = $lei->{-lms_ro} //= $lei->lms // return;
+ my $lms = $lei->{-lms_rw} //= $lei->lms // return;
if (defined $uri->uid) {
push @{$lei->{lcat_todo}}, $lms->imap_oidhex($lei, $uri);
} elsif (defined(my $fid = $lms->fid_for($$uri))) {
if (defined $uri->uid) {
push @{$lei->{lcat_todo}}, $lms->imap_oidhex($lei, $uri);
} elsif (defined(my $fid = $lms->fid_for($$uri))) {
my ($lei, $uri) = @_;
my $mid = $uri->message; # already unescaped by URI::news
return "mid:$mid" if defined($mid);
my ($lei, $uri) = @_;
my $mid = $uri->message; # already unescaped by URI::news
return "mid:$mid" if defined($mid);
- my $lms = $lei->{-lms_ro} //= $lei->lms // return;
+ my $lms = $lei->{-lms_rw} //= $lei->lms // return;
my ($ng, $beg, $end) = $uri->group;
$uri->group($ng);
lcat_folder($lei, $$uri, $beg, $end);
my ($ng, $beg, $end) = $uri->group;
$uri->group($ng);
lcat_folder($lei, $$uri, $beg, $end);
- delete $lei->{-lms_ro};
+ delete $lei->{-lms_rw};
@q ? join(' OR ', @q) : $lei->fail("no Message-ID in: @argv");
}
@q ? join(' OR ', @q) : $lei->fail("no Message-ID in: @argv");
}
use Carp ();
sub dbh_new {
use Carp ();
sub dbh_new {
my $f = $self->{filename};
my $f = $self->{filename};
- my $creat = $rw && !-s $f;
if ($creat) {
require PublicInbox::Syscall;
open my $fh, '+>>', $f or Carp::croak "open($f): $!";
if ($creat) {
require PublicInbox::Syscall;
open my $fh, '+>>', $f or Carp::croak "open($f): $!";
AutoCommit => 1,
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
RaiseError => 1,
PrintError => 0,
sqlite_use_immediate_transaction => 1,
});
# no sqlite_unicode, here, all strings are binary
sqlite_use_immediate_transaction => 1,
});
# no sqlite_unicode, here, all strings are binary
- create_tables($self, $dbh) if $rw;
+ create_tables($self, $dbh);
$dbh->do('PRAGMA journal_mode = WAL') if $creat;
$dbh->do('PRAGMA case_sensitive_like = ON');
$dbh;
$dbh->do('PRAGMA journal_mode = WAL') if $creat;
$dbh->do('PRAGMA case_sensitive_like = ON');
$dbh;
-sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0], 1)); $_[0] }
+sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0])); $_[0] }
sub lms_pause {
my ($self) = @_;
sub lms_pause {
my ($self) = @_;
- my ($sth, $folder, $dbh) = @_; # $dbh is set iff RW
+ my ($sth, $folder, $dbh) = @_;
$sth->bind_param(1, $folder, SQL_BLOB);
$sth->execute;
my ($fid) = $sth->fetchrow_array;
$sth->bind_param(1, $folder, SQL_BLOB);
$sth->execute;
my ($fid) = $sth->fetchrow_array;
- my ($self, $folder, $rw) = @_;
- my $dbh = $self->{dbh} //= dbh_new($self, $rw);
+ my ($self, $folder, $creat) = @_;
+ my $dbh = $self->{dbh} //= dbh_new($self);
my $sth = $dbh->prepare_cached(<<'', undef, 1);
SELECT fid FROM folders WHERE loc = ? LIMIT 1
my $sth = $dbh->prepare_cached(<<'', undef, 1);
SELECT fid FROM folders WHERE loc = ? LIMIT 1
- my $rw_dbh = $dbh->{ReadOnly} ? undef : $dbh;
- my $fid = get_fid($sth, $folder, $rw_dbh);
+ my $fid = get_fid($sth, $folder, $dbh);
return $fid if defined($fid);
# caller had trailing slash (LeiToMail)
if ($folder =~ s!\A((?:maildir|mh):.*?)/+\z!$1!i) {
return $fid if defined($fid);
# caller had trailing slash (LeiToMail)
if ($folder =~ s!\A((?:maildir|mh):.*?)/+\z!$1!i) {
- $fid = get_fid($sth, $folder, $rw_dbh);
+ $fid = get_fid($sth, $folder, $dbh);
- update_fid($dbh, $fid, $folder) if $rw;
+ update_fid($dbh, $fid, $folder);
return $fid;
}
# sometimes we stored trailing slash..
} elsif ($folder =~ m!\A(?:maildir|mh):!i) {
return $fid;
}
# sometimes we stored trailing slash..
} elsif ($folder =~ m!\A(?:maildir|mh):!i) {
- $fid = get_fid($sth, $folder, $rw_dbh);
+ $fid = get_fid($sth, $folder, $dbh);
- update_fid($dbh, $fid, $folder) if $rw;
+ update_fid($dbh, $fid, $folder);
- } elsif ($rw && $folder =~ m!\Aimaps?://!i) {
+ } elsif ($creat && $folder =~ m!\Aimaps?://!i) {
require PublicInbox::URIimap;
require PublicInbox::URIimap;
- PublicInbox::URIimap->new($folder)->uidvalidity //
+ my $uri = PublicInbox::URIimap->new($folder);
+ $uri->uidvalidity //
Carp::croak("BUG: $folder has no UIDVALIDITY");
Carp::croak("BUG: $folder has no UIDVALIDITY");
+ defined($uri->uid) and Carp::confess("BUG: $folder has UID");
($fid) = $dbh->selectrow_array('SELECT MAX(fid) FROM folders');
$fid += 1;
($fid) = $dbh->selectrow_array('SELECT MAX(fid) FROM folders');
$fid += 1;
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# read-only counterpart for PublicInbox::LeiStore
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# read-only counterpart for PublicInbox::LeiStore
my $git = $self->git;
my $xoids = {};
# no lms when used via {ale}:
my $git = $self->git;
my $xoids = {};
# no lms when used via {ale}:
- my $lms = $self->{-lms_ro} //= lms($self) if defined($self->{topdir});
+ my $lms = $self->{-lms_rw} //= lms($self) if defined($self->{topdir});
for my $mid (@$mids) {
for my $o (@overs) {
my ($id, $prev);
for my $mid (@$mids) {
for my $o (@overs) {
my ($id, $prev);
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# common reader code for IMAP and NNTP (and maybe JMAP)
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# common reader code for IMAP and NNTP (and maybe JMAP)
my ($self, $uri, $r_uidval, $mic) = @_;
return (undef, undef, $r_uidval) unless $self->{incremental};
my ($itrk, $l_uid, $l_uidval);
my ($self, $uri, $r_uidval, $mic) = @_;
return (undef, undef, $r_uidval) unless $self->{incremental};
my ($itrk, $l_uid, $l_uidval);
- if (defined(my $lms = $self->{-lms_ro})) { # LeiMailSync or 0
+ if (defined(my $lms = $self->{-lms_rw})) { # LeiMailSync or 0
$uri->uidvalidity($r_uidval) if defined $r_uidval;
if ($mic) {
my $auth = $mic->Authmechanism // '';
$uri->uidvalidity($r_uidval) if defined $r_uidval;
if ($mic) {
my $auth = $mic->Authmechanism // '';