Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
764875e1
Unverified
Commit
764875e1
authored
Oct 15, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure the config files have the right permissions
parent
f89cec94
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
2 deletions
+50
-2
poetry/config.py
+25
-1
poetry/utils/toml_file.py
+3
-0
tests/console/commands/test_config.py
+0
-1
tests/test_config.py
+22
-0
No files found.
poetry/config.py
View file @
764875e1
from
__future__
import
absolute_import
import
io
import
os
from
typing
import
Any
from
tomlkit
import
document
...
...
@@ -76,7 +81,26 @@ class Config:
self
.
dump
()
def
dump
(
self
):
self
.
_file
.
write
(
self
.
_content
)
# Ensuring the file is only readable and writable
# by the current user
mode
=
0
o600
umask
=
0
o777
^
mode
if
self
.
_file
.
exists
():
# If the file already exists, remove it
# if the permissions are higher than what we want
current_mode
=
os
.
stat
(
str
(
self
.
_file
))
.
st_mode
&
0
o777
if
current_mode
!=
384
:
os
.
remove
(
str
(
self
.
_file
))
umask_original
=
os
.
umask
(
umask
)
try
:
fd
=
os
.
open
(
str
(
self
.
_file
),
os
.
O_WRONLY
|
os
.
O_CREAT
,
mode
)
finally
:
os
.
umask
(
umask_original
)
with
io
.
open
(
fd
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
self
.
_content
.
as_string
())
@classmethod
def
create
(
cls
,
file
,
base_dir
=
None
):
# type: (...) -> Config
...
...
poetry/utils/toml_file.py
View file @
764875e1
...
...
@@ -17,3 +17,6 @@ class TomlFile(BaseTOMLFile):
def
__getattr__
(
self
,
item
):
return
getattr
(
self
.
_path_
,
item
)
def
__str__
(
self
):
return
str
(
self
.
_path
)
tests/console/commands/test_config.py
View file @
764875e1
...
...
@@ -4,7 +4,6 @@ import tempfile
from
cleo.testers
import
CommandTester
from
poetry.config
import
Config
from
poetry.utils._compat
import
Path
from
poetry.utils.toml_file
import
TomlFile
...
...
tests/test_config.py
0 → 100644
View file @
764875e1
import
os
import
pytest
import
tempfile
from
poetry.config
import
Config
from
poetry.utils.toml_file
import
TomlFile
@pytest.fixture
def
config
():
with
tempfile
.
NamedTemporaryFile
()
as
f
:
f
.
close
()
return
Config
(
TomlFile
(
f
.
name
))
def
test_config_sets_the_proper_file_permissions
(
config
):
config
.
add_property
(
"settings.virtualenvs.create"
,
True
)
mode
=
oct
(
os
.
stat
(
str
(
config
.
file
))
.
st_mode
&
0
o777
)
assert
int
(
mode
,
8
)
==
384
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment