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

remove() doesn't delete a subfolder inside my project folder. What is wrong here ? #532

Closed
RyanHannan opened this issue Dec 29, 2017 · 19 comments

Comments

@RyanHannan
Copy link

RyanHannan commented Dec 29, 2017

  • Operating System: Win 10 64 bit
  • Node.js version: 8.7.0
  • fs-extra version: 5.0.0

I am trying to delete a non-empty subfolder which is inside my project directory but i can't seem to delete it with fs.remove(folderPath). The code runs with no errors but the folder is still there and i can't even delete it manually unless i first empty the folder and delete all the files in there. I get a permission related error when i try to directly delete the folder even though i am the owner/admin. Could it be a permissions related issue ?

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 30, 2017

Might be permissions; not sure.

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 24, 2018

@RyanHannan are you still having this issue?

@mojavelinux
Copy link

mojavelinux commented Jan 26, 2018

I'm seeing a similar problem on Windows. Every now and again in the test suite, it fails to remove a directory because it claims the directory is not empty. But when the process completes, the directory is gone. So could it be that there's a race condition or that it's a false warning?

Error: ENOTEMPTY: directory not empty, rmdir ...
at Object.fs.rmdirSync (fs.js:846:18)
at rmkidsSync (node_modules\fs-extra\lib\remove\rimraf.js:304:27)

@Inve1951
Copy link

having this issue right now
fs.removeSync("lib")

Error: ENOTEMPTY: directory not empty, rmdir '........\lib\subfolder'
    at Object.fs.rmdirSync (fs.js:856:18)

@mojavelinux
Copy link

I've found that the only way to fix this is to put the remove operation in a loop (with a timeout) until it succeeds. It always seems to succeed after a few milliseconds.

@Inve1951
Copy link

in my case it fixed itself after trying other stuff and reverting

@mojavelinux
Copy link

For me, the problem always comes back. When I use it across a test suite of 500 methods, it fails maybe 2 times.

@RyanZim
Copy link
Collaborator

RyanZim commented Feb 5, 2018

@mojavelinux Do you have this issue when using https://github.com/isaacs/rimraf instead of fse.remove?

@mojavelinux
Copy link

@RyanZim Yes, it does seem to be a problem with rimraf. That's where it always dies.

I get something that looks like this:

Error: EBUSY: resource busy or locked, rmdir 'C:\projects\antora-odh8j\packages\cli\test\work'
  at Object.fs.rmdirSync (fs.js:846:18)
  at rmdirSync (node_modules\fs-extra\lib\remove\rimraf.js:276:13)
  at Object.rimrafSync (node_modules\fs-extra\lib\remove\rimraf.js:252:7)
  at Context.after (packages\cli\test\cli-test.js:79:10)

I've even tried rimraf directly and saw no improvement.

I have been very careful to ensure that no files or directories are locked. Windows just seems to be very unreliable at removing directories.

My only solution has been to use an infinite loop until Windows decides it actually wants to do what it was asked to do.

@Inve1951
Copy link

I find it more likely that the fault is with node/v8 rather than windows. I looked into it for a bit but my understanding of node's codebase it too bad to find anything in there.
As per MSDN: The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed. and thus provide an alternate interface for deleting the folder content as well.

@mojavelinux
Copy link

I don't even have words. So infinite loop it is.

@Inve1951
Copy link

Inve1951 commented May 1, 2018

What about childProcess.execSync("rd /s /q " + foldername)?
Never had that issue in msbatch files.
@RyanZim @mojavelinux

@manidlou
Copy link
Collaborator

manidlou commented Jun 1, 2018

@Inve1951 shelling out is not recommended as it can cause security issues.

@Inve1951
Copy link

Inve1951 commented Jun 1, 2018

@manidlou how so?

@manidlou
Copy link
Collaborator

manidlou commented Jun 2, 2018

@Inve1951 it can lead to issues like command injection.

https://hackernoon.com/nodejs-security-issue-javascript-node-example-tutorial-vulnerabilities-hack-line-url-command-injection-412011924d1b

childProcess.exec() is a bash interpreter, not a program launcher.

@Inve1951
Copy link

Inve1951 commented Jun 2, 2018

oh of course. nvm then

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 30, 2020

It seems we've never been able to pin this down concretely; so I'm gonna close this out. Happy to reopen if we figure out how to consistently reproduce.

@RyanZim RyanZim closed this as completed Jan 30, 2020
@agilgur5
Copy link

agilgur5 commented Jul 7, 2022

@RyanZim I was able to reproduce this with some frequency while writing integration tests for rollup-plugin-typescript2 in ezolenko/rollup-plugin-typescript2#371 .
I added a small timeout (1s) to workaround this issue with remove on this line.

Without that timeout, I was getting the error mentioned above (Error: ENOTEMPTY: directory not empty, rmdir) about 25-50% of the time running tests.
Since a tiny timeout helps, this definitely seems like a race condition. I call remove in the test's afterAll, so I don't believe it has to do with Jest's parallelization either.

As per MSDN: The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed. and thus provide an alternate interface for deleting the folder content as well.

Reading this older comment made me think that perhaps the file handles have not quite been closed when the tests finish, and that causes remove to fail, but I'm not sure.

I can try to make a more minimal repro of this if needed, though TBD if it'll actually show up minimally

pcattori added a commit to remix-run/remix that referenced this issue Nov 15, 2022
@ajiho
Copy link

ajiho commented Sep 11, 2024

I occasionally encounter this problem on the Windows 10 system, and then I restart VSCode to solve all the problems.I have encountered this issue before when using rimraf, only in VSCode and not in Webstorm. I just want the person who found it to know the solution to this problem

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

7 participants