vibe/vibe/core/utils/paths.py
Mathias Gesbert eb580209d4
v2.6.0 (#524)
Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Gauthier Guinet <43207538+Gguinet@users.noreply.github.com>
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Quentin <torroba.q@gmail.com>
Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
Co-authored-by: Simon Van de Kerckhove <simon.vandekerckhove@mistral.ai>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: angelapopopo <angele.lenglemetz@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-03-23 18:45:21 +01:00

42 lines
1.4 KiB
Python

from __future__ import annotations
from pathlib import Path
def is_dangerous_directory(path: Path | str = ".") -> tuple[bool, str]:
"""Check if the current directory is a dangerous folder that would cause
issues if we were to run the tool there.
Args:
path: Path to check (defaults to current directory)
Returns:
tuple[bool, str]: (is_dangerous, reason) where reason explains why it's dangerous
"""
path = Path(path).resolve()
home_dir = Path.home()
dangerous_paths = {
home_dir: "home directory",
home_dir / "Documents": "Documents folder",
home_dir / "Desktop": "Desktop folder",
home_dir / "Downloads": "Downloads folder",
home_dir / "Pictures": "Pictures folder",
home_dir / "Movies": "Movies folder",
home_dir / "Music": "Music folder",
home_dir / "Library": "Library folder",
Path("/Applications"): "Applications folder",
Path("/System"): "System folder",
Path("/Library"): "System Library folder",
Path("/usr"): "System usr folder",
Path("/private"): "System private folder",
}
for dangerous_path, description in dangerous_paths.items():
try:
if path == dangerous_path:
return True, f"You are in the {description}"
except (OSError, ValueError):
continue
return False, ""