Skip to content

Commit 77baf12

Browse files
committed
WIP
1 parent 88d22e6 commit 77baf12

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

src/ProcessManager.php

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ public function execute(array $config, bool $streamOutput): string
3434
{
3535
$this->debugLog("Starting execution");
3636

37-
// Create temporary config file
38-
$configFile = tempnam(sys_get_temp_dir(), 'volt_config_');
39-
$this->debugLog("Created config file: $configFile");
37+
// Create temporary directory for test files
38+
$tempDir = rtrim(sys_get_temp_dir(), '/\\') . '\\volt_' . uniqid();
39+
mkdir($tempDir);
40+
$this->debugLog("Created temp directory: $tempDir");
4041

41-
// Write config to file
42+
// Create config file
43+
$configFile = $tempDir . '\\config.json';
4244
file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
43-
$this->debugLog("Wrote config to file");
44-
45-
// Prepare command with config file argument
46-
$cmd = sprintf(
47-
'"%s" --config "%s"',
48-
$this->binaryPath,
49-
$configFile
50-
);
45+
$this->debugLog("Wrote config to file: $configFile");
46+
47+
// Change to temp directory and prepare command
48+
$currentDir = getcwd();
49+
chdir($tempDir);
50+
51+
// Prepare command without any flags - the binary should read config.json by default
52+
$cmd = sprintf('"%s"', $this->binaryPath);
5153
$this->debugLog("Command: $cmd");
5254

5355
// Start process
@@ -56,13 +58,13 @@ public function execute(array $config, bool $streamOutput): string
5658
2 => ['pipe', 'w'] // stderr
5759
];
5860

59-
$this->debugLog("Opening process");
60-
$process = proc_open($cmd, $descriptorspec, $pipes, null, null, [
61-
'bypass_shell' => false // Changed to false for Windows command
61+
$this->debugLog("Opening process in directory: " . getcwd());
62+
$process = proc_open($cmd, $descriptorspec, $pipes, $tempDir, null, [
63+
'bypass_shell' => false
6264
]);
6365

6466
if (!is_resource($process)) {
65-
unlink($configFile);
67+
$this->cleanup($tempDir, $currentDir);
6668
throw new RuntimeException("Failed to start process");
6769
}
6870

@@ -91,12 +93,6 @@ public function execute(array $config, bool $streamOutput): string
9193
throw new RuntimeException("Process timed out after {$this->timeout} seconds");
9294
}
9395

94-
// Check for data timeout
95-
if (time() - $lastDataTime > 5) {
96-
$this->debugLog("No data received for 5 seconds, checking process");
97-
$lastDataTime = time();
98-
}
99-
10096
$read = $pipes;
10197
$write = null;
10298
$except = null;
@@ -134,11 +130,8 @@ public function execute(array $config, bool $streamOutput): string
134130
$exitCode = proc_close($process);
135131
$this->debugLog("Process closed with exit code: $exitCode");
136132

137-
// Clean up config file
138-
if (file_exists($configFile)) {
139-
unlink($configFile);
140-
$this->debugLog("Cleaned up config file");
141-
}
133+
// Restore original directory and cleanup
134+
$this->cleanup($tempDir, $currentDir);
142135

143136
if ($exitCode !== 0) {
144137
throw new RuntimeException("Process failed with exit code $exitCode");
@@ -165,12 +158,26 @@ public function execute(array $config, bool $streamOutput): string
165158
proc_close($process);
166159
}
167160

168-
// Clean up config file
169-
if (file_exists($configFile)) {
170-
unlink($configFile);
171-
}
161+
// Restore directory and cleanup
162+
$this->cleanup($tempDir, $currentDir);
172163

173164
throw $e;
174165
}
175166
}
176-
}
167+
168+
private function cleanup(string $tempDir, string $currentDir): void
169+
{
170+
// Restore original directory
171+
chdir($currentDir);
172+
173+
// Clean up temp directory
174+
if (file_exists($tempDir)) {
175+
$files = glob($tempDir . '/*');
176+
foreach ($files as $file) {
177+
unlink($file);
178+
}
179+
rmdir($tempDir);
180+
$this->debugLog("Cleaned up temp directory");
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)