Skip to content

Commit f746507

Browse files
committed
Add permission check before configuration
1 parent 5190ef7 commit f746507

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/pip/_internal/configuration.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,16 @@ def save(self) -> None:
210210
# Ensure directory exists.
211211
ensure_dir(os.path.dirname(fname))
212212

213-
with open(fname, "w") as f:
214-
parser.write(f)
213+
# Ensure directory's permission(need to be writeable)
214+
if os.access(fname, os.W_OK):
215+
with open(fname, "w") as f:
216+
parser.write(f)
217+
else:
218+
raise ConfigurationError(
219+
"Configuation file not writeable".format(
220+
": ".join(fname)
221+
)
222+
)
215223

216224
#
217225
# Private routines

0 commit comments

Comments
 (0)