Appearance
Go 文件与路径平台抽象
系统概览
跨平台文件访问与路径管理抽象(fileaccess*.go + pathmgr*.go)。FileAccessor 接口统一桌面(os.*)与安卓(shared 模式 os.ReadDir 直读 /sdcard)的文件 IO;PathManager 抽象配置/缓存目录位置。安卓 SAF 相关细节与能力矩阵见 android-file-access 卡。
核心职责
fileaccess.go—FileAccessor接口 +isContentUri判定 + 应用层ReadTextFile/WriteTextFile/ReadFileBytes/ListDir*/FileExists。fileaccess_desktop.go— os.* 实现(桌面)。fileaccess_android.go— 安卓实现;content://直接返回ErrContentUriNotSupported。pathmgr.go+pathmgr_desktop.go/pathmgr_android.go—PathManager平台路径(UserConfigDir/UserCacheDir / 私有目录)。
对外 API(节选)
ReadTextFile(path)/WriteTextFile(path, content)/ReadFileBytes(path)— 文件读写绑定。ListDirRecursive(dir)— 递归列目录(返回 FileInfo 列表)。FileExists(path)— 存在性判断。
与其他子系统关系
- 被
go-app.md(配置读写)、go-watch.md、go-library.md统一调用。 - 前端契约对齐:
core-backend.md的readFileBytes与 GoReadFileBytesbase64 编解码。 - 安卓 shared/SAF 决策见 android-file-access.md(ADR-017/180/183)。
前端接入入口
- 后端适配层:
frontend/src/core/backend/go-adapter.ts的能力矩阵(fsSelectDir等)。
不变量
- 新增平台文件操作必须落在
FileAccessor实现内,禁止在业务文件散落 os.* 分支。 - 安卓禁止引入
content://依赖(后端ErrContentUriNotSupported兜底)。 - 前端能力矩阵(
go-adapter.ts)是平台能力唯一真相源,与后端实现双向核对。
验证入口
- 测试:
internal/app/fs_test.go。 - 命令:
go test ./internal/app/ -run "Fs|File"。