From 5eef3f9904fec3cadecac43563724507fa084c61 Mon Sep 17 00:00:00 2001 From: Slyke Date: Sun, 10 Nov 2024 04:09:55 -0800 Subject: [PATCH] Potential workaround for issue/1684 --- src/common/services/StorageService.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/common/services/StorageService.ts b/src/common/services/StorageService.ts index 473aaf2b9d..8c476654ac 100644 --- a/src/common/services/StorageService.ts +++ b/src/common/services/StorageService.ts @@ -47,12 +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; }