Skip to content

Commit 81c8a3f

Browse files
committed
Add permission check before configuration9
1 parent 8747268 commit 81c8a3f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/pip/_internal/configuration.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,24 @@ 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+
345359
# per-user configuration next
346360
should_load_user_config = not self.isolated and not (
347361
config_file and os.path.exists(config_file)
348-
) or not os.access(config_files[kinds.SITE], os.W_OK)
362+
) or not site_all_accessable == True
349363

350364
if should_load_user_config:
351365
# The legacy config file is overridden by the new config file

0 commit comments

Comments
 (0)