-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending error to callback after rename retry was successful #118
Comments
The cb(err) bit was added in 90a96bc If you read the explanation at the top there, it was added to allow capturing of EPERM errors due to things other than file locking (such as permission issues). Just removing the er in cb(er) will cause those errors to be swallowed. If you're right and the er value is just keeping it's assignment from the first attempt, then maybe it's scope should be adjusted somehow. How did you discover that the rename was actually successful, and that er just didn't get changed? |
Somehow my system throws an EPERM error when renaming but when the fs.stat does'nt throw any error at all Here is the code with debug console logging fs$rename(from, to, function CB(er) {
if (er) {
er.id = new Date().getTime();
console.log(`DEBUG: fs$rename error: ${er} `);
console.log(`DEBUG: assigning id to error: ${er.id}`);
} else {
console.log('DEBUG: fs$rename successful');
}
if (er && (er.code === "EACCES" || er.code === "EPERM") && Date.now() - start < 60000) {
setTimeout(function() {
fs.stat(to, function(stater, st) {
if (stater && stater.code === "ENOENT") {
console.log(`DEBUG: rename retry ${from}`);
fs$rename(from, to, CB);
} else {
console.log(`DEBUG: stat ok: callback with er ${er.id}: ${er}`);
cb(er);
}
})
}, backoff)
if (backoff < 100)
backoff += 10;
return;
}
if (cb)
cb(er)
}) And here is what is printed in the console C:\Users\A168943\dev\ng1-best-practices-app>npm install
DEBUG: fs$rename error: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\jquery\2.1.4\package.tgz.2121598981' -> 'C:\Users\A168943\AppData\Roaming\n
pm-cache2\jquery\2.1.4\package.tgz'
DEBUG: assigning id to error: 1507624235331
DEBUG: stat ok: callback with er 1507624235331: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\jquery\2.1.4\package.tgz.2121598981' -> 'C:\Users\A
168943\AppData\Roaming\npm-cache2\jquery\2.1.4\package.tgz'
DEBUG: fs$rename error: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-core-swl\1.0.0\package\package.json.3207089556' -> 'C:\Users\A168943
\AppData\Roaming\npm-cache2\bankia-core-swl\1.0.0\package\package.json'
DEBUG: assigning id to error: 1507624248391
DEBUG: stat ok: callback with er 1507624248391: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-core-swl\1.0.0\package\package.json.32070895
56' -> 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-core-swl\1.0.0\package\package.json'
npm ERR! addLocal Could not install C:\Users\A168943\AppData\Local\Temp\npm-13096-854fedcc\git-cache-9d36c7b1\ec2cab9e758695fc849dbfe1482eaea81c9ab49b
DEBUG: fs$rename error: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-ui-date\7.4.1\package\package.json.3533415015' -> 'C:\Users\A168943\
AppData\Roaming\npm-cache2\bankia-ui-date\7.4.1\package\package.json'
DEBUG: assigning id to error: 1507624249311
DEBUG: stat ok: callback with er 1507624249311: Error: EPERM: operation not permitted, rename 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-ui-date\7.4.1\package\package.json.353341501
5' -> 'C:\Users\A168943\AppData\Roaming\npm-cache2\bankia-ui-date\7.4.1\package\package.json'
npm ERR! addLocal Could not install C:\Users\A168943\AppData\Local\Temp\npm-13096-854fedcc\git-cache-259c42c5\1fc0b121eff12389bc6dc509453d67f57848f23a
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Users\\A168943\\bin\\nodejs\\node.exe" "C:\\Users\\A168943\\bin\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.9.1
npm ERR! npm v3.10.10
npm ERR! path C:\Users\A168943\AppData\Roaming\npm-cache2\jquery\2.1.4\package.tgz.2121598981
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename |
node-graceful-fs/polyfills.js
Line 106 in 65cf80d
Trying to resolve the painful npm install's EPERM (npm/npm#18380) error in a Windows system. I realized that after a successful rename retry, the 'er' variable was still assigned to the original EPERM error that the inmediate retry had just solved.
Therefore the er variable should not be defined when renaming retry is succesful (not ENOENT).
Since I've switched from cb(er) to cb() no EPERM has came up so far.
The text was updated successfully, but these errors were encountered: