]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMailSync.pm
lei_mail_sync: show non-matching SHA
[public-inbox.git] / lib / PublicInbox / LeiMailSync.pm
index 522a5ebc865e3e3a6b0e5b89e83f91d72eb226ac..e70cb5de2b6b5046736ba72feeeb51a05a6bdf7b 100644 (file)
@@ -47,7 +47,8 @@ sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0], 1)); $_[0] }
 sub lms_pause {
        my ($self) = @_;
        $self->{fmap} = {};
-       delete $self->{dbh};
+       my $dbh = delete $self->{dbh};
+       eval { $dbh->do('PRAGMA optimize') } if $dbh;
 }
 
 sub create_tables {
@@ -299,16 +300,19 @@ sub locations_for {
 
 # returns a list of folders used for completion
 sub folders {
-       my ($self, $pfx) = @_;
-       my $dbh = $self->{dbh} //= dbh_new($self);
+       my ($self, @pfx) = @_;
        my $sql = 'SELECT loc FROM folders';
-       my @pfx;
-       if (defined $pfx) {
+       if (defined($pfx[0])) {
                $sql .= ' WHERE loc LIKE ? ESCAPE ?';
-               @pfx = ($pfx, '\\');
+               my $anywhere = !!$pfx[1];
+               $pfx[1] = '\\';
                $pfx[0] =~ s/([%_\\])/\\$1/g; # glob chars
                $pfx[0] .= '%';
+               substr($pfx[0], 0, 0, '%') if $anywhere;
+       } else {
+               @pfx = (); # [0] may've been undef
        }
+       my $dbh = $self->{dbh} //= dbh_new($self);
        map { $_->[0] } @{$dbh->selectall_arrayref($sql, undef, @pfx)};
 }
 
@@ -335,9 +339,12 @@ WHERE b.oidbin = ?
                        next unless -s $fh;
                        local $/;
                        my $raw = <$fh>;
-                       if ($vrfy && git_sha(1, \$raw)->hexdigest ne $oidhex) {
-                               warn "$f changed $oidhex\n";
-                               next;
+                       if ($vrfy) {
+                               my $got = git_sha(1, \$raw)->hexdigest;
+                               if ($got ne $oidhex) {
+                                       warn "$f changed $oidhex => $got\n";
+                                       next;
+                               }
                        }
                        return \$raw;
                }
@@ -462,7 +469,7 @@ sub arg2folder {
 # using `$res' instead of `$orig'
 EOM
                        } else {
-                               $lei->err($res) if defined $res;
+                               warn($res, "\n") if defined $res;
                                push @no, $orig;
                        }
                } elsif (m!\A(?:nntps?|s?news)://!i) {
@@ -474,7 +481,7 @@ EOM
 # using `$res' instead of `$orig'
 EOM
                        } else {
-                               $lei->err($res) if defined $res;
+                               warn($res, "\n") if defined $res;
                                push @no, $orig;
                        }
                } else {