pub fn fix_pip_cache_ownership(user_home: &str) -> PipCacheFixResultExpand description
Fix ownership of the pip cache directory (~/.cache/pip).
When installation steps use sudo pip install, the pip cache directory
(~/.cache/pip) can end up owned by root. This prevents the unprivileged
user from writing to the cache, causing permission errors on subsequent
pip install runs.
This function:
- Checks if
~/.cache/pipexists - Compares the directory’s owner UID with the current effective UID
- If the owner is root (UID 0) and we know the target user (via
SUDO_USERorHOMEmetadata), runschown -Rto fix ownership
§Arguments
user_home- The user’s home directory path (e.g.,/home/user)
§Returns
A PipCacheFixResult indicating what action was taken.
§Safety
Uses libc::geteuid() to check current effective UID. The chown command
is only executed when running as root with SUDO_USER set, which is the
expected scenario when sudo pip operations have corrupted cache ownership.