aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic')
-rw-r--r--deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/LICENSE5
-rw-r--r--deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/README.md44
-rw-r--r--deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/index.js129
-rw-r--r--deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/package.json67
4 files changed, 245 insertions, 0 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/LICENSE b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/LICENSE
new file mode 100644
index 0000000000..af4588069d
--- /dev/null
+++ b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/LICENSE
@@ -0,0 +1,5 @@
+Copyright (c) 2015, Rebecca Turner
+
+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/README.md b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/README.md
new file mode 100644
index 0000000000..a9d3461db1
--- /dev/null
+++ b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/README.md
@@ -0,0 +1,44 @@
+write-file-atomic
+-----------------
+
+This is an extension for node's `fs.writeFile` that makes its operation
+atomic and allows you set ownership (uid/gid of the file).
+
+### var writeFileAtomic = require('write-file-atomic')<br>writeFileAtomic(filename, data, [options], callback)
+
+* filename **String**
+* data **String** | **Buffer**
+* options **Object**
+ * chown **Object**
+ * uid **Number**
+ * gid **Number**
+ * encoding **String** | **Null** default = 'utf8'
+ * mode **Number** default = 438 (aka 0666 in Octal)
+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)`.
+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
+pass the error back to the caller.
+
+If provided, the **chown** option requires both **uid** and **gid** properties or else
+you'll get an error.
+
+The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
+
+Example:
+
+```javascript
+writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
+ if (err) throw err;
+ console.log('It\'s saved!');
+});
+```
+
+### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
+
+The synchronous version of **writeFileAtomic**.
diff --git a/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/index.js b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/index.js
new file mode 100644
index 0000000000..7bacf32ad0
--- /dev/null
+++ b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/index.js
@@ -0,0 +1,129 @@
+'use strict'
+module.exports = writeFile
+module.exports.sync = writeFileSync
+module.exports._getTmpname = getTmpname // for testing
+
+var fs = require('graceful-fs')
+var chain = require('slide').chain
+var MurmurHash3 = require('imurmurhash')
+var extend = Object.assign || require('util')._extend
+
+var invocations = 0
+function getTmpname (filename) {
+ return filename + '.' +
+ MurmurHash3(__filename)
+ .hash(String(process.pid))
+ .hash(String(++invocations))
+ .result()
+}
+
+function writeFile (filename, data, options, callback) {
+ if (options instanceof Function) {
+ callback = options
+ options = null
+ }
+ if (!options) options = {}
+ fs.realpath(filename, function (_, realname) {
+ _writeFile(realname || filename, data, options, callback)
+ })
+}
+function _writeFile (filename, data, options, callback) {
+ var tmpfile = getTmpname(filename)
+
+ if (options.mode && options.chown) {
+ return thenWriteFile()
+ } else {
+ // Either mode or chown is not explicitly set
+ // Default behavior is to copy it from original file
+ return fs.stat(filename, function (err, stats) {
+ if (err || !stats) return thenWriteFile()
+
+ options = extend({}, options)
+ if (!options.mode) {
+ options.mode = stats.mode
+ }
+ if (!options.chown && process.getuid) {
+ options.chown = { uid: stats.uid, gid: stats.gid }
+ }
+ return thenWriteFile()
+ })
+ }
+
+ function thenWriteFile () {
+ chain([
+ [writeFileAsync, tmpfile, data, options.mode, options.encoding || 'utf8'],
+ options.chown && [fs, fs.chown, tmpfile, options.chown.uid, options.chown.gid],
+ options.mode && [fs, fs.chmod, tmpfile, options.mode],
+ [fs, fs.rename, tmpfile, filename]
+ ], function (err) {
+ err ? fs.unlink(tmpfile, function () { callback(err) })
+ : callback()
+ })
+ }
+
+ // doing this instead of `fs.writeFile` in order to get the ability to
+ // call `fsync`.
+ function writeFileAsync (file, data, mode, encoding, cb) {
+ fs.open(file, 'w', options.mode, function (err, fd) {
+ if (err) return cb(err)
+ if (Buffer.isBuffer(data)) {
+ return fs.write(fd, data, 0, data.length, 0, syncAndClose)
+ } else if (data != null) {
+ return fs.write(fd, String(data), 0, String(encoding), syncAndClose)
+ } else {
+ return syncAndClose()
+ }
+ function syncAndClose (err) {
+ if (err) return cb(err)
+ fs.fsync(fd, function (err) {
+ if (err) return cb(err)
+ fs.close(fd, cb)
+ })
+ }
+ })
+ }
+}
+
+function writeFileSync (filename, data, options) {
+ if (!options) options = {}
+ try {
+ filename = fs.realpathSync(filename)
+ } catch (ex) {
+ // it's ok, it'll happen on a not yet existing file
+ }
+ 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 = extend({}, 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 = fs.openSync(tmpfile, 'w', options.mode)
+ if (Buffer.isBuffer(data)) {
+ fs.writeSync(fd, data, 0, data.length, 0)
+ } else if (data != null) {
+ fs.writeSync(fd, String(data), 0, String(options.encoding || 'utf8'))
+ }
+ fs.fsyncSync(fd)
+ fs.closeSync(fd)
+ if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid)
+ if (options.mode) fs.chmodSync(tmpfile, options.mode)
+ fs.renameSync(tmpfile, filename)
+ } catch (err) {
+ try { fs.unlinkSync(tmpfile) } catch (e) {}
+ throw err
+ }
+}
diff --git a/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/package.json b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/package.json
new file mode 100644
index 0000000000..8444520100
--- /dev/null
+++ b/deps/npm/node_modules/update-notifier/node_modules/configstore/node_modules/write-file-atomic/package.json
@@ -0,0 +1,67 @@
+{
+ "_from": "write-file-atomic@^1.1.2",
+ "_id": "write-file-atomic@1.3.4",
+ "_inBundle": false,
+ "_integrity": "sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8=",
+ "_location": "/update-notifier/configstore/write-file-atomic",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "write-file-atomic@^1.1.2",
+ "name": "write-file-atomic",
+ "escapedName": "write-file-atomic",
+ "rawSpec": "^1.1.2",
+ "saveSpec": null,
+ "fetchSpec": "^1.1.2"
+ },
+ "_requiredBy": [
+ "/update-notifier/configstore"
+ ],
+ "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz",
+ "_shasum": "f807a4f0b1d9e913ae7a48112e6cc3af1991b45f",
+ "_spec": "write-file-atomic@^1.1.2",
+ "_where": "/Users/zkat/Documents/code/npm/node_modules/update-notifier/node_modules/configstore",
+ "author": {
+ "name": "Rebecca Turner",
+ "email": "me@re-becca.org",
+ "url": "http://re-becca.org"
+ },
+ "bugs": {
+ "url": "https://github.com/iarna/write-file-atomic/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "graceful-fs": "^4.1.11",
+ "imurmurhash": "^0.1.4",
+ "slide": "^1.1.5"
+ },
+ "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": "^9.0.2",
+ "tap": "^10.3.2"
+ },
+ "files": [
+ "index.js"
+ ],
+ "homepage": "https://github.com/iarna/write-file-atomic",
+ "keywords": [
+ "writeFile",
+ "atomic"
+ ],
+ "license": "ISC",
+ "main": "index.js",
+ "name": "write-file-atomic",
+ "repository": {
+ "type": "git",
+ "url": "git+ssh://git@github.com/iarna/write-file-atomic.git"
+ },
+ "scripts": {
+ "test": "standard && tap --coverage test/*.js"
+ },
+ "version": "1.3.4"
+}