Since "lei up" is more often useful than not and incurs neglible
overhead; enable --save by default and allow --no-save to work.
This also fixes a long-standing when overwriting --output
destinations with saved searches: dedupe data from previous
searches are reset and no longer influences the new (changed)
search, so results no longer go missing if two sequential
invocations of "lei q --save" point to the same --output.
Read search terms from stdin.
Read search terms from stdin.
-Save a search for L<lei-up(1)>.
+Do not save the search for L<lei-up(1)>.
'q' => [ '--stdin|SEARCH_TERMS...', 'search for messages matching terms',
'stdin|', # /|\z/ must be first for lone dash
@lxs_opt,
'q' => [ '--stdin|SEARCH_TERMS...', 'search for messages matching terms',
'stdin|', # /|\z/ must be first for lone dash
@lxs_opt,
- qw(save output|mfolder|o=s format|f=s dedupe|d=s threads|t+
+ qw(save! output|mfolder|o=s format|f=s dedupe|d=s threads|t+
sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+
shared color! mail-sync!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+
shared color! mail-sync!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
'torsocks=s' => ['VAL|auto|no|yes',
'whether or not to wrap git and curl commands with torsocks'],
'no-torsocks' => 'alias for --torsocks=no',
'torsocks=s' => ['VAL|auto|no|yes',
'whether or not to wrap git and curl commands with torsocks'],
'no-torsocks' => 'alias for --torsocks=no',
-'save' => "save a search for `lei up'",
+'save!' => "do not save a search for `lei up'",
'import-remote!' => 'do not memoize remote messages into local store',
'type=s' => [ 'any|mid|git', 'disambiguate type' ],
'import-remote!' => 'do not memoize remote messages into local store',
'type=s' => [ 'any|mid|git', 'disambiguate type' ],
+sub reset_dedupe {
+ my ($self) = @_;
+ prepare_dedupe($self);
+ my $lk = $self->lock_for_scope_fast;
+ for my $t (qw(xref3 over id2num)) {
+ $self->{oidx}->{dbh}->do("DELETE FROM $t");
+ }
+ pause_dedupe($self);
+}
+
sub mm { undef }
sub altid_map { {} }
sub mm { undef }
sub altid_map { {} }
-e $dst && !-d _ and die
"$dst exists and is not a directory\n";
$lei->{ovv}->{dst} = $dst .= '/' if substr($dst, -1) ne '/';
-e $dst && !-d _ and die
"$dst exists and is not a directory\n";
$lei->{ovv}->{dst} = $dst .= '/' if substr($dst, -1) ne '/';
+ $lei->{opt}->{save} //= \1 if $lei->{cmd} eq 'q';
} elsif (substr($fmt, 0, 4) eq 'mbox') {
require PublicInbox::MboxReader;
$self->can("eml2$fmt") or die "bad mbox format: $fmt\n";
$self->{base_type} = 'mbox';
} elsif (substr($fmt, 0, 4) eq 'mbox') {
require PublicInbox::MboxReader;
$self->can("eml2$fmt") or die "bad mbox format: $fmt\n";
$self->{base_type} = 'mbox';
+ if ($lei->{cmd} eq 'q' &&
+ (($lei->path_to_fd($dst) // -1) < 0) &&
+ (-f $dst || !-e _)) {
+ $lei->{opt}->{save} //= \1;
+ }
} elsif ($fmt =~ /\Aimaps?\z/) {
require PublicInbox::NetWriter;
require PublicInbox::URIimap;
} elsif ($fmt =~ /\Aimaps?\z/) {
require PublicInbox::NetWriter;
require PublicInbox::URIimap;
$dst = $lei->{ovv}->{dst} = $$uri; # canonicalized
$lei->{net} = $net;
$self->{base_type} = 'imap';
$dst = $lei->{ovv}->{dst} = $$uri; # canonicalized
$lei->{net} = $net;
$self->{base_type} = 'imap';
+ $lei->{opt}->{save} //= \1 if $lei->{cmd} eq 'q';
} elsif ($fmt eq 'text') {
require PublicInbox::LeiViewText;
$lei->{lvt} = PublicInbox::LeiViewText->new($lei);
} elsif ($fmt eq 'text') {
require PublicInbox::LeiViewText;
$lei->{lvt} = PublicInbox::LeiViewText->new($lei);
open $self->{poke_dh}, '<', "${dst}cur" or die "open ${dst}cur: $!";
}
open $self->{poke_dh}, '<', "${dst}cur" or die "open ${dst}cur: $!";
}
+sub clobber_dst_prepare ($;$) {
+ my ($lei, $f) = @_;
+ my $wait = (defined($f) && $lei->{sto}) ?
+ $lei->{sto}->ipc_do('lms_forget_folders', $f) : undef;
+ my $dedupe = $lei->{dedupe} or return;
+ $dedupe->reset_dedupe if $dedupe->can('reset_dedupe');
+}
+
sub _do_augment_maildir {
my ($self, $lei) = @_;
sub _do_augment_maildir {
my ($self, $lei) = @_;
- return if ($lei->{opt}->{save} // 0) < 0;
+ return if $lei->{cmd} eq 'up';
my $dst = $lei->{ovv}->{dst};
my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
my $mdr = PublicInbox::MdirReader->new;
my $dst = $lei->{ovv}->{dst};
my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
my $mdr = PublicInbox::MdirReader->new;
$dedupe->pause_dedupe;
}
} elsif ($lse) {
$dedupe->pause_dedupe;
}
} elsif ($lse) {
+ clobber_dst_prepare($lei, "maildir:$dst");
$mdr->{shard_info} = $self->{shard_info};
$mdr->maildir_each_eml($dst, \&_md_update, $lei, $lse, 1);
} else {# clobber existing Maildir
$mdr->{shard_info} = $self->{shard_info};
$mdr->maildir_each_eml($dst, \&_md_update, $lei, $lse, 1);
} else {# clobber existing Maildir
+ clobber_dst_prepare($lei, "maildir:$dst");
$mdr->maildir_each_file($dst, \&_unlink);
}
}
$mdr->maildir_each_file($dst, \&_unlink);
}
}
sub _do_augment_imap {
my ($self, $lei) = @_;
sub _do_augment_imap {
my ($self, $lei) = @_;
- return if ($lei->{opt}->{save} // 0) < 0;
+ return if $lei->{cmd} eq 'up';
my $net = $lei->{net};
my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
if ($lei->{opt}->{augment}) {
my $net = $lei->{net};
my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
if ($lei->{opt}->{augment}) {
}
} elsif ($lse) {
my $delete_mic;
}
} elsif ($lse) {
my $delete_mic;
+ clobber_dst_prepare($lei, "$self->{uri}");
$net->imap_each($self->{uri}, \&_imap_augment_or_delete,
$lei, $lse, \$delete_mic);
$delete_mic->expunge if $delete_mic;
} elsif (!$self->{-wq_worker_nr}) { # undef or 0
# clobber existing IMAP folder
$net->imap_each($self->{uri}, \&_imap_augment_or_delete,
$lei, $lse, \$delete_mic);
$delete_mic->expunge if $delete_mic;
} elsif (!$self->{-wq_worker_nr}) { # undef or 0
# clobber existing IMAP folder
+ clobber_dst_prepare($lei, "$self->{uri}");
$net->imap_delete_all($self->{uri});
}
}
$net->imap_delete_all($self->{uri});
}
}
if $imp_before && !ref($imp_before);
die "--augment specified but $dst is not seekable\n" if
$lei->{opt}->{augment};
if $imp_before && !ref($imp_before);
die "--augment specified but $dst is not seekable\n" if
$lei->{opt}->{augment};
+ die "cannot --save with unseekable $dst\n" if
+ $lei->{dedupe} && $lei->{dedupe}->can('reset_dedupe');
}
if ($self->{zsfx} = PublicInbox::MboxReader::zsfx($dst)) {
pipe(my ($r, $w)) or die "pipe: $!";
}
if ($self->{zsfx} = PublicInbox::MboxReader::zsfx($dst)) {
pipe(my ($r, $w)) or die "pipe: $!";
my ($self, $lei) = @_;
return unless $self->{seekable};
my $opt = $lei->{opt};
my ($self, $lei) = @_;
return unless $self->{seekable};
my $opt = $lei->{opt};
- return if ($opt->{save} // 0) < 0;
+ return if $lei->{cmd} eq 'up';
my $out = $lei->{1};
my ($fmt, $dst) = @{$lei->{ovv}}{qw(fmt dst)};
my $out = $lei->{1};
my ($fmt, $dst) = @{$lei->{ovv}}{qw(fmt dst)};
+ return clobber_dst_prepare($lei) unless -s $out;
unless ($opt->{augment} || $opt->{'import-before'}) {
truncate($out, 0) or die "truncate($dst): $!";
return;
unless ($opt->{augment} || $opt->{'import-before'}) {
truncate($out, 0) or die "truncate($dst): $!";
return;
if ($opt->{augment}) {
$dedupe = $lei->{dedupe};
$dedupe->prepare_dedupe if $dedupe;
if ($opt->{augment}) {
$dedupe = $lei->{dedupe};
$dedupe->prepare_dedupe if $dedupe;
+ } else {
+ clobber_dst_prepare($lei);
}
if ($opt->{'import-before'}) { # the default
my $lse = $lei->{lse};
}
if ($opt->{'import-before'}) { # the default
my $lse = $lei->{lse};
my ($lei, @outs) = @_;
$lei->{lse} = $lei->_lei_store(1)->search;
my $opt = $lei->{opt};
my ($lei, @outs) = @_;
$lei->{lse} = $lei->_lei_store(1)->search;
my $opt = $lei->{opt};
my @local;
if (defined $opt->{all}) {
return $lei->fail("--all and @outs incompatible") if @outs;
my @local;
if (defined $opt->{all}) {
return $lei->fail("--all and @outs incompatible") if @outs;
lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com));
@fn = glob("$o/cur/*:2,S");
lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com));
@fn = glob("$o/cur/*:2,S");
-is(scalar(@fn), 1, "`seen' flag set on Maildir file");
+is(scalar(@fn), 1, "`seen' flag set on Maildir file") or
+ diag "$o contents: ", explain([glob("$o/*/*")]);
# ensure --no-import-before works
my $n = $fn[0];
# ensure --no-import-before works
my $n = $fn[0];
my $home = $ENV{HOME};
my $in = $doc1->as_string;
lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
my $home = $ENV{HOME};
my $in = $doc1->as_string;
lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
- lei_ok qw(q -q --save z:0.. d:last.week..), '-o', "MAILDIR:$home/md/";
+ lei_ok qw(q -q z:0.. d:last.week..), '-o', "MAILDIR:$home/md/";
my %before = map { $_ => 1 } glob("$home/md/cur/*");
my $f = (keys %before)[0] or xbail({before => \%before});
is_deeply(eml_load($f), $doc1, 'doc1 matches');
my %before = map { $_ => 1 } glob("$home/md/cur/*");
my $f = (keys %before)[0] or xbail({before => \%before});
is_deeply(eml_load($f), $doc1, 'doc1 matches');
is_deeply(eml_load($f), $doc2, 'doc2 matches');
# check stdin
is_deeply(eml_load($f), $doc2, 'doc2 matches');
# check stdin
- lei_ok [qw(q --save - -o), "mboxcl2:mbcl2" ],
- undef, { -C => $home, %$lei_opt, 0 => \'d:last.week..'};
+ lei_ok [qw(q - -o), "mboxcl2:mbcl2" ], undef,
+ { -C => $home, %$lei_opt, 0 => \'d:last.week..'};
@s = glob("$home/.local/share/lei/saved-searches/mbcl2-*");
$cfg = PublicInbox::Config->new("$s[0]/lei.saved-search");
is_deeply $cfg->{'lei.q'}, 'd:last.week..',
@s = glob("$home/.local/share/lei/saved-searches/mbcl2-*");
$cfg = PublicInbox::Config->new("$s[0]/lei.saved-search");
is_deeply $cfg->{'lei.q'}, 'd:last.week..',
lei_ok([qw(up mbcl2)], undef, { -C => $home, %$lei_opt });
ok(-s "$home/mbcl2" > $size, 'size increased after up');
lei_ok([qw(up mbcl2)], undef, { -C => $home, %$lei_opt });
ok(-s "$home/mbcl2" > $size, 'size increased after up');
- ok(!lei(qw(up -q), $home), 'up fails w/o --save');
+ ok(!lei(qw(up -q), $home), 'up fails on unknown dir');
+ like($lei_err, qr/--save was not used/, 'error noted --save');
+
+ lei_ok(qw(q --no-save d:last.week.. -q -o), "$home/no-save");
+ ok(!lei(qw(up -q), "$home/no-save"), 'up fails on --no-save');
like($lei_err, qr/--save was not used/, 'error noted --save');
lei_ok qw(ls-search); my @d = split(/\n/, $lei_out);
like($lei_err, qr/--save was not used/, 'error noted --save');
lei_ok qw(ls-search); my @d = split(/\n/, $lei_out);
open my $mb, '>', "$home/mbrd" or xbail "open $!";
print $mb $pre_existing;
close $mb or xbail "close: $!";
open my $mb, '>', "$home/mbrd" or xbail "open $!";
print $mb $pre_existing;
close $mb or xbail "close: $!";
- lei_ok(qw(q --save -o mboxrd:mbrd m:qp@example.com -C), $home);
+ lei_ok(qw(q -o mboxrd:mbrd m:qp@example.com -C), $home);
open $mb, '<', "$home/mbrd" or xbail "open $!";
is_deeply([grep(/pre-existing/, <$mb>)], [],
'pre-existing messsage gone w/o augment');
open $mb, '<', "$home/mbrd" or xbail "open $!";
is_deeply([grep(/pre-existing/, <$mb>)], [],
'pre-existing messsage gone w/o augment');
open $mb, '>', "$home/mbrd-aug" or xbail "open $!";
print $mb $pre_existing;
close $mb or xbail "close: $!";
open $mb, '>', "$home/mbrd-aug" or xbail "open $!";
print $mb $pre_existing;
close $mb or xbail "close: $!";
- lei_ok(qw(q -a --save -o mboxrd:mbrd-aug m:qp@example.com -C), $home);
+ lei_ok(qw(q -a -o mboxrd:mbrd-aug m:qp@example.com -C), $home);
open $mb, '<', "$home/mbrd-aug" or xbail "open $!";
$mb = do { local $/; <$mb> };
like($mb, qr/pre-existing/, 'pre-existing message preserved w/ -a');
open $mb, '<', "$home/mbrd-aug" or xbail "open $!";
$mb = do { local $/; <$mb> };
like($mb, qr/pre-existing/, 'pre-existing message preserved w/ -a');
my $o = "$home/dd-mid";
$in = $doc2->as_string . "\n-------\nappended list sig\n";
lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
my $o = "$home/dd-mid";
$in = $doc2->as_string . "\n-------\nappended list sig\n";
lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
- lei_ok(qw(q --dedupe=mid --save m:testmessage@example.com -o), $o);
+ lei_ok(qw(q --dedupe=mid m:testmessage@example.com -o), $o);
my @m = glob("$o/cur/*");
is(scalar(@m), 1, '--dedupe=mid w/ --save');
$in = $doc2->as_string . "\n-------\nanother list sig\n";
my @m = glob("$o/cur/*");
is(scalar(@m), 1, '--dedupe=mid w/ --save');
$in = $doc2->as_string . "\n-------\nanother list sig\n";
for my $dd (qw(content)) {
$o = "$home/dd-$dd";
for my $dd (qw(content)) {
$o = "$home/dd-$dd";
- lei_ok(qw(q --save m:testmessage@example.com -o), $o,
- "--dedupe=$dd");
+ lei_ok(qw(q m:testmessage@example.com -o), $o, "--dedupe=$dd");
@m = glob("$o/cur/*");
is(scalar(@m), 3, 'all 3 matches with dedupe='.$dd);
}
@m = glob("$o/cur/*");
is(scalar(@m), 3, 'all 3 matches with dedupe='.$dd);
}
$o = "$home/dd-oid";
my $ibx = create_inbox 'ibx', indexlevel => 'medium',
tmpdir => "$home/v1", sub {};
$o = "$home/dd-oid";
my $ibx = create_inbox 'ibx', indexlevel => 'medium',
tmpdir => "$home/v1", sub {};
- lei_ok(qw(q --save --dedupe=oid m:qp@example.com -o), $o,
+ lei_ok(qw(q --dedupe=oid m:qp@example.com -o), $o,
'-I', $ibx->{inboxdir});
@m = glob("$o/cur/*");
is(scalar(@m), 1, 'got first result');
'-I', $ibx->{inboxdir});
@m = glob("$o/cur/*");
is(scalar(@m), 1, 'got first result');
lei_ok([qw(edit-search), $v2s], { VISUAL => 'cat', EDITOR => 'cat' });
like($lei_out, qr/^\[lei/sm, 'edit-search can cat');
lei_ok([qw(edit-search), $v2s], { VISUAL => 'cat', EDITOR => 'cat' });
like($lei_out, qr/^\[lei/sm, 'edit-search can cat');
- lei_ok('-C', "$home/v2s",
- qw(q -q --save -o ../s m:testmessage@example.com));
+ lei_ok('-C', "$home/v2s", qw(q -q -o ../s m:testmessage@example.com));
lei_ok qw(ls-search);
unlike $lei_out, qr{/\.\./s$}sm, 'relative path not in ls-search';
like $lei_out, qr{^\Q$home\E/s$}sm,
lei_ok qw(ls-search);
unlike $lei_out, qr{/\.\./s$}sm, 'relative path not in ls-search';
like $lei_out, qr{^\Q$home\E/s$}sm,
%out = map { $_ => 1 } split(/\s+/s, $lei_out);
for my $sw (qw(-f --format -o --output --mfolder --augment -a
--mua --no-local --local --verbose -v
%out = map { $_ => 1 } split(/\s+/s, $lei_out);
for my $sw (qw(-f --format -o --output --mfolder --augment -a
--mua --no-local --local --verbose -v
- --save --no-remote --remote --torsocks
+ --save --no-save --no-remote --remote --torsocks
--reverse -r )) {
ok($out{$sw}, "$sw offered as `lei q' completion");
}
--reverse -r )) {
ok($out{$sw}, "$sw offered as `lei q' completion");
}
my ($tmpdir, $for_destroy) = tmpdir();
local $ENV{TMPDIR} = $tmpdir;
open my $err, '>>', "$tmpdir/lei.err" or BAIL_OUT $!;
my ($tmpdir, $for_destroy) = tmpdir();
local $ENV{TMPDIR} = $tmpdir;
open my $err, '>>', "$tmpdir/lei.err" or BAIL_OUT $!;
-my $lei = bless { 2 => $err }, 'PublicInbox::LEI';
+my $lei = bless { 2 => $err, cmd => 'test' }, 'PublicInbox::LEI';
my $commit = sub {
$_[0] = undef; # wcb
delete $lei->{1};
my $commit = sub {
$_[0] = undef; # wcb
delete $lei->{1};