X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-init;h=6a867a22944d93e4b4d39cf49ced3f8b7e91f03a;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=7ac7783007a15d4cf98e51a545db503829909d0a;hpb=522bb4a4973d4ac41b83be58dd3257e8cd038744;p=public-inbox.git diff --git a/script/public-inbox-init b/script/public-inbox-init index 7ac77830..6a867a22 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2014-2020 all contributors +# Copyright (C) 2014-2021 all contributors # License: AGPL-3.0+ use strict; use v5.10.1; @@ -91,7 +91,8 @@ sysopen($lockfh, $lockfile, O_RDWR|O_CREAT|O_EXCL) or do { warn "could not open config file: $lockfile: $!\n"; exit(255); }; -my $auto_unlink = UnlinkMe->new($lockfile); +require PublicInbox::OnDestroy; +my $auto_unlink = PublicInbox::OnDestroy->new($$, sub { unlink $lockfile }); my ($perm, %seen); if (-e $pi_config) { open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n"; @@ -185,17 +186,20 @@ $ibx->init_inbox(0, $skip_epoch, $skip_artnum); # needed for git prior to v2.1.0 umask(0077) if defined $perm; +require PublicInbox::Spawn; +PublicInbox::Spawn->import(qw(run_die)); + foreach my $addr (@address) { next if $seen{lc($addr)}; - PublicInbox::Import::run_die([@x, "--add", "$pfx.address", $addr]); + run_die([@x, "--add", "$pfx.address", $addr]); } -PublicInbox::Import::run_die([@x, "$pfx.url", $http_url]); -PublicInbox::Import::run_die([@x, "$pfx.inboxdir", $inboxdir]); +run_die([@x, "$pfx.url", $http_url]); +run_die([@x, "$pfx.inboxdir", $inboxdir]); if (defined($indexlevel)) { - PublicInbox::Import::run_die([@x, "$pfx.indexlevel", $indexlevel]); + run_die([@x, "$pfx.indexlevel", $indexlevel]); } -PublicInbox::Import::run_die([@x, "$pfx.newsgroup", $ng]) if $ng ne ''; +run_die([@x, "$pfx.newsgroup", $ng]) if $ng ne ''; # needed for git prior to v2.1.0 if (defined $perm) { @@ -205,18 +209,4 @@ if (defined $perm) { rename $pi_config_tmp, $pi_config or die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n"; -$auto_unlink->DESTROY; - -package UnlinkMe; -use strict; - -sub new { - my ($klass, $file) = @_; - bless { file => $file }, $klass; -} - -sub DESTROY { - my $f = delete($_[0]->{file}); - unlink($f) if defined($f); -} -1; +undef $auto_unlink; # trigger ->DESTROY