]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei up: automatically use dt: for remote externals
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 41e761f8aabf939e81af2afb0b82bf7058b83e5e..8b0614f27980f8e4e53f31681562ae25cc83b119 100644 (file)
@@ -183,7 +183,8 @@ our %CMD = ( # sorted in order of importance/use:
        shared color! mail-sync!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
 
 'up' => [ 'OUTPUT...|--all', 'update saved search',
-       qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+ all:s), @c_opt ],
+       qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+
+       remote-fudge-time=s all:s), @c_opt ],
 
 'lcat' => [ '--stdin|MSGID_OR_URL...', 'display local copy of message(s)',
        'stdin|', # /|\z/ must be first for lone dash
@@ -420,7 +421,9 @@ my %OPTDESC = (
 'remote' => 'limit operations to those requiring network access',
 'remote!' => 'prevent operations requiring network access',
 
-'all:s up' => ['local', 'update all (local) saved searches' ],
+'all:s up' => ['local|remote', 'update all remote or local saved searches' ],
+'remote-fudge-time=s' => [ 'INTERVAL',
+       'look for mail INTERVAL older than the last successful query' ],
 
 'mid=s' => 'specify the Message-ID of a message',
 'oid=s' => 'specify the git object ID of a message',
@@ -1442,20 +1445,16 @@ sub refresh_watches {
        }
 
        # 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);
@@ -1463,7 +1462,6 @@ sub refresh_watches {
                        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};
@@ -1490,13 +1488,12 @@ sub git_oid {
        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)