my @c_opt = qw(c=s@ C=s@ quiet|q);
my @net_opt = (qw(no-torsocks torsocks=s), PublicInbox::LeiQuery::curl_opt());
-my @lxs_opt = qw(remote! local! external! include|I=s@ exclude=s@ only=s@
+my @lxs_opt = qw(remote! local! external! include|I=s@ exclude=s@ only|O=s@
import-remote!);
# we don't support -C as an alias for --find-copies since it's already
}, qw(config-file|system|global|file|f=s), # for conflict detection
qw(edit|e c=s@ C=s@), pass_through('git config') ],
'inspect' => [ 'ITEMS...|--stdin', 'inspect lei/store and/or local external',
- qw(stdin| pretty ascii dir=s), @c_opt ],
+ qw(stdin| pretty ascii dir|d=s), @c_opt ],
'init' => [ '[DIRNAME]', sub {
"initialize storage, default: ".store_path($_[0]);
'path-a|a=s' => 'pre-image pathname associated with OID',
'path-b|b=s' => 'post-image pathname associated with OID',
'git-dir=s@' => 'additional git repository to scan',
-'dir=s inspect' => 'specify a inboxdir, extindex topdir or Xapian shard',
+'dir|d=s inspect' =>
+ 'specify a inboxdir, extindex topdir or Xapian shard',
'proxy=s' => [ 'PROTO://HOST[:PORT]', # shared with curl(1)
"proxy for (e.g. `socks5h://0:9050')" ],
'torsocks=s' => ['VAL|auto|no|yes',
'exclude specified external(s) from search' ],
'include|I=s@ q' => [ 'LOCATION',
'include specified external(s) in search' ],
-'only=s@ q' => [ 'LOCATION',
+'only|O=s@ q' => [ 'LOCATION',
'only use specified external(s) for search' ],
'jobs=s q' => [ '[SEARCH_JOBS][,WRITER_JOBS]',
'control number of search and writer jobs' ],
# pronounced "exit": x_it(1 << 8) => exit(1); x_it(13) => SIGPIPE
sub x_it ($$) {
my ($self, $code) = @_;
+ local $current_lei = $self;
# make sure client sees stdout before exit
$self->{1}->autoflush(1) if $self->{1};
stop_pager($self);
sub fail_handler ($;$$) {
my ($lei, $code, $io) = @_;
+ local $current_lei = $lei;
close($io) if $io; # needed to avoid warnings on SIGPIPE
_drop_wq($lei);
x_it($lei, $code // (1 << 8));
sub fail ($$;$) {
my ($self, $buf, $exit_code) = @_;
+ local $current_lei = $self;
$self->{failed}++;
- err($self, $buf) if defined $buf;
+ warn($buf, "\n") if defined $buf;
$self->{pkt_op_p}->pkt_do('fail_handler') if $self->{pkt_op_p};
x_it($self, ($exit_code // 1) << 8);
undef;
sub child_error { # passes non-fatal curl exit codes to user
my ($self, $child_error, $msg) = @_; # child_error is $?
+ local $current_lei = $self;
$child_error ||= 1 << 8;
- $self->err($msg) if $msg;
+ warn($msg, "\n") if defined $msg;
if ($self->{pkt_op_p}) { # to top lei-daemon
$self->{pkt_op_p}->pkt_do('child_error', $child_error);
} elsif ($self->{sock}) { # to lei(1) client
eval 'no warnings; undef $PublicInbox::LeiNoteEvent::to_flush';
undef $errors_log;
$quit = \&CORE::exit;
- $self->{-eml_noisy} or # only "lei import" sets this atm
- $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
+ if (!$self->{-eml_noisy}) { # only "lei import" sets this atm
+ my $cb = $SIG{__WARN__} // \&CORE::warn;
+ $SIG{__WARN__} = sub {
+ $cb->(@_) unless PublicInbox::Eml::warn_ignore(@_)
+ };
+ }
$current_lei = $persist ? undef : $self; # for SIG{__WARN__}
}
$cmd = [ Text::ParseWords::shellwords($cmd) ];
send($sock, exec_buf($cmd, {}), MSG_EOR) if $sock;
} else {
- err($self, "W: unsupported --alert=$op"); # non-fatal
+ warn("W: unsupported --alert=$op\n"); # non-fatal
}
}
}
# display a message for user before spawning full-screen $VISUAL
sub pgr_err {
my ($self, @msg) = @_;
- return $self->err(@msg) unless $self->{sock} && -t $self->{2};
+ return warn(@msg) unless $self->{sock} && -t $self->{2};
start_pager($self, { LESS => 'RX' }); # no 'F' so we prompt
print { $self->{2} } @msg;
$self->{2}->autoflush(1);
sub dclose {
my ($self) = @_;
+ local $current_lei = $self;
delete $self->{-progress};
_drop_wq($self) if $self->{failed};
$self->close if $self->{-event_init_done}; # PublicInbox::DS::close
sub wq_done_wait { # dwaitpid callback
my ($arg, $pid) = @_;
my ($wq, $lei) = @$arg;
+ local $current_lei = $lei;
my $err_type = $lei->{-err_type};
$? and $lei->child_error($?,
$err_type ? "$err_type errors during $lei->{cmd}" : ());
sub wq_eof { # EOF callback for main daemon
my ($lei) = @_;
+ local $current_lei = $lei;
my $wq1 = delete $lei->{wq1} // return $lei->fail; # already failed
$wq1->wq_wait_old($wq1->can('_wq_done_wait') // \&wq_done_wait, $lei);
}
$seen{$url} = undef;
my $state = $cfg->get_1("watch.$url.state");
if (!watch_state_ok($state)) {
- $lei->err("watch.$url.state=$state not supported");
+ warn("watch.$url.state=$state not supported\n");
next;
}
if ($url =~ /\Amaildir:(.+)/i) {
sub sto_done_request {
my ($lei, $sock) = @_;
+ local $current_lei = $lei;
eval {
if ($sock //= $lei->{sock}) { # issue, async wait
$lei->{sto}->wq_io_do('done', [ $sock ]);
my $wait = $lei->{sto}->wq_do('done');
}
};
- $lei->err($@) if $@;
+ warn($@) if $@;
}
sub cfg_dump ($$) {
my ($lei, $f) = @_;
my $ret = eval { PublicInbox::Config->git_config_dump($f, $lei->{2}) };
return $ret if !$@;
- $lei->err($@);
+ warn($@);
undef;
}
+sub request_umask {
+ my ($lei) = @_;
+ my $s = $lei->{sock} // return;
+ send($s, 'umask', MSG_EOR) // die "send: $!";
+ vec(my $rvec = '', fileno($s), 1) = 1;
+ select($rvec, undef, undef, 2) or die 'timeout waiting for umask';
+ recv($s, my $v, 5, 0) // die "recv: $!";
+ (my $u, $lei->{client_umask}) = unpack('AV', $v);
+ $u eq 'u' or warn "E: recv $v has no umask";
+}
+
1;