raszi / node-tmp

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

Creating multiple directories in a tmp dir causes cleanup to fail #73

Closed nathasm closed 9 years ago

nathasm commented 9 years ago

To reproduce:

var tmp = require('tmp');
var fs = require('fs');

tmp.dir({ template: '/tmp/tmp-XXXXXX', unsafeCleanup: true }, function _tempDirCreated(err, path) {
  if (err) {
    throw err;
  }
  fs.mkdirSync(path + '/child1');
  fs.mkdirSync(path + '/child2');
});

It appears that the order that the directories are pushed on to the removal queue are unordered so when the top-level tmp directory is removed, child1/child2 directories still remain in the "to be removed" queue.

The tmp dir will not be cleaned up as there is an uncaught exception thrown when fs.rmdirSync(dir) tries to remove the directories that no longer exists.

nathasm commented 9 years ago

Duplicate of #62