@@ -375,7 +375,7 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
375
375
// under some node/windows related circumstances, a temporary file
376
376
// may have not be created as expected or the file was already closed
377
377
// by the user, in which case we will simply ignore the error
378
- if ( e . errno != - EBADF && e . errno != - ENOENT ) {
378
+ if ( ! isEBADF ( e ) && ! isENOENT ( e ) ) {
379
379
// reraise any unanticipated error
380
380
throw e ;
381
381
}
@@ -456,6 +456,44 @@ function _garbageCollector() {
456
456
}
457
457
}
458
458
459
+ /**
460
+ * Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
461
+ */
462
+ function isEBADF ( error ) {
463
+ return isExpectedError ( error , - EBADF , 'EBADF' ) ;
464
+ }
465
+
466
+ /**
467
+ * Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
468
+ */
469
+ function isENOENT ( error ) {
470
+ return isExpectedError ( error , - EBADF , 'EBADF' ) ;
471
+ }
472
+
473
+ /**
474
+ * Helper to determine whether the expected error code and errno match the actual code and errno,
475
+ * which will differ between the supported node versions.
476
+ *
477
+ * - Node >= 7.0:
478
+ * error.code {String}
479
+ * error.errno {String|Number} any numerical value will be negated
480
+ *
481
+ * - Node >= 6.0 < 7.0:
482
+ * error.code {String}
483
+ * error.errno {Number} negated
484
+ *
485
+ * - Node >= 4.0 < 6.0: introduces SystemError
486
+ * error.code {String}
487
+ * error.errno {Number} negated
488
+ *
489
+ * - Node >= 0.10 < 4.0:
490
+ * error.code {Number} negated
491
+ * error.errno n/a
492
+ */
493
+ function isExpectedError ( error , code , errno ) {
494
+ return error . code == code || error . code == errno ;
495
+ }
496
+
459
497
/**
460
498
* Sets the graceful cleanup.
461
499
*
0 commit comments