summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/cacache/lib/util/move-file.js
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2017-05-09 14:46:02 -0700
committerAnna Henningsen <anna@addaleax.net>2017-05-23 19:39:43 +0200
commitc0d858f8bb8ba5212548da2fba6a7bc02db0462b (patch)
tree99f043ec5aec3f5150a2aed0f62597234b158140 /deps/npm/node_modules/cacache/lib/util/move-file.js
parent994617370e8e66f3ea9488fec32fd912e7902396 (diff)
downloadnode-new-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.tar.gz
deps: upgrade npm beta to 5.0.0-beta.56
PR-URL: https://github.com/nodejs/node/pull/12936 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'deps/npm/node_modules/cacache/lib/util/move-file.js')
-rw-r--r--deps/npm/node_modules/cacache/lib/util/move-file.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/deps/npm/node_modules/cacache/lib/util/move-file.js b/deps/npm/node_modules/cacache/lib/util/move-file.js
new file mode 100644
index 0000000000..422c8294e3
--- /dev/null
+++ b/deps/npm/node_modules/cacache/lib/util/move-file.js
@@ -0,0 +1,50 @@
+'use strict'
+
+const fs = require('graceful-fs')
+const BB = require('bluebird')
+let move
+let pinflight
+
+module.exports = moveFile
+function moveFile (src, dest) {
+ // This isn't quite an fs.rename -- the assumption is that
+ // if `dest` already exists, and we get certain errors while
+ // trying to move it, we should just not bother.
+ //
+ // In the case of cache corruption, users will receive an
+ // EINTEGRITY error elsewhere, and can remove the offending
+ // content their own way.
+ //
+ // Note that, as the name suggests, this strictly only supports file moves.
+ return BB.fromNode(cb => {
+ fs.link(src, dest, err => {
+ if (err) {
+ if (err.code === 'EEXIST' || err.code === 'EBUSY') {
+ // file already exists, so whatever
+ } else if (err.code === 'EPERM' && process.platform === 'win32') {
+ // file handle stayed open even past graceful-fs limits
+ } else {
+ return cb(err)
+ }
+ }
+ return fs.unlink(src, cb)
+ })
+ }).catch(err => {
+ if (process.platform !== 'win32') {
+ throw err
+ } else {
+ if (!pinflight) { pinflight = require('promise-inflight') }
+ return pinflight('cacache-move-file:' + dest, () => {
+ return BB.promisify(fs.stat)(dest).catch(err => {
+ if (err !== 'ENOENT') {
+ // Something else is wrong here. Bail bail bail
+ throw err
+ }
+ // file doesn't already exist! let's try a rename -> copy fallback
+ if (!move) { move = require('move-concurrently') }
+ return move(src, dest, { BB, fs })
+ })
+ })
+ }
+ })
+}