--- trunk/webwork2/lib/WeBWorK/PG.pm 2002/09/16 20:56:27 554 +++ trunk/webwork2/lib/WeBWorK/PG.pm 2002/09/18 19:25:42 555 @@ -13,6 +13,7 @@ use strict; use warnings; +use File::Path qw(rmtree); use File::Temp qw(tempdir); use WeBWorK::DB::Classlist; use WeBWorK::DB::WW; @@ -94,7 +95,7 @@ # set the environment (from defineProblemEnvir) warn "PG: setting the environment (from defineProblemEnvir)\n"; - $translator->environment(defineProblemEnvir( + my $envir = defineProblemEnvir( $courseEnv, $user, $key, @@ -103,7 +104,8 @@ $psvn, $formFields, $translationOptions, - )); + ); + $translator->environment($envir); # initialize the Translator warn "PG: initializing the Translator\n"; @@ -156,6 +158,13 @@ warn "PG: translating the PG source into text\n"; $translator->translate(); + # after we're done translating, we may have to clean up after the translator. + # for example, 'images' mode uses a tempdir for dvipng's temp files. We have + # to remove it. + if ($translationOptions->{displayMode} eq 'images' && $envir->{dvipngTempDir}) { + rmtree($envir->{dvipngTempDir}, 0, 1); + } + my ($result, $state); # we'll need these on the other side of the if block! if ($translationOptions->{processAnswers}) { @@ -312,7 +321,9 @@ $envir{tempURL} = $courseEnv->{courseURLs}->{html_temp}; $envir{scriptDirectory} = undef; $envir{webworkDocsURL} = $courseEnv->{webworkURLs}->{docs}; - $envir{dvipngTempDir} = tempdir("webwork-dvipng-XXXXXXXX", TMPDIR => 1); + $envir{dvipngTempDir} = $options->{displayMode} eq 'images' + ? tempdir("webwork-dvipng-XXXXXXXX", TMPDIR => 1) + : undef; # Default values for evaluating answers