about summary refs log tree commit homepage
path: root/lib/PublicInbox/Xapcmd.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-23 09:36:57 +0000
committerEric Wong <e@80x24.org>2019-05-23 17:43:50 +0000
commit24363017ffeba73f5b02c5e2d1dc465c682c676b (patch)
treec1ac98b6d075a7ffb75312aa7e34ff4bda557eaa /lib/PublicInbox/Xapcmd.pm
parent6d60c03c298526713eff379fc339ccb030e32630 (diff)
downloadpublic-inbox-24363017ffeba73f5b02c5e2d1dc465c682c676b.tar.gz
`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.
Diffstat (limited to 'lib/PublicInbox/Xapcmd.pm')
-rw-r--r--lib/PublicInbox/Xapcmd.pm17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 860f90aa..aa3e4c09 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -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);