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.
 
 
 
 

29 lines
899 B

  1. import os
  2. import os.path
  3. from pip.compat import get_path_uid
  4. def check_path_owner(path):
  5. # If we don't have a way to check the effective uid of this process, then
  6. # we'll just assume that we own the directory.
  7. if not hasattr(os, "geteuid"):
  8. return True
  9. previous = None
  10. while path != previous:
  11. if os.path.lexists(path):
  12. # Check if path is writable by current user.
  13. if os.geteuid() == 0:
  14. # Special handling for root user in order to handle properly
  15. # cases where users use sudo without -H flag.
  16. try:
  17. path_uid = get_path_uid(path)
  18. except OSError:
  19. return False
  20. return path_uid == 0
  21. else:
  22. return os.access(path, os.W_OK)
  23. else:
  24. previous, path = path, os.path.dirname(path)