Skip to content

Commit fadc34b

Browse files
committed
fix regression - os.constants.errno are different from what WIN32 actually returns
1 parent 486205b commit fadc34b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/tmp.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const
2929

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

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

@@ -134,7 +136,7 @@ function file(options, callback) {
134136

135137
// create and open the file
136138
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
137-
/* istanbul ignore else */
139+
/* istanbu ignore else */
138140
if (err) return cb(err);
139141

140142
if (opts.discardDescriptor) {
@@ -604,13 +606,18 @@ function _isENOENT(error) {
604606
* error.code {string}
605607
* error.errno {number} any numerical value will be negated
606608
*
609+
* CAVEAT
610+
*
611+
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
612+
* is no different here.
613+
*
607614
* @param {SystemError} error
608615
* @param {number} errno
609616
* @param {string} code
610617
* @private
611618
*/
612619
function _isExpectedError(error, errno, code) {
613-
return error.code === code && error.errno === errno;
620+
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
614621
}
615622

616623
/**

test/outband/issue115-sync.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var fs = require('fs');
2+
3+
module.exports = function (result) {
4+
// creates a tmp file and then closes the file descriptor as per issue 115
5+
// https://github.com/raszi/node-tmp/issues/115
6+
const self = this;
7+
fs.closeSync(result.fd);
8+
result.removeCallback();
9+
self.out(result.name, self.exit);
10+
};

test/outband/issue115-sync.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"tc": "issue115",
2+
"tc": "issue115-sync",
33
"async": false,
44
"file": true,
55
"options": {},

0 commit comments

Comments
 (0)