init
This commit is contained in:
21
mc_test/node_modules/tmp/LICENSE
generated
vendored
Executable file
21
mc_test/node_modules/tmp/LICENSE
generated
vendored
Executable 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.
|
||||
391
mc_test/node_modules/tmp/README.md
generated
vendored
Executable file
391
mc_test/node_modules/tmp/README.md
generated
vendored
Executable file
@ -0,0 +1,391 @@
|
||||
# Tmp
|
||||
|
||||
A simple temporary file and directory creator for [node.js.][1]
|
||||
|
||||
[](https://github.com/raszi/node-tmp/actions/workflows/node.js.yml)
|
||||
[](https://libraries.io/github/raszi/node-tmp)
|
||||
[](https://badge.fury.io/js/tmp)
|
||||
[](https://raszi.github.io/node-tmp/)
|
||||
[](https://snyk.io/test/npm/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. There also exists a promisified version of the
|
||||
API, see [tmp-promise][5].
|
||||
|
||||
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.
|
||||
|
||||
If you do not want to store your temporary directories and files in the
|
||||
standard OS temporary directory, then you are free to override that as well.
|
||||
|
||||
## An Important Note on Previously Undocumented Breaking Changes
|
||||
|
||||
All breaking changes that had been introduced, i.e.
|
||||
|
||||
- tmpdir must be located under the system defined tmpdir root.
|
||||
- Spaces being collapsed into single spaces
|
||||
- Removal of all single and double quote characters
|
||||
|
||||
have been reverted in v0.2.2 and tmp should now behave as it did before the
|
||||
introduction of these breaking changes.
|
||||
|
||||
Other breaking changes, i.e.
|
||||
|
||||
- template must be relative to tmpdir
|
||||
- name must be relative to tmpdir
|
||||
- dir option must be relative to tmpdir
|
||||
|
||||
are still in place.
|
||||
|
||||
In order to override the system's tmpdir, you will have to use the newly
|
||||
introduced tmpdir option.
|
||||
|
||||
## An Important Note on Compatibility
|
||||
|
||||
See the [CHANGELOG](./CHANGELOG.md) for more information.
|
||||
|
||||
### Version 0.2.3
|
||||
|
||||
- Node version <= 14.4 has been dropped.
|
||||
- rimraf has been dropped from the dependencies
|
||||
|
||||
### Version 0.2.2
|
||||
|
||||
Since version 0.2.2, all support for node version <= 14 has been dropped.
|
||||
|
||||
### Version 0.1.0
|
||||
|
||||
Since version 0.1.0, all support for node versions < 0.10.0 has been dropped.
|
||||
|
||||
Most importantly, any support for earlier versions of node-tmp was also dropped.
|
||||
|
||||
If you still require node versions < 0.10.0, then you must limit your node-tmp
|
||||
dependency to versions below 0.1.0.
|
||||
|
||||
### Version 0.0.33
|
||||
|
||||
Since version 0.0.33, all support for node versions < 0.8 has been dropped.
|
||||
|
||||
If you still require node version 0.8, then you must limit your node-tmp
|
||||
dependency to version 0.0.33.
|
||||
|
||||
For node versions < 0.8 you must limit your node-tmp dependency to
|
||||
versions < 0.0.33.
|
||||
|
||||
## How to install
|
||||
|
||||
```bash
|
||||
npm install tmp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Please also check [API docs][4].
|
||||
|
||||
## Graceful cleanup
|
||||
|
||||
If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary object removal.
|
||||
|
||||
To enforce this, you can call the `setGracefulCleanup()` method:
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.setGracefulCleanup();
|
||||
```
|
||||
|
||||
### Asynchronous file creation
|
||||
|
||||
Simple temporary file creation, the file will be closed and unlinked on process exit.
|
||||
|
||||
```javascript
|
||||
const 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
const 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
|
||||
const 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
const 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
|
||||
const 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
const 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.file({ mode: 0o644, 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
const tmpobj = tmp.fileSync({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' });
|
||||
console.log('File: ', tmpobj.name);
|
||||
console.log('Filedescriptor: ', tmpobj.fd);
|
||||
```
|
||||
|
||||
### Controlling the Descriptor
|
||||
|
||||
As a side effect of creating a unique file `tmp` gets a file descriptor that is
|
||||
returned to the user as the `fd` parameter. The descriptor may be used by the
|
||||
application and is closed when the `removeCallback` is invoked.
|
||||
|
||||
In some use cases the application does not need the descriptor, needs to close it
|
||||
without removing the file, or needs to remove the file without closing the
|
||||
descriptor. Two options control how the descriptor is managed:
|
||||
|
||||
* `discardDescriptor` - if `true` causes `tmp` to close the descriptor after the file
|
||||
is created. In this case the `fd` parameter is undefined.
|
||||
* `detachDescriptor` - if `true` causes `tmp` to return the descriptor in the `fd`
|
||||
parameter, but it is the application's responsibility to close it when it is no
|
||||
longer needed.
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
|
||||
if (err) throw err;
|
||||
// fd will be undefined, allowing application to use fs.createReadStream(path)
|
||||
// without holding an unused descriptor open.
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
|
||||
if (err) throw err;
|
||||
|
||||
cleanupCallback();
|
||||
// Application can store data through fd here; the space used will automatically
|
||||
// be reclaimed by the operating system when the descriptor is closed or program
|
||||
// terminates.
|
||||
});
|
||||
```
|
||||
|
||||
### Asynchronous directory creation
|
||||
|
||||
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.dir({ mode: 0o750, 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
|
||||
const tmp = require('tmp');
|
||||
|
||||
const tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
|
||||
console.log('Dir: ', tmpobj.name);
|
||||
```
|
||||
|
||||
### mkstemp like, asynchronously
|
||||
|
||||
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
|
||||
const tmp = require('tmp');
|
||||
|
||||
tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('Dir: ', path);
|
||||
});
|
||||
```
|
||||
|
||||
### mkstemp like, synchronously
|
||||
|
||||
This will behave similarly to the asynchronous version.
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
const tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
|
||||
console.log('Dir: ', tmpobj.name);
|
||||
```
|
||||
|
||||
### Asynchronous filename generation
|
||||
|
||||
Using `tmpName()` you can create temporary file names asynchronously.
|
||||
The function accepts all standard options, e.g. `prefix`, `postfix`, `dir`, and so on.
|
||||
|
||||
You can also leave out the options altogether and just call the function with a callback as first parameter.
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
|
||||
const options = {};
|
||||
|
||||
tmp.tmpName(options, function _tempNameGenerated(err, path) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('Created temporary filename: ', path);
|
||||
});
|
||||
```
|
||||
|
||||
### Synchronous filename generation
|
||||
|
||||
The `tmpNameSync()` function works similarly to `tmpName()`.
|
||||
Again, you can leave out the options altogether and just invoke the function without any parameters.
|
||||
|
||||
```javascript
|
||||
const tmp = require('tmp');
|
||||
const options = {};
|
||||
const tmpname = tmp.tmpNameSync(options);
|
||||
console.log('Created temporary filename: ', tmpname);
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
All options are optional :)
|
||||
|
||||
* `name`: a fixed name that overrides random name generation, the name must be relative and must not contain path segments
|
||||
* `mode`: the file mode to create with, falls back to `0o600` on file creation and `0o700` on directory creation
|
||||
* `prefix`: the optional prefix, defaults to `tmp`
|
||||
* `postfix`: the optional postfix
|
||||
* `template`: [`mkstemp`][3] like filename template, no default, must include `XXXXXX` once for random name generation, e.g.
|
||||
'foo-bar-XXXXXX'.
|
||||
* `dir`: the optional temporary directory that must be relative to the system's default temporary directory.
|
||||
absolute paths are fine as long as they point to a location under the system's default temporary directory.
|
||||
Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access,
|
||||
as tmp will not check the availability of the path, nor will it establish the requested path for you.
|
||||
* `tmpdir`: allows you to override the system's root tmp directory
|
||||
* `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`
|
||||
* In order to clean up, you will have to call the provided `cleanupCallback` function manually.
|
||||
* `unsafeCleanup`: recursively removes the created temporary directory, even when it's not empty. default is `false`
|
||||
* `detachDescriptor`: detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
|
||||
* `discardDescriptor`: discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection
|
||||
|
||||
[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
|
||||
[4]: https://raszi.github.io/node-tmp/
|
||||
[5]: https://github.com/benjamingr/tmp-promise
|
||||
842
mc_test/node_modules/tmp/lib/tmp.js
generated
vendored
Executable file
842
mc_test/node_modules/tmp/lib/tmp.js
generated
vendored
Executable file
@ -0,0 +1,842 @@
|
||||
/*!
|
||||
* Tmp
|
||||
*
|
||||
* Copyright (c) 2011-2017 KARASZI Istvan <github@spam.raszi.hu>
|
||||
*
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/*
|
||||
* Module dependencies.
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const _c = { fs: fs.constants, os: os.constants };
|
||||
|
||||
/*
|
||||
* The working inner variables.
|
||||
*/
|
||||
const // the random characters to choose from
|
||||
RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
||||
TEMPLATE_PATTERN = /XXXXXX/,
|
||||
DEFAULT_TRIES = 3,
|
||||
CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
|
||||
// constants are off on the windows platform and will not match the actual errno codes
|
||||
IS_WIN32 = os.platform() === 'win32',
|
||||
EBADF = _c.EBADF || _c.os.errno.EBADF,
|
||||
ENOENT = _c.ENOENT || _c.os.errno.ENOENT,
|
||||
DIR_MODE = 0o700 /* 448 */,
|
||||
FILE_MODE = 0o600 /* 384 */,
|
||||
EXIT = 'exit',
|
||||
// this will hold the objects need to be removed on exit
|
||||
_removeObjects = [],
|
||||
// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
|
||||
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);
|
||||
|
||||
let _gracefulCleanup = false;
|
||||
|
||||
/**
|
||||
* Recursively remove a directory and its contents.
|
||||
*
|
||||
* @param {string} dirPath path of directory to remove
|
||||
* @param {Function} callback
|
||||
* @private
|
||||
*/
|
||||
function rimraf(dirPath, callback) {
|
||||
return fs.rm(dirPath, { recursive: true }, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively remove a directory and its contents, synchronously.
|
||||
*
|
||||
* @param {string} dirPath path of directory to remove
|
||||
* @private
|
||||
*/
|
||||
function FN_RIMRAF_SYNC(dirPath) {
|
||||
return fs.rmSync(dirPath, { recursive: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a temporary file name.
|
||||
*
|
||||
* @param {(Options|tmpNameCallback)} options options or callback
|
||||
* @param {?tmpNameCallback} callback the callback function
|
||||
*/
|
||||
function tmpName(options, callback) {
|
||||
const args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1];
|
||||
|
||||
_assertAndSanitizeOptions(opts, function (err, sanitizedOptions) {
|
||||
if (err) return cb(err);
|
||||
|
||||
let tries = sanitizedOptions.tries;
|
||||
(function _getUniqueName() {
|
||||
try {
|
||||
const name = _generateTmpName(sanitizedOptions);
|
||||
|
||||
// check whether the path exists then retry if needed
|
||||
fs.stat(name, function (err) {
|
||||
/* istanbul ignore else */
|
||||
if (!err) {
|
||||
/* istanbul ignore else */
|
||||
if (tries-- > 0) return _getUniqueName();
|
||||
|
||||
return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
|
||||
}
|
||||
|
||||
cb(null, name);
|
||||
});
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
}
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of tmpName.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {string} the generated random name
|
||||
* @throws {Error} if the options are invalid or could not generate a filename
|
||||
*/
|
||||
function tmpNameSync(options) {
|
||||
const args = _parseArguments(options),
|
||||
opts = args[0];
|
||||
|
||||
const sanitizedOptions = _assertAndSanitizeOptionsSync(opts);
|
||||
|
||||
let tries = sanitizedOptions.tries;
|
||||
do {
|
||||
const name = _generateTmpName(sanitizedOptions);
|
||||
try {
|
||||
fs.statSync(name);
|
||||
} catch (e) {
|
||||
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 {(Options|null|undefined|fileCallback)} options the config options or the callback function or null or undefined
|
||||
* @param {?fileCallback} callback
|
||||
*/
|
||||
function file(options, callback) {
|
||||
const args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1];
|
||||
|
||||
// gets a temporary filename
|
||||
tmpName(opts, function _tmpNameCreated(err, name) {
|
||||
/* istanbul ignore else */
|
||||
if (err) return cb(err);
|
||||
|
||||
// create and open the file
|
||||
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
|
||||
/* istanbu ignore else */
|
||||
if (err) return cb(err);
|
||||
|
||||
if (opts.discardDescriptor) {
|
||||
return fs.close(fd, function _discardCallback(possibleErr) {
|
||||
// the chance of getting an error on close here is rather low and might occur in the most edgiest cases only
|
||||
return cb(possibleErr, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts, false));
|
||||
});
|
||||
} else {
|
||||
// detachDescriptor passes the descriptor whereas discardDescriptor closes it, either way, we no longer care
|
||||
// about the descriptor
|
||||
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
||||
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, false));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of file.
|
||||
*
|
||||
* @param {Options} options
|
||||
* @returns {FileSyncObject} object consists of name, fd and removeCallback
|
||||
* @throws {Error} if cannot create a file
|
||||
*/
|
||||
function fileSync(options) {
|
||||
const args = _parseArguments(options),
|
||||
opts = args[0];
|
||||
|
||||
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
||||
const name = tmpNameSync(opts);
|
||||
let fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
|
||||
/* istanbul ignore else */
|
||||
if (opts.discardDescriptor) {
|
||||
fs.closeSync(fd);
|
||||
fd = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
name: name,
|
||||
fd: fd,
|
||||
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, true)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary directory.
|
||||
*
|
||||
* @param {(Options|dirCallback)} options the options or the callback function
|
||||
* @param {?dirCallback} callback
|
||||
*/
|
||||
function dir(options, callback) {
|
||||
const args = _parseArguments(options, callback),
|
||||
opts = args[0],
|
||||
cb = args[1];
|
||||
|
||||
// gets a temporary filename
|
||||
tmpName(opts, function _tmpNameCreated(err, name) {
|
||||
/* istanbul ignore else */
|
||||
if (err) return cb(err);
|
||||
|
||||
// create the directory
|
||||
fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
|
||||
/* istanbul ignore else */
|
||||
if (err) return cb(err);
|
||||
|
||||
cb(null, name, _prepareTmpDirRemoveCallback(name, opts, false));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous version of dir.
|
||||
*
|
||||
* @param {Options} options
|
||||
* @returns {DirSyncObject} object consists of name and removeCallback
|
||||
* @throws {Error} if it cannot create a directory
|
||||
*/
|
||||
function dirSync(options) {
|
||||
const args = _parseArguments(options),
|
||||
opts = args[0];
|
||||
|
||||
const name = tmpNameSync(opts);
|
||||
fs.mkdirSync(name, opts.mode || DIR_MODE);
|
||||
|
||||
return {
|
||||
name: name,
|
||||
removeCallback: _prepareTmpDirRemoveCallback(name, opts, true)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes files asynchronously.
|
||||
*
|
||||
* @param {Object} fdPath
|
||||
* @param {Function} next
|
||||
* @private
|
||||
*/
|
||||
function _removeFileAsync(fdPath, next) {
|
||||
const _handler = function (err) {
|
||||
if (err && !_isENOENT(err)) {
|
||||
// reraise any unanticipated error
|
||||
return next(err);
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
if (0 <= fdPath[0])
|
||||
fs.close(fdPath[0], function () {
|
||||
fs.unlink(fdPath[1], _handler);
|
||||
});
|
||||
else fs.unlink(fdPath[1], _handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes files synchronously.
|
||||
*
|
||||
* @param {Object} fdPath
|
||||
* @private
|
||||
*/
|
||||
function _removeFileSync(fdPath) {
|
||||
let rethrownException = null;
|
||||
try {
|
||||
if (0 <= fdPath[0]) fs.closeSync(fdPath[0]);
|
||||
} catch (e) {
|
||||
// reraise any unanticipated error
|
||||
if (!_isEBADF(e) && !_isENOENT(e)) throw e;
|
||||
} finally {
|
||||
try {
|
||||
fs.unlinkSync(fdPath[1]);
|
||||
} catch (e) {
|
||||
// reraise any unanticipated error
|
||||
if (!_isENOENT(e)) rethrownException = e;
|
||||
}
|
||||
}
|
||||
if (rethrownException !== null) {
|
||||
throw rethrownException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the callback for removal of the temporary file.
|
||||
*
|
||||
* Returns either a sync callback or a async callback depending on whether
|
||||
* fileSync or file was called, which is expressed by the sync parameter.
|
||||
*
|
||||
* @param {string} name the path of the file
|
||||
* @param {number} fd file descriptor
|
||||
* @param {Object} opts
|
||||
* @param {boolean} sync
|
||||
* @returns {fileCallback | fileCallbackSync}
|
||||
* @private
|
||||
*/
|
||||
function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
|
||||
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name], sync);
|
||||
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], sync, removeCallbackSync);
|
||||
|
||||
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
||||
|
||||
return sync ? removeCallbackSync : removeCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the callback for removal of the temporary directory.
|
||||
*
|
||||
* Returns either a sync callback or a async callback depending on whether
|
||||
* tmpFileSync or tmpFile was called, which is expressed by the sync parameter.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Object} opts
|
||||
* @param {boolean} sync
|
||||
* @returns {Function} the callback
|
||||
* @private
|
||||
*/
|
||||
function _prepareTmpDirRemoveCallback(name, opts, sync) {
|
||||
const removeFunction = opts.unsafeCleanup ? rimraf : fs.rmdir.bind(fs);
|
||||
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
|
||||
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
|
||||
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
|
||||
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
||||
|
||||
return sync ? removeCallbackSync : removeCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a guarded function wrapping the removeFunction call.
|
||||
*
|
||||
* The cleanup callback is save to be called multiple times.
|
||||
* Subsequent invocations will be ignored.
|
||||
*
|
||||
* @param {Function} removeFunction
|
||||
* @param {string} fileOrDirName
|
||||
* @param {boolean} sync
|
||||
* @param {cleanupCallbackSync?} cleanupCallbackSync
|
||||
* @returns {cleanupCallback | cleanupCallbackSync}
|
||||
* @private
|
||||
*/
|
||||
function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCallbackSync) {
|
||||
let called = false;
|
||||
|
||||
// if sync is true, the next parameter will be ignored
|
||||
return function _cleanupCallback(next) {
|
||||
/* istanbul ignore else */
|
||||
if (!called) {
|
||||
// remove cleanupCallback from cache
|
||||
const toRemove = cleanupCallbackSync || _cleanupCallback;
|
||||
const index = _removeObjects.indexOf(toRemove);
|
||||
/* istanbul ignore else */
|
||||
if (index >= 0) _removeObjects.splice(index, 1);
|
||||
|
||||
called = true;
|
||||
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
|
||||
return removeFunction(fileOrDirName);
|
||||
} else {
|
||||
return removeFunction(fileOrDirName, next || function () {});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The garbage collector.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _garbageCollector() {
|
||||
/* istanbul ignore else */
|
||||
if (!_gracefulCleanup) return;
|
||||
|
||||
// the function being called removes itself from _removeObjects,
|
||||
// loop until _removeObjects is empty
|
||||
while (_removeObjects.length) {
|
||||
try {
|
||||
_removeObjects[0]();
|
||||
} catch (e) {
|
||||
// already removed?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Random name generator based on crypto.
|
||||
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
||||
*
|
||||
* @param {number} howMany
|
||||
* @returns {string} the generated random name
|
||||
* @private
|
||||
*/
|
||||
function _randomChars(howMany) {
|
||||
let 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 (let 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
|
||||
* @returns {boolean} true if the object is undefined
|
||||
* @private
|
||||
*/
|
||||
function _isUndefined(obj) {
|
||||
return typeof obj === 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the function arguments.
|
||||
*
|
||||
* This function helps to have optional arguments.
|
||||
*
|
||||
* @param {(Options|null|undefined|Function)} options
|
||||
* @param {?Function} callback
|
||||
* @returns {Array} parsed arguments
|
||||
* @private
|
||||
*/
|
||||
function _parseArguments(options, callback) {
|
||||
/* istanbul ignore else */
|
||||
if (typeof options === 'function') {
|
||||
return [{}, options];
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (_isUndefined(options)) {
|
||||
return [{}, callback];
|
||||
}
|
||||
|
||||
// copy options so we do not leak the changes we make internally
|
||||
const actualOptions = {};
|
||||
for (const key of Object.getOwnPropertyNames(options)) {
|
||||
actualOptions[key] = options[key];
|
||||
}
|
||||
|
||||
return [actualOptions, callback];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified path name in respect to tmpDir.
|
||||
*
|
||||
* The specified name might include relative path components, e.g. ../
|
||||
* so we need to resolve in order to be sure that is is located inside tmpDir
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _resolvePath(name, tmpDir, cb) {
|
||||
const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
|
||||
|
||||
fs.stat(pathToResolve, function (err) {
|
||||
if (err) {
|
||||
fs.realpath(path.dirname(pathToResolve), function (err, parentDir) {
|
||||
if (err) return cb(err);
|
||||
|
||||
cb(null, path.join(parentDir, path.basename(pathToResolve)));
|
||||
});
|
||||
} else {
|
||||
fs.realpath(pathToResolve, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified path name in respect to tmpDir.
|
||||
*
|
||||
* The specified name might include relative path components, e.g. ../
|
||||
* so we need to resolve in order to be sure that is is located inside tmpDir
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _resolvePathSync(name, tmpDir) {
|
||||
const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
|
||||
|
||||
try {
|
||||
fs.statSync(pathToResolve);
|
||||
return fs.realpathSync(pathToResolve);
|
||||
} catch (_err) {
|
||||
const parentDir = fs.realpathSync(path.dirname(pathToResolve));
|
||||
|
||||
return path.join(parentDir, path.basename(pathToResolve));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new temporary name.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @returns {string} the new random name according to opts
|
||||
* @private
|
||||
*/
|
||||
function _generateTmpName(opts) {
|
||||
const tmpDir = opts.tmpdir;
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (!_isUndefined(opts.name)) {
|
||||
return path.join(tmpDir, opts.dir, opts.name);
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (!_isUndefined(opts.template)) {
|
||||
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
|
||||
}
|
||||
|
||||
// prefix and postfix
|
||||
const name = [
|
||||
opts.prefix ? opts.prefix : 'tmp',
|
||||
'-',
|
||||
process.pid,
|
||||
'-',
|
||||
_randomChars(12),
|
||||
opts.postfix ? '-' + opts.postfix : ''
|
||||
].join('');
|
||||
|
||||
return path.join(tmpDir, opts.dir, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts and sanitizes the basic options.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _assertOptionsBase(options) {
|
||||
if (!_isUndefined(options.name)) {
|
||||
const name = options.name;
|
||||
|
||||
// assert that name is not absolute and does not contain a path
|
||||
if (path.isAbsolute(name)) throw new Error(`name option must not contain an absolute path, found "${name}".`);
|
||||
|
||||
// must not fail on valid .<name> or ..<name> or similar such constructs
|
||||
const basename = path.basename(name);
|
||||
if (basename === '..' || basename === '.' || basename !== name)
|
||||
throw new Error(`name option must not contain a path, found "${name}".`);
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (!_isUndefined(options.template) && !options.template.match(TEMPLATE_PATTERN)) {
|
||||
throw new Error(`Invalid template, found "${options.template}".`);
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if ((!_isUndefined(options.tries) && isNaN(options.tries)) || options.tries < 0) {
|
||||
throw new Error(`Invalid tries, found "${options.tries}".`);
|
||||
}
|
||||
|
||||
// if a name was specified we will try once
|
||||
options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
|
||||
options.keep = !!options.keep;
|
||||
options.detachDescriptor = !!options.detachDescriptor;
|
||||
options.discardDescriptor = !!options.discardDescriptor;
|
||||
options.unsafeCleanup = !!options.unsafeCleanup;
|
||||
|
||||
// for completeness' sake only, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
||||
options.prefix = _isUndefined(options.prefix) ? '' : options.prefix;
|
||||
options.postfix = _isUndefined(options.postfix) ? '' : options.postfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relative directory to tmpDir.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _getRelativePath(option, name, tmpDir, cb) {
|
||||
if (_isUndefined(name)) return cb(null);
|
||||
|
||||
_resolvePath(name, tmpDir, function (err, resolvedPath) {
|
||||
if (err) return cb(err);
|
||||
|
||||
const relativePath = path.relative(tmpDir, resolvedPath);
|
||||
|
||||
if (!resolvedPath.startsWith(tmpDir)) {
|
||||
return cb(new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`));
|
||||
}
|
||||
|
||||
cb(null, relativePath);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relative path to tmpDir.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _getRelativePathSync(option, name, tmpDir) {
|
||||
if (_isUndefined(name)) return;
|
||||
|
||||
const resolvedPath = _resolvePathSync(name, tmpDir);
|
||||
const relativePath = path.relative(tmpDir, resolvedPath);
|
||||
|
||||
if (!resolvedPath.startsWith(tmpDir)) {
|
||||
throw new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`);
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
|
||||
* options.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _assertAndSanitizeOptions(options, cb) {
|
||||
_getTmpDir(options, function (err, tmpDir) {
|
||||
if (err) return cb(err);
|
||||
|
||||
options.tmpdir = tmpDir;
|
||||
|
||||
try {
|
||||
_assertOptionsBase(options, tmpDir);
|
||||
} catch (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// sanitize dir, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
||||
_getRelativePath('dir', options.dir, tmpDir, function (err, dir) {
|
||||
if (err) return cb(err);
|
||||
|
||||
options.dir = _isUndefined(dir) ? '' : dir;
|
||||
|
||||
// sanitize further if template is relative to options.dir
|
||||
_getRelativePath('template', options.template, tmpDir, function (err, template) {
|
||||
if (err) return cb(err);
|
||||
|
||||
options.template = template;
|
||||
|
||||
cb(null, options);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
|
||||
* options.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _assertAndSanitizeOptionsSync(options) {
|
||||
const tmpDir = (options.tmpdir = _getTmpDirSync(options));
|
||||
|
||||
_assertOptionsBase(options, tmpDir);
|
||||
|
||||
const dir = _getRelativePathSync('dir', options.dir, tmpDir);
|
||||
options.dir = _isUndefined(dir) ? '' : dir;
|
||||
|
||||
options.template = _getRelativePathSync('template', options.template, tmpDir);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _isEBADF(error) {
|
||||
return _isExpectedError(error, -EBADF, 'EBADF');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _isENOENT(error) {
|
||||
return _isExpectedError(error, -ENOENT, 'ENOENT');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to determine whether the expected error code matches the actual code and errno,
|
||||
* which will differ between the supported node versions.
|
||||
*
|
||||
* - Node >= 7.0:
|
||||
* error.code {string}
|
||||
* error.errno {number} any numerical value will be negated
|
||||
*
|
||||
* CAVEAT
|
||||
*
|
||||
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
|
||||
* is no different here.
|
||||
*
|
||||
* @param {SystemError} error
|
||||
* @param {number} errno
|
||||
* @param {string} code
|
||||
* @private
|
||||
*/
|
||||
function _isExpectedError(error, errno, code) {
|
||||
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the graceful cleanup.
|
||||
*
|
||||
* If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the
|
||||
* temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary
|
||||
* object removals.
|
||||
*/
|
||||
function setGracefulCleanup() {
|
||||
_gracefulCleanup = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured tmp dir from os.tmpdir().
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _getTmpDir(options, cb) {
|
||||
return fs.realpath((options && options.tmpdir) || os.tmpdir(), cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured tmp dir from os.tmpdir().
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _getTmpDirSync(options) {
|
||||
return fs.realpathSync((options && options.tmpdir) || os.tmpdir());
|
||||
}
|
||||
|
||||
// Install process exit listener
|
||||
process.addListener(EXIT, _garbageCollector);
|
||||
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @typedef {Object} Options
|
||||
* @property {?boolean} keep the temporary object (file or dir) will not be garbage collected
|
||||
* @property {?number} tries the number of tries before give up the name generation
|
||||
* @property (?int) mode the access mode, defaults are 0o700 for directories and 0o600 for files
|
||||
* @property {?string} template the "mkstemp" like filename template
|
||||
* @property {?string} name fixed name relative to tmpdir or the specified dir option
|
||||
* @property {?string} dir tmp directory relative to the root tmp directory in use
|
||||
* @property {?string} prefix prefix for the generated name
|
||||
* @property {?string} postfix postfix for the generated name
|
||||
* @property {?string} tmpdir the root tmp directory which overrides the os tmpdir
|
||||
* @property {?boolean} unsafeCleanup recursively removes the created temporary directory, even when it's not empty
|
||||
* @property {?boolean} detachDescriptor detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
|
||||
* @property {?boolean} discardDescriptor discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} FileSyncObject
|
||||
* @property {string} name the name of the file
|
||||
* @property {string} fd the file descriptor or -1 if the fd has been discarded
|
||||
* @property {fileCallback} removeCallback the callback function to remove the file
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} DirSyncObject
|
||||
* @property {string} name the name of the directory
|
||||
* @property {fileCallback} removeCallback the callback function to remove the directory
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback tmpNameCallback
|
||||
* @param {?Error} err the error object if anything goes wrong
|
||||
* @param {string} name the temporary file name
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback fileCallback
|
||||
* @param {?Error} err the error object if anything goes wrong
|
||||
* @param {string} name the temporary file name
|
||||
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
||||
* @param {cleanupCallback} fn the cleanup callback function
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback fileCallbackSync
|
||||
* @param {?Error} err the error object if anything goes wrong
|
||||
* @param {string} name the temporary file name
|
||||
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
||||
* @param {cleanupCallbackSync} fn the cleanup callback function
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback dirCallback
|
||||
* @param {?Error} err the error object if anything goes wrong
|
||||
* @param {string} name the temporary file name
|
||||
* @param {cleanupCallback} fn the cleanup callback function
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback dirCallbackSync
|
||||
* @param {?Error} err the error object if anything goes wrong
|
||||
* @param {string} name the temporary file name
|
||||
* @param {cleanupCallbackSync} fn the cleanup callback function
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes the temporary created file or directory.
|
||||
*
|
||||
* @callback cleanupCallback
|
||||
* @param {simpleCallback} [next] function to call whenever the tmp object needs to be removed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes the temporary created file or directory.
|
||||
*
|
||||
* @callback cleanupCallbackSync
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback function for function composition.
|
||||
* @see {@link https://github.com/raszi/node-tmp/issues/57|raszi/node-tmp#57}
|
||||
*
|
||||
* @callback simpleCallback
|
||||
*/
|
||||
|
||||
// exporting all the needed methods
|
||||
|
||||
// evaluate _getTmpDir() lazily, mainly for simplifying testing but it also will
|
||||
// allow users to reconfigure the temporary directory
|
||||
Object.defineProperty(module.exports, 'tmpdir', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: function () {
|
||||
return _getTmpDirSync();
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.dir = dir;
|
||||
module.exports.dirSync = dirSync;
|
||||
|
||||
module.exports.file = file;
|
||||
module.exports.fileSync = fileSync;
|
||||
|
||||
module.exports.tmpName = tmpName;
|
||||
module.exports.tmpNameSync = tmpNameSync;
|
||||
|
||||
module.exports.setGracefulCleanup = setGracefulCleanup;
|
||||
56
mc_test/node_modules/tmp/package.json
generated
vendored
Executable file
56
mc_test/node_modules/tmp/package.json
generated
vendored
Executable file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "tmp",
|
||||
"version": "0.2.5",
|
||||
"description": "Temporary file and directory creator",
|
||||
"author": "KARASZI István <github@spam.raszi.hu>",
|
||||
"contributors": [
|
||||
"Carsten Klein <trancesilken@gmail.com> (https://github.com/silkentrance)"
|
||||
],
|
||||
"keywords": [
|
||||
"temporary",
|
||||
"tmp",
|
||||
"temp",
|
||||
"tempdir",
|
||||
"tempfile",
|
||||
"tmpdir",
|
||||
"tmpfile"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/raszi/node-tmp.git",
|
||||
"homepage": "http://github.com/raszi/node-tmp",
|
||||
"bugs": {
|
||||
"url": "http://github.com/raszi/node-tmp/issues"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.14"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.3.0",
|
||||
"eslint-plugin-mocha": "^6.1.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"lerna-changelog": "^1.0.1",
|
||||
"mocha": "^10.2.0"
|
||||
},
|
||||
"main": "lib/tmp.js",
|
||||
"files": [
|
||||
"lib/"
|
||||
],
|
||||
"changelog": {
|
||||
"labels": {
|
||||
"breaking": ":boom: Breaking Change",
|
||||
"enhancement": ":rocket: Enhancement",
|
||||
"bug": ":bug: Bug Fix",
|
||||
"documentation": ":memo: Documentation",
|
||||
"internal": ":house: Internal"
|
||||
},
|
||||
"cacheDir": ".changelog"
|
||||
},
|
||||
"scripts": {
|
||||
"changelog": "lerna-changelog",
|
||||
"lint": "eslint lib --env mocha test",
|
||||
"clean": "rm -Rf ./coverage",
|
||||
"test": "npm run clean && istanbul cover ./node_modules/mocha/bin/_mocha --report none --print none --dir ./coverage/json -u exports -R test/*-test.js && istanbul report --root ./coverage/json html && istanbul report text-summary",
|
||||
"doc": "jsdoc -c .jsdoc.json"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user