Skip to content

Commit 5110e94

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

File tree

6 files changed

+50
-26
lines changed

6 files changed

+50
-26
lines changed

docs/global.html

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ <h5>Parameters:</h5>
251251

252252
<dt class="tag-source">Source:</dt>
253253
<dd class="tag-source"><ul class="dummy"><li>
254-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line189">line 189</a>
254+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line191">line 191</a>
255255
</li></ul></dd>
256256

257257

@@ -388,7 +388,7 @@ <h5>Parameters:</h5>
388388

389389
<dt class="tag-source">Source:</dt>
390390
<dd class="tag-source"><ul class="dummy"><li>
391-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line217">line 217</a>
391+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line219">line 219</a>
392392
</li></ul></dd>
393393

394394

@@ -628,7 +628,7 @@ <h5>Parameters:</h5>
628628

629629
<dt class="tag-source">Source:</dt>
630630
<dd class="tag-source"><ul class="dummy"><li>
631-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line124">line 124</a>
631+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line126">line 126</a>
632632
</li></ul></dd>
633633

634634

@@ -765,7 +765,7 @@ <h5>Parameters:</h5>
765765

766766
<dt class="tag-source">Source:</dt>
767767
<dd class="tag-source"><ul class="dummy"><li>
768-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line162">line 162</a>
768+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line164">line 164</a>
769769
</li></ul></dd>
770770

771771

@@ -908,7 +908,7 @@ <h4 class="name" id="setGracefulCleanup"><span class="type-signature"></span>set
908908

909909
<dt class="tag-source">Source:</dt>
910910
<dd class="tag-source"><ul class="dummy"><li>
911-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line623">line 623</a>
911+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line630">line 630</a>
912912
</li></ul></dd>
913913

914914

@@ -1091,7 +1091,7 @@ <h5>Parameters:</h5>
10911091

10921092
<dt class="tag-source">Source:</dt>
10931093
<dd class="tag-source"><ul class="dummy"><li>
1094-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line56">line 56</a>
1094+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line58">line 58</a>
10951095
</li></ul></dd>
10961096

10971097

@@ -1228,7 +1228,7 @@ <h5>Parameters:</h5>
12281228

12291229
<dt class="tag-source">Source:</dt>
12301230
<dd class="tag-source"><ul class="dummy"><li>
1231-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line98">line 98</a>
1231+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line100">line 100</a>
12321232
</li></ul></dd>
12331233

12341234

@@ -1434,7 +1434,7 @@ <h5>Parameters:</h5>
14341434

14351435
<dt class="tag-source">Source:</dt>
14361436
<dd class="tag-source"><ul class="dummy"><li>
1437-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line706">line 706</a>
1437+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line713">line 713</a>
14381438
</li></ul></dd>
14391439

14401440

@@ -1522,7 +1522,7 @@ <h4 class="name" id="cleanupCallbackSync"><span class="type-signature"></span>cl
15221522

15231523
<dt class="tag-source">Source:</dt>
15241524
<dd class="tag-source"><ul class="dummy"><li>
1525-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line713">line 713</a>
1525+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line720">line 720</a>
15261526
</li></ul></dd>
15271527

15281528

@@ -1729,7 +1729,7 @@ <h5>Parameters:</h5>
17291729

17301730
<dt class="tag-source">Source:</dt>
17311731
<dd class="tag-source"><ul class="dummy"><li>
1732-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line692">line 692</a>
1732+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line699">line 699</a>
17331733
</li></ul></dd>
17341734

17351735

@@ -1936,7 +1936,7 @@ <h5>Parameters:</h5>
19361936

19371937
<dt class="tag-source">Source:</dt>
19381938
<dd class="tag-source"><ul class="dummy"><li>
1939-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line699">line 699</a>
1939+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line706">line 706</a>
19401940
</li></ul></dd>
19411941

19421942

@@ -2093,7 +2093,7 @@ <h5 class="subsection-title">Properties:</h5>
20932093

20942094
<dt class="tag-source">Source:</dt>
20952095
<dd class="tag-source"><ul class="dummy"><li>
2096-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line664">line 664</a>
2096+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line671">line 671</a>
20972097
</li></ul></dd>
20982098

20992099

@@ -2317,7 +2317,7 @@ <h5>Parameters:</h5>
23172317

23182318
<dt class="tag-source">Source:</dt>
23192319
<dd class="tag-source"><ul class="dummy"><li>
2320-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line676">line 676</a>
2320+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line683">line 683</a>
23212321
</li></ul></dd>
23222322

23232323

@@ -2555,7 +2555,7 @@ <h5>Parameters:</h5>
25552555

25562556
<dt class="tag-source">Source:</dt>
25572557
<dd class="tag-source"><ul class="dummy"><li>
2558-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line684">line 684</a>
2558+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line691">line 691</a>
25592559
</li></ul></dd>
25602560

25612561

@@ -2735,7 +2735,7 @@ <h5 class="subsection-title">Properties:</h5>
27352735

27362736
<dt class="tag-source">Source:</dt>
27372737
<dd class="tag-source"><ul class="dummy"><li>
2738-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line657">line 657</a>
2738+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line664">line 664</a>
27392739
</li></ul></dd>
27402740

27412741

@@ -3172,7 +3172,7 @@ <h5 class="subsection-title">Properties:</h5>
31723172

31733173
<dt class="tag-source">Source:</dt>
31743174
<dd class="tag-source"><ul class="dummy"><li>
3175-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line640">line 640</a>
3175+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line647">line 647</a>
31763176
</li></ul></dd>
31773177

31783178

@@ -3246,7 +3246,7 @@ <h4 class="name" id="simpleCallback"><span class="type-signature"></span>simpleC
32463246

32473247
<dt class="tag-source">Source:</dt>
32483248
<dd class="tag-source"><ul class="dummy"><li>
3249-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line719">line 719</a>
3249+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line726">line 726</a>
32503250
</li></ul></dd>
32513251

32523252

@@ -3429,7 +3429,7 @@ <h5>Parameters:</h5>
34293429

34303430
<dt class="tag-source">Source:</dt>
34313431
<dd class="tag-source"><ul class="dummy"><li>
3432-
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line670">line 670</a>
3432+
<a href="tmp.js.html">tmp.js</a>, <a href="tmp.js.html#line677">line 677</a>
34333433
</li></ul></dd>
34343434

34353435

@@ -3479,7 +3479,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
34793479
<br class="clear">
34803480

34813481
<footer>
3482-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 00:30:58 GMT+0100 (Mitteleuropäische Normalzeit)
3482+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 01:04:48 GMT+0100 (GMT+01:00)
34833483
</footer>
34843484

34853485
<script> prettyPrint(); </script>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
322322
<br class="clear">
323323

324324
<footer>
325-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 00:30:58 GMT+0100 (Mitteleuropäische Normalzeit)
325+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 01:04:48 GMT+0100 (GMT+01:00)
326326
</footer>
327327

328328
<script> prettyPrint(); </script>

docs/tmp.js.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ <h1 class="page-title">Source: tmp.js</h1>
5757

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

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

@@ -162,7 +164,7 @@ <h1 class="page-title">Source: tmp.js</h1>
162164

163165
// create and open the file
164166
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
165-
/* istanbul ignore else */
167+
/* istanbu ignore else */
166168
if (err) return cb(err);
167169

168170
if (opts.discardDescriptor) {
@@ -632,13 +634,18 @@ <h1 class="page-title">Source: tmp.js</h1>
632634
* error.code {string}
633635
* error.errno {number} any numerical value will be negated
634636
*
637+
* CAVEAT
638+
*
639+
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
640+
* is no different here.
641+
*
635642
* @param {SystemError} error
636643
* @param {number} errno
637644
* @param {string} code
638645
* @private
639646
*/
640647
function _isExpectedError(error, errno, code) {
641-
return error.code === code &amp;&amp; error.errno === errno;
648+
return IS_WIN32 ? error.code === code : error.code === code &amp;&amp; error.errno === errno;
642649
}
643650

644651
/**
@@ -789,7 +796,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
789796
<br class="clear">
790797

791798
<footer>
792-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 00:30:58 GMT+0100 (Mitteleuropäische Normalzeit)
799+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Feb 08 2020 01:04:48 GMT+0100 (GMT+01:00)
793800
</footer>
794801

795802
<script> prettyPrint(); </script>

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)