Skip to content

Commit

Permalink
simplify tmp file deletion for command converters
Browse files Browse the repository at this point in the history
  • Loading branch information
bicpi committed May 6, 2013
1 parent ee57256 commit 4a9ea4b
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/bicpi/HtmlConverter/Converter/AbstractCommandTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ public function convert($html)
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(uniqid(mt_rand()));
file_put_contents($path, $html);

try {
$process = new Process(sprintf($this->getCommand(), escapeshellarg($path)));
$process->run();
$process = new Process(sprintf($this->getCommand(), escapeshellarg($path)));
$process->run();

unlink($path);

if (!$process->isSuccessful()) {
throw new ConverterException($process->getErrorOutput());
}

return $process->getOutput();

unlink($path);
} catch (\Exception $e) {
unlink($path);
throw $e;
if (!$process->isSuccessful()) {
throw new ConverterException($process->getErrorOutput());
}

return $process->getOutput();
}
}

0 comments on commit 4a9ea4b

Please sign in to comment.