raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
736 stars 92 forks source link

Bug in tmpName() will cause it to try resolve a unique name even though there was no error #174

Closed silkentrance closed 6 years ago

silkentrance commented 6 years ago
  (function _getUniqueName() {
    const name = _generateTmpName(opts);

    // check whether the path exists then retry if needed
    fs.stat(name, function (err) {
      /* istanbul ignore else */
      if (!err) {
        /* istanbul ignore else */
        if (tries-- > 0) return _getUniqueName();

        return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
      }

      cb(null, name);
    });
  }());

Here, it reads if (!err) whereas it should read if(err).

silkentrance commented 6 years ago

heck, what must I be smoking...