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/index.js42
-rw-r--r--deps/npm/node_modules/write-file-atomic/package.json51
2 files changed, 54 insertions, 39 deletions
diff --git a/deps/npm/node_modules/write-file-atomic/index.js b/deps/npm/node_modules/write-file-atomic/index.js
index 519aacad98..7939828e53 100644
--- a/deps/npm/node_modules/write-file-atomic/index.js
+++ b/deps/npm/node_modules/write-file-atomic/index.js
@@ -1,38 +1,48 @@
'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
-function murmurhex () {
- var hash = new MurmurHash3()
- for (var ii = 0; ii < arguments.length; ++ii) hash.hash('' + arguments[ii])
- return hash.result()
-}
var invocations = 0
-var getTmpname = function (filename) {
- return filename + '.' + murmurhex(__filename, process.pid, ++invocations)
+function getTmpname (filename) {
+ return filename + '.' +
+ MurmurHash3(__filename)
+ .hash(String(process.pid))
+ .hash(String(++invocations))
+ .result()
}
-module.exports = function writeFile (filename, data, options, callback) {
+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.chmod) {
+ 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 (!err && stats && !options.mode) {
+ if (!options.mode) {
options.mode = stats.mode
}
- if (!err && stats && !options.chown && process.getuid) {
+ if (!options.chown && process.getuid) {
options.chown = { uid: stats.uid, gid: stats.gid }
}
return thenWriteFile()
@@ -52,17 +62,21 @@ module.exports = function writeFile (filename, data, options, callback) {
}
}
-module.exports.sync = function writeFileSync (filename, data, options) {
+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.chmod) {
+ 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
diff --git a/deps/npm/node_modules/write-file-atomic/package.json b/deps/npm/node_modules/write-file-atomic/package.json
index 76e9e9bf03..2b1db0d603 100644
--- a/deps/npm/node_modules/write-file-atomic/package.json
+++ b/deps/npm/node_modules/write-file-atomic/package.json
@@ -2,50 +2,50 @@
"_args": [
[
{
- "raw": "write-file-atomic@1.2.0",
+ "raw": "write-file-atomic@1.3.1",
"scope": null,
"escapedName": "write-file-atomic",
"name": "write-file-atomic",
- "rawSpec": "1.2.0",
- "spec": "1.2.0",
+ "rawSpec": "1.3.1",
+ "spec": "1.3.1",
"type": "version"
},
- "/Users/zkat/Documents/code/npm"
+ "/Users/rebecca/code/npm"
]
],
- "_from": "write-file-atomic@1.2.0",
- "_id": "write-file-atomic@1.2.0",
+ "_from": "write-file-atomic@1.3.1",
+ "_id": "write-file-atomic@1.3.1",
"_inCache": true,
"_location": "/write-file-atomic",
- "_nodeVersion": "4.5.0",
+ "_nodeVersion": "7.3.0",
"_npmOperationalInternal": {
- "host": "packages-12-west.internal.npmjs.com",
- "tmp": "tmp/write-file-atomic-1.2.0.tgz_1471552371956_0.5829780481290072"
+ "host": "packages-18-east.internal.npmjs.com",
+ "tmp": "tmp/write-file-atomic-1.3.1.tgz_1483776142964_0.11427561868913472"
},
"_npmUser": {
"name": "iarna",
"email": "me@re-becca.org"
},
- "_npmVersion": "3.10.7",
+ "_npmVersion": "4.1.1",
"_phantomChildren": {},
"_requested": {
- "raw": "write-file-atomic@1.2.0",
+ "raw": "write-file-atomic@1.3.1",
"scope": null,
"escapedName": "write-file-atomic",
"name": "write-file-atomic",
- "rawSpec": "1.2.0",
- "spec": "1.2.0",
+ "rawSpec": "1.3.1",
+ "spec": "1.3.1",
"type": "version"
},
"_requiredBy": [
"#USER",
"/"
],
- "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.2.0.tgz",
- "_shasum": "14c66d4e4cb3ca0565c28cf3b7a6f3e4d5938fab",
+ "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.1.tgz",
+ "_shasum": "7d45ba32316328dd1ec7d90f60ebc0d845bb759a",
"_shrinkwrap": null,
- "_spec": "write-file-atomic@1.2.0",
- "_where": "/Users/zkat/Documents/code/npm",
+ "_spec": "write-file-atomic@1.3.1",
+ "_where": "/Users/rebecca/code/npm",
"author": {
"name": "Rebecca Turner",
"email": "me@re-becca.org",
@@ -55,26 +55,27 @@
"url": "https://github.com/iarna/write-file-atomic/issues"
},
"dependencies": {
- "graceful-fs": "^4.1.2",
+ "graceful-fs": "^4.1.11",
"imurmurhash": "^0.1.4",
"slide": "^1.1.5"
},
"description": "Write files in an atomic fashion w/configurable ownership",
"devDependencies": {
- "require-inject": "^1.1.0",
+ "mkdirp": "^0.5.1",
+ "require-inject": "^1.4.0",
+ "rimraf": "^2.5.4",
"standard": "^5.4.1",
- "tap": "^2.3.1",
- "tmp": "0.0.28"
+ "tap": "^2.3.1"
},
"directories": {},
"dist": {
- "shasum": "14c66d4e4cb3ca0565c28cf3b7a6f3e4d5938fab",
- "tarball": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.2.0.tgz"
+ "shasum": "7d45ba32316328dd1ec7d90f60ebc0d845bb759a",
+ "tarball": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.1.tgz"
},
"files": [
"index.js"
],
- "gitHead": "c29f37cb5955f597066ad7aedea7aa6f7408a5b7",
+ "gitHead": "56fef5763513905d7e43aa685adad80002445474",
"homepage": "https://github.com/iarna/write-file-atomic",
"keywords": [
"writeFile",
@@ -102,5 +103,5 @@
"scripts": {
"test": "standard && tap --coverage test/*.js"
},
- "version": "1.2.0"
+ "version": "1.3.1"
}