Skip to content

Commit

Permalink
Potential workaround for issue/1684
Browse files Browse the repository at this point in the history
  • Loading branch information
Slyke committed Nov 10, 2024
1 parent e311047 commit c0e6b55
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/common/services/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ class Storage {

try {
fs.accessSync(path, fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {
throw new Error(
'Cannot read/write to storage file for Home Assistant nodes',
);
} catch (errFirst) {
// Actually test if there's no permissions, for NFS environments
// See: https://github.com/nodejs/node/issues/28656
const dateTime = new Date().getTime();
const filePath = `${path}/tmp_${dateTime}.test`;
try {
const content = `NodeRed ${PACKAGE_NAME} ${dateTime}`;

fs.writeFileSync(filePath, content);
const readContent = fs.readFileSync(filePath, 'utf8');
if (readContent !== content) {
throw new Error('Content mismatch');
}
fs.unlinkSync(filePath);
} catch (err) {
console.error({ filePath }, err);
throw new Error(
`Cannot read/write to storage file for Home Assistant nodes`,
);
}
}

return true;
Expand Down

0 comments on commit c0e6b55

Please sign in to comment.