Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ module.exports = (dirname, name) => {
write: (obj) => new Promise((resolve, reject) => {
jsonfile.writeFile(fullpath, obj, (err) => {
if (err) return reject(err);
// same as chmod 600
fs.chmodSync(fullpath, fs.constants.S_IRUSR | fs.constants.S_IWUSR);
// if a platform is not Windows(include x64)
if ('win32' !== process.platform) {
// same as chmod 600
fs.chmodSync(fullpath, fs.constants.S_IRUSR | fs.constants.S_IWUSR);
}
resolve(obj);
});
}),
Expand Down
23 changes: 13 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ test('write', async (t) => {
const writeGlobal = await dotglobal.write({a: 1});
const writeLocal = await dotlocal.write({a: 1});

// If file permission is incorrect,
// {{file permission value} logical AND {777 in octal}}
// !== {correct permission value}.
if ((fs.statSync(dotglobalfullpath).mode & 0o777) !== (fs.constants.S_IRUSR
| fs.constants.S_IWUSR)) {
t.fail();
}
if ((fs.statSync(dotlocalfullpath).mode & 0o777) !== (fs.constants.S_IRUSR
| fs.constants.S_IWUSR)) {
t.fail();
// if a platform is not Windows(include x64)
if ('win32' !== process.platform) {
// If file permission is incorrect,
// {{file permission value} logical AND {777 in octal}}
// !== {correct permission value}.
if ((fs.statSync(dotglobalfullpath).mode & 0o777) !== (fs.constants.S_IRUSR
| fs.constants.S_IWUSR)) {
t.fail();
}
if ((fs.statSync(dotlocalfullpath).mode & 0o777) !== (fs.constants.S_IRUSR
| fs.constants.S_IWUSR)) {
t.fail();
}
}
t.pass();
await dotglobal.delete();
Expand Down