You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

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