Skip to content

Commit

Permalink
check home directory is writable or not
Browse files Browse the repository at this point in the history
if home directory is not writable, libreoffice can not write tmp file so it can not complete convert
  • Loading branch information
zxp86021 authored Sep 11, 2018
1 parent c5620ab commit acf2022
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/OfficeConverter/OfficeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ private function getAllowedConverter($extension = null)
*/
private function exec($cmd, $input = '')
{
$cmd = "export HOME=/tmp && " . $cmd;
// Cannot use $_SERVER superglobal since that's empty during UnitUnishTestCase
// getenv('HOME') isn't set on Windows and generates a Notice.
$home = getenv('HOME');
if (!is_writable($home)) {
$cmd = 'export HOME=/tmp && ' . $cmd;
}
$process = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
fwrite($pipes[0], $input);
fclose($pipes[0]);
Expand Down

0 comments on commit acf2022

Please sign in to comment.