From 034b35c838c1434ffc827f400cc9081da84a8687 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 11 Oct 2016 16:48:31 +0200 Subject: [PATCH] asciidoc-pve: cleanup temporary files --- asciidoc-pve.in | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/asciidoc-pve.in b/asciidoc-pve.in index 109b066..59f652d 100644 --- a/asciidoc-pve.in +++ b/asciidoc-pve.in @@ -9,6 +9,9 @@ use IO::File; use JSON; +my $verbose; +my $keep_artifacts; + my $release = '@RELEASE@'; my $clicmd = shift or @@ -62,9 +65,15 @@ sub pop_environment { } } +my $files_for_cleanup = []; + sub cleanup { - # TODO: anything ? + return if $keep_artifacts; + + foreach my $file (@$files_for_cleanup) { + unlink $file; + } } sub replace_wiki_xref { @@ -162,6 +171,8 @@ sub prepare_adoc_file { my $outfh = IO::File->new("$outfilename", "w") or die "unable to open temporary file '$outfilename'\n"; + push @$files_for_cleanup, $outfilename; + while (defined (my $line = <$fh>)) { chomp $line; if ($line =~ m/^if(n?)def::(\S+)\[(.*)\]\s*$/) { @@ -205,10 +216,10 @@ sub prepare_adoc_file { sub compile_asciidoc { my ($env) = @_; - my $verbose; my $outfile; GetOptions ("outfile=s" => \$outfile, + "keep-artifacts" => \$keep_artifacts, "verbose" => \$verbose) or die("Error in command line arguments\n"); @@ -291,6 +302,8 @@ sub compile_asciidoc { push @$cmd, '--out-file', $tmpxmlfile; + push @$files_for_cleanup, $tmpxmlfile; + my $new_infile = prepare_adoc_file($env, $infile, $attributes); push @$cmd, $new_infile; -- 2.39.2