Skip to content

Commit

Permalink
fix #143
Browse files Browse the repository at this point in the history
  • Loading branch information
silkentrance committed Jul 11, 2017
1 parent 8f73d89 commit 6b499de
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,14 @@ console.log('Dir: ', tmpobj.name);

Creates a new temporary directory with mode `0700` and filename like `/tmp/tmp-nk2J1u`.

IMPORTANT NOTE: template no longer accepts a path. Use the dir option instead if you
require tmp to create your temporary filesystem object in a different place than the
default `tmp.tmpdir`.

```javascript
var tmp = require('tmp');

tmp.dir({ template: '/tmp/tmp-XXXXXX' }, function _tempDirCreated(err, path) {
tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
if (err) throw err;

console.log('Dir: ', path);
Expand All @@ -254,7 +258,7 @@ This will behave similarly to the asynchronous version.
```javascript
var tmp = require('tmp');

var tmpobj = tmp.dirSync({ template: '/tmp/tmp-XXXXXX' });
var tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
console.log('Dir: ', tmpobj.name);
```

Expand Down
3 changes: 2 additions & 1 deletion lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ function _generateTmpName(opts) {

// mkstemps like template
if (opts.template) {
return opts.template.replace(TEMPLATE_PATTERN, _randomChars(6));
if (path.basename(opts.template) != opts.template) throw new Error('template must not be a path, use the dir option instead.');
return path.join(opts.dir || tmpDir, opts.template.replace(TEMPLATE_PATTERN, _randomChars(6)));
}

// prefix and postfix
Expand Down
2 changes: 1 addition & 1 deletion test/dir-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ vows.describe('Synchronous directory creation').addBatch({

'when using template': {
topic: function () {
return tmp.dirSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
return tmp.dirSync({ template: 'clike-XXXXXX-postfix' });
},

'should return with a name': Test.assertNameSync,
Expand Down
2 changes: 1 addition & 1 deletion test/dir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ vows.describe('Directory creation').addBatch({

'when using template': {
topic: function () {
tmp.dir({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
tmp.dir({ template: 'clike-XXXXXX-postfix' }, this.callback);
},

'should not return with error': assert.isNull,
Expand Down
2 changes: 1 addition & 1 deletion test/file-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ vows.describe('Synchronous file creation').addBatch({

'when using template': {
topic: function () {
return tmp.fileSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
return tmp.fileSync({ template: 'clike-XXXXXX-postfix' });
},

'should return with a name': Test.assertNameSync,
Expand Down
2 changes: 1 addition & 1 deletion test/file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ vows.describe('File creation').addBatch({

'when using template': {
topic: function () {
tmp.file({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
tmp.file({ template: 'clike-XXXXXX-postfix' }, this.callback);
},

'should not return with an error': assert.isNull,
Expand Down
2 changes: 1 addition & 1 deletion test/name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ vows.describe('Name creation').addBatch({

'when using template': {
topic: function () {
tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
tmp.tmpName({ template: 'clike-XXXXXX-postfix' }, this.callback);
},

'should not return with error': assert.isNull,
Expand Down

0 comments on commit 6b499de

Please sign in to comment.