1 | # infer-owner
|
---|
2 |
|
---|
3 | Infer the owner of a path based on the owner of its nearest existing parent
|
---|
4 |
|
---|
5 | ## USAGE
|
---|
6 |
|
---|
7 | ```js
|
---|
8 | const inferOwner = require('infer-owner')
|
---|
9 |
|
---|
10 | inferOwner('/some/cache/folder/file').then(owner => {
|
---|
11 | // owner is {uid, gid} that should be attached to
|
---|
12 | // the /some/cache/folder/file, based on ownership
|
---|
13 | // of /some/cache/folder, /some/cache, /some, or /,
|
---|
14 | // whichever is the first to exist
|
---|
15 | })
|
---|
16 |
|
---|
17 | // same, but not async
|
---|
18 | const owner = inferOwner.sync('/some/cache/folder/file')
|
---|
19 |
|
---|
20 | // results are cached! to reset the cache (eg, to change
|
---|
21 | // permissions for whatever reason), do this:
|
---|
22 | inferOwner.clearCache()
|
---|
23 | ```
|
---|
24 |
|
---|
25 | This module endeavors to be as performant as possible. Parallel requests
|
---|
26 | for ownership of the same path will only stat the directories one time.
|
---|
27 |
|
---|
28 | ## API
|
---|
29 |
|
---|
30 | * `inferOwner(path) -> Promise<{ uid, gid }>`
|
---|
31 |
|
---|
32 | If the path exists, return its uid and gid. If it does not, look to
|
---|
33 | its parent, then its grandparent, and so on.
|
---|
34 |
|
---|
35 | * `inferOwner(path) -> { uid, gid }`
|
---|
36 |
|
---|
37 | Sync form of `inferOwner(path)`.
|
---|
38 |
|
---|
39 | * `inferOwner.clearCache()`
|
---|
40 |
|
---|
41 | Delete all cached ownership information and in-flight tracking.
|
---|