Skip to content

Commit e877cae

Browse files
authored
Merge pull request #575 from nextcloud/fix/562
fix(DeployDaemon): support for daemon names containing spaces
2 parents 0d21a18 + 6c2bf2a commit e877cae

3 files changed

Lines changed: 45 additions & 20 deletions

File tree

lib/Controller/DaemonConfigController.php

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

176-
if (!$this->service->runOccCommand(
177-
sprintf("app_api:app:register --silent %s %s --info-xml %s --test-deploy-mode",
178-
Application::TEST_DEPLOY_APPID, $daemonConfig->getName(), Application::TEST_DEPLOY_INFO_XML)
179-
)) {
176+
$commandParts = [
177+
'app_api:app:register',
178+
'--silent',
179+
Application::TEST_DEPLOY_APPID,
180+
$daemonConfig->getName(),
181+
'--info-xml',
182+
Application::TEST_DEPLOY_INFO_XML,
183+
'--test-deploy-mode',
184+
];
185+
if (!$this->service->runOccCommand($commandParts)) {
180186
return new JSONResponse(['error' => $this->l10n->t('Error starting install of ExApp')], Http::STATUS_INTERNAL_SERVER_ERROR);
181187
}
182188

@@ -199,7 +205,13 @@ public function startTestDeploy(string $name): Response {
199205
public function stopTestDeploy(string $name): Response {
200206
$exApp = $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID);
201207
if ($exApp !== null) {
202-
$this->service->runOccCommand(sprintf("app_api:app:unregister --silent --force %s", Application::TEST_DEPLOY_APPID));
208+
$commandParts = [
209+
'app_api:app:unregister',
210+
'--silent',
211+
'--force',
212+
Application::TEST_DEPLOY_APPID,
213+
];
214+
$this->service->runOccCommand($commandParts);
203215
$elapsedTime = 0;
204216
while ($elapsedTime < 5000000 && $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID) !== null) {
205217
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)