From d107b133eecb30237b86f6676fee22f43144ce5a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 09:06:11 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20path=20containme?= =?UTF-8?q?nt=20checks=20in=20helpers/files.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: thirdeyenation <133812267+thirdeyenation@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ helpers/files.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000000..72d2490fb8 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,4 @@ + +## $(date +%Y-%m-%d) - Path Containment Performance +**Learning:** `os.path.commonpath` is a significant bottleneck for frequent path containment checks due to internal list allocations and path splitting. +**Action:** Use `os.path.abspath` and `str.startswith()` instead, ensuring a trailing `os.sep` is conditionally appended to the absolute directory before comparison to securely handle root directory edge cases and prevent path traversal bugs. diff --git a/helpers/files.py b/helpers/files.py index c77ab54cf1..e1351dcc76 100644 --- a/helpers/files.py +++ b/helpers/files.py @@ -653,7 +653,9 @@ def is_in_dir(path: str, dir: str): # check if the given path is within the directory abs_path = os.path.abspath(path) abs_dir = os.path.abspath(dir) - return os.path.commonpath([abs_path, abs_dir]) == abs_dir + + # ⚡ Bolt: optimized path containment check avoids slow os.path.commonpath + return abs_path == abs_dir or abs_path.startswith(abs_dir + ('' if abs_dir.endswith(os.sep) else os.sep)) def get_subdirectories(