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

index.js « mkdirp-infer-owner « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 750743f51a9f9151fa1c0cd3d252b6bba243a2ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const inferOwner = require('infer-owner')
const mkdirp = require('mkdirp')
const {promisify} = require('util')
const chownr = promisify(require('chownr'))

const platform = process.env.__TESTING_MKDIRP_INFER_OWNER_PLATFORM__
  || process.platform
const isWindows = platform === 'win32'
const isRoot = process.getuid && process.getuid() === 0
const doChown = !isWindows && isRoot

module.exports = !doChown ? (path, opts) => mkdirp(path, opts)
  : (path, opts) => inferOwner(path).then(({uid, gid}) =>
    mkdirp(path, opts).then(made =>
      uid !== 0 || gid !== process.getgid()
      ? chownr(made || path, uid, gid).then(() => made)
      : made))

module.exports.sync = !doChown ? (path, opts) => mkdirp.sync(path, opts)
  : (path, opts) => {
    const {uid, gid} = inferOwner.sync(path)
    const made = mkdirp.sync(path)
    if (uid !== 0 || gid !== process.getgid())
      chownr.sync(made || path, uid, gid)
    return made
  }