Skip to content

Commit f762e59

Browse files
authored
Merge pull request #579 from nextcloud/backport/575/stable31
[stable31] fix(DeployDaemon): support for daemon names containing spaces
2 parents 1b3867d + 5288f1d commit f762e59

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

lib/Controller/DaemonConfigController.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,16 @@ public function startTestDeploy(string $name): Response {
183183
return new JSONResponse(['error' => $this->l10n->t('Daemon config not found')], Http::STATUS_NOT_FOUND);
184184
}
185185

186-
if (!$this->service->runOccCommand(
187-
sprintf("app_api:app:register --silent %s %s --info-xml %s --test-deploy-mode",
188-
Application::TEST_DEPLOY_APPID, $daemonConfig->getName(), Application::TEST_DEPLOY_INFO_XML)
189-
)) {
186+
$commandParts = [
187+
'app_api:app:register',
188+
'--silent',
189+
Application::TEST_DEPLOY_APPID,
190+
$daemonConfig->getName(),
191+
'--info-xml',
192+
Application::TEST_DEPLOY_INFO_XML,
193+
'--test-deploy-mode',
194+
];
195+
if (!$this->service->runOccCommand($commandParts)) {
190196
return new JSONResponse(['error' => $this->l10n->t('Error starting install of ExApp')], Http::STATUS_INTERNAL_SERVER_ERROR);
191197
}
192198

@@ -209,7 +215,13 @@ public function startTestDeploy(string $name): Response {
209215
public function stopTestDeploy(string $name): Response {
210216
$exApp = $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID);
211217
if ($exApp !== null) {
212-
$this->service->runOccCommand(sprintf("app_api:app:unregister --silent --force %s", Application::TEST_DEPLOY_APPID));
218+
$commandParts = [
219+
'app_api:app:unregister',
220+
'--silent',
221+
'--force',
222+
Application::TEST_DEPLOY_APPID,
223+
];
224+
$this->service->runOccCommand($commandParts);
213225
$elapsedTime = 0;
214226
while ($elapsedTime < 5000000 && $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID) !== null) {
215227
usleep(150000); // 0.15

lib/Controller/ExAppsPageController.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,23 +320,32 @@ public function enableApp(string $appId, array $deployOptions = []): JSONRespons
320320

321321
$envOptions = isset($deployOptions['environment_variables'])
322322
? array_keys($deployOptions['environment_variables']) : [];
323-
$envOptionsString = '';
323+
$envArgs = [];
324324
foreach ($envOptions as $envOption) {
325-
$envOptionsString .= sprintf(' --env %s=%s', $envOption, $deployOptions['environment_variables'][$envOption]);
325+
$envArgs[] = '--env';
326+
$envArgs[] = sprintf('%s=%s', $envOption, $deployOptions['environment_variables'][$envOption]);
326327
}
327-
$envOptionsString = trim($envOptionsString);
328328

329329
$mountOptions = $deployOptions['mounts'] ?? [];
330-
$mountOptionsString = '';
330+
$mountArgs = [];
331331
foreach ($mountOptions as $mountOption) {
332332
$readonlyModifier = $mountOption['readonly'] ? 'ro' : 'rw';
333-
$mountOptionsString .= sprintf(' --mount %s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier);
333+
$mountArgs[] = '--mount';
334+
$mountArgs[] = sprintf('%s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier);
334335
}
335-
$mountOptionsString = trim($mountOptionsString);
336336

337337
// If ExApp is not registered - then it's a "Deploy and Enable" action.
338338
if (!$exApp) {
339-
if (!$this->service->runOccCommand(sprintf("app_api:app:register --silent %s %s %s", $appId, $envOptionsString, $mountOptionsString))) {
339+
$commandParts = array_merge(
340+
[
341+
'app_api:app:register',
342+
'--silent',
343+
$appId,
344+
],
345+
$envArgs,
346+
$mountArgs
347+
);
348+
if (!$this->service->runOccCommand($commandParts)) {
340349
return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting install of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR);
341350
}
342351
$elapsedTime = 0;
@@ -394,7 +403,12 @@ public function updateApp(string $appId): JSONResponse {
394403
}
395404

396405
$exAppOldVersion = $this->exAppService->getExApp($appId)->getVersion();
397-
if (!$this->service->runOccCommand(sprintf("app_api:app:update --silent %s", $appId))) {
406+
$commandParts = [
407+
'app_api:app:update',
408+
'--silent',
409+
$appId,
410+
];
411+
if (!$this->service->runOccCommand($commandParts)) {
398412
return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting update of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR);
399413
}
400414

lib/Service/AppAPIService.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,16 @@ public function dispatchExAppInitInternal(ExApp $exApp): void {
426426
/**
427427
* Dispatch ExApp initialization step, that may take a long time to display the progress of initialization.
428428
*/
429-
public function runOccCommand(string $command): bool {
430-
$args = array_map(function ($arg) {
431-
return $arg === '' ? null : escapeshellarg($arg);
432-
}, explode(' ', $command));
433-
$args = array_filter($args, fn ($arg) => $arg !== null);
434-
$args[] = '--no-ansi --no-warnings';
429+
public function runOccCommand(array $commandParts): bool {
430+
$args = array_filter($commandParts, static fn ($part) => $part !== null);
431+
$args[] = '--no-ansi';
432+
$args[] = '--no-warnings';
435433
return $this->runOccCommandInternal($args);
436434
}
437435

438436
public function runOccCommandInternal(array $args): bool {
439-
$args = implode(' ', $args);
437+
$escapedArgs = array_map('escapeshellarg', $args);
438+
$args = implode(' ', $escapedArgs);
440439
$descriptors = [
441440
0 => ['pipe', 'r'],
442441
1 => ['pipe', 'w'],

0 commit comments

Comments
 (0)