diff options
author | Eric Wong <e@80x24.org> | 2020-12-31 13:51:43 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-01 05:00:39 +0000 |
commit | 9867a7279070e06caf2768bdb04099e09fea2358 (patch) | |
tree | ca2267c1f6a5b83351fbfbe1186a4bffee2781ad | |
parent | 9c7737d056f832824812086373a13922dd08a0c5 (diff) | |
download | public-inbox-9867a7279070e06caf2768bdb04099e09fea2358.tar.gz |
PublicInbox::OnDestroy can do the same thing
-rwxr-xr-x | script/public-inbox-init | 19 |
1 files 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 |