- my $dir;
- if (defined $dst) { # updating existing saved search via "lei up"
- my $f;
- $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);
- $self->{'-f'} = $f;
- } else { # new saved search "lei q --save"
- my $dst = $lei->{ovv}->{dst};
- $dir = lss_dir_for($lei, \$dst);
- require File::Path;
- File::Path::make_path($dir); # raises on error
- $self->{-cfg} = {};
- my $f = $self->{'-f'} = "$dir/lei.saved-search";
- 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';
- if (ref $q) {
- $q = join("\n", map { "\tq = ".cquote_val($_) } @$q);
- } else {
- $q = "\tq = ".cquote_val($q);
- }
- $dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i;
- print $fh <<EOM;
+ my $dir = $dst;
+ output2lssdir($self, $lei, \$dir, \$f) or
+ return $lei->fail("--no-save was used with $dst cwd=".
+ $lei->rel2abs('.'));
+ $self->{-cfg} = $lei->cfg_dump($f) // return $lei->fail;
+ $self->{-ovf} = "$dir/over.sqlite3";
+ $self->{'-f'} = $f;
+ $self->{lock_path} = "$self->{-f}.flock";
+ $self;
+}
+
+sub new { # new saved search "lei q --save"
+ my ($cls, $lei) = @_;
+ my $self = bless { ale => $lei->ale }, $cls;
+ require File::Path;
+ my $dst = $lei->{ovv}->{dst};
+
+ # 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 $dir = lss_dir_for($lei, \$dst);
+ File::Path::make_path($dir); # raises on error
+ $self->{-cfg} = {};
+ my $f = $self->{'-f'} = "$dir/lei.saved-search";
+ my $dd = $lei->{opt}->{dedupe};
+ translate_dedupe($self, $lei, $dd) 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';
+ if (ref $q) {
+ $q = join("\n", map { "\tq = ".cquote_val($_) } @$q);
+ } else {
+ $q = "\tq = ".cquote_val($q);
+ }
+ $dst = "$lei->{ovv}->{fmt}:$dst" if $dst !~ m!\Aimaps?://!i;
+ print $fh <<EOM;