$
This commit is contained in:
20
node_modules/@npmcli/fs/lib/common/get-options.js
generated
vendored
Normal file
20
node_modules/@npmcli/fs/lib/common/get-options.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// given an input that may or may not be an object, return an object that has
|
||||
// a copy of every defined property listed in 'copy'. if the input is not an
|
||||
// object, assign it to the property named by 'wrap'
|
||||
const getOptions = (input, { copy, wrap }) => {
|
||||
const result = {}
|
||||
|
||||
if (input && typeof input === 'object') {
|
||||
for (const prop of copy) {
|
||||
if (input[prop] !== undefined) {
|
||||
result[prop] = input[prop]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result[wrap] = input
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = getOptions
|
9
node_modules/@npmcli/fs/lib/common/node.js
generated
vendored
Normal file
9
node_modules/@npmcli/fs/lib/common/node.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const semver = require('semver')
|
||||
|
||||
const satisfies = (range) => {
|
||||
return semver.satisfies(process.version, range, { includePrerelease: true })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
satisfies,
|
||||
}
|
96
node_modules/@npmcli/fs/lib/common/owner-sync.js
generated
vendored
Normal file
96
node_modules/@npmcli/fs/lib/common/owner-sync.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
const { dirname, resolve } = require('path')
|
||||
const url = require('url')
|
||||
|
||||
const fs = require('../fs.js')
|
||||
|
||||
// given a path, find the owner of the nearest parent
|
||||
const find = (path) => {
|
||||
// if we have no getuid, permissions are irrelevant on this platform
|
||||
if (!process.getuid) {
|
||||
return {}
|
||||
}
|
||||
|
||||
// fs methods accept URL objects with a scheme of file: so we need to unwrap
|
||||
// those into an actual path string before we can resolve it
|
||||
const resolved = path != null && path.href && path.origin
|
||||
? resolve(url.fileURLToPath(path))
|
||||
: resolve(path)
|
||||
|
||||
let stat
|
||||
|
||||
try {
|
||||
stat = fs.lstatSync(resolved)
|
||||
} finally {
|
||||
// if we got a stat, return its contents
|
||||
if (stat) {
|
||||
return { uid: stat.uid, gid: stat.gid }
|
||||
}
|
||||
|
||||
// try the parent directory
|
||||
if (resolved !== dirname(resolved)) {
|
||||
return find(dirname(resolved))
|
||||
}
|
||||
|
||||
// no more parents, never got a stat, just return an empty object
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
// given a path, uid, and gid update the ownership of the path if necessary
|
||||
const update = (path, uid, gid) => {
|
||||
// nothing to update, just exit
|
||||
if (uid === undefined && gid === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// see if the permissions are already the same, if they are we don't
|
||||
// need to do anything, so return early
|
||||
const stat = fs.statSync(path)
|
||||
if (uid === stat.uid && gid === stat.gid) {
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// ignore errors
|
||||
}
|
||||
|
||||
try {
|
||||
fs.chownSync(path, uid, gid)
|
||||
} catch {
|
||||
// ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
// accepts a `path` and the `owner` property of an options object and normalizes
|
||||
// it into an object with numerical `uid` and `gid`
|
||||
const validate = (path, input) => {
|
||||
let uid
|
||||
let gid
|
||||
|
||||
if (typeof input === 'string' || typeof input === 'number') {
|
||||
uid = input
|
||||
gid = input
|
||||
} else if (input && typeof input === 'object') {
|
||||
uid = input.uid
|
||||
gid = input.gid
|
||||
}
|
||||
|
||||
if (uid === 'inherit' || gid === 'inherit') {
|
||||
const owner = find(path)
|
||||
if (uid === 'inherit') {
|
||||
uid = owner.uid
|
||||
}
|
||||
|
||||
if (gid === 'inherit') {
|
||||
gid = owner.gid
|
||||
}
|
||||
}
|
||||
|
||||
return { uid, gid }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
find,
|
||||
update,
|
||||
validate,
|
||||
}
|
96
node_modules/@npmcli/fs/lib/common/owner.js
generated
vendored
Normal file
96
node_modules/@npmcli/fs/lib/common/owner.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
const { dirname, resolve } = require('path')
|
||||
const url = require('url')
|
||||
|
||||
const fs = require('../fs.js')
|
||||
|
||||
// given a path, find the owner of the nearest parent
|
||||
const find = async (path) => {
|
||||
// if we have no getuid, permissions are irrelevant on this platform
|
||||
if (!process.getuid) {
|
||||
return {}
|
||||
}
|
||||
|
||||
// fs methods accept URL objects with a scheme of file: so we need to unwrap
|
||||
// those into an actual path string before we can resolve it
|
||||
const resolved = path != null && path.href && path.origin
|
||||
? resolve(url.fileURLToPath(path))
|
||||
: resolve(path)
|
||||
|
||||
let stat
|
||||
|
||||
try {
|
||||
stat = await fs.lstat(resolved)
|
||||
} finally {
|
||||
// if we got a stat, return its contents
|
||||
if (stat) {
|
||||
return { uid: stat.uid, gid: stat.gid }
|
||||
}
|
||||
|
||||
// try the parent directory
|
||||
if (resolved !== dirname(resolved)) {
|
||||
return find(dirname(resolved))
|
||||
}
|
||||
|
||||
// no more parents, never got a stat, just return an empty object
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
// given a path, uid, and gid update the ownership of the path if necessary
|
||||
const update = async (path, uid, gid) => {
|
||||
// nothing to update, just exit
|
||||
if (uid === undefined && gid === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// see if the permissions are already the same, if they are we don't
|
||||
// need to do anything, so return early
|
||||
const stat = await fs.stat(path)
|
||||
if (uid === stat.uid && gid === stat.gid) {
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// ignore errors
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.chown(path, uid, gid)
|
||||
} catch {
|
||||
// ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
// accepts a `path` and the `owner` property of an options object and normalizes
|
||||
// it into an object with numerical `uid` and `gid`
|
||||
const validate = async (path, input) => {
|
||||
let uid
|
||||
let gid
|
||||
|
||||
if (typeof input === 'string' || typeof input === 'number') {
|
||||
uid = input
|
||||
gid = input
|
||||
} else if (input && typeof input === 'object') {
|
||||
uid = input.uid
|
||||
gid = input.gid
|
||||
}
|
||||
|
||||
if (uid === 'inherit' || gid === 'inherit') {
|
||||
const owner = await find(path)
|
||||
if (uid === 'inherit') {
|
||||
uid = owner.uid
|
||||
}
|
||||
|
||||
if (gid === 'inherit') {
|
||||
gid = owner.gid
|
||||
}
|
||||
}
|
||||
|
||||
return { uid, gid }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
find,
|
||||
update,
|
||||
validate,
|
||||
}
|
Reference in New Issue
Block a user