On 7/28/24 18:35, Zac Medico wrote:
@@ -201,20 +226,40 @@ def _userpriv_test_write_file(settings, file_path):
      if rval is not None:
          return rval
+ # Optimize away the spawn when privileges do not need to be dropped.
+    if not (
+        "userfetch" in settings.features
+        and os.getuid() == 0
+        and portage_gid
+        and portage_uid
+        and hasattr(os, "setgroups")
+    ):
+        rval = os.access(os.path.dirname(file_path), os.W_OK)
+        _userpriv_test_write_file_cache[file_path] = rval
+        return rval
+
+    # Optimize away the spawn if we can detect a portage group write
+    # permission bit, but if this optimization fails then continue with
+    # the spawn for ACL support.
+    st = os.stat(os.path.dirname(file_path))
+    if st.st_gid == int(portage_gid) and stat.S_IMODE(st.st_mode) & 0o020:
+        _userpriv_test_write_file_cache[file_path] = True
+        return True
+

It turned out that all of the above could be reduced to this because os.access works in any case that _want_userfetch returns False:

    # Optimize away the spawn when privileges do not need to be dropped.
    if not _want_userfetch(settings):
        rval = os.access(os.path.dirname(file_path), os.W_OK)
        _userpriv_test_write_file_cache[file_path] = rval
        return rval
--
Thanks,
Zac

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to