fs-extra version: 5.0.0I 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 ?
Might be permissions; not sure.
@RyanHannan are you still having this issue?
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)
having this issue right now
fs.removeSync("lib")
Error: ENOTEMPTY: directory not empty, rmdir '........\lib\subfolder'
at Object.fs.rmdirSync (fs.js:856:18)
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.
in my case it fixed itself after trying other stuff and reverting
For me, the problem always comes back. When I use it across a test suite of 500 methods, it fails maybe 2 times.
@mojavelinux Do you have this issue when using https://github.com/isaacs/rimraf instead of fse.remove?
@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.
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.
I don't even have words. So infinite loop it is.
What about childProcess.execSync("rd /s /q " + foldername)?
Never had that issue in msbatch files.
@RyanZim @mojavelinux
@Inve1951 shelling out is not recommended as it can cause security issues.
@manidlou how so?
@Inve1951 it can lead to issues like command injection.
childProcess.exec() is a bash interpreter, not a program launcher.
oh of course. nvm then
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.
Most helpful comment
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?