Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions scripts/migrate_searxng_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,24 @@ def migrate_settings(path: Path) -> bool:
try:
# chmod before chown: the Compose cap set is `cap_drop: ALL` plus
# CHOWN/SETGID/SETUID/DAC_OVERRIDE, with no FOWNER. Once the temporary
# file belongs to searxng:searxng which every retained settings file
# does, because searxng's entrypoint chowns /etc/searxng root can no
# file belongs to searxng:searxng -- which every retained settings file
# does, because searxng's entrypoint chowns /etc/searxng -- root can no
# longer chmod it and the migration dies with EPERM.
os.fchmod(fd, stat.S_IMODE(source_stat.st_mode))
os.fchown(fd, source_stat.st_uid, source_stat.st_gid)
if sys.platform != "win32":
os.fchown(fd, source_stat.st_uid, source_stat.st_gid)
with os.fdopen(fd, "wb") as handle:
fd = -1
handle.write(updated)
handle.flush()
os.fsync(handle.fileno())
os.replace(temporary, path)
directory_fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY)
try:
os.fsync(directory_fd)
finally:
os.close(directory_fd)
if sys.platform != "win32":
directory_fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY)
try:
os.fsync(directory_fd)
finally:
os.close(directory_fd)
finally:
if fd >= 0:
os.close(fd)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_searxng_settings_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import pytest
import yaml

pytestmark = pytest.mark.skipif(
sys.platform == "win32",
reason=(
"SearXNG settings migration relies on POSIX-only os.fchown and "
"os.O_DIRECTORY; the migration script runs only inside the Linux "
"SearXNG container and is not exercised on native Windows."
),
)

ROOT = Path(__file__).resolve().parent.parent
MIGRATION = ROOT / "scripts" / "migrate_searxng_settings.py"
Expand Down
Loading