mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-02-04 05:50:50 +00:00
nhj
more
This commit is contained in:
71
unified-ai-platform/node_modules/infer-owner/index.js
generated
vendored
Normal file
71
unified-ai-platform/node_modules/infer-owner/index.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
const cache = new Map()
|
||||
const fs = require('fs')
|
||||
const { dirname, resolve } = require('path')
|
||||
|
||||
|
||||
const lstat = path => new Promise((res, rej) =>
|
||||
fs.lstat(path, (er, st) => er ? rej(er) : res(st)))
|
||||
|
||||
const inferOwner = path => {
|
||||
path = resolve(path)
|
||||
if (cache.has(path))
|
||||
return Promise.resolve(cache.get(path))
|
||||
|
||||
const statThen = st => {
|
||||
const { uid, gid } = st
|
||||
cache.set(path, { uid, gid })
|
||||
return { uid, gid }
|
||||
}
|
||||
const parent = dirname(path)
|
||||
const parentTrap = parent === path ? null : er => {
|
||||
return inferOwner(parent).then((owner) => {
|
||||
cache.set(path, owner)
|
||||
return owner
|
||||
})
|
||||
}
|
||||
return lstat(path).then(statThen, parentTrap)
|
||||
}
|
||||
|
||||
const inferOwnerSync = path => {
|
||||
path = resolve(path)
|
||||
if (cache.has(path))
|
||||
return cache.get(path)
|
||||
|
||||
const parent = dirname(path)
|
||||
|
||||
// avoid obscuring call site by re-throwing
|
||||
// "catch" the error by returning from a finally,
|
||||
// only if we're not at the root, and the parent call works.
|
||||
let threw = true
|
||||
try {
|
||||
const st = fs.lstatSync(path)
|
||||
threw = false
|
||||
const { uid, gid } = st
|
||||
cache.set(path, { uid, gid })
|
||||
return { uid, gid }
|
||||
} finally {
|
||||
if (threw && parent !== path) {
|
||||
const owner = inferOwnerSync(parent)
|
||||
cache.set(path, owner)
|
||||
return owner // eslint-disable-line no-unsafe-finally
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const inflight = new Map()
|
||||
module.exports = path => {
|
||||
path = resolve(path)
|
||||
if (inflight.has(path))
|
||||
return Promise.resolve(inflight.get(path))
|
||||
const p = inferOwner(path).then(owner => {
|
||||
inflight.delete(path)
|
||||
return owner
|
||||
})
|
||||
inflight.set(path, p)
|
||||
return p
|
||||
}
|
||||
module.exports.sync = inferOwnerSync
|
||||
module.exports.clearCache = () => {
|
||||
cache.clear()
|
||||
inflight.clear()
|
||||
}
|
||||
26
unified-ai-platform/node_modules/infer-owner/package.json
generated
vendored
Normal file
26
unified-ai-platform/node_modules/infer-owner/package.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "infer-owner",
|
||||
"version": "1.0.4",
|
||||
"description": "Infer the owner of a path based on the owner of its nearest existing parent",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"test": "tap -J test/*.js --100",
|
||||
"snap": "TAP_SNAPSHOT=1 tap -J test/*.js --100",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"postpublish": "git push origin --follow-tags"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mutate-fs": "^2.1.1",
|
||||
"tap": "^12.4.2"
|
||||
},
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/npm/infer-owner",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user