Skip to content

Commit c57bad6

Browse files
committed
Add permission check before configuration10
1 parent 81c8a3f commit c57bad6

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/pip/_internal/configuration.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ def save(self) -> None:
211211
ensure_dir(os.path.dirname(fname))
212212

213213
# Ensure directory's permission(need to be writeable)
214-
if os.access(fname, os.W_OK):
214+
try:
215215
with open(fname, "w") as f:
216216
parser.write(f)
217-
else:
217+
except IOError as error:
218218
raise ConfigurationError(
219-
"Configuation file not writeable {}".format(': '.join(fname))
219+
"An error occurred while writing to the configuration file: {0}\nError message: {1}".format(fname, error)
220220
)
221221

222222
#
@@ -342,24 +342,10 @@ def iter_config_files(self) -> Iterable[Tuple[Kind, List[str]]]:
342342
# at the base we have any global configuration
343343
yield kinds.GLOBAL, config_files[kinds.GLOBAL]
344344

345-
site_accessable = int
346-
site_index = 0
347-
site_all_accessable = bool
348-
349-
for fname in config_files[kinds.SITE]:
350-
site_index += 1
351-
if os.access(fname, os.W_OK):
352-
site_accessable += 1
353-
354-
if site_accessable < site_index:
355-
site_all_accessable = False
356-
elif site_accessable == site_index:
357-
site_all_accessable = True
358-
359345
# per-user configuration next
360346
should_load_user_config = not self.isolated and not (
361347
config_file and os.path.exists(config_file)
362-
) or not site_all_accessable == True
348+
)
363349

364350
if should_load_user_config:
365351
# The legacy config file is overridden by the new config file

0 commit comments

Comments
 (0)