From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: 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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5C2511FFB0 for ; Thu, 31 Dec 2020 13:51:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 25/36] init: remove embedded UnlinkMe package Date: Thu, 31 Dec 2020 13:51:43 +0000 Message-Id: <20201231135154.6070-26-e@80x24.org> In-Reply-To: <20201231135154.6070-1-e@80x24.org> References: <20201231135154.6070-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: PublicInbox::OnDestroy can do the same thing --- script/public-inbox-init | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/script/public-inbox-init b/script/public-inbox-init index 85d14377..693f5ca1 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -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"; @@ -208,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