Wednesday, 15 March 2017

Node scandir permission denied

I am programming a Node js application which will be running on Raspberry PI 3. I am making a functionallity that will scan the /media/pi folder and then scan the folders inside that folder to find config.json

I have this two functions which do that:

function findUSBFolders() {
    return fs.readdirSync(mediaFolder);
}

function findConfigFiles(p) {
    ret = [];
    files = fs.readdirSync(p);
    for(var i in files) {
        if(files[i].startsWith('config')) {
            ret.push(path.join(p, files[i])); 
        }
    }
    return ret;
}

On one raspberry I don't get any errors but on the other I get this:

fs.js:912 return binding.readdir(pathModule._makeLong(path), options.encoding); ^

Error: EACCES: permission denied, scandir '/media/pi/D03E-191B'
at Object.fs.readdirSync (fs.js:912:18)
at findConfigFiles (/home/pi/seatcontroller/src/waitConfig.js:78:13)
at findConfigs (/home/pi/seatcontroller/src/waitConfig.js:61:21)
at Timeout._onTimeout (/home/pi/seatcontroller/src/waitConfig.js:35:15)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)

these are the permissions for /media/pi:

pi@raspberrypi:~ $ ls -l /media/pi
total 4
drwx------ 4 pi pi 4096 Jan  1  1970 D03E-191B

I also tried to run sudo with node server.js but it acts strange, it seems that it gets stuck when I run it with sudo.

Let me know if you need some more code.

What could be the problem?



via durisvk10

No comments:

Post a Comment