mirror of
https://github.com/S2-/gitlit
synced 2025-08-03 12:50:04 +02:00
add node modules to repo
This commit is contained in:
2
node_modules/tmp/.npmignore
generated
vendored
Normal file
2
node_modules/tmp/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
.idea/
|
8
node_modules/tmp/.travis.yml
generated
vendored
Normal file
8
node_modules/tmp/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.6"
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4.0"
|
||||
- "4.1"
|
18
node_modules/tmp/Gruntfile.js
generated
vendored
Normal file
18
node_modules/tmp/Gruntfile.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
module.exports = function(grunt) {
|
||||
grunt.initConfig({
|
||||
jshint: {
|
||||
all: ['Gruntfile.js', 'lib/*.js', 'test/*.js']
|
||||
},
|
||||
vows: {
|
||||
all: {
|
||||
src: ['test/*.js'],
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
//grunt.loadNpmTasks('grunt-vows-runner');
|
||||
grunt.loadNpmTasks('grunt-vows');
|
||||
|
||||
grunt.registerTask('default', ['jshint', 'vows']);
|
||||
};
|
21
node_modules/tmp/LICENSE
generated
vendored
Normal file
21
node_modules/tmp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 KARASZI István
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
266
node_modules/tmp/README.md
generated
vendored
Normal file
266
node_modules/tmp/README.md
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
# Tmp
|
||||
|
||||
A simple temporary file and directory creator for [node.js.][1]
|
||||
|
||||
[](http://travis-ci.org/raszi/node-tmp)
|
||||
|
||||
## About
|
||||
|
||||
This is a [widely used library][2] to create temporary files and directories
|
||||
in a [node.js][1] environment.
|
||||
|
||||
Tmp offers both an asynchronous and a synchronous API. For all API calls, all
|
||||
the parameters are optional.
|
||||
|
||||
Tmp uses crypto for determining random file names, or, when using templates,
|
||||
a six letter random identifier. And just in case that you do not have that much
|
||||
entropy left on your system, Tmp will fall back to pseudo random numbers.
|
||||
|
||||
You can set whether you want to remove the temporary file on process exit or
|
||||
not, and the destination directory can also be set.
|
||||
|
||||
## How to install
|
||||
|
||||
```bash
|
||||
npm install tmp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Asynchronous file creation
|
||||
|
||||
Simple temporary file creation, the file will be closed and unlinked on process exit.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("File: ", path);
|
||||
console.log("Filedescriptor: ", fd);
|
||||
|
||||
// If we don't need the file anymore we could manually call the cleanupCallback
|
||||
// But that is not necessary if we didn't pass the keep option because the library
|
||||
// will clean after itself.
|
||||
cleanupCallback();
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous file creation
|
||||
|
||||
A synchronous version of the above.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var tmpobj = tmp.fileSync();
|
||||
console.log("File: ", tmpobj.name);
|
||||
console.log("Filedescriptor: ", tmpobj.fd);
|
||||
|
||||
// If we don't need the file anymore we could manually call the removeCallback
|
||||
// But that is not necessary if we didn't pass the keep option because the library
|
||||
// will clean after itself.
|
||||
tmpobj.removeCallback();
|
||||
```
|
||||
|
||||
Note that this might throw an exception if either the maximum limit of retries
|
||||
for creating a temporary name fails, or, in case that you do not have the permission
|
||||
to write to the directory where the temporary file should be created in.
|
||||
|
||||
### Asynchronous directory creation
|
||||
|
||||
Simple temporary directory creation, it will be removed on process exit.
|
||||
|
||||
If the directory still contains items on process exit, then it won't be removed.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.dir(function _tempDirCreated(err, path, cleanupCallback) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("Dir: ", path);
|
||||
|
||||
// Manual cleanup
|
||||
cleanupCallback();
|
||||
});
|
||||
```
|
||||
|
||||
If you want to cleanup the directory even when there are entries in it, then
|
||||
you can pass the `unsafeCleanup` option when creating it.
|
||||
|
||||
### Synchronous directory creation
|
||||
|
||||
A synchronous version of the above.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var tmpobj = tmp.dirSync();
|
||||
console.log("Dir: ", tmpobj.name);
|
||||
// Manual cleanup
|
||||
tmpobj.removeCallback();
|
||||
```
|
||||
|
||||
Note that this might throw an exception if either the maximum limit of retries
|
||||
for creating a temporary name fails, or, in case that you do not have the permission
|
||||
to write to the directory where the temporary directory should be created in.
|
||||
|
||||
### Asynchronous filename generation
|
||||
|
||||
It is possible with this library to generate a unique filename in the specified
|
||||
directory.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.tmpName(function _tempNameGenerated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("Created temporary filename: ", path);
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous filename generation
|
||||
|
||||
A synchronous version of the above.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var name = tmp.tmpNameSync();
|
||||
console.log("Created temporary filename: ", name);
|
||||
```
|
||||
|
||||
## Advanced usage
|
||||
|
||||
### Asynchronous file creation
|
||||
|
||||
Creates a file with mode `0644`, prefix will be `prefix-` and postfix will be `.txt`.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("File: ", path);
|
||||
console.log("Filedescriptor: ", fd);
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous file creation
|
||||
|
||||
A synchronous version of the above.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var tmpobj = tmp.fileSync({ mode: 0644, prefix: 'prefix-', postfix: '.txt' });
|
||||
console.log("File: ", tmpobj.name);
|
||||
console.log("Filedescriptor: ", tmpobj.fd);
|
||||
```
|
||||
|
||||
### Asynchronous directory creation
|
||||
|
||||
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("Dir: ", path);
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous directory creation
|
||||
|
||||
Again, a synchronous version of the above.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
|
||||
console.log("Dir: ", tmpobj.name);
|
||||
```
|
||||
|
||||
### mkstemps like, asynchronously
|
||||
|
||||
Creates a new temporary directory with mode `0700` and filename like `/tmp/tmp-nk2J1u`.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.dir({ template: '/tmp/tmp-XXXXXX' }, function _tempDirCreated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("Dir: ", path);
|
||||
});
|
||||
```
|
||||
|
||||
### mkstemps like, synchronously
|
||||
|
||||
This will behave similarly to the asynchronous version.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
var tmpobj = tmp.dirSync({ template: '/tmp/tmp-XXXXXX' });
|
||||
console.log("Dir: ", tmpobj.name);
|
||||
```
|
||||
|
||||
### Asynchronous filename generation
|
||||
|
||||
The `tmpName()` function accepts the `prefix`, `postfix`, `dir`, etc. parameters also:
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
|
||||
tmp.tmpName({ template: '/tmp/tmp-XXXXXX' }, function _tempNameGenerated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log("Created temporary filename: ", path);
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous filename generation
|
||||
|
||||
The `tmpNameSync()` function works similarly to `tmpName()`.
|
||||
|
||||
```javascript
|
||||
var tmp = require('tmp');
|
||||
var tmpname = tmp.tmpNameSync({ template: '/tmp/tmp-XXXXXX' });
|
||||
console.log("Created temporary filename: ", tmpname);
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
All options are optional :)
|
||||
|
||||
* `mode`: the file mode to create with, it fallbacks to `0600` on file creation and `0700` on directory creation
|
||||
* `prefix`: the optional prefix, fallbacks to `tmp-` if not provided
|
||||
* `postfix`: the optional postfix, fallbacks to `.tmp` on file creation
|
||||
* `template`: [`mkstemps`][3] like filename template, no default
|
||||
* `dir`: the optional temporary directory, fallbacks to system default (guesses from environment)
|
||||
* `tries`: how many times should the function try to get a unique filename before giving up, default `3`
|
||||
* `keep`: signals that the temporary file or directory should not be deleted on exit, default is `false`, means delete
|
||||
* Please keep in mind that it is recommended in this case to call the provided `cleanupCallback` function manually.
|
||||
* `unsafeCleanup`: recursively removes the created temporary directory, even when it's not empty. default is `false`
|
||||
|
||||
[1]: http://nodejs.org/
|
||||
[2]: https://www.npmjs.com/browse/depended/tmp
|
||||
[3]: http://www.kernel.org/doc/man-pages/online/pages/man3/mkstemp.3.html
|
3
node_modules/tmp/cleanup.sh
generated
vendored
Executable file
3
node_modules/tmp/cleanup.sh
generated
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -vrf ${TMPDIR}/{foo,tmp,something,complicated,clike,using}*
|
462
node_modules/tmp/lib/tmp.js
generated
vendored
Normal file
462
node_modules/tmp/lib/tmp.js
generated
vendored
Normal file
@@ -0,0 +1,462 @@
|
||||
/*!
|
||||
* Tmp
|
||||
*
|
||||
* Copyright (c) 2011-2015 KARASZI Istvan <github@spam.raszi.hu>
|
||||
*
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
os = require('os'),
|
||||
crypto = require('crypto'),
|
||||
exists = fs.exists || path.exists,
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
tmpDir = require('os-tmpdir'),
|
||||
_c = require('constants');
|
||||
|
||||
|
||||
/**
|
||||
* The working inner variables.
|
||||
*/
|
||||
var
|
||||
// store the actual TMP directory
|
||||
_TMP = tmpDir(),
|
||||
|
||||
// the random characters to choose from
|
||||
RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
||||
|
||||
TEMPLATE_PATTERN = /XXXXXX/,
|
||||
|
||||
DEFAULT_TRIES = 3,
|
||||
|
||||
CREATE_FLAGS = _c.O_CREAT | _c.O_EXCL | _c.O_RDWR,
|
||||
|
||||
DIR_MODE = 448 /* 0700 */,
|
||||
FILE_MODE = 384 /* 0600 */,
|
||||
|
||||
// this will hold the objects need to be removed on exit
|
||||
_removeObjects = [],
|
||||
|
||||
_gracefulCleanup = false,
|
||||
_uncaughtException = false;
|
||||
|
||||
/**
|
||||
* Random name generator based on crypto.
|
||||
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
||||
*
|
||||
* @param {Number} howMany
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
function _randomChars(howMany) {
|
||||
var
|
||||
value = [],
|
||||
rnd = null;
|
||||
|
||||
// make sure that we do not fail because we ran out of entropy
|
||||
try {
|
||||
rnd = crypto.randomBytes(howMany);
|
||||
} catch (e) {
|
||||
rnd = crypto.pseudoRandomBytes(howMany);
|
||||
}
|
||||
|
||||
for (var i = 0; i < howMany; i++) {
|
||||
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
||||
}
|
||||
|
||||
return value.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the `obj` parameter is defined or not.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
function _isUndefined(obj) {
|
||||
return typeof obj === 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the function arguments.
|
||||
*
|
||||
* This function helps to have optional arguments.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} callback
|
||||
* @api private
|
||||
*/
|
||||
function _parseArguments(options, callback) {
|
||||
if (typeof options == 'function') {
|
||||
var
|
||||
tmp = options;
|
||||
options = callback || {};
|
||||
callback = tmp;
|
||||
} else if (typeof options == 'undefined') {
|
||||
options = {};
|
||||
}
|
||||
|
||||
return [options, callback];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new temporary name.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @returns {String}
|
||||
* @api private
|
||||
*/
|
||||
function _generateTmpName(opts) {
|
||||
if (opts.name) {
|
||||
return path.join(opts.dir || _TMP, opts.name);
|
||||
}
|
||||
|
||||
// mkstemps like template
|
||||
if (opts.template) {
|
||||
return opts.template.replace(TEMPLATE_PATTERN, _randomChars(6));
|
||||
}
|
||||
|
||||
// prefix and postfix
|
||||
var name = [
|
||||
opts.prefix || 'tmp-',
|
||||
process.pid,
|
||||
_randomChars(12),
|
||||
opts.postfix || ''
|
||||
].join('');
|
||||
|
||||
return path.join(opts.dir || _TMP, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a temporary file name.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} callback
|
||||
* @api private
|
||||
*/
|
||||
function _getTmpName(options, callback) {
|
||||
var
|
||||
args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1],
|
||||
tries = opts.tries || DEFAULT_TRIES;
|
||||
|
||||
if (isNaN(tries) || tries < 0)
|
||||
return cb(new Error('Invalid tries'));
|
||||
|
||||
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
||||
return cb(new Error('Invalid template provided'));
|
||||
|
||||
(function _getUniqueName() {
|
||||
var name = _generateTmpName(opts);
|
||||
|
||||
// check whether the path exists then retry if needed
|
||||
exists(name, function _pathExists(pathExists) {
|
||||
if (pathExists) {
|
||||
if (tries-- > 0) return _getUniqueName();
|
||||
|
||||
return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
|
||||
}
|
||||
|
||||
cb(null, name);
|
||||
});
|
||||
}());
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of _getTmpName.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {String}
|
||||
* @api private
|
||||
*/
|
||||
function _getTmpNameSync(options) {
|
||||
var
|
||||
args = _parseArguments(options),
|
||||
opts = args[0],
|
||||
tries = opts.tries || DEFAULT_TRIES;
|
||||
|
||||
if (isNaN(tries) || tries < 0)
|
||||
throw new Error('Invalid tries');
|
||||
|
||||
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
||||
throw new Error('Invalid template provided');
|
||||
|
||||
do {
|
||||
var name = _generateTmpName(opts);
|
||||
if (!existsSync(name)) {
|
||||
return name;
|
||||
}
|
||||
} while (tries-- > 0);
|
||||
|
||||
throw new Error('Could not get a unique tmp filename, max tries reached');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and opens a temporary file.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} callback
|
||||
* @api public
|
||||
*/
|
||||
function _createTmpFile(options, callback) {
|
||||
var
|
||||
args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1];
|
||||
|
||||
opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;
|
||||
|
||||
// gets a temporary filename
|
||||
_getTmpName(opts, function _tmpNameCreated(err, name) {
|
||||
if (err) return cb(err);
|
||||
|
||||
// create and open the file
|
||||
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
|
||||
if (err) return cb(err);
|
||||
|
||||
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of _createTmpFile.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {Object} object consists of name, fd and removeCallback
|
||||
* @api private
|
||||
*/
|
||||
function _createTmpFileSync(options) {
|
||||
var
|
||||
args = _parseArguments(options),
|
||||
opts = args[0];
|
||||
|
||||
opts.postfix = opts.postfix || '.tmp';
|
||||
|
||||
var name = _getTmpNameSync(opts);
|
||||
var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
|
||||
|
||||
return {
|
||||
name : name,
|
||||
fd : fd,
|
||||
removeCallback : _prepareTmpFileRemoveCallback(name, fd, opts)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes files and folders in a directory recursively.
|
||||
*
|
||||
* @param {String} root
|
||||
* @api private
|
||||
*/
|
||||
function _rmdirRecursiveSync(root) {
|
||||
var dirs = [root];
|
||||
|
||||
do {
|
||||
var
|
||||
dir = dirs.pop(),
|
||||
deferred = false,
|
||||
files = fs.readdirSync(dir);
|
||||
|
||||
for (var i = 0, length = files.length; i < length; i++) {
|
||||
var
|
||||
file = path.join(dir, files[i]),
|
||||
stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
if (!deferred) {
|
||||
deferred = true;
|
||||
dirs.push(dir);
|
||||
}
|
||||
dirs.push(file);
|
||||
} else {
|
||||
fs.unlinkSync(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!deferred) {
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
} while (dirs.length !== 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary directory.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} callback
|
||||
* @api public
|
||||
*/
|
||||
function _createTmpDir(options, callback) {
|
||||
var
|
||||
args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1];
|
||||
|
||||
// gets a temporary filename
|
||||
_getTmpName(opts, function _tmpNameCreated(err, name) {
|
||||
if (err) return cb(err);
|
||||
|
||||
// create the directory
|
||||
fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of _createTmpDir.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {Object} object consists of name and removeCallback
|
||||
* @api private
|
||||
*/
|
||||
function _createTmpDirSync(options) {
|
||||
var
|
||||
args = _parseArguments(options),
|
||||
opts = args[0];
|
||||
|
||||
var name = _getTmpNameSync(opts);
|
||||
fs.mkdirSync(name, opts.mode || DIR_MODE);
|
||||
|
||||
return {
|
||||
name : name,
|
||||
removeCallback : _prepareTmpDirRemoveCallback(name, opts)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the callback for removal of the temporary file.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {int} fd
|
||||
* @param {Object} opts
|
||||
* @api private
|
||||
* @returns {Function} the callback
|
||||
*/
|
||||
function _prepareTmpFileRemoveCallback(name, fd, opts) {
|
||||
var removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
|
||||
try {
|
||||
fs.closeSync(fdPath[0]);
|
||||
}
|
||||
catch (e) {
|
||||
// under some node/windows related circumstances, a temporary file
|
||||
// may have not be created as expected or the file was already closed
|
||||
// by the user, in which case we will simply ignore the error
|
||||
if (e.errno != -_c.EBADF && e.errno != -c.ENOENT) {
|
||||
// reraise any unanticipated error
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
fs.unlinkSync(fdPath[1]);
|
||||
}, [fd, name]);
|
||||
|
||||
if (!opts.keep) {
|
||||
_removeObjects.unshift(removeCallback);
|
||||
}
|
||||
|
||||
return removeCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the callback for removal of the temporary directory.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} opts
|
||||
* @returns {Function} the callback
|
||||
* @api private
|
||||
*/
|
||||
function _prepareTmpDirRemoveCallback(name, opts) {
|
||||
var removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs.rmdirSync.bind(fs);
|
||||
var removeCallback = _prepareRemoveCallback(removeFunction, name);
|
||||
|
||||
if (!opts.keep) {
|
||||
_removeObjects.unshift(removeCallback);
|
||||
}
|
||||
|
||||
return removeCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a guarded function wrapping the removeFunction call.
|
||||
*
|
||||
* @param {Function} removeFunction
|
||||
* @param {Object} arg
|
||||
* @returns {Function}
|
||||
* @api private
|
||||
*/
|
||||
function _prepareRemoveCallback(removeFunction, arg) {
|
||||
var called = false;
|
||||
|
||||
return function _cleanupCallback() {
|
||||
if (called) return;
|
||||
|
||||
var index = _removeObjects.indexOf(removeFunction);
|
||||
if (index >= 0) {
|
||||
_removeObjects.splice(index, 1);
|
||||
}
|
||||
|
||||
called = true;
|
||||
removeFunction(arg);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The garbage collector.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
function _garbageCollector() {
|
||||
if (_uncaughtException && !_gracefulCleanup) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0, length = _removeObjects.length; i < length; i++) {
|
||||
try {
|
||||
_removeObjects[i].call(null);
|
||||
} catch (e) {
|
||||
// already removed?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _setGracefulCleanup() {
|
||||
_gracefulCleanup = true;
|
||||
}
|
||||
|
||||
var version = process.versions.node.split('.').map(function (value) {
|
||||
return parseInt(value, 10);
|
||||
});
|
||||
|
||||
if (version[0] === 0 && (version[1] < 9 || version[1] === 9 && version[2] < 5)) {
|
||||
process.addListener('uncaughtException', function _uncaughtExceptionThrown(err) {
|
||||
_uncaughtException = true;
|
||||
_garbageCollector();
|
||||
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
process.addListener('exit', function _exit(code) {
|
||||
if (code) _uncaughtException = true;
|
||||
_garbageCollector();
|
||||
});
|
||||
|
||||
// exporting all the needed methods
|
||||
module.exports.tmpdir = _TMP;
|
||||
module.exports.dir = _createTmpDir;
|
||||
module.exports.dirSync = _createTmpDirSync;
|
||||
module.exports.file = _createTmpFile;
|
||||
module.exports.fileSync = _createTmpFileSync;
|
||||
module.exports.tmpName = _getTmpName;
|
||||
module.exports.tmpNameSync = _getTmpNameSync;
|
||||
module.exports.setGracefulCleanup = _setGracefulCleanup;
|
70
node_modules/tmp/package.json
generated
vendored
Normal file
70
node_modules/tmp/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"tmp@0.0.28",
|
||||
"/home/s2/Documents/Code/gitlit"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "tmp@0.0.28",
|
||||
"_id": "tmp@0.0.28",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-Fyc1t/YU6nrzlmT6hM8N5OUV0SA=",
|
||||
"_location": "/tmp",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "tmp@0.0.28",
|
||||
"name": "tmp",
|
||||
"escapedName": "tmp",
|
||||
"rawSpec": "0.0.28",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.28"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/asar"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.28.tgz",
|
||||
"_spec": "0.0.28",
|
||||
"_where": "/home/s2/Documents/Code/gitlit",
|
||||
"author": {
|
||||
"name": "KARASZI István",
|
||||
"email": "github@spam.raszi.hu",
|
||||
"url": "http://raszi.hu/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/raszi/node-tmp/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"os-tmpdir": "~1.0.1"
|
||||
},
|
||||
"description": "Temporary file and directory creator",
|
||||
"devDependencies": {
|
||||
"vows": "~0.7.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"homepage": "http://github.com/raszi/node-tmp",
|
||||
"keywords": [
|
||||
"temporary",
|
||||
"tmp",
|
||||
"temp",
|
||||
"tempdir",
|
||||
"tempfile",
|
||||
"tmpdir",
|
||||
"tmpfile"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/tmp.js",
|
||||
"name": "tmp",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/raszi/node-tmp.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vows test/*-test.js"
|
||||
},
|
||||
"version": "0.0.28"
|
||||
}
|
149
node_modules/tmp/test/base.js
generated
vendored
Normal file
149
node_modules/tmp/test/base.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
var
|
||||
assert = require('assert'),
|
||||
path = require('path'),
|
||||
exec = require('child_process').exec,
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
// make sure that we do not test spam the global tmp
|
||||
tmp.TMP_DIR = './tmp';
|
||||
|
||||
|
||||
function _spawnTestWithError(testFile, params, cb) {
|
||||
_spawnTest(true, testFile, params, cb);
|
||||
}
|
||||
|
||||
function _spawnTestWithoutError(testFile, params, cb) {
|
||||
_spawnTest(false, testFile, params, cb);
|
||||
}
|
||||
|
||||
function _spawnTest(passError, testFile, params, cb) {
|
||||
var
|
||||
node_path = process.argv[0],
|
||||
command = [ node_path, 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.mode, mode);
|
||||
}
|
||||
|
||||
function _testPrefix(prefix) {
|
||||
return function _testPrefixGenerated(err, name) {
|
||||
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
|
||||
};
|
||||
}
|
||||
|
||||
function _testPrefixSync(prefix) {
|
||||
return function _testPrefixGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testPrefix(prefix)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testPostfix(postfix) {
|
||||
return function _testPostfixGenerated(err, name) {
|
||||
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
|
||||
};
|
||||
}
|
||||
|
||||
function _testPostfixSync(postfix) {
|
||||
return function _testPostfixGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testPostfix(postfix)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testKeep(type, keep, cb) {
|
||||
_spawnTestWithError('keep.js', [ type, keep ], cb);
|
||||
}
|
||||
|
||||
function _testKeepSync(type, keep, cb) {
|
||||
_spawnTestWithError('keep-sync.js', [ type, keep ], cb);
|
||||
}
|
||||
|
||||
function _testGraceful(type, graceful, cb) {
|
||||
_spawnTestWithoutError('graceful.js', [ type, graceful ], cb);
|
||||
}
|
||||
|
||||
function _testGracefulSync(type, graceful, cb) {
|
||||
_spawnTestWithoutError('graceful-sync.js', [ type, graceful ], cb);
|
||||
}
|
||||
|
||||
function _assertName(err, name) {
|
||||
assert.isString(name);
|
||||
assert.isNotZero(name.length, 'an empty string is not a valid name');
|
||||
}
|
||||
|
||||
function _assertNameSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
var name = typeof(result) == 'string' ? result : result.name;
|
||||
_assertName(null, name);
|
||||
}
|
||||
|
||||
function _testName(expected){
|
||||
return function _testNameGenerated(err, name) {
|
||||
assert.equal(expected, name, 'should have the provided name');
|
||||
};
|
||||
}
|
||||
|
||||
function _testNameSync(expected){
|
||||
return function _testNameGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testName(expected)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testUnsafeCleanup(unsafe, cb) {
|
||||
_spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
|
||||
}
|
||||
|
||||
function _testIssue62(cb) {
|
||||
_spawnTestWithoutError('issue62.js', [], cb);
|
||||
}
|
||||
|
||||
function _testUnsafeCleanupSync(unsafe, cb) {
|
||||
_spawnTestWithoutError('unsafe-sync.js', [ 'dir', unsafe ], cb);
|
||||
}
|
||||
|
||||
function _testIssue62Sync(cb) {
|
||||
_spawnTestWithoutError('issue62-sync.js', [], cb);
|
||||
}
|
||||
|
||||
module.exports.testStat = _testStat;
|
||||
module.exports.testPrefix = _testPrefix;
|
||||
module.exports.testPrefixSync = _testPrefixSync;
|
||||
module.exports.testPostfix = _testPostfix;
|
||||
module.exports.testPostfixSync = _testPostfixSync;
|
||||
module.exports.testKeep = _testKeep;
|
||||
module.exports.testKeepSync = _testKeepSync;
|
||||
module.exports.testGraceful = _testGraceful;
|
||||
module.exports.testGracefulSync = _testGracefulSync;
|
||||
module.exports.assertName = _assertName;
|
||||
module.exports.assertNameSync = _assertNameSync;
|
||||
module.exports.testName = _testName;
|
||||
module.exports.testNameSync = _testNameSync;
|
||||
module.exports.testUnsafeCleanup = _testUnsafeCleanup;
|
||||
module.exports.testIssue62 = _testIssue62;
|
||||
module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
|
||||
module.exports.testIssue62Sync = _testIssue62Sync;
|
230
node_modules/tmp/test/dir-sync-test.js
generated
vendored
Normal file
230
node_modules/tmp/test/dir-sync-test.js
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testDir(mode) {
|
||||
return function _testDirGenerated(result) {
|
||||
assert.ok(existsSync(result.name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(result.name);
|
||||
assert.ok(stat.isDirectory(), 'should be a directory');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Synchronous directory creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
return tmp.dirSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the default prefix': Test.testPrefixSync('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'something' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefixSync('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ postfix: '.txt' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided postfix': Test.testPostfixSync('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefixSync('clike-'),
|
||||
'should have the provided postfix': Test.testPostfixSync('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ name: 'using-name' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')),
|
||||
'should be a directory': function (result) {
|
||||
_testDir(040700)(result);
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'foo', postfix: 'bar', mode: 0750 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040750),
|
||||
'should have the provided prefix': Test.testPrefixSync('foo'),
|
||||
'should have the provided postfix': Test.testPostfixSync('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'complicated', postfix: 'options', mode: 0755 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040755),
|
||||
'should have the provided prefix': Test.testPrefixSync('complicated'),
|
||||
'should have the provided postfix': Test.testPostfixSync('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
try {
|
||||
return tmp.dirSync({ tries: -1 });
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
},
|
||||
|
||||
'should return with an error': function (topic) {
|
||||
assert.instanceOf(topic, Error);
|
||||
}
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)({ name: name });
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'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.testGracefulSync('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)({ name: name });
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('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');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanupSync('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');
|
||||
},
|
||||
'should remove symlinked dir': function(err, name) {
|
||||
assert.ok(
|
||||
!existsSync(name + '/symlinkme-target'),
|
||||
'should remove target'
|
||||
);
|
||||
},
|
||||
'should not remove contents of symlink dir': function(err, name) {
|
||||
assert.ok(
|
||||
existsSync(__dirname + '/symlinkme/file.js'),
|
||||
'should not remove symlinked directory\'s content'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true with issue62 structure': {
|
||||
topic: function () {
|
||||
Test.testIssue62Sync(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');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === false': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanupSync('0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': function (err, name) {
|
||||
_testDir(040700)({name:name});
|
||||
// make sure that everything gets cleaned up
|
||||
fs.unlinkSync(path.join(name, 'should-be-removed.file'));
|
||||
fs.unlinkSync(path.join(name, 'symlinkme-target'));
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
return tmp.dirSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'removeCallback should remove directory': function (result) {
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'Directory should be removed');
|
||||
}
|
||||
}
|
||||
}).exportTo(module);
|
225
node_modules/tmp/test/dir-test.js
generated
vendored
Normal file
225
node_modules/tmp/test/dir-test.js
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testDir(mode) {
|
||||
return function _testDirGenerated(err, name) {
|
||||
assert.ok(existsSync(name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(name);
|
||||
assert.ok(stat.isDirectory(), 'should be a directory');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Directory creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.dir(this.callback);
|
||||
},
|
||||
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the default prefix': Test.testPrefix('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'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 prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.dir({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'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')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.dir({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
tmp.dir({ name: 'using-name' }, this.callback);
|
||||
},
|
||||
|
||||
'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 name': Test.testName(path.join(tmp.tmpdir, 'using-name'))
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'foo', postfix: 'bar', mode: 0750 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040750),
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'complicated', postfix: 'options', mode: 0755 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040755),
|
||||
'should have the provided prefix': Test.testPrefix('complicated'),
|
||||
'should have the provided postfix': Test.testPostfix('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.dir({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should return with an error': assert.isObject
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)(err, name);
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'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');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanup('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');
|
||||
},
|
||||
'should remove symlinked dir': function(err, name) {
|
||||
assert.ok(
|
||||
!existsSync(name + '/symlinkme-target'),
|
||||
'should remove target'
|
||||
);
|
||||
},
|
||||
'should not remove contents of symlink dir': function(err, name) {
|
||||
assert.ok(
|
||||
existsSync(__dirname + '/symlinkme/file.js'),
|
||||
'should not remove symlinked directory\'s content'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true with issue62 structure': {
|
||||
topic: function () {
|
||||
Test.testIssue62(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');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === false': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanup('0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': function (err, name) {
|
||||
_testDir(040700)(err, name);
|
||||
// make sure that everything gets cleaned up
|
||||
fs.unlinkSync(path.join(name, 'should-be-removed.file'));
|
||||
fs.unlinkSync(path.join(name, 'symlinkme-target'));
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
tmp.dir(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'removeCallback should remove directory': function (_err, name, removeCallback) {
|
||||
removeCallback();
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
}
|
||||
}).exportTo(module);
|
190
node_modules/tmp/test/file-sync-test.js
generated
vendored
Normal file
190
node_modules/tmp/test/file-sync-test.js
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testFile(mode, fdTest) {
|
||||
return function _testFileGenerated(result) {
|
||||
assert.ok(existsSync(result.name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(result.name);
|
||||
assert.equal(stat.size, 0, 'should have zero size');
|
||||
assert.ok(stat.isFile(), 'should be a file');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
|
||||
// check with fstat as well (fd checking)
|
||||
if (fdTest) {
|
||||
var fstat = fs.fstatSync(result.fd);
|
||||
assert.deepEqual(fstat, stat, 'fstat results should be the same');
|
||||
|
||||
var data = new Buffer('something');
|
||||
assert.equal(fs.writeSync(result.fd, data, 0, data.length, 0), data.length, 'should be writable');
|
||||
assert.ok(!fs.closeSync(result.fd), 'should not return with error');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Synchronous file creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
return tmp.fileSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the default prefix': Test.testPrefixSync('tmp-'),
|
||||
'should have the default postfix': Test.testPostfixSync('.tmp')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'something' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ postfix: '.txt' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided postfix': Test.testPostfixSync('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('clike-'),
|
||||
'should have the provided postfix': Test.testPostfixSync('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ name: 'using-name.tmp' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name.tmp')),
|
||||
'should be a file': function (result) {
|
||||
_testFile(0100600, true);
|
||||
fs.unlinkSync(result.name);
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'foo', postfix: 'bar', mode: 0640 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100640, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('foo'),
|
||||
'should have the provided postfix': Test.testPostfixSync('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'complicated', postfix: 'options', mode: 0644 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100644, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('complicated'),
|
||||
'should have the provided postfix': Test.testPostfixSync('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
try {
|
||||
return tmp.fileSync({ tries: -1 });
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
},
|
||||
|
||||
'should return with an error': function (topic) {
|
||||
assert.instanceOf(topic, Error);
|
||||
}
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, false)({name:name});
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('file', '0', 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), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'non graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('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)({name:name});
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('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) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
return tmp.fileSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'removeCallback should remove file': function (result) {
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'File should be removed');
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
191
node_modules/tmp/test/file-test.js
generated
vendored
Normal file
191
node_modules/tmp/test/file-test.js
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testFile(mode, fdTest) {
|
||||
return function _testFileGenerated(err, name, fd) {
|
||||
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');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
|
||||
// check with fstat as well (fd checking)
|
||||
if (fdTest) {
|
||||
var fstat = fs.fstatSync(fd);
|
||||
assert.deepEqual(fstat, stat, 'fstat results should be the same');
|
||||
|
||||
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');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('File creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.file(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the default prefix': Test.testPrefix('tmp-'),
|
||||
'should have the default postfix': Test.testPostfix('.tmp')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.file({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided postfix': Test.testPostfix('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.file({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
tmp.file({ name: 'using-name.tmp' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name.tmp')),
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, true);
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'foo', postfix: 'bar', mode: 0640 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100640, true),
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'complicated', postfix: 'options', mode: 0644 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100644, true),
|
||||
'should have the provided prefix': Test.testPrefix('complicated'),
|
||||
'should have the provided postfix': Test.testPostfix('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.file({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should not be created': assert.isObject
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an 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);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('file', '0', 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), '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) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
tmp.file(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'removeCallback should remove file': function (_err, name, _fd, removeCallback) {
|
||||
removeCallback();
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
20
node_modules/tmp/test/graceful-sync.js
generated
vendored
Normal file
20
node_modules/tmp/test/graceful-sync.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var
|
||||
tmp = require('../lib/tmp'),
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
var graceful = spawn.arg;
|
||||
|
||||
if (graceful) {
|
||||
tmp.setGracefulCleanup();
|
||||
}
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction();
|
||||
spawn.out(result.name, function () {
|
||||
throw new Error('Thrown on purpose');
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(e, spawn.exit);
|
||||
}
|
||||
|
15
node_modules/tmp/test/graceful.js
generated
vendored
Normal file
15
node_modules/tmp/test/graceful.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var
|
||||
tmp = require('../lib/tmp'),
|
||||
spawn = require('./spawn');
|
||||
|
||||
var graceful = spawn.arg;
|
||||
|
||||
if (graceful) {
|
||||
tmp.setGracefulCleanup();
|
||||
}
|
||||
|
||||
spawn.tmpFunction(function (err, name) {
|
||||
spawn.out(name, function () {
|
||||
throw new Error('Thrown on purpose');
|
||||
});
|
||||
});
|
27
node_modules/tmp/test/issue62-sync.js
generated
vendored
Normal file
27
node_modules/tmp/test/issue62-sync.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ unsafeCleanup: true });
|
||||
try {
|
||||
// creates structure from issue 62
|
||||
// https://github.com/raszi/node-tmp/issues/62
|
||||
|
||||
fs.mkdirSync(join(result.name, 'issue62'));
|
||||
|
||||
['foo', 'bar'].forEach(function(subdir) {
|
||||
fs.mkdirSync(join(result.name, 'issue62', subdir));
|
||||
fs.writeFileSync(join(result.name, 'issue62', subdir, 'baz.txt'), '');
|
||||
});
|
||||
|
||||
spawn.out(result.name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(e, spawn.exit);
|
||||
}
|
27
node_modules/tmp/test/issue62.js
generated
vendored
Normal file
27
node_modules/tmp/test/issue62.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn');
|
||||
|
||||
spawn.tmpFunction({ unsafeCleanup: true }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// creates structure from issue 62
|
||||
// https://github.com/raszi/node-tmp/issues/62
|
||||
|
||||
fs.mkdirSync(join(name, 'issue62'));
|
||||
|
||||
['foo', 'bar'].forEach(function(subdir) {
|
||||
fs.mkdirSync(join(name, 'issue62', subdir));
|
||||
fs.writeFileSync(join(name, 'issue62', subdir, 'baz.txt'), '');
|
||||
});
|
||||
|
||||
spawn.out(name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
});
|
12
node_modules/tmp/test/keep-sync.js
generated
vendored
Normal file
12
node_modules/tmp/test/keep-sync.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var spawn = require('./spawn-sync');
|
||||
|
||||
var keep = spawn.arg;
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ keep: keep });
|
||||
spawn.out(result.name, spawn.exit);
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(err, spawn.exit);
|
||||
}
|
||||
|
11
node_modules/tmp/test/keep.js
generated
vendored
Normal file
11
node_modules/tmp/test/keep.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var spawn = require('./spawn');
|
||||
|
||||
var keep = spawn.arg;
|
||||
|
||||
spawn.tmpFunction({ keep: keep }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
} else {
|
||||
spawn.out(name, spawn.exit);
|
||||
}
|
||||
});
|
82
node_modules/tmp/test/name-test.js
generated
vendored
Normal file
82
node_modules/tmp/test/name-test.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
vows.describe('Name creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.tmpName(this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the default prefix': Test.testPrefix('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided postfix': Test.testPostfix('.txt')
|
||||
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix'),
|
||||
'should have template filled': function (err, name) {
|
||||
assert.isTrue(/[a-zA-Z0-9]{6}/.test(name));
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ prefix: 'foo', postfix: 'bar', tries: 5 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should fail': function (err, name) {
|
||||
assert.isObject(err);
|
||||
}
|
||||
},
|
||||
|
||||
'tries not numeric': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ tries: 'hello'}, this.callback);
|
||||
},
|
||||
|
||||
'should fail': function (err, name) {
|
||||
assert.isObject(err);
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
32
node_modules/tmp/test/spawn-sync.js
generated
vendored
Normal file
32
node_modules/tmp/test/spawn-sync.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
function _writeSync(stream, str, cb) {
|
||||
var flushed = stream.write(str);
|
||||
if (flushed) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
stream.once('drain', function _flushed() {
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.out = function (str, cb) {
|
||||
_writeSync(process.stdout, str, cb);
|
||||
};
|
||||
|
||||
module.exports.err = function (str, cb) {
|
||||
_writeSync(process.stderr, str, cb);
|
||||
};
|
||||
|
||||
module.exports.exit = function () {
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
var type = process.argv[2];
|
||||
module.exports.tmpFunction = (type == 'file') ? tmp.fileSync : tmp.dirSync;
|
||||
|
||||
var arg = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
|
||||
module.exports.arg = arg;
|
32
node_modules/tmp/test/spawn.js
generated
vendored
Normal file
32
node_modules/tmp/test/spawn.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
function _writeSync(stream, str, cb) {
|
||||
var flushed = stream.write(str);
|
||||
if (flushed) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
stream.once('drain', function _flushed() {
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.out = function (str, cb) {
|
||||
_writeSync(process.stdout, str, cb);
|
||||
};
|
||||
|
||||
module.exports.err = function (str, cb) {
|
||||
_writeSync(process.stderr, str, cb);
|
||||
};
|
||||
|
||||
module.exports.exit = function () {
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
var type = process.argv[2];
|
||||
module.exports.tmpFunction = (type == 'file') ? tmp.file : tmp.dir;
|
||||
|
||||
var arg = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
|
||||
module.exports.arg = arg;
|
0
node_modules/tmp/test/symlinkme/file.js
generated
vendored
Normal file
0
node_modules/tmp/test/symlinkme/file.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe-sync.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe-sync.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
var unsafe = spawn.arg;
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ unsafeCleanup: unsafe });
|
||||
try {
|
||||
// file that should be removed
|
||||
var fd = fs.openSync(join(result.name, 'should-be-removed.file'), 'w');
|
||||
fs.closeSync(fd);
|
||||
|
||||
// in tree source
|
||||
var symlinkSource = join(__dirname, 'symlinkme');
|
||||
// testing target
|
||||
var symlinkTarget = join(result.name, 'symlinkme-target');
|
||||
|
||||
// symlink that should be removed but the contents should be preserved.
|
||||
fs.symlinkSync(symlinkSource, symlinkTarget, 'dir');
|
||||
|
||||
spawn.out(result.name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(err, spawn.exit);
|
||||
}
|
30
node_modules/tmp/test/unsafe.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn');
|
||||
|
||||
var unsafe = spawn.arg;
|
||||
spawn.tmpFunction({ unsafeCleanup: unsafe }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// file that should be removed
|
||||
var fd = fs.openSync(join(name, 'should-be-removed.file'), 'w');
|
||||
fs.closeSync(fd);
|
||||
|
||||
// in tree source
|
||||
var symlinkSource = join(__dirname, 'symlinkme');
|
||||
// testing target
|
||||
var symlinkTarget = join(name, 'symlinkme-target');
|
||||
|
||||
// symlink that should be removed but the contents should be preserved.
|
||||
fs.symlinkSync(symlinkSource, symlinkTarget, 'dir');
|
||||
|
||||
spawn.out(name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user