]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMirror.pm
www_stream: add trailing slash for help and color links
[public-inbox.git] / lib / PublicInbox / LeiMirror.pm
index 13795a58c82d6eafb9f10eaffbe275e8dff19f01..658187960271c9f57e64637f65484b1575eb6bb9 100644 (file)
@@ -8,7 +8,6 @@ use v5.10.1;
 use parent qw(PublicInbox::IPC);
 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
 use PublicInbox::Spawn qw(popen_rd spawn);
-use PublicInbox::PktOp;
 
 sub do_finish_mirror { # dwaitpid callback
        my ($arg, $pid) = @_;
@@ -31,9 +30,9 @@ sub try_scrape {
        my $uri = URI->new($self->{src});
        my $lei = $self->{lei};
        my $curl = $self->{curl} //= PublicInbox::LeiCurl->new($lei) or return;
-       my $cmd = $curl->for_uri($lei, $uri);
+       my $cmd = $curl->for_uri($lei, $uri, '--compressed');
        my $opt = { 0 => $lei->{0}, 2 => $lei->{2} };
-       my $fh = popen_rd($cmd, $lei->{env}, $opt);
+       my $fh = popen_rd($cmd, undef, $opt);
        my $html = do { local $/; <$fh> } // die "read(curl $uri): $!";
        close($fh) or return $lei->child_error($?, "@$cmd failed");
 
@@ -93,8 +92,7 @@ sub _try_config {
        my $path = $uri->path;
        chop($path) eq '/' or die "BUG: $uri not canonicalized";
        $uri->path($path . '/_/text/config/raw');
-       my $cmd = $self->{curl}->for_uri($lei, $uri);
-       push @$cmd, '--compressed'; # curl decompresses for us
+       my $cmd = $self->{curl}->for_uri($lei, $uri, '--compressed');
        my $ce = "$dst/inbox.config.example";
        my $f = "$ce-$$.tmp";
        open(my $fh, '+>', $f) or return $lei->err("open $f: $! (non-fatal)");
@@ -144,7 +142,7 @@ sub run_reap {
        my ($lei, $cmd, $opt) = @_;
        $lei->qerr("# @$cmd");
        $opt->{pgid} = 0;
-       my $pid = spawn($cmd, $lei->{env}, $opt);
+       my $pid = spawn($cmd, undef, $opt);
        my $reap = PublicInbox::OnDestroy->new($lei->can('sigint_reap'), $pid);
        my $err = waitpid($pid, 0) == $pid ? undef : "waitpid @$cmd: $!";
        @$reap = (); # cancel reap
@@ -207,7 +205,7 @@ sub try_manifest {
        my $cmd = $curl->for_uri($lei, $uri);
        $lei->qerr("# @$cmd");
        my $opt = { 0 => $lei->{0}, 2 => $lei->{2} };
-       my ($fh, $pid) = popen_rd($cmd, $lei->{env}, $opt);
+       my ($fh, $pid) = popen_rd($cmd, undef, $opt);
        my $reap = PublicInbox::OnDestroy->new($lei->can('sigint_reap'), $pid);
        my $gz = do { local $/; <$fh> } // die "read(curl $uri): $!";
        close $fh;
@@ -251,7 +249,7 @@ sub start_clone_url {
        die "TODO: non-HTTP/HTTPS clone of $self->{src} not supported, yet";
 }
 
-sub do_mirror { # via wq_do
+sub do_mirror { # via wq_io_do
        my ($self) = @_;
        my $lei = $self->{lei};
        eval {
@@ -280,22 +278,12 @@ sub start {
        require PublicInbox::Inbox;
        require PublicInbox::Admin;
        require PublicInbox::InboxWritable;
-       my $ops = {
-               '!' => [ $lei->can('fail_handler'), $lei ],
-               'x_it' => [ $lei->can('x_it'), $lei ],
-               'child_error' => [ $lei->can('child_error'), $lei ],
-               '' => [ \&mirror_done, $lei ],
-       };
-       ($lei->{pkt_op_c}, $lei->{pkt_op_p}) = PublicInbox::PktOp->pair($ops);
-       $self->wq_workers_start('lei_mirror', 1, $lei->oldset, {lei => $lei});
-       my $op = delete $lei->{pkt_op_c};
-       delete $lei->{pkt_op_p};
-       $self->wq_do('do_mirror', []);
+       my $op = $lei->workers_start($self, 'lei_mirror', 1, {
+               '' => [ \&mirror_done, $lei ]
+       });
+       $self->wq_io_do('do_mirror', []);
        $self->wq_close(1);
-       $lei->event_step_init; # wait for shutdowns
-       if ($lei->{oneshot}) {
-               while ($op->{sock}) { $op->event_step }
-       }
+       while ($op && $op->{sock}) { $op->event_step }
 }
 
 sub ipc_atfork_child {