d93c518a14
Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1023 B
Python
34 lines
1023 B
Python
"""Validation helpers for remote absolute paths (SSH file operations)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from server.utils.posix_paths import (
|
|
PosixPathError,
|
|
normalize_remote_abs_path,
|
|
normalize_remote_dest,
|
|
remote_join,
|
|
)
|
|
|
|
# Backward-compatible alias used by API layers
|
|
RemotePathError = PosixPathError
|
|
|
|
__all__ = [
|
|
"RemotePathError",
|
|
"normalize_remote_abs_path",
|
|
"normalize_remote_dest",
|
|
"remote_join",
|
|
"assert_clipboard_transfer_safe",
|
|
]
|
|
|
|
|
|
def assert_clipboard_transfer_safe(sources: list[str], dest_dir: str) -> tuple[list[str], str]:
|
|
"""Return normalized sources and dest_dir; raise RemotePathError if unsafe."""
|
|
dest = normalize_remote_abs_path(dest_dir)
|
|
normalized: list[str] = []
|
|
for raw in sources:
|
|
src = normalize_remote_abs_path(raw)
|
|
if dest == src or dest.startswith(src + "/"):
|
|
raise RemotePathError(f"目标目录不能是源路径自身或其子目录: {src}")
|
|
normalized.append(src)
|
|
return normalized, dest
|