diff --git a/lib/Migration/InstallDeps.php b/lib/Migration/InstallDeps.php index db0bcf059..af2de45d4 100644 --- a/lib/Migration/InstallDeps.php +++ b/lib/Migration/InstallDeps.php @@ -50,10 +50,12 @@ final class InstallDeps implements IRepairStep { private string $ffmpegInstallScript; private string $tfjsGPUPath; private IBinaryFinder $binaryFinder; + private string $nodeModulesDir; public function __construct(IAppConfig $config, IClientService $clientService, LoggerInterface $logger, IBinaryFinder $binaryFinder) { $this->config = $config; $this->binaryDir = dirname(__DIR__, 2) . '/bin/'; + $this->nodeModulesDir = dirname(__DIR__, 2) . '/node_modules/'; $this->preGypBinaryDir = dirname(__DIR__, 2) . '/node_modules/@mapbox/node-pre-gyp/bin/'; $this->ffmpegDir = dirname(__DIR__, 2) . '/node_modules/ffmpeg-static/'; $this->ffmpegInstallScript = dirname(__DIR__, 2) . '/node_modules/ffmpeg-static/install.js'; @@ -89,6 +91,7 @@ public function run(IOutput $output): void { $this->runTfjsInstall($binaryPath); $this->runFfmpegInstall($binaryPath); $this->runTfjsGpuInstall($binaryPath); + $this->setNodeModulesPermissions(); $this->setNiceBinaryPath(); } catch (\Throwable $e) { $output->warning('Failed to automatically install dependencies for recognize. Check the recognize admin panel for potential problems.'); @@ -268,6 +271,24 @@ protected function setBinariesPermissions(): void { } } + /** + * Set write permissions recursively for node_modules + */ + protected function setNodeModulesPermissions(): void { + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->nodeModulesDir)); + /** @var \SplFileInfo $item */ + foreach ($iterator as $item) { + $realpath = realpath($item->getPathname()); + if ($realpath === false || ($item->getPerms() & 0700) === 0700) { + continue; + } + $mode = $item->isDir() ? 0755 : 0644; + if (chmod($realpath, $mode) === false) { + throw new \Exception('Error when setting '.$this->nodeModulesDir.'* permissions: ' . $realpath); + } + } + } + protected function isAVXSupported(): bool { try { $cpuinfo = file_get_contents('/proc/cpuinfo');