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 8, 2020
1 parent 486205b commit 5110e94
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
38 changes: 19 additions & 19 deletions docs/global.html
Expand Up @@ -251,7 +251,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -388,7 +388,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -628,7 +628,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -765,7 +765,7 @@ <h5>Parameters:</h5>

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


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

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


Expand Down Expand Up @@ -1091,7 +1091,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -1228,7 +1228,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -1434,7 +1434,7 @@ <h5>Parameters:</h5>

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


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

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


Expand Down Expand Up @@ -1729,7 +1729,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -1936,7 +1936,7 @@ <h5>Parameters:</h5>

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


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

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


Expand Down Expand Up @@ -2317,7 +2317,7 @@ <h5>Parameters:</h5>

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


Expand Down Expand Up @@ -2555,7 +2555,7 @@ <h5>Parameters:</h5>

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


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

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


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

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


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

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


Expand Down Expand Up @@ -3429,7 +3429,7 @@ <h5>Parameters:</h5>

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


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

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -322,7 +322,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
13 changes: 10 additions & 3 deletions docs/tmp.js.html
Expand Up @@ -57,6 +57,8 @@ <h1 class="page-title">Source: tmp.js</h1>

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

// 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 @@ -632,13 +634,18 @@ <h1 class="page-title">Source: tmp.js</h1>
* 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 &amp;&amp; error.errno === errno;
return IS_WIN32 ? error.code === code : error.code === code &amp;&amp; error.errno === errno;
}

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

<footer>
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)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
11 changes: 9 additions & 2 deletions lib/tmp.js
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
@@ -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
@@ -1,5 +1,5 @@
{
"tc": "issue115",
"tc": "issue115-sync",
"async": false,
"file": true,
"options": {},
Expand Down

0 comments on commit 5110e94

Please sign in to comment.