From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2EAE120607 for ; Thu, 23 May 2019 09:37:12 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 19/26] xapcmd: use "print STDERR" for progress reporting Date: Thu, 23 May 2019 09:36:57 +0000 Message-Id: <20190523093704.18367-20-e@80x24.org> In-Reply-To: <20190523093704.18367-1-e@80x24.org> References: <20190523093704.18367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: `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 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 860f90a..aa3e4c0 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); -- EW