From f94ce695b7921343dc2c747d283628a723f29dbe Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 17 Apr 2020 16:45:33 +0800 Subject: [PATCH 1/3] Try to fix EPERM See https://github.com/isaacs/node-graceful-fs/issues/104 --- polyfills.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyfills.js b/polyfills.js index a5808d2..2f600f5 100644 --- a/polyfills.js +++ b/polyfills.js @@ -99,7 +99,7 @@ function patch (fs) { && Date.now() - start < 60000) { setTimeout(function() { fs.stat(to, function (stater, st) { - if (stater && stater.code === "ENOENT") + if (stater && (stater.code === "ENOENT" || st.isFile())) fs$rename(from, to, CB); else cb(er) From fd70e062da28f83b131c1ad3a701fa32eeb8cac4 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 17 Apr 2020 16:47:18 +0800 Subject: [PATCH 2/3] Update polyfills.js --- polyfills.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyfills.js b/polyfills.js index 2f600f5..7b22190 100644 --- a/polyfills.js +++ b/polyfills.js @@ -99,7 +99,7 @@ function patch (fs) { && Date.now() - start < 60000) { setTimeout(function() { fs.stat(to, function (stater, st) { - if (stater && (stater.code === "ENOENT" || st.isFile())) + if ((stater && stater.code === "ENOENT") || (st && st.isFile())) fs$rename(from, to, CB); else cb(er) From 442ae995d1466d40130e8fe4b21d1c2a415b7493 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 17 Apr 2020 20:12:43 +0800 Subject: [PATCH 3/3] Update polyfills.js --- polyfills.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/polyfills.js b/polyfills.js index 7b22190..f084bde 100644 --- a/polyfills.js +++ b/polyfills.js @@ -99,6 +99,11 @@ function patch (fs) { && Date.now() - start < 60000) { setTimeout(function() { fs.stat(to, function (stater, st) { + // If "to" already exists but is open by another process, + // windows gives EPERM when trying to overwrite the destination. + // We retry because it may be caused by anti-virus or something else + // out of our control (#104). If "to" is a directory, however, + // we must fail fast, because Windows will never allow this (#98) if ((stater && stater.code === "ENOENT") || (st && st.isFile())) fs$rename(from, to, CB); else