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 5eef3f9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/common/services/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Check failure on line 57 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red ^3)

Delete `················`

Check failure on line 57 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red 3.1.1)

Delete `················`

Check failure on line 57 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 20 - node-red ^3)

Delete `················`
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`);

Check failure on line 66 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red ^3)

Replace ``Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`` with `⏎····················`Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`,⏎················`

Check failure on line 66 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red 3.1.1)

Replace ``Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`` with `⏎····················`Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`,⏎················`

Check failure on line 66 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 20 - node-red ^3)

Replace ``Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`` with `⏎····················`Cannot·read/write·to·storage·file·for·Home·Assistant·nodes`,⏎················`
}
}

Check failure on line 69 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red ^3)

Delete `····`

Check failure on line 69 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red 3.1.1)

Delete `····`

Check failure on line 69 in src/common/services/StorageService.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 20 - node-red ^3)

Delete `····`
return true;
}

Expand Down

0 comments on commit 5eef3f9

Please sign in to comment.