1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Merge pull request #2303 from dstufft/ensure-directory-exists

Ensure that the directory exists when we create the user cache dir
(cherry picked from commit d89f3eaa20)
This commit is contained in:
Donald Stufft 2015-01-02 23:55:37 -05:00
parent 9981efdd89
commit 45f0a12e8a
3 changed files with 20 additions and 0 deletions

View file

@ -22,6 +22,9 @@
* Document the default cache directories for each operating system.
* Create the cache directory when the pip version check needs to save to it
instead of silently logging an error.
**6.0.3 (2014-12-23)**

View file

@ -1,6 +1,7 @@
from __future__ import absolute_import
import datetime
import errno
import json
import logging
import os.path
@ -12,6 +13,7 @@ from pip._vendor import pkg_resources
from pip.compat import total_seconds
from pip.index import PyPI
from pip.locations import USER_CACHE_DIR, running_under_virtualenv
from pip.utils.filesystem import check_path_owner
SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"
@ -57,6 +59,19 @@ class GlobalSelfCheckState(object):
self.state = {}
def save(self, pypi_version, current_time):
# Check to make sure that we own the directory
if not check_path_owner(
os.path.dirname(self.statefile_path), os.geteuid()):
return
# Now that we've ensured the directory is owned by this user, we'll go
# ahead and make sure that all our directories are created.
try:
os.makedirs(os.path.dirname(self.statefile_path))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
# Attempt to write out our version check file
with lockfile.LockFile(self.statefile_path):
with open(self.statefile_path) as statefile:

View file

@ -128,6 +128,8 @@ def test_global_state(monkeypatch):
def fake_lock(filename):
yield
monkeypatch.setattr(outdated, "check_path_owner", lambda p, u: True)
monkeypatch.setattr(lockfile, 'LockFile', fake_lock)
monkeypatch.setattr(outdated, 'running_under_virtualenv',