From 4e79e68a465bc85dd20253aa40624c578c8e5f3e Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 8 Feb 2024 16:36:14 -0500 Subject: [PATCH] make vipc and msgq prefix paths easier to cleanup (#31378) * ensure order * cleanup cleaner * cleaner * this needs prefix * rm vipc * bump --------- Co-authored-by: Comma Device old-commit-hash: e87135727d54fc497fa556984bd879023bf0fa9a --- cereal | 2 +- common/prefix.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cereal b/cereal index 80e1e55f0d..6712c46a90 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 80e1e55f0dd71cea7f596e8b80c7c33865b689f3 +Subproject commit 6712c46a907dac5eea982437f7464020ab2516e2 diff --git a/common/prefix.py b/common/prefix.py index d027e3e5a1..484cbec188 100644 --- a/common/prefix.py +++ b/common/prefix.py @@ -5,23 +5,21 @@ import uuid from typing import Optional from openpilot.common.params import Params -from openpilot.system.hardware.hw import Paths -from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT +from openpilot.system.hardware.hw import Paths, DEFAULT_DOWNLOAD_CACHE_ROOT class OpenpilotPrefix: def __init__(self, prefix: Optional[str] = None, clean_dirs_on_exit: bool = True, shared_download_cache: bool = False): self.prefix = prefix if prefix else str(uuid.uuid4().hex[0:15]) self.msgq_path = os.path.join('/dev/shm', self.prefix) + self.vipc_path = os.path.join('/tmp', f"{self.prefix}") self.clean_dirs_on_exit = clean_dirs_on_exit self.shared_download_cache = shared_download_cache def __enter__(self): self.original_prefix = os.environ.get('OPENPILOT_PREFIX', None) os.environ['OPENPILOT_PREFIX'] = self.prefix - try: - os.mkdir(self.msgq_path) - except FileExistsError: - pass + os.makedirs(self.msgq_path, exist_ok=True) + os.makedirs(self.vipc_path, exist_ok=True) os.makedirs(Paths.log_root(), exist_ok=True) if self.shared_download_cache: @@ -46,6 +44,7 @@ class OpenpilotPrefix: shutil.rmtree(os.path.realpath(symlink_path), ignore_errors=True) os.remove(symlink_path) shutil.rmtree(self.msgq_path, ignore_errors=True) + shutil.rmtree(self.vipc_path, ignore_errors=True) shutil.rmtree(Paths.log_root(), ignore_errors=True) if not os.environ.get("COMMA_CACHE", False): shutil.rmtree(Paths.download_cache_root(), ignore_errors=True)