From 9867a7279070e06caf2768bdb04099e09fea2358 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 31 Dec 2020 13:51:43 +0000 Subject: init: remove embedded UnlinkMe package PublicInbox::OnDestroy can do the same thing --- script/public-inbox-init | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'script') 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 -- cgit v1.2.3-24-ge0c7