]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-init
init+convert: create non-existing directory hierarchies
[public-inbox.git] / script / public-inbox-init
index 037e8e56409bfd229aad25371f0c3461708b0e54..c775eb3146ba485bb22f16a03d45506c1cef85cb 100755 (executable)
@@ -5,9 +5,8 @@ use strict;
 use v5.10.1;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use Fcntl qw(:DEFAULT);
-my $usage = 'public-inbox-init NAME INBOX_DIR HTTP_URL ADDRESS [ADDRESS..]';
 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
-usage: $usage
+usage: public-inbox-init NAME INBOX_DIR HTTP_URL ADDRESS [ADDRESS..]
 
   Initialize a public-inbox
 
@@ -44,10 +43,10 @@ my %opts = (
        'j|jobs=i' => \$jobs,
        'ng|newsgroup=s' => \$ng,
        'skip-docdata' => \$skip_docdata,
-       'help|?' => \$show_help,
+       'help|h' => \$show_help,
 );
 my $usage_cb = sub {
-       print STDERR "Usage: $usage\n";
+       print STDERR $help;
        exit 1;
 };
 GetOptions(%opts) or $usage_cb->();
@@ -139,8 +138,9 @@ close($fh) or die "failed to close $pi_config_tmp: $!\n";
 my $pfx = "publicinbox.$name";
 my @x = (qw/git config/, "--file=$pi_config_tmp");
 
-require Cwd;
-$inboxdir = Cwd::abs_path($inboxdir);
+require File::Spec;
+$inboxdir = File::Spec->canonpath($inboxdir);
+
 die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
 if (-f "$inboxdir/inbox.lock") {
        if (!defined $version) {
@@ -186,6 +186,11 @@ if ($skip_docdata) {
        $ibx->{-skip_docdata} = $skip_docdata;
 }
 $ibx->init_inbox(0, $skip_epoch, $skip_artnum);
+require Cwd;
+my $tmp = Cwd::abs_path($inboxdir);
+defined($tmp) or die "failed to resolve $inboxdir: $!\n";
+$inboxdir = $tmp;
+die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s;
 
 # needed for git prior to v2.1.0
 umask(0077) if defined $perm;