Skip to content

Commit

Permalink
Eagerly normalize the cache directory
Browse files Browse the repository at this point in the history
Fixes pypa#7541
  • Loading branch information
sbidoul committed Jan 8, 2020
1 parent 5529bac commit 4d79037
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/7541.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly handle relative cache directory provided via --cache-dir.
3 changes: 2 additions & 1 deletion src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pip._internal.utils.deprecation import deprecated
from pip._internal.utils.filesystem import check_path_owner
from pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
from pip._internal.utils.misc import get_prog
from pip._internal.utils.misc import get_prog, normalize_path
from pip._internal.utils.temp_dir import global_tempdir_manager
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.utils.virtualenv import running_under_virtualenv
Expand Down Expand Up @@ -170,6 +170,7 @@ def _main(self, args):
sys.exit(VIRTUALENV_NOT_FOUND)

if options.cache_dir:
options.cache_dir = normalize_path(options.cache_dir)
if not check_path_owner(options.cache_dir):
logger.warning(
"The directory '%s' or its parent directory is not owned "
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def check_path_owner(path):
if sys.platform == "win32" or not hasattr(os, "geteuid"):
return True

assert os.path.isabs(path)

previous = None
while path != previous:
if os.path.lexists(path):
Expand Down

0 comments on commit 4d79037

Please sign in to comment.