From b3b2c551c24179769b76ddebb8ac66b732cf5bf0 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 14 Oct 2024 15:37:48 -0700 Subject: [PATCH] fix get_sock_file symlink process --- archivebox/queues/settings.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/archivebox/queues/settings.py b/archivebox/queues/settings.py index ab1a975c..85dfb869 100644 --- a/archivebox/queues/settings.py +++ b/archivebox/queues/settings.py @@ -1,5 +1,6 @@ import tempfile from pathlib import Path +from functools import cache from archivebox.config import CONSTANTS from archivebox.config.paths import get_collection_id @@ -14,20 +15,26 @@ SOCK_FILE = TMP_DIR / "supervisord.sock" LOG_FILE = TMP_DIR / "supervisord.log" WORKERS_DIR = TMP_DIR / "workers" - +@cache def get_sock_file(): + """Get the path to the supervisord socket file, symlinking to a shorter path if needed due to unix path length limits""" TMP_DIR.mkdir(parents=True, exist_ok=True) - if len(str(SOCK_FILE)) > 100: - # socket absolute paths cannot be longer than 108 characters on some systems + if len(f'file://{SOCK_FILE.absolute().resolve()}') > 98: + # socket absolute paths cannot be longer than 104 bytes on macos, and 108 bytes on linux # symlink it to a shorter path and use that instead - # use tmpfile to atomically overwrite any existing symlink - symlink = Path(tempfile.gettempdir()) / f"archivebox_supervisord_{get_collection_id()}.sock.tmp" + # place the actual socket file in a shorter tmp dir + # /var/folders/qy/6tpfrpx100j1t4l312nz683m0000gn/T/archivebox_supervisord_3d1e544e.sock + shorter_sock_file = Path(tempfile.gettempdir()) / f"archivebox_supervisord_{get_collection_id()}.sock" + + # symlink ./data/tmp//supervisord.sock -> /var/folders/qy/abc234235/T/archivebox_supervisord_3d1e544e.sock + # for convenience/consistency + symlink = SOCK_FILE symlink.unlink(missing_ok=True) - symlink.symlink_to(SOCK_FILE) - symlink.rename(str(symlink).replace('.sock.tmp', '.sock')) - assert len(str(symlink)) <= 100, f'Failed to create supervisord SOCK_FILE, system tmp dir location is too long {symlink} (unix only allows 108 characters for socket paths)' - return symlink + symlink.symlink_to(shorter_sock_file) + + assert len(f'file://{shorter_sock_file}') <= 98, f'Failed to create supervisord SOCK_FILE, system tmp dir location is too long {shorter_sock_file} (unix only allows 108 characters for socket paths)' + return shorter_sock_file return SOCK_FILE