bower / decompress-zip

Module that decompresses zip files
MIT License
102 stars 76 forks source link

Fix ENOENT bug by moving dir cache to DecompressZip instance #41

Closed prust closed 9 years ago

prust commented 9 years ago

This is a more robust fix for #29. As explained on that pull request (and demonstrated in the included test), decompress-zip will throw an ENOENT if you attempt to unzip a file to a directory, then delete the directory and unzip the file to that directory again. This is due to the directory cache living at the module level and not being invalidated between runs.

My previous fix for this (#38) invalidated the cache between runs, but as discussed on that pull request, it wouldn't work well for people using decompress-zip concurrently. This pull request uses the approach suggested by @BCooper63 and seconded by @sindresorhus: moving the cache to the DecompressZip instance, so a new cache is created for each instance.

The code changes are minimal and straightforward. All tests pass, including a new one that covers this issue. @sindresorhus: would you be able to take a quick look?

For my test, I needed to recursively rmdir the temp directory. To do this, I bumped to a newer version of the tmp module, which passes a cleanupCallback that recursively removes the temp directory.