commit: 97307968d585b92414449a2f41b68ccbb13a509c
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Mon Oct 27 18:42:42 2025 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 27 21:28:10 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=97307968
feat!: chuck sunos support.
See 03070538 for when it was added (>15y ago). sunos
had a broken ass access, so this was added.
Most other snakeoil code, pkgcore, etc, all actually
use os.access two spots in snakeoil that never got
changed from back then.
TL;dr: if your OS sucks, well, snakeoil likely was already
broken for you. Thus throw out sunos support.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/osutils/__init__.py | 51 ----------------------------------------
src/snakeoil/process/__init__.py | 6 ++---
src/snakeoil/process/spawn.py | 3 +--
tests/test_osutils.py | 19 ++-------------
4 files changed, 5 insertions(+), 74 deletions(-)
diff --git a/src/snakeoil/osutils/__init__.py b/src/snakeoil/osutils/__init__.py
index 1910859..9548974 100644
--- a/src/snakeoil/osutils/__init__.py
+++ b/src/snakeoil/osutils/__init__.py
@@ -55,10 +55,6 @@ import sys
from . import native_readdir as module
-# delay this... it's a 1ms hit, and not a lot of the consumers
-# force utf8 codepaths yet.
-from ..klass import steal_docs
-
listdir = os.listdir
listdir_dirs = module.listdir_dirs
listdir_files = module.listdir_files
@@ -278,53 +274,6 @@ def normpath(mypath: str) -> str:
pjoin = join = os.path.join
-@steal_docs(os.access)
-def fallback_access(path, mode, root=0):
- try:
- st = os.lstat(path)
- except EnvironmentError:
- return False
- if mode == os.F_OK:
- return True
- # rules roughly are as follows; if process uid == file uid, those perms
- # apply.
- # if groups match... that perm group is the fallback (authorative)
- # if neither, then other
- # if root, w/r is guranteed, x is actually checked
- # note posix says X_OK can be True, which is a worthless result, hence this
- # fallback for systems that take advantage of that posix misfeature.
-
- myuid = os.getuid()
-
- # if we're root... pull out X_OK and check that alone. the rules of
- # X_OK under linux (which this function emulates) are that any +x is a True
- # as for WR, that's always allowed (well not always- selinux may change
that)
-
- if myuid == 0:
- mode &= os.X_OK
- if not mode:
- # w/r are always True for root, so return up front
- return True
- # py3k doesn't like octal syntax; this is 0111
- return bool(st.st_mode & 73)
-
- mygroups = os.getgroups()
-
- if myuid == st.st_uid:
- # shift to the user octet, filter to 3 bits, verify intersect.
- return mode == (mode & ((st.st_mode >> 6) & 0x7))
- if st.st_gid in mygroups:
- return mode == (mode & ((st.st_mode >> 3) & 0x7))
- return mode == (mode & (st.st_mode & 0x7))
-
-
-if os.uname()[0].lower() == "sunos":
- access = fallback_access
- access.__name__ = "access"
-else:
- access = os.access
-
-
def unlink_if_exists(path):
"""wrap os.unlink, ignoring if the file doesn't exist
diff --git a/src/snakeoil/process/__init__.py b/src/snakeoil/process/__init__.py
index 63c605d..f6f514d 100644
--- a/src/snakeoil/process/__init__.py
+++ b/src/snakeoil/process/__init__.py
@@ -8,14 +8,12 @@ import signal
import sys
import time
-from ..osutils import access
-
def find_binary(binary: str, paths=None, fallback=None) -> str:
"""look through the PATH environment, finding the binary to execute"""
if os.path.isabs(binary):
- if not (os.path.isfile(binary) and access(binary, os.X_OK)):
+ if not (os.path.isfile(binary) and os.access(binary, os.X_OK)):
raise CommandNotFound(binary)
return binary
@@ -24,7 +22,7 @@ def find_binary(binary: str, paths=None, fallback=None) ->
str:
for path in paths:
filename = os.path.join(os.path.abspath(path), binary)
- if access(filename, os.X_OK) and os.path.isfile(filename):
+ if os.access(filename, os.X_OK) and os.path.isfile(filename):
return filename
if fallback is not None:
diff --git a/src/snakeoil/process/spawn.py b/src/snakeoil/process/spawn.py
index 9908c8d..e48b3ce 100644
--- a/src/snakeoil/process/spawn.py
+++ b/src/snakeoil/process/spawn.py
@@ -19,7 +19,6 @@ import sys
from typing import Iterable, Optional, Sequence, Union
from ..mappings import ProtectedDict
-from ..osutils import access
from . import find_binary
BASH_BINARY = find_binary("bash", fallback="/bin/bash")
@@ -468,7 +467,7 @@ def is_sandbox_capable(force: bool = False):
if "SANDBOX_ACTIVE" in os.environ:
# we can not spawn a sandbox inside another one
res = False
- elif not (os.path.isfile(SANDBOX_BINARY) and access(SANDBOX_BINARY,
os.X_OK)):
+ elif not (os.path.isfile(SANDBOX_BINARY) and os.access(SANDBOX_BINARY,
os.X_OK)):
res = False
else:
try:
diff --git a/tests/test_osutils.py b/tests/test_osutils.py
index 5b5e742..a164d7e 100644
--- a/tests/test_osutils.py
+++ b/tests/test_osutils.py
@@ -8,9 +8,10 @@ import sys
from unittest import mock
import pytest
+
from snakeoil import osutils
from snakeoil.contexts import Namespace
-from snakeoil.osutils import native_readdir, supported_systems, sizeof_fmt
+from snakeoil.osutils import native_readdir, sizeof_fmt, supported_systems
from snakeoil.osutils.mount import MNT_DETACH, MS_BIND, mount, umount
@@ -243,22 +244,6 @@ class Test_Native_NormPath:
check(b"/f\xc3\xb6\xc3\xb3/..", b"/")
[email protected](os.getuid() != 0, reason="these tests must be ran as root")
-class TestAccess:
- func = staticmethod(osutils.fallback_access)
-
- def test_fallback(self, tmp_path):
- fp = tmp_path / "file"
- # create the file
- fp.touch()
- fp.chmod(0o000)
- assert not self.func(fp, os.X_OK)
- assert self.func(fp, os.W_OK)
- assert self.func(fp, os.R_OK)
- assert self.func(fp, os.W_OK | os.R_OK)
- assert not self.func(fp, os.W_OK | os.R_OK | os.X_OK)
-
-
class Test_unlink_if_exists:
func = staticmethod(osutils.unlink_if_exists)