ioBroker / ioBroker.javascript

Script engine for JavaScript and Blockly
MIT License
322 stars 120 forks source link

[Bug]: `readdirSync` - "Error: Permission denied". Inside ioBroker folders tree. Needed a replacement, similar to `readFile`. #1529

Closed PeterVoronov closed 3 months ago

PeterVoronov commented 3 months ago

I'm sure that

Script type

JavaScript

The problem

Can't read content of folders under 'iobroker/iobroker-data/files/0_userdata.0'. Code:

// @ts-ignore
const nodeFS = require('node:fs');
const folder = nodeFS.readdirSync(backupDir);
error: javascript.0 (306800) May not read /opt/iobroker/iobroker-data/files/0_userdata.0/test - use writeFile/readFile instead
error: javascript.0 (306800) Error in callback: Error: Permission denied

iobroker.current.log (in debug mode!)

error: javascript.0 (306800) May not read /opt/iobroker/iobroker-data/files/0_userdata.0/test- use writeFile/readFile instead error: javascript.0 (306800) Error in callback: Error: Permission denied error: javascript.0 (306800) at checkObjectsJson (/opt/iobroker/node_modules/iobroker.javascript/lib/protectFs.js:21:19) error: javascript.0 (306800) at ProtectFs.readdirSync (/opt/iobroker/node_modules/iobroker.javascript/lib/protectFs.js:170:9) error: javascript.0 (306800) at backupGetFolderList (script.js.backup:121:34)

Version of nodejs

v18.19.1

Version of ioBroker js-controller

5.0.19

Version of adapter

v7.11.1

klein0r commented 3 months ago

I've restricted the access to iobroker-data/files to avoid file changes / writes via node:fs (to avoid missing / incorrect meta data). But you're right: It should be possible to read / list all files. Going to fix this in the next version.

PeterVoronov commented 3 months ago

I've restricted the access to iobroker-data/files to avoid file changes / writes via node:fs (to avoid missing / incorrect meta data). But you're right: It should be possible to read / list all files. Going to fix this in the next version.

Thanks for the understanding!

vowill commented 3 months ago

I got the same issue using Version 7.11.1 installed on March 29. What is the version number where the 'fix' is included?

PS: Thx, @klein0r, for your continous and great effort in improving this adapter 👍!

klein0r commented 3 months ago

What is the version number where the 'fix' is included?

Not released right now