From 8b7222127cb9b34189800a3b8422de7f9c54d1c4 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 1 Nov 2026 23:28:07 +0800 Subject: [PATCH] Fix social deploy pack to skip __pycache__ and extract safely on 82. Co-authored-by: Cursor --- deploy/social/deploy_82.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/deploy/social/deploy_82.py b/deploy/social/deploy_82.py index ddf0204..1f14996 100644 --- a/deploy/social/deploy_82.py +++ b/deploy/social/deploy_82.py @@ -63,6 +63,30 @@ def run(c: paramiko.SSHClient, cmd: str, timeout: int = 1200) -> tuple[str, int] return out, code +_SKIP_DIR = {"__pycache__", "node_modules", ".next", ".git"} + + +def _add_tree(tar: tarfile.TarFile, path: Path, arcname: str) -> None: + if path.is_file(): + if path.suffix == ".pyc": + return + tar.add(path, arcname=arcname) + return + for root, dirs, files in os.walk(path): + dirs[:] = [d for d in dirs if d not in _SKIP_DIR] + root_path = Path(root) + rel_root = root_path.relative_to(path) + for name in files: + if name.endswith(".pyc"): + continue + fp = root_path / name + if str(rel_root) == ".": + arc = f"{arcname}/{name}" + else: + arc = f"{arcname}/{rel_root.as_posix()}/{name}" + tar.add(fp, arcname=arc) + + def pack() -> Path: tmp = Path(tempfile.mkdtemp()) / "social82.tgz" with tarfile.open(tmp, "w:gz") as tar: @@ -71,7 +95,7 @@ def pack() -> Path: if not p.exists(): print("skip missing", rel) continue - tar.add(p, arcname=rel) + _add_tree(tar, p, rel) print("packed", tmp, "bytes", tmp.stat().st_size) return tmp @@ -92,7 +116,9 @@ def main() -> int: set -euo pipefail cd {APP} sudo cp -a data/remote-config.json /tmp/remote-config.pre-social.json || true -tar -xzf /tmp/social82.tgz +sudo chown -R ubuntu:ubuntu {APP} +find {APP}/apps/api/services/social_svc -type d -name '__pycache__' -prune -exec rm -rf {{}} + 2>/dev/null || true +tar -xzf /tmp/social82.tgz --no-same-owner # restore operational remote-config then merge social module key via python python3 - <<'PY' import json