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

makedirs: fix mode flag is being ignored starting from Python 3.7 #2790

Merged
merged 6 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def makedirs(path, exist_ok=False, mode=None):
_makedirs(path, exist_ok=exist_ok)
return

umask = os.umask(0)
umask = os.umask(0o777 - mode)
shcheklein marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put a comment explaining what is going on :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

try:
_makedirs(path, exist_ok=exist_ok, mode=mode)
_makedirs(path, exist_ok=exist_ok)
finally:
os.umask(umask)

Expand Down
16 changes: 16 additions & 0 deletions tests/func/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import filecmp
import os
import shutil
import stat

import pytest

from dvc import utils
from tests.basic_env import TestDvc
Expand Down Expand Up @@ -69,3 +72,16 @@ def test_boxify(self):
)

assert expected == utils.boxify("message")


@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
def test_makedirs_permissions():
dir_mode = 0o755
intermediate_dir = "testdir"
test_dir = os.path.join(intermediate_dir, "data")
Copy link
Contributor

@efiop efiop Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are creating this directory in the project's root, which is not nice. Please use tmpdir fixture or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, simplified using tmpdir

utils.makedirs(test_dir, mode=dir_mode)

assert stat.S_IMODE(os.stat(test_dir).st_mode) == dir_mode
assert stat.S_IMODE(os.stat(intermediate_dir).st_mode) == dir_mode

shutil.rmtree(test_dir)