Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion diskcache/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ def __init__(self, directory=None, timeout=60, disk=Disk, **settings):

if not op.isdir(directory):
try:
os.makedirs(directory, 0o755)
# Let the OS apply the umask to the default mode rather than
# hard-coding 0o755, so the cache directory's permissions
# honor the caller's umask like any other newly created
# directory would.
os.makedirs(directory)
except OSError as error:
if error.errno != errno.EEXIST:
raise EnvironmentError(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ def test_init_makedirs():
raise


def test_init_makedirs_respects_umask():
cache_dir = tempfile.mkdtemp()
shutil.rmtree(cache_dir)
makedirs = mock.Mock(wraps=os.makedirs)

try:
with mock.patch('os.makedirs', makedirs):
cache = dc.Cache(cache_dir)
cache.close()
finally:
shutil.rmtree(cache_dir, ignore_errors=True)

# No explicit mode should be passed, so the OS applies the umask to the
# default mode like it does for any other new directory.
makedirs.assert_called_once_with(cache_dir)


def test_pragma_error(cache):
local = mock.Mock()
con = mock.Mock()
Expand Down