user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: [PATCH 2/4] convert+compact: fix when running without ~/.public-inbox/config
Date: Fri, 11 May 2018 19:20:16 +0000	[thread overview]
Message-ID: <20180511192018.6432-3-e@80x24.org> (raw)
In-Reply-To: <20180511192018.6432-1-e@80x24.org>

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) };

  parent reply	other threads:[~2018-05-11 19:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11 19:20 [PATCH 0/4] test fixes for latest CPAN modules Eric Wong
2018-05-11 19:20 ` [PATCH 1/4] content_id: workaround quote handling change in Email::* modules Eric Wong
2018-05-11 19:20 ` Eric Wong [this message]
2018-05-11 19:20 ` [PATCH 3/4] t/v2mda: setup emergency Maildir for test Eric Wong
2018-05-11 19:20 ` [PATCH 4/4] t/search: quiet warning from Encode.pm Eric Wong
2018-05-11 19:27 ` [PATCH 0/4] test fixes for latest CPAN modules Konstantin Ryabitsev
2018-05-11 19:38   ` Eric Wong
2018-05-11 19:50     ` Konstantin Ryabitsev
2018-05-16  5:12       ` Eric Wong
2018-05-23 21:51         ` Konstantin Ryabitsev
2018-05-24  8:41           ` Eric Wong
2018-05-24 15:15             ` Konstantin Ryabitsev
2018-05-30 11:57               ` Eric Wong
2018-05-30 15:28                 ` Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180511192018.6432-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=konstantin@linuxfoundation.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).