]> Sergey Matveev's repositories - public-inbox.git/commitdiff
xapcmd: use "print STDERR" for progress reporting
authorEric Wong <e@80x24.org>
Thu, 23 May 2019 09:36:57 +0000 (09:36 +0000)
committerEric Wong <e@80x24.org>
Thu, 23 May 2019 17:43:50 +0000 (17:43 +0000)
`warn' is reserved for actual warnings, as it respects
$SIG{__WARN__} and we rely on that override to print
message context information when we are indexing.

lib/PublicInbox/Xapcmd.pm

index 860f90aa512acc1e35e09c3a7f38393b70fad5c3..aa3e4c09a6298c60a9b6f1e40cd8f1205c43345d 100644 (file)
@@ -95,7 +95,7 @@ sub progress_prepare ($) {
                $opt->{1} = fileno($null);
                $opt->{-dev_null} = $null;
        } else {
-               $opt->{-progress} = 1;
+               $opt->{-progress} = sub { print STDERR @_ };
        }
 }
 
@@ -212,6 +212,7 @@ sub cpdb {
        my ($it, $end);
        my $pfx = '';
        my ($nr, $tot, $fmt); # progress output
+       my $pr = $opt->{-progress};
 
        do {
                eval {
@@ -222,11 +223,11 @@ sub cpdb {
                        $it = $src->postlist_begin('');
                        $end = $src->postlist_end('');
                        $pfx = (split('/', $old))[-1].':';
-                       if ($opt->{-progress}) {
+                       if ($pr) {
                                $nr = 0;
                                $tot = $src->get_doccount;
                                $fmt = "$pfx % ".length($tot)."u/$tot\n";
-                               warn "$pfx copying $tot documents\n";
+                               $pr->("$pfx copying $tot documents\n");
                        }
                };
        } while (cpdb_retryable($src, $pfx));
@@ -238,8 +239,8 @@ sub cpdb {
                                my $doc = $src->get_document($docid);
                                $dst->replace_document($docid, $doc);
                                $it->inc;
-                               if ($fmt && !(++$nr & 1023)) {
-                                       warn(sprintf($fmt, $nr));
+                               if ($pr && !(++$nr & 1023)) {
+                                       $pr->(sprintf($fmt, $nr));
                                }
                        }
 
@@ -250,13 +251,13 @@ sub cpdb {
                };
        } while (cpdb_retryable($src, $pfx));
 
-       warn(sprintf($fmt, $nr)) if $fmt;
+       $pr->(sprintf($fmt, $nr)) if $pr;
        return unless $opt->{compact};
 
        $src = $dst = undef; # flushes and closes
        $pfx = undef unless $fmt;
 
-       warn "$pfx compacting...\n" if $pfx;
+       $pr->("$pfx compacting...\n") if $pr;
        # this is probably the best place to do xapian-compact
        # since $dst isn't readable by HTTP or NNTP clients, yet:
        my $cmd = [ $XAPIAN_COMPACT, '--no-renumber', $tmp, $new ];
@@ -275,7 +276,7 @@ sub cpdb {
                close $w or die "close: \$w: $!";
                foreach (<$r>) {
                        s/\r/\r$pfx /g;
-                       warn "$pfx $_";
+                       $pr->("$pfx $_");
                }
        }
        my $rp = waitpid($pid, 0);