aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
commit6c8128f9fd5a5d0be115806c35a21b3d683df8d6 (patch)
treef46c2f6b3b9b294ff32bd75c08ccdc9e7a8cc4ef /sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js
parent2400b84e95913665da6279114168148444b8f9ab (diff)
parent7d3640f824f46490b47bd95f1c5a16644f712068 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into logo
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js b/sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js
new file mode 100644
index 00000000..e3468b07
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/@npmcli/fs/lib/common/owner.js
@@ -0,0 +1,92 @@
+const { dirname, resolve } = require('path')
+
+const fileURLToPath = require('./file-url-to-path/index.js')
+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(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 (err) {}
+
+ try {
+ await fs.chown(path, uid, gid)
+ } catch (err) {}
+}
+
+// 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,
+}