-
Notifications
You must be signed in to change notification settings - Fork 1.3k
makedirs: fix mode flag is being ignored starting from Python 3.7 #2790
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
Changes from all commits
2b93447
eec7618
303d52e
ecfbc3a
aa6a772
1c752a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,9 +152,12 @@ def makedirs(path, exist_ok=False, mode=None): | |
| _makedirs(path, exist_ok=exist_ok) | ||
| return | ||
|
|
||
| umask = os.umask(0) | ||
| # utilize umask to set proper permissions since Python 3.7 the `mode` | ||
| # `makedirs` argument no longer affects the file permission bits of | ||
| # newly-created intermediate-level directories. | ||
| umask = os.umask(0o777 - mode) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's put a comment explaining what is going on :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| # encoding: utf-8 | ||
| import filecmp | ||
| import os | ||
| import shutil | ||
| import stat | ||
|
|
||
| import pytest | ||
|
|
||
| from dvc import utils | ||
| from tests.basic_env import TestDvc | ||
|
|
@@ -69,3 +73,18 @@ def test_boxify(self): | |
| ) | ||
|
|
||
| assert expected == utils.boxify("message") | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.") | ||
| def test_makedirs_permissions(tmpdir): | ||
| dir_mode = 0o755 | ||
| os.chdir(str(tmpdir)) | ||
| intermediate_dir = "тестовая-директория" | ||
| test_dir = os.path.join(intermediate_dir, "data") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, simplified using tmpdir |
||
|
|
||
| assert not os.path.exists(intermediate_dir) | ||
|
|
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.