Skip to content

Commit

Permalink
fix regression - os.constants.errno are different from what WIN32 act…
Browse files Browse the repository at this point in the history
…ually returns
  • Loading branch information
silkentrance committed Feb 7, 2020
1 parent 486205b commit fadc34b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const

CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),

// constants are off on the windows platform and will not match the actual errno codes
IS_WIN32 = os.platform() === 'win32',
EBADF = _c.EBADF || _c.os.errno.EBADF,
ENOENT = _c.ENOENT || _c.os.errno.ENOENT,

Expand Down Expand Up @@ -134,7 +136,7 @@ function file(options, callback) {

// create and open the file
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
/* istanbul ignore else */
/* istanbu ignore else */
if (err) return cb(err);

if (opts.discardDescriptor) {
Expand Down Expand Up @@ -604,13 +606,18 @@ function _isENOENT(error) {
* error.code {string}
* error.errno {number} any numerical value will be negated
*
* CAVEAT
*
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
* is no different here.
*
* @param {SystemError} error
* @param {number} errno
* @param {string} code
* @private
*/
function _isExpectedError(error, errno, code) {
return error.code === code && error.errno === errno;
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/outband/issue115-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var fs = require('fs');

module.exports = function (result) {
// creates a tmp file and then closes the file descriptor as per issue 115
// https://github.com/raszi/node-tmp/issues/115
const self = this;
fs.closeSync(result.fd);
result.removeCallback();
self.out(result.name, self.exit);
};
2 changes: 1 addition & 1 deletion test/outband/issue115-sync.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tc": "issue115",
"tc": "issue115-sync",
"async": false,
"file": true,
"options": {},
Expand Down

0 comments on commit fadc34b

Please sign in to comment.