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:
authorclaudiahdz <cghr1990@gmail.com>2020-02-06 23:25:33 +0300
committerisaacs <i@izs.me>2020-05-08 04:11:51 +0300
commit0a45514d8beba749bebbd973ca9750ee0dc13b40 (patch)
treeeec0c989c38fcb7395c9fd565f2a44c79369c59e /node_modules/cacache/lib/util/fix-owner.js
parent019e6c41a85edf62727b517e1dfe2d5b9e53ba0e (diff)
cacache@15.0.0
Diffstat (limited to 'node_modules/cacache/lib/util/fix-owner.js')
-rw-r--r--node_modules/cacache/lib/util/fix-owner.js55
1 files changed, 36 insertions, 19 deletions
diff --git a/node_modules/cacache/lib/util/fix-owner.js b/node_modules/cacache/lib/util/fix-owner.js
index f5c33db5f..9afa638a8 100644
--- a/node_modules/cacache/lib/util/fix-owner.js
+++ b/node_modules/cacache/lib/util/fix-owner.js
@@ -1,9 +1,9 @@
'use strict'
-const BB = require('bluebird')
+const util = require('util')
-const chownr = BB.promisify(require('chownr'))
-const mkdirp = BB.promisify(require('mkdirp'))
+const chownr = util.promisify(require('chownr'))
+const mkdirp = require('mkdirp')
const inflight = require('promise-inflight')
const inferOwner = require('infer-owner')
@@ -32,19 +32,20 @@ const getSelf = () => {
}
module.exports.chownr = fixOwner
+
function fixOwner (cache, filepath) {
if (!process.getuid) {
// This platform doesn't need ownership fixing
- return BB.resolve()
+ return Promise.resolve()
}
getSelf()
if (self.uid !== 0) {
// almost certainly can't chown anyway
- return BB.resolve()
+ return Promise.resolve()
}
- return BB.resolve(inferOwner(cache)).then(owner => {
+ return Promise.resolve(inferOwner(cache)).then((owner) => {
const { uid, gid } = owner
// No need to override if it's already what we used.
@@ -52,18 +53,23 @@ function fixOwner (cache, filepath) {
return
}
- return inflight(
- 'fixOwner: fixing ownership on ' + filepath,
- () => chownr(
+ return inflight('fixOwner: fixing ownership on ' + filepath, () =>
+ chownr(
filepath,
typeof uid === 'number' ? uid : self.uid,
typeof gid === 'number' ? gid : self.gid
- ).catch({ code: 'ENOENT' }, () => null)
+ ).catch((err) => {
+ if (err.code === 'ENOENT') {
+ return null
+ }
+ throw err
+ })
)
})
}
module.exports.chownr.sync = fixOwnerSync
+
function fixOwnerSync (cache, filepath) {
if (!process.getuid) {
// This platform doesn't need ownership fixing
@@ -71,6 +77,11 @@ function fixOwnerSync (cache, filepath) {
}
const { uid, gid } = inferOwner.sync(cache)
getSelf()
+ if (self.uid !== 0) {
+ // almost certainly can't chown anyway
+ return
+ }
+
if (self.uid === uid && self.gid === gid) {
// No need to override if it's already what we used.
return
@@ -91,24 +102,30 @@ function fixOwnerSync (cache, filepath) {
}
module.exports.mkdirfix = mkdirfix
+
function mkdirfix (cache, p, cb) {
// we have to infer the owner _before_ making the directory, even though
// we aren't going to use the results, since the cache itself might not
// exist yet. If we mkdirp it, then our current uid/gid will be assumed
// to be correct if it creates the cache folder in the process.
- return BB.resolve(inferOwner(cache)).then(() => {
- return mkdirp(p).then(made => {
- if (made) {
- return fixOwner(cache, made).then(() => made)
- }
- }).catch({ code: 'EEXIST' }, () => {
- // There's a race in mkdirp!
- return fixOwner(cache, p).then(() => null)
- })
+ return Promise.resolve(inferOwner(cache)).then(() => {
+ return mkdirp(p)
+ .then((made) => {
+ if (made) {
+ return fixOwner(cache, made).then(() => made)
+ }
+ })
+ .catch((err) => {
+ if (err.code === 'EEXIST') {
+ return fixOwner(cache, p).then(() => null)
+ }
+ throw err
+ })
})
}
module.exports.mkdirfix.sync = mkdirfixSync
+
function mkdirfixSync (cache, p) {
try {
inferOwner.sync(cache)