]> Sergey Matveev's repositories - public-inbox.git/commitdiff
init: remove embedded UnlinkMe package
authorEric Wong <e@80x24.org>
Thu, 31 Dec 2020 13:51:43 +0000 (13:51 +0000)
committerEric Wong <e@80x24.org>
Fri, 1 Jan 2021 05:00:39 +0000 (05:00 +0000)
PublicInbox::OnDestroy can do the same thing

script/public-inbox-init

index 85d14377c2c7aab7c8500ca79cd86fe0ab802eab..693f5ca17ced941ac936ba4e43895fc739628d2e 100755 (executable)
@@ -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