raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
737 stars 93 forks source link

Cleaning up tmp directory throws an error #82

Closed rubenvereecken closed 8 years ago

rubenvereecken commented 8 years ago

The error is

Error: ENOTEMPTY: directory not empty, rmdir '/tmp/tmp-96377PyPfMXvxq0t'

and it's pretty obvious what it's complaining about. I wrote to the temporary directory and now it doesn't want to clean it up because something is inside. In rm terms, I should use -f.

The problem I have with this is that there's probably always something inside this temporary directory. Shouldn't the library clean this up regardless?

raszi commented 8 years ago

I am not sure. If you create temporary directories and you create files in them which should be cleaned up after your program exits then you should create those files as temp files as well.

rubenvereecken commented 8 years ago

Ah didn't know I could have temp files within a certain directory. I could have a look at that.

rosskevin commented 8 years ago

@raszi I have the same problem. I create a tmp.dirSync() and pass the name downstream as a base path with for other plugins to write tmp files in that directory. At the end of my gulp, I just want to cleanup anything there, which would effectively mean rm -Rf. I can work around it but I agree with @rubenvereecken that this is expected behavior.

rubenvereecken commented 8 years ago

I'm glad I'm not the only one. Could we change the current implementation to match the semantics those of us who use it expect? There's no one actually hoping for an error while there are still files in the temp directory which they are trying to clean.

On Thu, 24 Mar 2016 18:50 Kevin Ross, notifications@github.com wrote:

@raszi https://github.com/raszi I have the same problem. I create a tmp.dirSync() and pass the name downstream as a base path with for other plugins to write tmp files in that directory. At the end of my gulp, I just want to cleanup anything there, which would effectively mean rm -Rf. I can work around it but I agree with @rubenvereecken https://github.com/rubenvereecken that this is expected behavior.

— You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub https://github.com/raszi/node-tmp/issues/82#issuecomment-200947789

raszi commented 8 years ago

Well, did you try the unsafeCleanup option?

nicolas-raoul commented 8 years ago

Stupid question: How to use the options? tmp.dirSync("unsafeCleanup"); does not work.

raszi commented 8 years ago
tmp.dirSync({ unsafeCleanup: true });