Skip to content

Commit 5e3b7af

Browse files
committed
#102 - env_path setting overrides the PATH within shellWhich(). convertString does better cleaning up temp files
1 parent c7712a8 commit 5e3b7af

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/Configuration/ConfigurationDefaults.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getAllConverters() {
1616
}
1717

1818
public function __construct(&$settings) {
19-
$settings = array(
19+
$settings = array_replace(array(
2020
// Ubuntu 12.04 LTS:
2121
// /tmp
2222
// Linux
@@ -28,16 +28,18 @@ public function __construct(&$settings) {
2828
'temp_dir' => sys_get_temp_dir(),
2929
'operating_system' => php_uname('s'),
3030
'operating_system_version' => php_uname('r'),
31-
);
31+
// Override the default $PATH environmental variable.
32+
'env_path' => NULL,
33+
), (array) $settings);
3234

3335
// Attempt to get better OS information.
3436
// lsb_release is available on Ubun
3537
if ($settings['operating_system'] === 'Linux') {
3638
$lsb = trim(`which lsb_release`);
3739
if ($lsb !== '') {
3840
$lsb = escapeshellarg($lsb);
39-
$settings['operating_system'] = trim(`$lsb -is`);
40-
$settings['operating_system_version'] = trim(`$lsb -rs`);
41+
$settings['operating_system'] = trim(`$lsb -is`);
42+
$settings['operating_system_version'] = trim(`$lsb -rs`);
4143
}
4244
}
4345
elseif ($settings['operating_system'] === 'Windows NT') {

src/Engine/EngineBase.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,19 @@ public function convertString($source, &$destination) {
128128

129129
// Convert the string.
130130
file_put_contents($s_path, $source);
131-
$this->convertFile($s_path, $d_path);
132-
$destination = file_get_contents($d_path);
133-
134-
// Remove the files.
135-
unlink($s_path);
136-
unlink($d_path);
131+
try {
132+
$this->convertFile($s_path, $d_path);
133+
$destination = file_get_contents($d_path);
134+
135+
// Remove the files.
136+
unlink($s_path);
137+
unlink($d_path);
138+
} catch (\Exception $e) {
139+
// Remove the files.
140+
unlink($s_path);
141+
unlink($d_path);
142+
throw $e;
143+
}
137144

138145
return $this;
139146
}
@@ -267,13 +274,25 @@ public function shellWhich($command) {
267274
return $cache[$command];
268275
}
269276

270-
// Look in the bin folder (symlinks work fine).
277+
// Look in the bin folder for FileConverter-provided bins (symlinks work fine).
271278
$bin = realpath(__DIR__ . '/../../bin/' . $command);
272279
if ($bin !== FALSE && is_executable($bin)) {
273280
$cache[$command] = $bin;
274281
return $bin;
275282
}
276283

284+
// Look for overrides to the env_path
285+
$dirs = $this->converter->getSetting('env_path');
286+
if (isset($dirs) && strlen($dirs) > 1) {
287+
foreach (explode(':', $dirs) as $dir) {
288+
$bin = realpath("$dir/$command");
289+
if ($bin !== FALSE && is_executable($bin)) {
290+
$cache[$command] = $bin;
291+
return $bin;
292+
}
293+
}
294+
}
295+
277296
// Use the which/where command to locate the binary.
278297
$which = preg_match('@Win@', $this->settings['operating_system']) ? 'where'
279298
: 'which';

0 commit comments

Comments
 (0)