use PublicInbox::ContentHash qw(git_sha);
use PublicInbox::MID qw(mids_for_index);
use Digest::SHA qw(sha256_hex);
use PublicInbox::ContentHash qw(git_sha);
use PublicInbox::MID qw(mids_for_index);
use Digest::SHA qw(sha256_hex);
# move this to PublicInbox::Config if other things use it:
my %cquote = ("\n" => '\\n', "\t" => '\\t', "\b" => '\\b');
sub cquote_val ($) { # cf. git-config(1)
my ($val) = @_;
$val =~ s/([\n\t\b])/$cquote{$1}/g;
# move this to PublicInbox::Config if other things use it:
my %cquote = ("\n" => '\\n', "\t" => '\\t', "\b" => '\\b');
sub cquote_val ($) { # cf. git-config(1)
my ($val) = @_;
$val =~ s/([\n\t\b])/$cquote{$1}/g;
if ($$dstref =~ m,\Aimaps?://,i) { # already canonicalized
require PublicInbox::URIimap;
my $uri = PublicInbox::URIimap->new($$dstref)->canonical;
$$dstref = $$uri;
if ($$dstref =~ m,\Aimaps?://,i) { # already canonicalized
require PublicInbox::URIimap;
my $uri = PublicInbox::URIimap->new($$dstref)->canonical;
$$dstref = $$uri;
print $fh "\tpath = ", cquote_val($p), "\n";
}
close $fh or die "close $f: $!";
print $fh "\tpath = ", cquote_val($p), "\n";
}
close $fh or die "close $f: $!";
-sub translate_dedupe ($$$) {
- my ($self, $lei, $dd) = @_;
- $dd //= 'content';
+sub translate_dedupe ($$) {
+ my ($self, $lei) = @_;
+ my $dd = $lei->{opt}->{dedupe} // 'content';
return 1 if $dd eq 'content'; # the default
return $self->{"-dedupe_$dd"} = 1 if ($dd eq 'oid' || $dd eq 'mid');
return 1 if $dd eq 'content'; # the default
return $self->{"-dedupe_$dd"} = 1 if ($dd eq 'oid' || $dd eq 'mid');
my $self = bless { ale => $lei->ale }, $cls;
my $dir = $dst;
output2lssdir($self, $lei, \$dir, \$f) or
my $self = bless { ale => $lei->ale }, $cls;
my $dir = $dst;
output2lssdir($self, $lei, \$dir, \$f) or
- return $lei->fail("--save was not used with $dst cwd=".
- $lei->rel2abs('.'));
- $self->{-cfg} = PublicInbox::Config->git_config_dump($f);
+ return die("--no-save was used with $dst cwd=".
+ $lei->rel2abs('.')."\n");
+ $self->{-cfg} = $lei->cfg_dump($f) // return $lei->child_error;
sub new { # new saved search "lei q --save"
my ($cls, $lei) = @_;
my $self = bless { ale => $lei->ale }, $cls;
sub new { # new saved search "lei q --save"
my ($cls, $lei) = @_;
my $self = bless { ale => $lei->ale }, $cls;
+
+ # canonicalize away relative paths into the config
+ if ($lei->{ovv}->{fmt} eq 'maildir' &&
+ $dst =~ m!(?:/*|\A)\.\.(?:/*|\z)! && !-d $dst) {
+ File::Path::make_path($dst);
+ $lei->{ovv}->{dst} = $dst = $lei->abs_path($dst);
+ }
- my $dd = $lei->{opt}->{dedupe};
- translate_dedupe($self, $lei, $dd) or return;
+ translate_dedupe($self, $lei) or return;
open my $fh, '>', $f or return $lei->fail("open $f: $!");
my $sq_dst = PublicInbox::Config::squote_maybe($dst);
my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
open my $fh, '>', $f or return $lei->fail("open $f: $!");
my $sq_dst = PublicInbox::Config::squote_maybe($dst);
my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
+ for my $k (SINGLE_FIELDS) {
+ my $val = $lei->{opt}->{$k} // next;
+ print $fh "\t$k = $val\n";
+ }
+ $lei->{opt}->{stdin} and print $fh <<EOM;
+[lei "internal"]
+ rawstr = 1 # stdin was used initially
+EOM
close($fh) or return $lei->fail("close $f: $!");
$self->{lock_path} = "$self->{-f}.flock";
$self->{-ovf} = "$dir/over.sqlite3";
close($fh) or return $lei->fail("close $f: $!");
$self->{lock_path} = "$self->{-f}.flock";
$self->{-ovf} = "$dir/over.sqlite3";
sub is_dup {
my ($self, $eml, $smsg) = @_;
my $oidx = $self->{oidx} // die 'BUG: no {oidx}';
sub is_dup {
my ($self, $eml, $smsg) = @_;
my $oidx = $self->{oidx} // die 'BUG: no {oidx}';
for my $mid (@{mids_for_index($eml)}) {
my ($id, $prv);
return 1 if $oidx->next_by_mid($mid, \$id, \$prv);
}
}
for my $mid (@{mids_for_index($eml)}) {
my ($id, $prv);
return 1 if $oidx->next_by_mid($mid, \$id, \$prv);
}
}
if (my $xoids = PublicInbox::LeiSearch::xoids_for($self, $eml, 1)) {
for my $docid (values %$xoids) {
$oidx->add_xref3($docid, -1, $blob, '.');
}
$oidx->commit_lazy;
if ($self->{-dedupe_oid}) {
if (my $xoids = PublicInbox::LeiSearch::xoids_for($self, $eml, 1)) {
for my $docid (values %$xoids) {
$oidx->add_xref3($docid, -1, $blob, '.');
}
$oidx->commit_lazy;
if ($self->{-dedupe_oid}) {
- $oidx->add_xref3($smsg->{num}, -1, $smsg->{blob}, '.');
+ $oidx->add_xref3($smsg->{num}, -1, $blob, '.');
-sub git { $_[0]->{ale}->git }
+# don't use ale->git directly since is_dup is called inside
+# ale->git->cat_async callbacks
+sub git { $_[0]->{git} //= PublicInbox::Git->new($_[0]->{ale}->git->{git_dir}) }
my $lockfh = delete $self->{lockfh}; # from lock_for_scope_fast;
my $oidx = delete($self->{oidx}) // return;
$oidx->commit_lazy;
}
my $lockfh = delete $self->{lockfh}; # from lock_for_scope_fast;
my $oidx = delete($self->{oidx}) // return;
$oidx->commit_lazy;
}
my $dir = lss_dir_for($lei, \$dst, 1);
my $f = "$dir/lei.saved-search";
if (-f $f && -r _) {
my $dir = lss_dir_for($lei, \$dst, 1);
my $f = "$dir/lei.saved-search";
if (-f $f && -r _) {