Documentation
¶
Overview ¶
Package remotecanon 提供与远端 SFTP/POSIX 路径相关的纯无状态规范化、作用域漂移复核、 INV-B4 单次上传容器展开与有界读取原语,供 core/internal/usecase/transfer 复用(ADR-016 / INV-B4 / INV-E5)。
Index ¶
- func HashRemoteStage(ctx context.Context, rfs ports.RemoteFSPort, ...) (security.Digest, error)
- func InspectUploadTarget(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath) (exists, isDir bool, err error)
- func JoinRemoteBase(dir pathalg.RemotePath, base string, invalidErr error) (pathalg.RemotePath, error)
- func ReadBoundedFile(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, ...) (st ports.RemoteFileStat, data []byte, dig security.Digest, err error)
- func ReadChunkExact(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, ...) ([]byte, error)
- func ResolveCanonicalList(ctx context.Context, rfs ports.RemoteFSPort, rpaths []pathalg.RemotePath, ...) ([]string, error)
- func ResolveCanonicalPath(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, s Sentinels) (pathalg.RemotePath, error)
- func ResolveUploadTarget(ctx context.Context, rfs ports.RemoteFSPort, dest pathalg.RemotePath, ...) (pathalg.RemotePath, error)
- func VerifyDownloadSource(ctx context.Context, enforce bool, rfs ports.RemoteFSPort, ...) error
- func VerifyPathAuthorized(ctx context.Context, enforce bool, rfs ports.RemoteFSPort, ...) error
- type Sentinels
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HashRemoteStage ¶
func HashRemoteStage(ctx context.Context, rfs ports.RemoteFSPort, stageOpt algebraic.Option[pathalg.RemotePath], totalBytes uint64, chunkSize int64, invalidErr error) (security.Digest, error)
HashRemoteStage 经 SFTP 分片顺序回读远端暂存文件并计算完整 SHA-256 摘要,校验文件类型与预期总字节数。
func InspectUploadTarget ¶
func InspectUploadTarget(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath) (exists, isDir bool, err error)
InspectUploadTarget 经 Lstat 与必要时 Stat 识别远端目标存在性(含悬空软链)及是否为目录。
func JoinRemoteBase ¶
func JoinRemoteBase(dir pathalg.RemotePath, base string, invalidErr error) (pathalg.RemotePath, error)
JoinRemoteBase 校验并拼接单个远端文件名至目录路径(严禁引入 path/filepath)。
func ReadBoundedFile ¶
func ReadBoundedFile(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, limits ports.ReadLimits) (st ports.RemoteFileStat, data []byte, dig security.Digest, err error)
ReadBoundedFile 执行有界读取并在读写前后复核远端 Stat 锚点、大小与修改时间,防止并发篡改。
func ReadChunkExact ¶
func ReadChunkExact(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, offset, want int64) ([]byte, error)
ReadChunkExact 从远端文件偏移处精确读取 want 字节,读短即返回 io.ErrUnexpectedEOF。
func ResolveCanonicalList ¶
func ResolveCanonicalList(ctx context.Context, rfs ports.RemoteFSPort, rpaths []pathalg.RemotePath, expandBase string, extra []string, s Sentinels) ([]string, error)
ResolveCanonicalList 展开目标列表对应的远端真实 POSIX 路径及可选单次容器展开候选,用于 Gate Round-2 规范化。
func ResolveCanonicalPath ¶
func ResolveCanonicalPath(ctx context.Context, rfs ports.RemoteFSPort, p pathalg.RemotePath, s Sentinels) (pathalg.RemotePath, error)
ResolveCanonicalPath 在有界跳数预算(pathalg.MaxSymlinkHops)内解析远端真实 POSIX 路径: 先经 RealPath(".") 锚定相对路径,再在统一祖先回溯循环中逐级展开末端及中间悬空软链(零本地路径库依赖)。
func ResolveUploadTarget ¶
func ResolveUploadTarget(ctx context.Context, rfs ports.RemoteFSPort, dest pathalg.RemotePath, sourceBase string, expandIntoDir, noClobber, wantDir bool, invalidErr error) (pathalg.RemotePath, error)
ResolveUploadTarget 严守 INV-B4:至多一次远端容器目录展开,经 Lstat 识别悬空软链与目录/文件类型冲突。
func VerifyDownloadSource ¶
func VerifyDownloadSource(ctx context.Context, enforce bool, rfs ports.RemoteFSPort, binding security.OperationBinding, rs pathalg.RemotePath, expAnchor ports.RemoteFileAnchor, expSize int64, expModTime time.Time, s Sentinels) error
VerifyDownloadSource 复核远端下载源未发生软链漂移且 Lstat 锚点/大小/修改时间与起始快照完全一致。
func VerifyPathAuthorized ¶
func VerifyPathAuthorized(ctx context.Context, enforce bool, rfs ports.RemoteFSPort, binding security.OperationBinding, target pathalg.RemotePath, s Sentinels) error
VerifyPathAuthorized 在非 DirectOperator 配置档下复核远端目标真实路径未漂移出授权 CanonicalPaths/RecursivePaths。