fe9dc7b0af7b554a5c1eb52c11c4cab0cf63958b4bc84ff1dd461f09cbaa5631e8482d781e34a4edc381a7c4fe8fb12358565c7afcf6c1204bc6e3ef094d53 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.