Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on umask for default directory permissions #2924

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion notebook/nbextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
jupyter_data_dir, jupyter_config_path, jupyter_path,
SYSTEM_JUPYTER_PATH, ENV_JUPYTER_PATH,
)
from ipython_genutils.path import ensure_dir_exists
from notebook.utils import ensure_dir_exists
from ipython_genutils.py3compat import string_types, cast_unicode_py2
from ipython_genutils.tempdir import TemporaryDirectory
from ._version import __version__
Expand Down
2 changes: 1 addition & 1 deletion notebook/services/contents/filecheckpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from .fileio import FileManagerMixin

from ipython_genutils.path import ensure_dir_exists
from notebook.utils import ensure_dir_exists
from ipython_genutils.py3compat import getcwd
from traitlets import Unicode

Expand Down
17 changes: 17 additions & 0 deletions notebook/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,20 @@ def _check_pid_posix(pid):
check_pid = _check_pid_win32
else:
check_pid = _check_pid_posix


def ensure_dir_exists(path, mode=0o777):
"""ensure that a directory exists

If it doesn't exist, try to create it and protect against a race condition
if another process is doing the same.

The default permissions are determined by the current umask.
"""
try:
os.makedirs(path, mode=mode)
except OSError as e:
if e.errno != errno.EEXIST:
raise
if not os.path.isdir(path):
raise IOError("%r exists but is not a directory" % path)