Skip to content
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

fs.removeSync silently fails #407

Closed
FredrikJohansson-SATO opened this issue Apr 25, 2017 · 7 comments
Closed

fs.removeSync silently fails #407

FredrikJohansson-SATO opened this issue Apr 25, 2017 · 7 comments

Comments

@FredrikJohansson-SATO
Copy link

When using fs.removeSync in a try/catch block, it silently fails. However, if I instead use fs.remove with an error callback function, it does end up in the callback method.

try {
    fs.removeSync('C:\\Projects\\testdir');
} catch (err) { 
    console.log("Error", err); 
}

Gives no output, but directory is not removed when looking in Windows.

fs.removeSync('C:\\Projects\\testdir', function(err) { 
    console.log("Error", err); 
});

Gives me the following output:

{ Error: EBUSY: resource busy or locked, rmdir 'C:\Projects\testdir'
    at Error (native)
  errno: -4082,
  code: 'EBUSY',
  syscall: 'rmdir',
  path: 'C:\\Projects\\testdir' }

Using the following:

Windows 10
node v6.10.1
fs-extra v2.1.2

@RyanZim
Copy link
Collaborator

RyanZim commented Apr 25, 2017

Ugh, looks like another windows bug. Issues like this are hard to track down since I can't actually test them locally.

I'm looking at https://github.com/jprichardson/node-fs-extra/blob/master/lib/remove/rimraf.js#L277; there's no else statement there; I wonder if that's the issue.

@RyanZim
Copy link
Collaborator

RyanZim commented Apr 25, 2017

@FredrikJohansson83 Give this branch a try: https://github.com/jprichardson/node-fs-extra/tree/rmSync-patch

Run:

npm uninstall node-fs-extra
npm install jprichardson/node-fs-extra#rmSync-patch

Then test again. Let me know your results.

@FredrikJohansson-SATO
Copy link
Author

@RyanZim Thanks! I tried it and it seems to work! One difference compared to the async error callback though, it seems to include a stack trace of the error, but maybe this is how it's supposed to work when using it in a try/catch?

try { 
    fs.removeSync('C:\\Projects\\testdir') 
} catch (err) { 
    console.log("err", err); 
}

Gives the following output:

err { Error: EBUSY: resource busy or locked, rmdir 'C:\Projects\testdir'
    at Error (native)
    at Object.fs.rmdirSync (fs.js:887:18)
    at rmdirSync (C:\Projects\git\...\node_modules\fs-extra\lib\remove\rimraf.js:276:13)
    at Function.rimrafSync [as sync] (C:\Projects\git\...\node_modules\fs-extra\lib\remove\rimraf.js:252:7)
    at Object.removeSync (C:\Projects\git\...\node_modules\fs-extra\lib\remove\index.js:6:17)
    at repl:1:9
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:73:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:340:29)
  errno: -4082,
  code: 'EBUSY',
  syscall: 'rmdir',
  path: 'C:\\Projects\\testdir' }

@RyanZim
Copy link
Collaborator

RyanZim commented Apr 25, 2017

I think that looks like correct behavior. PR coming!

@RyanZim
Copy link
Collaborator

RyanZim commented Apr 25, 2017

PR done: #408

@FredrikJohansson-SATO
Copy link
Author

@RyanZim Great! Thanks for your support!

@Clonkex
Copy link

Clonkex commented Oct 31, 2022

For anyone else encountering this issue, it appears that fs-extra switched to using Node's own fs.rmSync method at some point, and fs.rmSync also had this issue at least as recently as 16.15.0. I've tested and confirmed it's fixed in 18.12.0, but probably also in 17.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants