MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / ensure_directory

Function ensure_directory

codewiki/cli/utils/fs.py:13–37  ·  view source on GitHub ↗

Ensure directory exists, create if necessary. Args: path: Directory path mode: Directory permissions (default: 0o700 - user only) Returns: Path to the directory Raises: FileSystemError: If directory cannot be created

(path: Path, mode: int = 0o700)

Source from the content-addressed store, hash-verified

11
12
13def ensure_directory(path: Path, mode: int = 0o700) -> Path:
14 """
15 Ensure directory exists, create if necessary.
16
17 Args:
18 path: Directory path
19 mode: Directory permissions (default: 0o700 - user only)
20
21 Returns:
22 Path to the directory
23
24 Raises:
25 FileSystemError: If directory cannot be created
26 """
27 try:
28 path = Path(path).expanduser().resolve()
29 path.mkdir(parents=True, exist_ok=True, mode=mode)
30 return path
31 except PermissionError:
32 raise FileSystemError(
33 f"Permission denied: Cannot create directory {path}\nTry: chmod u+w {path.parent}"
34 )
35 except OSError as e:
36 raise FileSystemError(f"Cannot create directory {path}: {e}")
37
38
39def check_writable(path: Path) -> bool:
40 """

Callers 2

_save_api_key_to_fileMethod · 0.90
saveMethod · 0.90

Calls 2

FileSystemErrorClass · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected