From 692a64b2d3189a322d8719f8e04a0b31dff65285 Mon Sep 17 00:00:00 2001 From: Marcus Ekwall Date: Tue, 10 Oct 2017 15:49:49 +0200 Subject: [PATCH 1/2] Use fs.rename instead of fs.renameSync fs.renameSync does not have the workarounds added by graceful-fs, and this causes issue in Windows. [See the polyfill in graceful-fs for more info.](https://github.com/isaacs/node-graceful-fs/blob/master/polyfills.js#L94). This should fix #104 and any outstanding EACCES and EPERM on Windows for all packages that uses write-file-atomic as dependency. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3b5607d..9b8dd9e 100644 --- a/index.js +++ b/index.js @@ -189,8 +189,9 @@ function writeFileSync (filename, data, options) { fs.closeSync(fd) if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid) if (options.mode) fs.chmodSync(tmpfile, options.mode) - fs.renameSync(tmpfile, filename) - removeOnExit() + fs.rename(tmpfile, filename, function () { + removeOnExit() + }) } catch (err) { removeOnExit() try { fs.unlinkSync(tmpfile) } catch (e) {} From 4e4ece9d797dfc06f1ece87d5b7a48a4403e9d90 Mon Sep 17 00:00:00 2001 From: mekwall Date: Tue, 10 Oct 2017 16:10:12 +0200 Subject: [PATCH 2/2] Throw error on rename failure --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9b8dd9e..8bd7b33 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,8 @@ function writeFileSync (filename, data, options) { fs.closeSync(fd) if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid) if (options.mode) fs.chmodSync(tmpfile, options.mode) - fs.rename(tmpfile, filename, function () { + fs.rename(tmpfile, filename, function (err) { + if (err) throw err removeOnExit() }) } catch (err) {