From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0A5171F51C; Fri, 11 May 2018 19:20:19 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: Konstantin Ryabitsev Subject: [PATCH 2/4] convert+compact: fix when running without ~/.public-inbox/config Date: Fri, 11 May 2018 19:20:16 +0000 Message-Id: <20180511192018.6432-3-e@80x24.org> In-Reply-To: <20180511192018.6432-1-e@80x24.org> References: <20180511192018.6432-1-e@80x24.org> List-Id: Some users may not have any public-inboxes configured, especially in tests. --- script/public-inbox-compact | 10 ++++++---- script/public-inbox-convert | 10 ++++++---- t/convert-compact.t | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/script/public-inbox-compact b/script/public-inbox-compact index 5f18497..d22e403 100755 --- a/script/public-inbox-compact +++ b/script/public-inbox-compact @@ -13,12 +13,14 @@ use File::Path qw(remove_tree); use PublicInbox::Spawn qw(spawn); my $usage = "Usage: public-inbox-compact REPO_DIR\n"; my $dir = shift or die $usage; -my $config = PublicInbox::Config->new; +my $config = eval { PublicInbox::Config->new }; my $ibx; $dir = abs_path($dir); -$config->each_inbox(sub { - $ibx = $_[0] if abs_path($_[0]->{mainrepo}) eq $dir -}); +if ($config) { + $config->each_inbox(sub { + $ibx = $_[0] if abs_path($_[0]->{mainrepo}) eq $dir + }); +} unless ($ibx) { warn "W: $dir not configured in ". PublicInbox::Config::default_file() . "\n"; diff --git a/script/public-inbox-convert b/script/public-inbox-convert index 2979a0c..bd8fb98 100755 --- a/script/public-inbox-convert +++ b/script/public-inbox-convert @@ -25,12 +25,14 @@ my $old_dir = shift or die $usage; my $new_dir = shift or die $usage; die "$new_dir exists\n" if -d $new_dir; die "$old_dir not a directory\n" unless -d $old_dir; -my $config = PublicInbox::Config->new; +my $config = eval { PublicInbox::Config->new }; $old_dir = abs_path($old_dir); my $old; -$config->each_inbox(sub { - $old = $_[0] if abs_path($_[0]->{mainrepo}) eq $old_dir; -}); +if ($config) { + $config->each_inbox(sub { + $old = $_[0] if abs_path($_[0]->{mainrepo}) eq $old_dir; + }); +} unless ($old) { warn "W: $old_dir not configured in " . PublicInbox::Config::default_file() . "\n"; diff --git a/t/convert-compact.t b/t/convert-compact.t index ced4541..e923200 100644 --- a/t/convert-compact.t +++ b/t/convert-compact.t @@ -54,6 +54,7 @@ foreach (@xdir) { } local $ENV{PATH} = "blib/script:$ENV{PATH}"; +local $ENV{PI_CONFIG} = '/dev/null'; open my $err, '>>', "$tmpdir/err.log" or die "open: err.log $!\n"; open my $out, '>>', "$tmpdir/out.log" or die "open: out.log $!\n"; my $rdr = { 1 => fileno($out), 2 => fileno($err) };