Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2017-04-29 01:11:18 +0300
committerRebecca Turner <me@re-becca.org>2017-05-26 02:13:33 +0300
commitc8b66854adef8d91c4ad2b058db6f1ca48031b58 (patch)
tree5e34a1bc728c551d5fa1cbf6bd50d53a04c634f3 /node_modules/cacache/lib/util/move-file.js
parentcbaf1c914036bc8ac1f9ea965ccba4fd690c8c45 (diff)
pacote@2.7.4
Diffstat (limited to 'node_modules/cacache/lib/util/move-file.js')
-rw-r--r--node_modules/cacache/lib/util/move-file.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/node_modules/cacache/lib/util/move-file.js b/node_modules/cacache/lib/util/move-file.js
new file mode 100644
index 000000000..422c8294e
--- /dev/null
+++ b/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 })
+ })
+ })
+ }
+ })
+}