Socket
Socket
Sign inDemoInstall

tmp

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tmp - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

test/graceful.js

8

lib/tmp.js

@@ -216,2 +216,9 @@ /*!

function _gracefulCleanup() {
process.on('uncaughtException', function (err) {
_garbageCollector();
throw err;
});
}
// adding to the exit listener

@@ -225,1 +232,2 @@ process.addListener('exit', _garbageCollector);

module.exports.tmpName = _getTmpName;
module.exports.setGracefulCleanup = _gracefulCleanup;

2

package.json
{
"name": "tmp",
"version": "0.0.15",
"version": "0.0.16",
"description": "Temporary file and directory creator",

@@ -5,0 +5,0 @@ "author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)",

@@ -133,2 +133,13 @@ # Tmp

## Graceful cleanup
One may want to cleanup the temporary files even when an uncaught exception
occurs. To enforce this, you can call the `setGracefulCleanup()` method:
```javascript
var tmp = require('tmp');
tmp.setGracefulCleanup();
```
## Options

@@ -135,0 +146,0 @@

var
assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn;
exec = require('child_process').exec;
function _spawnTest(passError, testFile, params, cb) {
var
filename,
command = [ 'node', path.join(__dirname, testFile) ].concat(params).join(' ');
exec(command, function _execDone(err, stdout, stderr) {
if (passError) {
if (err) {
return cb(err);
} else if (stderr.length > 0) {
return cb(stderr.toString());
}
}
return cb(null, stdout.toString());
});
}
function _testStat(stat, mode) {
assert.equal(stat.uid, process.getuid(), 'Should have the same UID');
assert.equal(stat.gid, process.getgid(), 'Should have the same GUID');
assert.equal(stat.uid, process.getuid(), 'should have the same UID');
assert.equal(stat.gid, process.getgid(), 'should have the same GUID');
assert.equal(stat.mode, mode);

@@ -14,3 +32,3 @@ }

return function _testPrefixGenerated(err, name, fd) {
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'Should have the provided prefix');
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
};

@@ -21,3 +39,3 @@ }

return function _testPostfixGenerated(err, name, fd) {
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'Should have the provided postfix');
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
};

@@ -27,23 +45,14 @@ }

function _testKeep(type, keep, cb) {
var
filename,
cbCalled,
keepTest = spawn('node', [ path.join(__dirname, 'keep.js'), type, keep ]);
_spawnTest(true, 'keep.js', [ type, keep ], cb);
}
keepTest.stdout.on('data', function (data) {
filename = data.toString().replace(/\n/, "");
});
keepTest.stderr.on('data', function (data) {
cbCalled = true;
cb(new Error(data.toString()));
});
keepTest.on('exit', function _exited(code) {
if (cbCalled) return;
function _testGraceful(type, graceful, cb) {
_spawnTest(false, 'graceful.js', [ type, graceful ], cb);
}
if (code !== 0) return cb(new Error('Exited with error code: ' + code));
cb(null, filename);
});
function _assertName(err, name) {
assert.isString(name);
}
module.exports.testStat = _testStat;

@@ -53,1 +62,3 @@ module.exports.testPrefix = _testPrefix;

module.exports.testKeep = _testKeep;
module.exports.testGraceful = _testGraceful;
module.exports.assertName = _assertName;

@@ -15,6 +15,6 @@ var

return function _testDirGenerated(err, name) {
assert.ok(existsSync(name), 'Should exist');
assert.ok(existsSync(name), 'should exist');
var stat = fs.statSync(name);
assert.ok(stat.isDirectory(), 'Should be a directory');
assert.ok(stat.isDirectory(), 'should be a directory');

@@ -25,3 +25,2 @@ Test.testStat(stat, mode);

vows.describe('Directory creation').addBatch({

@@ -33,3 +32,2 @@ 'when using without parameters': {

'should not return with error': assert.isNull,
'should be a directory': _testDir(040700),

@@ -44,3 +42,4 @@ 'should have the default prefix': Test.testPrefix('tmp-')

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a directory': _testDir(040700),

@@ -55,6 +54,6 @@ 'should have the provided prefix': Test.testPrefix('something')

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a directory': _testDir(040700),
'should have the provided postfix': Test.testPostfix('.txt')
},

@@ -68,2 +67,3 @@

'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testDir(040700),

@@ -79,3 +79,4 @@ 'should have the provided prefix': Test.testPrefix('clike-'),

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a directory': _testDir(040750),

@@ -91,3 +92,4 @@ 'should have the provided prefix': Test.testPrefix('foo'),

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a directory': _testDir(040755),

@@ -103,5 +105,3 @@ 'should have the provided prefix': Test.testPrefix('complicated'),

'should not be created': function (err, name) {
assert.isObject(err);
}
'should return with an error': assert.isObject
},

@@ -114,3 +114,4 @@

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a dir': function(err, name) {

@@ -128,6 +129,32 @@ _testDir(040700)(err, name);

'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function(err, name) {
assert.ok(!existsSync(name), "Directory should be removed");
}
},
'non graceful testing': {
topic: function () {
Test.testGraceful('dir', '0', this.callback);
},
'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should be a dir': function(err, name) {
_testDir(040700)(err, name);
fs.rmdirSync(name);
}
},
'graceful testing': {
topic: function () {
Test.testGraceful('dir', '1', this.callback);
},
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function(err, name) {
assert.ok(!existsSync(name), "Directory should be removed");
}
}
}).export(module);
}).exportTo(module);

@@ -15,7 +15,7 @@ var

return function _testFileGenerated(err, name, fd) {
assert.ok(existsSync(name), 'Should exist');
assert.ok(existsSync(name), 'should exist');
var stat = fs.statSync(name);
assert.equal(stat.size, 0, 'Should have zero size');
assert.ok(stat.isFile(), 'Should be a file');
assert.equal(stat.size, 0, 'should have zero size');
assert.ok(stat.isFile(), 'should be a file');

@@ -30,4 +30,4 @@ Test.testStat(stat, mode);

var data = new Buffer('something');
assert.equal(fs.writeSync(fd, data, 0, data.length, 0), data.length, 'Should be writable');
assert.ok(!fs.closeSync(fd), 'Should not return with error');
assert.equal(fs.writeSync(fd, data, 0, data.length, 0), data.length, 'should be writable');
assert.ok(!fs.closeSync(fd), 'should not return with error');
}

@@ -43,3 +43,4 @@ };

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100600, true),

@@ -55,3 +56,4 @@ 'should have the default prefix': Test.testPrefix('tmp-'),

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100600, true),

@@ -66,3 +68,4 @@ 'should have the provided prefix': Test.testPrefix('something')

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100600, true),

@@ -78,3 +81,4 @@ 'should have the provided postfix': Test.testPostfix('.txt')

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100600, true),

@@ -90,3 +94,4 @@ 'should have the provided prefix': Test.testPrefix('clike-'),

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100640, true),

@@ -102,3 +107,4 @@ 'should have the provided prefix': Test.testPrefix('foo'),

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testFile(0100644, true),

@@ -114,5 +120,3 @@ 'should have the provided prefix': Test.testPrefix('complicated'),

'should not be created': function (err, name) {
assert.isObject(err);
}
'should not be created': assert.isObject
},

@@ -125,3 +129,4 @@

'should not return with error': assert.isNull,
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': function(err, name) {

@@ -138,3 +143,29 @@ _testFile(0100600, false)(err, name, null);

'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function(err, name) {
assert.ok(!existsSync(name), "File should be removed");
}
},
'non graceful testing': {
topic: function () {
Test.testGraceful('file', '0', this.callback);
},
'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': function(err, name) {
_testFile(0100600, false)(err, name, null);
fs.unlinkSync(name);
}
},
'graceful testing': {
topic: function () {
Test.testGraceful('file', '1', this.callback);
},
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function(err, name) {

@@ -145,2 +176,2 @@ assert.ok(!existsSync(name), "File should be removed");

}).export(module);
}).exportTo(module);

@@ -1,33 +0,11 @@

var tmp = require('../lib/tmp.js');
var spawn = require('./spawn');
var
type = process.argv[2],
keep = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
var keep = spawn.arg;
switch (type) {
case 'file':
tmp.file({ keep: keep }, function(err, name, fd) {
if (err) {
console.error(err);
process.exit(2);
}
console.log(name);
});
break;
case 'dir':
tmp.dir({ keep: keep }, function(err, name) {
if (err) {
console.error(err);
process.exit(2);
}
console.log(name);
});
break;
default:
console.error("Invalid type");
process.exit(1);
}
spawn.tmpFunction({ keep: keep }, function (err, name) {
if (err) {
spawn.err(err, spawn.exit);
} else {
spawn.out(name, spawn.exit);
}
});

@@ -82,2 +82,2 @@ var

}).export(module);
}).exportTo(module);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc