filesystem

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package filesystem 提供受管根目录内经过安全校验的文件操作。

Index

Constants

View Source
const MaxRuntimeLogBytes int64 = 128 << 20

MaxRuntimeLogBytes 限制单文件容量;拒绝整条追加,不截断已记录内容。

View Source
const MaxStateFileBytes int64 = 256 * 1024

MaxStateFileBytes 是受管状态文件默认允许的最大字节数。

Variables

View Source
var (
	ErrInvalidArgument            = errors.New("filesystem argument is invalid")
	ErrClosed                     = errors.New("filesystem capability is closed")
	ErrInvalidToken               = errors.New("filesystem token is invalid")
	ErrIdentityChanged            = errors.New("filesystem object identity changed")
	ErrDestinationExists          = errors.New("filesystem destination exists")
	ErrUnsafeHardLink             = errors.New("filesystem hard link is unsafe")
	ErrStateFileNotFound          = errors.New("state file not found")
	ErrStateFileTooLarge          = errors.New("state file exceeds size limit")
	ErrStateRecoveryRequired      = errors.New("state file recovery is required")
	ErrPOSIXUnlinkUnsupported     = errors.New("filesystem POSIX unlink is unsupported")
	ErrUnsupportedCaseSensitivity = errors.New("filesystem case-sensitive directory is unsupported")
)
View Source
var (
	// ErrExternalPathUnsafe 表示路径链包含无法安全证明的重解析点。
	ErrExternalPathUnsafe = errors.New("external path identity is unsafe")
	// ErrExternalPathNotOrdinary 表示叶子类型与调用方要求不符。
	ErrExternalPathNotOrdinary = errors.New("external path is not ordinary")
)
View Source
var ErrRuntimeLogCapacity = errors.New("runtime log file capacity exceeded")

ErrRuntimeLogCapacity 表示下一次完整追加会超过日志文件容量。

View Source
var ErrStateGuardTimeout = errors.New("state guard wait budget exceeded")

ErrStateGuardTimeout 表示状态守卫在独立获取预算内一直被占用。

Functions

func FileSystemName added in v0.1.24

func FileSystemName(ctx context.Context, _ string) (string, error)

FileSystemName 在尚未实现卷探测的平台返回不支持。

func PathContains

func PathContains(ctx context.Context, parent, child string) (bool, error)

PathContains 以规范化身份判断 child 是否等于 parent 或位于其后代, 同时拒绝无法证明身份的重解析点与别名路径。

func ReadManagedFile added in v0.1.23

func ReadManagedFile(context.Context, *config.Layout, string, int64) ([]byte, error)

ReadManagedFile 在尚未实现固定路径语义的平台失败关闭。

func ReplaceManagedFile added in v0.1.23

func ReplaceManagedFile(context.Context, *config.Layout, string, []byte) error

ReplaceManagedFile 在尚未实现固定路径语义的平台失败关闭。

Types

type AbortResult

type AbortResult struct {
	Removed bool
}

AbortResult 报告下载临时文件是否已经移除。

type AuditError

type AuditError struct {
	Phase           DeleteAuditPhase
	MutationApplied bool
	Cause           error
}

AuditError 报告审计阶段及副作用是否已经发生。

func (*AuditError) Error

func (e *AuditError) Error() string

func (*AuditError) Unwrap

func (e *AuditError) Unwrap() error

type Auditor

type Auditor interface {
	RecordDeletion(ctx context.Context, record DeleteAuditRecord) error
}

Auditor 记录受控删除的双阶段审计事件。

type DeleteAuditPhase

type DeleteAuditPhase string

DeleteAuditPhase 标识删除审计的阶段。

const (
	DeleteAuditStarted  DeleteAuditPhase = "started"
	DeleteAuditFinished DeleteAuditPhase = "finished"
)

func (DeleteAuditPhase) String

func (p DeleteAuditPhase) String() string

func (DeleteAuditPhase) Valid

func (p DeleteAuditPhase) Valid() bool

type DeleteAuditRecord

type DeleteAuditRecord struct {
	Phase       DeleteAuditPhase
	OperationID string
	Kind        DeleteKind
	Target      string
	Reason      string
	Removed     bool
	Partial     bool
	Result      string
}

DeleteAuditRecord 保存一次删除审计事件的稳定字段。

type DeleteKind

type DeleteKind string

DeleteKind 限制受控删除可接受的目标类别。

const (
	DeleteUVCache           DeleteKind = "uv_cache"
	DeleteUVVersion         DeleteKind = "uv_version"
	DeleteManagedVenv       DeleteKind = "managed_venv"
	DeleteManagedPython     DeleteKind = "managed_python"
	DeleteRepositoryUpdate  DeleteKind = "repository_update"
	DeleteRepositoryRetired DeleteKind = "repository_retired"
	DeleteDownloadTemporary DeleteKind = "download_temporary"
	DeleteUVStaging         DeleteKind = "uv_staging"
	DeletePythonCache       DeleteKind = "python_cache"
	DeleteBuildCache        DeleteKind = "build_cache"
	DeleteDependencySync    DeleteKind = "dependency_sync"
)

func (DeleteKind) String

func (k DeleteKind) String() string

func (DeleteKind) Valid

func (k DeleteKind) Valid() bool

type DeleteRequest

type DeleteRequest struct {
	Kind        DeleteKind
	Target      string
	OperationID string
	Version     string
	Reason      string
	// ExpectedIdentity 可选地约束删除目标必须仍是分类时的同一目录叶子。
	ExpectedIdentity *DirectoryIdentity
}

DeleteRequest 描述一次受控递归删除请求。

type DeleteResult

type DeleteResult struct {
	Removed        bool
	Partial        bool
	AuditCompleted bool
}

DeleteResult 报告删除副作用与审计收口事实。

type DirectoryIdentity

type DirectoryIdentity struct {
	// contains filtered or unexported fields
}

DirectoryIdentity 是受管目录叶子的不可变 volume/file-ID token。

字段保持包内不可变,调用方只能保存并回传由 InspectManagedDirectory 取得的 token。

func (*DirectoryIdentity) Equal

func (i *DirectoryIdentity) Equal(other *DirectoryIdentity) bool

Equal 比较两个目录 token 的稳定对象身份。

其他属性可能因目录内容变化而改变,目录身份只由 volume serial 与 file ID 决定。

type DirectoryLease

type DirectoryLease struct {
	// contains filtered or unexported fields
}

DirectoryLease 固定一个受管目录及其祖先句柄,防止操作期间路径身份被替换。

func EnsureManagedDirectory added in v0.1.21

func EnsureManagedDirectory(ctx context.Context, layout *config.Layout, path string) (*DirectoryLease, error)

EnsureManagedDirectory 逐层固定已有目录并创建缺失子目录,最终租约覆盖全部祖先。 安装根必须已存在;不沿未知 Reparse 链创建目录。

func OpenManagedDirectory

func OpenManagedDirectory(
	ctx context.Context,
	layout *config.Layout,
	path string,
) (*DirectoryLease, error)

OpenManagedDirectory 打开并固定一个已经存在的受管目录。

返回的租约同时持有目标及其祖先句柄,调用方必须在所有基于该目录的 路径读取完成后关闭租约。目标不存在、不是普通目录或身份无法证明时 返回错误,且不会创建任何目录。

func PinManagedDirectory

func PinManagedDirectory(
	ctx context.Context,
	layout *config.Layout,
	path string,
) (*DirectoryLease, error)

PinManagedDirectory 是 OpenManagedDirectory 的语义别名,强调租约在读取期间 固定目录身份并阻止同用户通过重命名替换目录叶子。

func PrepareManagedDirectory

func PrepareManagedDirectory(
	ctx context.Context,
	layout *config.Layout,
	path string,
) (*DirectoryLease, error)

PrepareManagedDirectory 在受管根内原子准备一个新的目录租约。

目标必须不存在;调用方应在所有基于该目录的 I/O 完成后关闭租约。

func (*DirectoryLease) Close

func (l *DirectoryLease) Close() error

Close 释放租约持有的所有句柄;重复关闭是幂等的。

func (*DirectoryLease) Identity

func (l *DirectoryLease) Identity() *DirectoryIdentity

Identity 返回租约创建时固定的目录叶子身份 token。

func (*DirectoryLease) Path

func (l *DirectoryLease) Path() string

Path 返回租约保护的目录路径。

type DownloadFiles

type DownloadFiles struct {
	// contains filtered or unexported fields
}

DownloadFiles 表示受管下载目录能力。

type DownloadSession

type DownloadSession struct {
	// contains filtered or unexported fields
}

DownloadSession 表示绑定到单个临时文件句柄的下载会话。

type Error

type Error struct {
	Operation string
	Path      string
	Err       error
	// contains filtered or unexported fields
}

Error 携带可映射到协议层的文件系统错误码。

func (*Error) Code

func (e *Error) Code() protocol.Code

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ExternalPathInspection

type ExternalPathInspection struct {
	Exists bool
}

ExternalPathInspection 是开发模式对 app-root 外路径的只读身份事实。

func InspectExternalPath

func InspectExternalPath(ctx context.Context, path string, wantDirectory bool) (ExternalPathInspection, error)

InspectExternalPath 以句柄约束(Windows)或等价只读身份检查(其他平台) 验证路径链,绝不创建或改写目标。不存在的叶子返回 Exists=false。

type FileError

type FileError struct {
	Operation string
	Path      string
	Err       error
}

FileError 为单个文件系统操作补充操作名和路径上下文。

func (*FileError) Error

func (e *FileError) Error() string

func (*FileError) Unwrap

func (e *FileError) Unwrap() error

type FileInspection

type FileInspection struct {
	Exists bool
}

FileInspection 描述受管普通文件的只读存在性事实。

func InspectManagedFile

func InspectManagedFile(
	ctx context.Context,
	layout *config.Layout,
	path string,
) (FileInspection, error)

InspectManagedFile 校验文件路径链不含重解析点,并确认叶子是普通文件。

该能力只读且不会创建文件;不存在的末端返回 Exists=false。任何身份、 路径边界或文件类型无法证明的情况都返回错误,调用方必须失败关闭。

type Operator

type Operator struct {
	// contains filtered or unexported fields
}

Operator 执行受管删除与原子重命名操作。

type Option

type Option func(*options) error

Option 配置 Operator 的可注入等待策略。

func WithRenameDelays

func WithRenameDelays(delays ...time.Duration) Option

WithRenameDelays 配置有限重试的等待序列。

func WithWait

func WithWait(wait WaitFunc) Option

WithWait 注入可取消的有限重试等待实现。

type PublishResult

type PublishResult struct {
	Published bool
}

PublishResult 报告 no-replace 发布是否已经生效。

type RemoveResult

type RemoveResult struct {
	MutationApplied bool
}

RemoveResult 报告日志删除副作用是否已经发生。

type RenameKind

type RenameKind string

RenameKind 限制原子重命名可接受的迁移类别。

const (
	RenameRepositoryToRetired RenameKind = "repository_to_retired"
	RenameUpdateToRepository  RenameKind = "update_to_repository"
	RenameRepositoryRollback  RenameKind = "repository_rollback"
	RenameUVStagingToVersion  RenameKind = "uv_staging_to_version"
)

func (RenameKind) String

func (k RenameKind) String() string

func (RenameKind) Valid

func (k RenameKind) Valid() bool

type RenameRequest

type RenameRequest struct {
	Kind        RenameKind
	Source      string
	Destination string
	OperationID string
	Version     string
	Reason      string
	// ExpectedSourceIdentity 可选地约束源目录必须仍是分类时的同一目录叶子。
	ExpectedSourceIdentity *DirectoryIdentity
}

RenameRequest 描述一次受控原子重命名请求。

type RenameResult

type RenameResult struct {
	MutationApplied bool
}

RenameResult 报告重命名副作用是否已经生效。

type RuntimeLogFile

type RuntimeLogFile struct {
	// contains filtered or unexported fields
}

RuntimeLogFile 表示只能由所属目录能力消费的日志文件令牌。

func (RuntimeLogFile) Name

func (f RuntimeLogFile) Name() string

Name 返回仅供诊断的日志文件名。

func (RuntimeLogFile) Path

func (f RuntimeLogFile) Path() string

Path 返回仅供诊断的日志文件绝对路径。

type RuntimeLogFiles

type RuntimeLogFiles struct {
	// contains filtered or unexported fields
}

RuntimeLogFiles 表示受管 Runtime 日志目录能力。

type RuntimeLogWriter

type RuntimeLogWriter struct {
	// contains filtered or unexported fields
}

RuntimeLogWriter 表示绑定到已验证日志文件的写入能力。

type StateFileKind

type StateFileKind string

StateFileKind 标识受管状态文件类别。

const (
	StateBackend     StateFileKind = "backend"
	StateMutation    StateFileKind = "mutation"
	StateUpdate      StateFileKind = "update"
	StateEnvironment StateFileKind = "environment"
)

func (StateFileKind) String

func (k StateFileKind) String() string

func (StateFileKind) Valid

func (k StateFileKind) Valid() bool

type StateFileSnapshot

type StateFileSnapshot struct {
	// contains filtered or unexported fields
}

StateFileSnapshot 绑定读取内容与其物理文件身份。

func (StateFileSnapshot) Bytes

func (s StateFileSnapshot) Bytes() []byte

Bytes 返回 snapshot payload 的防御性副本。

func (StateFileSnapshot) Kind

Kind 返回 snapshot 对应的封闭状态文件类别。

type StateFiles

type StateFiles struct {
	// contains filtered or unexported fields
}

StateFiles 表示受管状态目录能力。

type StateRemoveError

type StateRemoveError struct {
	Cause        error
	CleanupError error
}

StateRemoveError 分离条件删除的主因和独立清理错误。

func (*StateRemoveError) Error

func (e *StateRemoveError) Error() string

func (*StateRemoveError) Unwrap

func (e *StateRemoveError) Unwrap() []error

type StateRemoveResult

type StateRemoveResult struct {
	MutationApplied  bool
	RecoveryRequired bool
}

StateRemoveResult 报告条件删除的副作用与恢复事实。

type StateWriteError

type StateWriteError struct {
	Phase            StateWritePhase
	MutationApplied  bool
	RecoveryRequired bool
	Cause            error
	CleanupError     error
}

StateWriteError 保存写入阶段、主因和独立清理错误。

func (*StateWriteError) Error

func (e *StateWriteError) Error() string

func (*StateWriteError) Unwrap

func (e *StateWriteError) Unwrap() []error

type StateWritePhase

type StateWritePhase string

StateWritePhase 标识原子状态写入失败发生的阶段。

const (
	StateWritePhaseRecover  StateWritePhase = "recover"
	StateWritePhaseCreate   StateWritePhase = "create"
	StateWritePhaseWrite    StateWritePhase = "write"
	StateWritePhaseSync     StateWritePhase = "sync"
	StateWritePhaseRename   StateWritePhase = "rename"
	StateWritePhaseFinalize StateWritePhase = "finalize"
	StateWritePhaseClose    StateWritePhase = "close"
)

func (StateWritePhase) String

func (p StateWritePhase) String() string

func (StateWritePhase) Valid

func (p StateWritePhase) Valid() bool

type VenvReport added in v0.1.5

type VenvReport struct {
	// Intact 表示 venv 具备启动所需的最小结构。
	Intact bool
	// Missing 按检查顺序列出缺失或类型不对的路径,Intact 为 true 时为空。
	Missing []string
}

VenvReport 是受管项目虚拟环境的结构完整性快照。

func InspectVenv added in v0.1.5

func InspectVenv(layout *config.Layout) VenvReport

InspectVenv 报告受管项目虚拟环境是否结构完整。

只做结构判断,不执行解释器:判据是 pyvenv.cfg 与 venv 内 python.exe 两个普通文件 同时存在。真机上出现过「目录还在、python.exe 还在,只有 pyvenv.cfg 被删掉」的残骸 ——一次撞上后端进程未退尽的 venv 重建会删掉未被占用的文件、在被锁住的 python.exe 上 失败退出。此时 CPython 算不出 home,一启动就以 `No pyvenv.cfg file` 退出,而只查 目录是否存在的判据完全看不出问题,环境会被当成就绪一路交给后端启动。

type WaitFunc

type WaitFunc func(ctx context.Context, delay time.Duration) error

WaitFunc 为有限重试提供可取消的等待实现。

type WriteAtomicResult

type WriteAtomicResult struct {
	MutationApplied  bool
	RecoveryRequired bool
}

WriteAtomicResult 报告原子写入的副作用与恢复事实。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL