| from pip._internal.utils.compat import get_path_uid |
| def check_path_owner(path): |
| # If we don't have a way to check the effective uid of this process, then |
| # we'll just assume that we own the directory. |
| if not hasattr(os, "geteuid"): |
| if os.path.lexists(path): |
| # Check if path is writable by current user. |
| # Special handling for root user in order to handle properly |
| # cases where users use sudo without -H flag. |
| path_uid = get_path_uid(path) |
| return os.access(path, os.W_OK) |
| previous, path = path, os.path.dirname(path) |
| return False # assume we don't own the path |