summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/write-file-atomic
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/write-file-atomic')
-rw-r--r--deps/npm/node_modules/write-file-atomic/CHANGELOG.md20
-rw-r--r--deps/npm/node_modules/write-file-atomic/README.md19
-rw-r--r--deps/npm/node_modules/write-file-atomic/index.js110
-rw-r--r--deps/npm/node_modules/write-file-atomic/package.json36
4 files changed, 122 insertions, 63 deletions
diff --git a/deps/npm/node_modules/write-file-atomic/CHANGELOG.md b/deps/npm/node_modules/write-file-atomic/CHANGELOG.md
new file mode 100644
index 0000000000..61fb4d2233
--- /dev/null
+++ b/deps/npm/node_modules/write-file-atomic/CHANGELOG.md
@@ -0,0 +1,20 @@
+# 2.4.2
+
+* A pair of patches to fix some fd leaks. We would leak fds with sync use
+ when errors occured and with async use any time fsync was not in use. (#34)
+
+# 2.4.1
+
+* Fix a bug where `signal-exit` instances would be leaked. This was fixed when addressing #35.
+
+# 2.4.0
+
+## Features
+
+* Allow chown and mode options to be set to false to disable the defaulting behavior. (#20)
+* Support passing encoding strings in options slot for compat with Node.js API. (#31)
+* Add support for running inside of worker threads (#37)
+
+## Fixes
+
+* Remove unneeded call when returning success (#36)
diff --git a/deps/npm/node_modules/write-file-atomic/README.md b/deps/npm/node_modules/write-file-atomic/README.md
index af385f3b70..ca28e99a2b 100644
--- a/deps/npm/node_modules/write-file-atomic/README.md
+++ b/deps/npm/node_modules/write-file-atomic/README.md
@@ -8,20 +8,21 @@ atomic and allows you set ownership (uid/gid of the file).
* filename **String**
* data **String** | **Buffer**
-* options **Object**
- * chown **Object**
+* options **Object** | **String**
+ * chown **Object** default, uid & gid of existing file, if any
* uid **Number**
* gid **Number**
* encoding **String** | **Null** default = 'utf8'
* fsync **Boolean** default = true
- * mode **Number** default = 438 (aka 0666 in Octal)
+ * mode **Number** default, from existing file, if any
* Promise **Object** default = native Promise object
-callback **Function**
+* callback **Function**
Atomically and asynchronously writes data to a file, replacing the file if it already
exists. data can be a string or a buffer.
The file is initially named `filename + "." + murmurhex(__filename, process.pid, ++invocations)`.
+Note that `require('worker_threads').threadId` is used in addition to `process.pid` if running inside of a worker thread.
If writeFile completes successfully then, if passed the **chown** option it will change
the ownership of the file. Finally it renames the file back to the filename you specified. If
it encounters errors at any of these steps it will attempt to unlink the temporary file and then
@@ -29,9 +30,15 @@ pass the error back to the caller.
If multiple writes are concurrently issued to the same file, the write operations are put into a queue and serialized in the order they were called, using Promises. Native promises are used by default, but you can inject your own promise-like object with the **Promise** option. Writes to different files are still executed in parallel.
If provided, the **chown** option requires both **uid** and **gid** properties or else
-you'll get an error.
+you'll get an error. If **chown** is not specified it will default to using
+the owner of the previous file. To prevent chown from being ran you can
+also pass `false`, in which case the file will be created with the current user's credentials.
-The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
+If **mode** is not specified, it will default to using the permissions from
+an existing file, if any. Expicitly setting this to `false` remove this default, resulting
+in a file created with the system default permissions.
+
+If options is a String, it's assumed to be the **encoding** option. The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
If the **fsync** option is **false**, writeFile will skip the final fsync call.
diff --git a/deps/npm/node_modules/write-file-atomic/index.js b/deps/npm/node_modules/write-file-atomic/index.js
index 3b5607d154..fe9fdfb9db 100644
--- a/deps/npm/node_modules/write-file-atomic/index.js
+++ b/deps/npm/node_modules/write-file-atomic/index.js
@@ -10,11 +10,26 @@ var onExit = require('signal-exit')
var path = require('path')
var activeFiles = {}
+// if we run inside of a worker_thread, `process.pid` is not unique
+/* istanbul ignore next */
+var threadId = (function getId () {
+ try {
+ var workerThreads = require('worker_threads')
+
+ /// if we are in main thread, this is set to `0`
+ return workerThreads.threadId
+ } catch (e) {
+ // worker_threads are not available, fallback to 0
+ return 0
+ }
+})()
+
var invocations = 0
function getTmpname (filename) {
return filename + '.' +
MurmurHash3(__filename)
.hash(String(process.pid))
+ .hash(String(threadId))
.hash(String(++invocations))
.result()
}
@@ -28,17 +43,23 @@ function cleanupOnExit (tmpfile) {
}
function writeFile (filename, data, options, callback) {
- if (options instanceof Function) {
- callback = options
- options = null
+ if (options) {
+ if (options instanceof Function) {
+ callback = options
+ options = {}
+ } else if (typeof options === 'string') {
+ options = { encoding: options }
+ }
+ } else {
+ options = {}
}
- if (!options) options = {}
var Promise = options.Promise || global.Promise
var truename
var fd
var tmpfile
- var removeOnExit = cleanupOnExit(() => tmpfile)
+ /* istanbul ignore next -- The closure only gets called when onExit triggers */
+ var removeOnExitHandler = onExit(cleanupOnExit(() => tmpfile))
var absoluteName = path.resolve(filename)
new Promise(function serializeSameFile (resolve) {
@@ -66,10 +87,10 @@ function writeFile (filename, data, options, callback) {
else {
options = Object.assign({}, options)
- if (!options.mode) {
+ if (options.mode == null) {
options.mode = stats.mode
}
- if (!options.chown && process.getuid) {
+ if (options.chown == null && process.getuid) {
options.chown = { uid: stats.uid, gid: stats.gid }
}
resolve()
@@ -100,15 +121,18 @@ function writeFile (filename, data, options, callback) {
} else resolve()
})
}).then(function syncAndClose () {
- if (options.fsync !== false) {
- return new Promise(function (resolve, reject) {
+ return new Promise(function (resolve, reject) {
+ if (options.fsync !== false) {
fs.fsync(fd, function (err) {
- if (err) reject(err)
+ if (err) fs.close(fd, () => reject(err))
else fs.close(fd, resolve)
})
- })
- }
+ } else {
+ fs.close(fd, resolve)
+ }
+ })
}).then(function chown () {
+ fd = null
if (options.chown) {
return new Promise(function (resolve, reject) {
fs.chown(tmpfile, options.chown.uid, options.chown.gid, function (err) {
@@ -134,12 +158,16 @@ function writeFile (filename, data, options, callback) {
})
})
}).then(function success () {
- removeOnExit()
+ removeOnExitHandler()
callback()
- }).catch(function fail (err) {
- removeOnExit()
- fs.unlink(tmpfile, function () {
- callback(err)
+ }, function fail (err) {
+ return new Promise(resolve => {
+ return fd ? fs.close(fd, resolve) : resolve()
+ }).then(() => {
+ removeOnExitHandler()
+ fs.unlink(tmpfile, function () {
+ callback(err)
+ })
})
}).then(function checkQueue () {
activeFiles[absoluteName].shift() // remove the element added by serializeSameFile
@@ -150,7 +178,8 @@ function writeFile (filename, data, options, callback) {
}
function writeFileSync (filename, data, options) {
- if (!options) options = {}
+ if (typeof options === 'string') options = { encoding: options }
+ else if (!options) options = {}
try {
filename = fs.realpathSync(filename)
} catch (ex) {
@@ -158,26 +187,30 @@ function writeFileSync (filename, data, options) {
}
var tmpfile = getTmpname(filename)
- try {
- if (!options.mode || !options.chown) {
- // Either mode or chown is not explicitly set
- // Default behavior is to copy it from original file
- try {
- var stats = fs.statSync(filename)
- options = Object.assign({}, options)
- if (!options.mode) {
- options.mode = stats.mode
- }
- if (!options.chown && process.getuid) {
- options.chown = { uid: stats.uid, gid: stats.gid }
- }
- } catch (ex) {
- // ignore stat errors
+ if (!options.mode || !options.chown) {
+ // Either mode or chown is not explicitly set
+ // Default behavior is to copy it from original file
+ try {
+ var stats = fs.statSync(filename)
+ options = Object.assign({}, options)
+ if (!options.mode) {
+ options.mode = stats.mode
+ }
+ if (!options.chown && process.getuid) {
+ options.chown = { uid: stats.uid, gid: stats.gid }
}
+ } catch (ex) {
+ // ignore stat errors
}
+ }
+
+ var fd
+ var cleanup = cleanupOnExit(tmpfile)
+ var removeOnExitHandler = onExit(cleanup)
+
+ try {
- var removeOnExit = onExit(cleanupOnExit(tmpfile))
- var fd = fs.openSync(tmpfile, 'w', options.mode)
+ fd = fs.openSync(tmpfile, 'w', options.mode)
if (Buffer.isBuffer(data)) {
fs.writeSync(fd, data, 0, data.length, 0)
} else if (data != null) {
@@ -190,10 +223,11 @@ function writeFileSync (filename, data, options) {
if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid)
if (options.mode) fs.chmodSync(tmpfile, options.mode)
fs.renameSync(tmpfile, filename)
- removeOnExit()
+ removeOnExitHandler()
} catch (err) {
- removeOnExit()
- try { fs.unlinkSync(tmpfile) } catch (e) {}
+ if (fd) fs.closeSync(fd)
+ removeOnExitHandler()
+ cleanup()
throw err
}
}
diff --git a/deps/npm/node_modules/write-file-atomic/package.json b/deps/npm/node_modules/write-file-atomic/package.json
index cdf47414a4..f8f55fbd22 100644
--- a/deps/npm/node_modules/write-file-atomic/package.json
+++ b/deps/npm/node_modules/write-file-atomic/package.json
@@ -1,35 +1,31 @@
{
- "_args": [
- [
- "write-file-atomic@2.3.0",
- "/Users/rebecca/code/npm"
- ]
- ],
- "_from": "write-file-atomic@2.3.0",
- "_id": "write-file-atomic@2.3.0",
+ "_from": "write-file-atomic@^2.3.0",
+ "_id": "write-file-atomic@2.4.2",
"_inBundle": false,
- "_integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==",
+ "_integrity": "sha512-s0b6vB3xIVRLWywa6X9TOMA7k9zio0TMOsl9ZnDkliA/cfJlpHXAscj0gbHVJiTdIuAYpIyqS5GW91fqm6gG5g==",
"_location": "/write-file-atomic",
"_phantomChildren": {},
"_requested": {
- "type": "version",
+ "type": "range",
"registry": true,
- "raw": "write-file-atomic@2.3.0",
+ "raw": "write-file-atomic@^2.3.0",
"name": "write-file-atomic",
"escapedName": "write-file-atomic",
- "rawSpec": "2.3.0",
+ "rawSpec": "^2.3.0",
"saveSpec": null,
- "fetchSpec": "2.3.0"
+ "fetchSpec": "^2.3.0"
},
"_requiredBy": [
+ "#USER",
"/",
"/bin-links",
"/configstore",
"/tap"
],
- "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz",
- "_spec": "2.3.0",
- "_where": "/Users/rebecca/code/npm",
+ "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.2.tgz",
+ "_shasum": "a7181706dfba17855d221140a9c06e15fcdd87b9",
+ "_spec": "write-file-atomic@^2.3.0",
+ "_where": "/Users/zkat/Documents/code/work/npm",
"author": {
"name": "Rebecca Turner",
"email": "me@re-becca.org",
@@ -38,18 +34,20 @@
"bugs": {
"url": "https://github.com/iarna/write-file-atomic/issues"
},
+ "bundleDependencies": false,
"dependencies": {
"graceful-fs": "^4.1.11",
"imurmurhash": "^0.1.4",
"signal-exit": "^3.0.2"
},
+ "deprecated": false,
"description": "Write files in an atomic fashion w/configurable ownership",
"devDependencies": {
"mkdirp": "^0.5.1",
"require-inject": "^1.4.0",
"rimraf": "^2.5.4",
- "standard": "^10.0.2",
- "tap": "^10.3.2"
+ "standard": "^12.0.1",
+ "tap": "^12.1.3"
},
"files": [
"index.js"
@@ -69,5 +67,5 @@
"scripts": {
"test": "standard && tap --100 test/*.js"
},
- "version": "2.3.0"
+ "version": "2.4.2"
}