@@ -97,10 +97,12 @@ function _isUndefined(obj) {
97
97
* @private
98
98
*/
99
99
function _parseArguments ( options , callback ) {
100
+ /* istanbul ignore else */
100
101
if ( typeof options == 'function' ) {
101
102
return [ { } , options ] ;
102
103
}
103
104
105
+ /* istanbul ignore else */
104
106
if ( _isUndefined ( options ) ) {
105
107
return [ { } , callback ] ;
106
108
}
@@ -116,14 +118,17 @@ function _parseArguments(options, callback) {
116
118
* @private
117
119
*/
118
120
function _generateTmpName ( opts ) {
121
+ /* istanbul ignore else */
119
122
if ( opts . name ) {
120
123
return path . join ( opts . dir || tmpDir , opts . name ) ;
121
124
}
122
125
123
126
// mkstemps like template
127
+ /* istanbul ignore else */
124
128
if ( opts . template ) {
125
129
var template = opts . template ;
126
130
// make sure that we prepend the tmp path if none was given
131
+ /* istanbul ignore else */
127
132
if ( path . basename ( template ) == template )
128
133
template = path . join ( opts . dir || tmpDir , template ) ;
129
134
return template . replace ( TEMPLATE_PATTERN , _randomChars ( 6 ) ) ;
@@ -153,9 +158,11 @@ function tmpName(options, callback) {
153
158
cb = args [ 1 ] ,
154
159
tries = opts . name ? 1 : opts . tries || DEFAULT_TRIES ;
155
160
161
+ /* istanbul ignore else */
156
162
if ( isNaN ( tries ) || tries < 0 )
157
163
return cb ( new Error ( 'Invalid tries' ) ) ;
158
164
165
+ /* istanbul ignore else */
159
166
if ( opts . template && ! opts . template . match ( TEMPLATE_PATTERN ) )
160
167
return cb ( new Error ( 'Invalid template provided' ) ) ;
161
168
@@ -164,7 +171,9 @@ function tmpName(options, callback) {
164
171
165
172
// check whether the path exists then retry if needed
166
173
fs . stat ( name , function ( err ) {
174
+ /* istanbul ignore else */
167
175
if ( ! err ) {
176
+ /* istanbul ignore else */
168
177
if ( tries -- > 0 ) return _getUniqueName ( ) ;
169
178
170
179
return cb ( new Error ( 'Could not get a unique tmp filename, max tries reached ' + name ) ) ;
@@ -188,9 +197,11 @@ function tmpNameSync(options) {
188
197
opts = args [ 0 ] ,
189
198
tries = opts . name ? 1 : opts . tries || DEFAULT_TRIES ;
190
199
200
+ /* istanbul ignore else */
191
201
if ( isNaN ( tries ) || tries < 0 )
192
202
throw new Error ( 'Invalid tries' ) ;
193
203
204
+ /* istanbul ignore else */
194
205
if ( opts . template && ! opts . template . match ( TEMPLATE_PATTERN ) )
195
206
throw new Error ( 'Invalid template provided' ) ;
196
207
@@ -222,14 +233,17 @@ function file(options, callback) {
222
233
223
234
// gets a temporary filename
224
235
tmpName ( opts , function _tmpNameCreated ( err , name ) {
236
+ /* istanbul ignore else */
225
237
if ( err ) return cb ( err ) ;
226
238
227
239
// create and open the file
228
240
fs . open ( name , CREATE_FLAGS , opts . mode || FILE_MODE , function _fileCreated ( err , fd ) {
241
+ /* istanbul ignore else */
229
242
if ( err ) return cb ( err ) ;
230
243
231
244
if ( opts . discardDescriptor ) {
232
245
return fs . close ( fd , function _discardCallback ( err ) {
246
+ /* istanbul ignore else */
233
247
if ( err ) {
234
248
// Low probability, and the file exists, so this could be
235
249
// ignored. If it isn't we certainly need to unlink the
@@ -247,6 +261,7 @@ function file(options, callback) {
247
261
cb ( null , name , undefined , _prepareTmpFileRemoveCallback ( name , - 1 , opts ) ) ;
248
262
} ) ;
249
263
}
264
+ /* istanbul ignore else */
250
265
if ( opts . detachDescriptor ) {
251
266
return cb ( null , name , fd , _prepareTmpFileRemoveCallback ( name , - 1 , opts ) ) ;
252
267
}
@@ -272,6 +287,7 @@ function fileSync(options) {
272
287
const discardOrDetachDescriptor = opts . discardDescriptor || opts . detachDescriptor ;
273
288
const name = tmpNameSync ( opts ) ;
274
289
var fd = fs . openSync ( name , CREATE_FLAGS , opts . mode || FILE_MODE ) ;
290
+ /* istanbul ignore else */
275
291
if ( opts . discardDescriptor ) {
276
292
fs . closeSync ( fd ) ;
277
293
fd = undefined ;
@@ -305,6 +321,7 @@ function _rmdirRecursiveSync(root) {
305
321
stat = fs . lstatSync ( file ) ; // lstat so we don't recurse into symlinked directories
306
322
307
323
if ( stat . isDirectory ( ) ) {
324
+ /* istanbul ignore else */
308
325
if ( ! deferred ) {
309
326
deferred = true ;
310
327
dirs . push ( dir ) ;
@@ -315,6 +332,7 @@ function _rmdirRecursiveSync(root) {
315
332
}
316
333
}
317
334
335
+ /* istanbul ignore else */
318
336
if ( ! deferred ) {
319
337
fs . rmdirSync ( dir ) ;
320
338
}
@@ -335,10 +353,12 @@ function dir(options, callback) {
335
353
336
354
// gets a temporary filename
337
355
tmpName ( opts , function _tmpNameCreated ( err , name ) {
356
+ /* istanbul ignore else */
338
357
if ( err ) return cb ( err ) ;
339
358
340
359
// create the directory
341
360
fs . mkdir ( name , opts . mode || DIR_MODE , function _dirCreated ( err ) {
361
+ /* istanbul ignore else */
342
362
if ( err ) return cb ( err ) ;
343
363
344
364
cb ( null , name , _prepareTmpDirRemoveCallback ( name , opts ) ) ;
@@ -379,6 +399,7 @@ function dirSync(options) {
379
399
function _prepareTmpFileRemoveCallback ( name , fd , opts ) {
380
400
const removeCallback = _prepareRemoveCallback ( function _removeCallback ( fdPath ) {
381
401
try {
402
+ /* istanbul ignore else */
382
403
if ( 0 <= fdPath [ 0 ] ) {
383
404
fs . closeSync ( fdPath [ 0 ] ) ;
384
405
}
@@ -387,6 +408,7 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
387
408
// under some node/windows related circumstances, a temporary file
388
409
// may have not be created as expected or the file was already closed
389
410
// by the user, in which case we will simply ignore the error
411
+ /* istanbul ignore else */
390
412
if ( ! isEBADF ( e ) && ! isENOENT ( e ) ) {
391
413
// reraise any unanticipated error
392
414
throw e ;
@@ -396,13 +418,15 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
396
418
fs . unlinkSync ( fdPath [ 1 ] ) ;
397
419
}
398
420
catch ( e ) {
421
+ /* istanbul ignore else */
399
422
if ( ! isENOENT ( e ) ) {
400
423
// reraise any unanticipated error
401
424
throw e ;
402
425
}
403
426
}
404
427
} , [ fd , name ] ) ;
405
428
429
+ /* istanbul ignore else */
406
430
if ( ! opts . keep ) {
407
431
_removeObjects . unshift ( removeCallback ) ;
408
432
}
@@ -422,6 +446,7 @@ function _prepareTmpDirRemoveCallback(name, opts) {
422
446
const removeFunction = opts . unsafeCleanup ? _rmdirRecursiveSync : fs . rmdirSync . bind ( fs ) ;
423
447
const removeCallback = _prepareRemoveCallback ( removeFunction , name ) ;
424
448
449
+ /* istanbul ignore else */
425
450
if ( ! opts . keep ) {
426
451
_removeObjects . unshift ( removeCallback ) ;
427
452
}
@@ -441,8 +466,10 @@ function _prepareRemoveCallback(removeFunction, arg) {
441
466
var called = false ;
442
467
443
468
return function _cleanupCallback ( next ) {
469
+ /* istanbul ignore else */
444
470
if ( ! called ) {
445
471
const index = _removeObjects . indexOf ( _cleanupCallback ) ;
472
+ /* istanbul ignore else */
446
473
if ( index >= 0 ) {
447
474
_removeObjects . splice ( index , 1 ) ;
448
475
}
@@ -451,6 +478,7 @@ function _prepareRemoveCallback(removeFunction, arg) {
451
478
removeFunction ( arg ) ;
452
479
}
453
480
481
+ /* istanbul ignore else */
454
482
if ( next ) next ( null ) ;
455
483
} ;
456
484
}
@@ -461,6 +489,7 @@ function _prepareRemoveCallback(removeFunction, arg) {
461
489
* @private
462
490
*/
463
491
function _garbageCollector ( ) {
492
+ /* istanbul ignore else */
464
493
if ( ! _gracefulCleanup ) {
465
494
return ;
466
495
}
@@ -521,10 +550,6 @@ function setGracefulCleanup() {
521
550
_gracefulCleanup = true ;
522
551
}
523
552
524
- const version = process . versions . node . split ( '.' ) . map ( function ( value ) {
525
- return parseInt ( value , 10 ) ;
526
- } ) ;
527
-
528
553
/**
529
554
* If there are multiple different versions of tmp in place, make sure that
530
555
* we recognize the old listeners.
@@ -541,7 +566,9 @@ function _safely_install_listener() {
541
566
var existingListeners = [ ] ;
542
567
for ( var i = 0 , length = listeners . length ; i < length ; i ++ ) {
543
568
var lstnr = listeners [ i ] ;
569
+ /* istanbul ignore else */
544
570
if ( lstnr . name == '_tmp$safe_listener' || _is_legacy_listener ( lstnr ) ) {
571
+ /* istanbul ignore else */
545
572
if ( lstnr . name != '_uncaughtExceptionThrown' ) existingListeners . push ( lstnr ) ;
546
573
process . removeListener ( EVENT , lstnr ) ;
547
574
}
@@ -566,6 +593,7 @@ function _safely_install_listener() {
566
593
} ) ;
567
594
568
595
process . addListener ( EVENT , function _tmp$safe_listener ( data ) {
596
+ /* istanbul ignore else */
569
597
if ( existingListeners . length ) {
570
598
for ( var i = 0 , length = existingListeners . length ; i < length ; i ++ ) {
571
599
existingListeners [ i ] ( data ) ;
0 commit comments