]> git.proxmox.com Git - pve-docs.git/commitdiff
asciidoc-pve: cleanup temporary files
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Oct 2016 14:48:31 +0000 (16:48 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Oct 2016 14:48:31 +0000 (16:48 +0200)
asciidoc-pve.in

index 109b06669b8813862cec3311be1d9e619a48d559..59f652d57bd6cbaa7c1deb1a5ee950c08089b154 100644 (file)
@@ -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;