diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-05-27 07:27:39 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-05-27 07:27:39 +0300 |
commit | 271c2e2aa52dd2fc749b8c06aadf44c86ffbe205 (patch) | |
tree | a9ecc6e1ff7162c0881e4b93c8639e34a43588da | |
parent | a57226f3259c76d42a385f0bea64680018dcdad8 (diff) | |
download | config-haproxy-271c2e2aa52dd2fc749b8c06aadf44c86ffbe205.tar.gz config-haproxy-271c2e2aa52dd2fc749b8c06aadf44c86ffbe205.tar.bz2 |
Unlink tempfile on error
-rw-r--r-- | lib/Config/HAProxy.pm | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/Config/HAProxy.pm b/lib/Config/HAProxy.pm index 44cc3fb..175e402 100644 --- a/lib/Config/HAProxy.pm +++ b/lib/Config/HAProxy.pm @@ -226,24 +226,25 @@ sub save { my @wrargs = %_; return unless $self->tree;# FIXME return unless $self->tree->is_dirty; my ($fh, $tempfile) = tempfile('haproxy.XXXXXX', DIR => dirname($self->filename)); $self->write($fh, @wrargs); close($fh); if (my $cmd = $self->lint) { my ($ok, $err, $full, $outbuf, $errbuf) = run(command => "$cmd $tempfile"); unless ($ok) { + unlink $tempfile; if ($errbuf && @$errbuf) { croak "Syntax check failed: ".join("\n", @$errbuf)."\n"; } croak $err; } } return 1 if $dry_run; my $sb = stat($self->filename); $self->backup; rename($tempfile, $self->filename) or croak "can't rename $tempfile to ".$self->tempfile.": $!"; |