@@ -50,10 +50,12 @@ final class InstallDeps implements IRepairStep {
5050 private string $ ffmpegInstallScript ;
5151 private string $ tfjsGPUPath ;
5252 private IBinaryFinder $ binaryFinder ;
53+ private string $ nodeModulesDir ;
5354
5455 public function __construct (IAppConfig $ config , IClientService $ clientService , LoggerInterface $ logger , IBinaryFinder $ binaryFinder ) {
5556 $ this ->config = $ config ;
5657 $ this ->binaryDir = dirname (__DIR__ , 2 ) . '/bin/ ' ;
58+ $ this ->nodeModulesDir = dirname (__DIR__ , 2 ) . '/node_modules/ ' ;
5759 $ this ->preGypBinaryDir = dirname (__DIR__ , 2 ) . '/node_modules/@mapbox/node-pre-gyp/bin/ ' ;
5860 $ this ->ffmpegDir = dirname (__DIR__ , 2 ) . '/node_modules/ffmpeg-static/ ' ;
5961 $ this ->ffmpegInstallScript = dirname (__DIR__ , 2 ) . '/node_modules/ffmpeg-static/install.js ' ;
@@ -89,6 +91,7 @@ public function run(IOutput $output): void {
8991 $ this ->runTfjsInstall ($ binaryPath );
9092 $ this ->runFfmpegInstall ($ binaryPath );
9193 $ this ->runTfjsGpuInstall ($ binaryPath );
94+ $ this ->setNodeModulesPermissions ();
9295 $ this ->setNiceBinaryPath ();
9396 } catch (\Throwable $ e ) {
9497 $ 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 {
268271 }
269272 }
270273
274+ /**
275+ * Set write permissions recursively for node_modules
276+ */
277+ protected function setNodeModulesPermissions (): void {
278+ $ iterator = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this ->nodeModulesDir ));
279+ /** @var \SplFileInfo $item */
280+ foreach ($ iterator as $ item ) {
281+ $ realpath = realpath ($ item ->getPathname ());
282+ if ($ realpath === false || ($ item ->getPerms () & 0700 ) === 0700 ) {
283+ continue ;
284+ }
285+ $ mode = $ item ->isDir () ? 0755 : 0644 ;
286+ if (chmod ($ realpath , $ mode ) === false ) {
287+ throw new \Exception ('Error when setting ' .$ this ->nodeModulesDir .'* permissions: ' . $ realpath );
288+ }
289+ }
290+ }
291+
271292 protected function isAVXSupported (): bool {
272293 try {
273294 $ cpuinfo = file_get_contents ('/proc/cpuinfo ' );
0 commit comments