Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

64 lines
1.8 KiB
Python

"""Filesystem helpers for local skill source ingestion."""
from __future__ import annotations
import os
import tempfile
from fnmatch import fnmatch
from pathlib import Path
from typing import Iterator
def _allowed_base_paths() -> list[str]:
return [
os.path.normpath(os.path.realpath(os.getcwd())),
os.path.normpath(os.path.realpath(tempfile.gettempdir())),
]
def _is_under_allowed_base(full_path: str) -> bool:
for base in _allowed_base_paths():
if full_path == base or full_path.startswith(
base if base.endswith(os.sep) else f"{base}{os.sep}"
):
return True
return False
def _safe_path_string(path: Path) -> str:
full_path = os.path.normpath(os.path.realpath(os.path.abspath(os.fspath(path))))
if not _is_under_allowed_base(full_path):
raise ValueError("Path is outside the current working directory")
return full_path
def trusted_is_file(path: Path) -> bool:
return os.path.isfile(_safe_path_string(path))
def trusted_is_dir(path: Path) -> bool:
return os.path.isdir(_safe_path_string(path))
def trusted_iterdir(path: Path) -> Iterator[Path]:
full_path = _safe_path_string(path)
for entry in os.scandir(full_path):
yield Path(entry.path)
def trusted_rglob(path: Path, pattern: str) -> Iterator[Path]:
full_path = _safe_path_string(path)
for root, dirs, files in os.walk(full_path):
for name in dirs:
if fnmatch(name, pattern):
yield Path(root) / name
for name in files:
if fnmatch(name, pattern):
yield Path(root) / name
def trusted_read_text(path: Path, encoding: str = "utf-8", errors: str | None = None) -> str:
full_path = _safe_path_string(path)
with open(full_path, encoding=encoding, errors=errors) as file:
return file.read()