Skip to content

Commit 2144008

Browse files
authored
Merge pull request #12089 from JasonMo1/main
2 parents 778b42f + 256af8f commit 2144008

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

news/11920.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add permission check before configuration

src/pip/_internal/configuration.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,15 @@ 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+
try:
215+
with open(fname, "w") as f:
216+
parser.write(f)
217+
except OSError as error:
218+
raise ConfigurationError(
219+
f"An error occurred while writing to the configuration file "
220+
f"{fname}: {error}"
221+
)
215222

216223
#
217224
# Private routines

0 commit comments

Comments
 (0)