Skip to content

Commit 8d948b4

Browse files
committed
fix #194: make graceful cleanup the default and let user override that by calling setGracefulCleanup(false)
1 parent 05aba23 commit 8d948b4

File tree

8 files changed

+9
-23
lines changed

8 files changed

+9
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ console.log('Created temporary filename: ', tmpname);
328328

329329
## Graceful cleanup
330330

331-
One may want to cleanup the temporary files even when an uncaught exception
332-
occurs. To enforce this, you can call the `setGracefulCleanup()` method:
331+
By default, tmp will clean up all temporary files and empty directories on termination of the process.
332+
To change this behaviour, you can call `setGracefulCleanup(false)`:
333333

334334
```javascript
335335
var tmp = require('tmp');
336336

337-
tmp.setGracefulCleanup();
337+
tmp.setGracefulCleanup(false);
338338
```
339339

340340
## Options

lib/tmp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const
4545
_removeObjects = [];
4646

4747
var
48-
_gracefulCleanup = false;
48+
_gracefulCleanup = true;
4949

5050
/**
5151
* Random name generator based on crypto.
@@ -571,9 +571,11 @@ function isBlank(s) {
571571

572572
/**
573573
* Sets the graceful cleanup.
574+
*
575+
* The default is to always try to clean up the temporary files and empty directories on process termination.
574576
*/
575-
function setGracefulCleanup() {
576-
_gracefulCleanup = true;
577+
function setGracefulCleanup(graceful) {
578+
_gracefulCleanup = graceful != undefined ? graceful : true;
577579
}
578580

579581
/**

test/dir-sync-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ var
1212
tmp = require('../lib/tmp');
1313

1414

15-
// make sure that everything gets cleaned up
16-
tmp.setGracefulCleanup();
17-
1815
describe('tmp', function () {
1916
describe('#dirSync()', function () {
2017
describe('when running inband standard tests', function () {

test/dir-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ var
1212
tmp = require('../lib/tmp');
1313

1414

15-
// make sure that everything gets cleaned up
16-
tmp.setGracefulCleanup();
17-
18-
1915
describe('tmp', function () {
2016
describe('#dir()', function () {
2117
describe('when running inband standard tests', function () {

test/file-sync-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ var
1111
tmp = require('../lib/tmp');
1212

1313

14-
// make sure that everything gets cleaned up
15-
tmp.setGracefulCleanup();
16-
17-
1814
describe('tmp', function () {
1915
describe('#fileSync()', function () {
2016
describe('when running inband standard tests', function () {

test/file-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ var
1111
tmp = require('../lib/tmp');
1212

1313

14-
// make sure that everything gets cleaned up
15-
tmp.setGracefulCleanup();
16-
1714
describe('tmp', function () {
1815
describe('#file()', function () {
1916
describe('when running inband standard tests', function () {

test/outband/issue121.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const
77
// https://github.com/raszi/node-tmp/issues/121
88
module.exports = function () {
99

10-
tmp.setGracefulCleanup();
11-
1210
const result = tmp.dirSync({ unsafeCleanup: true });
1311

1412
this.out(result.name, function () { });

test/spawn-generic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (config.async) fnUnderTest = (config.file) ? tmp.file : tmp.dir;
1515
else fnUnderTest = (config.file) ? tmp.fileSync : tmp.dirSync;
1616

1717
// do we test against tmp doing a graceful cleanup?
18-
if (config.graceful) tmp.setGracefulCleanup();
18+
tmp.setGracefulCleanup(config.graceful)
1919

2020
// import the test case function and execute it
2121
var fn = require(path.join(__dirname, 'outband', config.tc));

0 commit comments

Comments
 (0)