]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiSavedSearch.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / LeiSavedSearch.pm
index 48d252f16cec8ac6b8b2eebf776db891deaecd7a..fd51fe38681612c6f9f07a7aec888a3700e1d160 100644 (file)
@@ -14,7 +14,7 @@ use PublicInbox::Spawn qw(run_die);
 use PublicInbox::ContentHash qw(git_sha);
 use PublicInbox::MID qw(mids_for_index);
 use Digest::SHA qw(sha256_hex);
-my $LOCAL_PFX = qr!\A(?:maildir|mh|mbox.+|mmdf):!i; # TODO: put in LeiToMail?
+my $LOCAL_PFX = qr!\A(?:maildir|mh|mbox.+|mmdf|v2):!i; # TODO: put in LeiToMail?
 
 # move this to PublicInbox::Config if other things use it:
 my %cquote = ("\n" => '\\n', "\t" => '\\t', "\b" => '\\b');
@@ -115,9 +115,16 @@ sub up { # updating existing saved search via "lei up"
 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);
-       require File::Path;
        File::Path::make_path($dir); # raises on error
        $self->{-cfg} = {};
        my $f = $self->{'-f'} = "$dir/lei.saved-search";
@@ -236,6 +243,16 @@ sub pause_dedupe {
        $oidx->commit_lazy;
 }
 
+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 { {} }
@@ -290,6 +307,12 @@ EOM
        my $dir_old = lss_dir_for($lei, \$old_path, 1);
        my $dir_new = lss_dir_for($lei, \$new_path);
        return if $dir_new eq $dir_old; # no change, likely
+
+       ($old_out =~ m!\Av2:!i || $new_out =~ m!\Av2:!) and
+               return $lei->fail(<<EOM);
+conversions from/to v2 inboxes not supported at this time
+EOM
+
        return $lei->fail(<<EOM) if -e $dir_new;
 lei.q.output changed from `$old_out' to `$new_out'
 However, $dir_new exists
@@ -309,11 +332,11 @@ E: rename($dir_old, $dir_new) error: $!
 EOM
 }
 
-# cf. LeiDedupe->dedupe_nr
-sub dedupe_nr {
+# cf. LeiDedupe->has_entries
+sub has_entries {
        my $oidx = $_[0]->{oidx} // die 'BUG: no {oidx}';
-       my @n = $oidx->{dbh}->selectrow_array('SELECT COUNT(*) FROM over');
-       $n[0];
+       my @n = $oidx->{dbh}->selectrow_array('SELECT num FROM over LIMIT 1');
+       scalar(@n) ? 1 : undef;
 }
 
 no warnings 'once';