use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::Lock;
use PublicInbox::Eml;
+use PublicInbox::Import;
+use PublicInbox::ContentHash qw(git_sha);
use Time::HiRes qw(stat); # ctime comparisons for config cache
use File::Path qw(mkpath);
use File::Spec;
@c_opt ],
'import' => [ 'LOCATION...|--stdin',
'one-time import/update from URL or filesystem',
- qw(stdin| offset=i recursive|r exclude=s include|I=s jobs=s new-only
+ qw(stdin| offset=i recursive|r exclude=s include|I=s new-only
lock=s@ in-format|F=s kw! verbose|v+ incremental! mail-sync!),
@net_opt, @c_opt ],
'forget-mail-sync' => [ 'LOCATION...',
'forget sync information for a mail folder', @c_opt ],
-'prune-mail-sync' => [ 'LOCATION...|--all',
+'refresh-mail-sync' => [ 'LOCATION...|--all',
'prune dangling sync data for a mail folder', 'all:s', @c_opt ],
'export-kw' => [ 'LOCATION...|--all',
'one-time export of keywords of sync sources',
$ops->{x_it} = [ \&x_it, $lei ];
$ops->{child_error} = [ \&child_error, $lei ];
$ops->{incr} = [ \&incr, $lei ];
+ $ops->{sto_done_request} = [ \&sto_done_request, $lei, $lei->{sock} ];
$ops;
}
my $end = $lei->pkt_op_pair;
my $ident = $wq->{-wq_ident} // "lei-$lei->{cmd} worker";
$flds->{lei} = $lei;
+ $wq->{-wq_nr_workers} //= $jobs; # lock, no incrementing
$wq->wq_workers_start($ident, $jobs, $lei->oldset, $flds);
delete $lei->{pkt_op_p};
my $op_c = delete $lei->{pkt_op_c};
}
# add all known Maildir folders as implicit watches
- my $sto = $lei->_lei_store;
- my $renames = 0;
- if (my $lms = $sto ? $sto->search->lms : undef) {
+ my $lms = $lei->lms;
+ if ($lms) {
+ $lms->lms_write_prepare;
for my $d ($lms->folders('maildir:')) {
substr($d, 0, length('maildir:')) = '';
- my $cd = canonpath_harder($d);
- my $f = "maildir:$cd";
# fixup old bugs while we're iterating:
- if ($d ne $cd) {
- $sto->ipc_do('lms_rename_folder',
- "maildir:$d", $f);
- ++$renames;
- }
+ my $cd = canonpath_harder($d);
+ my $f = "maildir:$cd";
+ $lms->rename_folder("maildir:$d", $f) if $d ne $cd;
next if $watches->{$f}; # may be set to pause
require PublicInbox::LeiWatch;
$watches->{$f} = PublicInbox::LeiWatch->new($f);
add_maildir_watch($cd, $cfg_f);
}
}
- $lei->sto_done_request if $renames;
if ($old) { # cull old non-existent entries
for my $url (keys %$old) {
next if exists $seen{$url};
}
}
-sub git_blob_id {
- my ($lei, $eml) = @_;
- ($lei->{sto} // _lei_store($lei, 1))->git_blob_id($eml);
+# TODO: support SHA-256
+sub git_oid {
+ my $eml = $_[-1];
+ $eml->header_set($_) for @PublicInbox::Import::UNWANTED_HEADERS;
+ git_sha(1, $eml);
}
-sub lms { # read-only LeiMailSync
- my ($lei) = @_;
- my $lse = $lei->{lse} // do {
- my $sto = $lei->{sto} // _lei_store($lei);
- $sto ? $sto->search : undef
- };
- $lse ? $lse->lms : undef;
+sub lms {
+ my ($lei, $rw) = @_;
+ 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;
}
sub sto_done_request { # only call this from lei-daemon process (not workers)