Repository navigation
Commit 5a9dad3
Fastace
fix(cloud): 云端仓库初始化统一前置校验,WebDAV 端口改为独立输入
一、现象与核对
用户反馈:新建 SMB 账户(威联通 NAS 192.168.10.10),userA 在根目录只有列共享
权限、folderA 才有写权限。URL 栏填 192.168.10.10 时「测试连接」成功,初始化
云端仓库却报「init 报成功但仓库 config 未写入 SMB(疑似 rclone serve /认证失败)」;
URL 栏填 192.168.10.10/folderA 时「测试连接」直接失败。
横向核对 8 种云账户页(FTP / SFTP / SMB / WebDAV / S3 / AWS S3 / Aliyun OSS /
Huawei OBS)与 8 个云端 Restic 后端后确认:这不是权限误判,而是「URL 只承载
主机、目标目录必须由 高级 → 远程路径 单独选择」这一既有设计缺少校验与提示。
上述现象为用户反馈;本次修改完成后已由用户实机测试,确认符合预期。
二、根因
1. URL 输入框的 smb:// / ftp:// / sftp:// 只是 OutlinedTextField 的 prefix 装饰,
不进入值;IndexViewModel.UpdateEntity 原样 host = intent.url。所有连接串拼接
只做 removePrefix(scheme) + removeSuffix("/"),不解析路径,故把 /folderA 写进
URL 栏会整段塞进 rclone 的 host 参数,newConnection 拼出
192.168.10.10/folderA:445 后拨号失败。
2. 测试连接只做只读列举:IndexViewModel.TestConnection 对所有协议统一
skipRemoteCheck = true,各 testConnection() 分别是 remote=""(SMB/FTP)、
remote="."(SFTP)、opendalList("/")(WebDAV / 对象存储),既不验证写权限,
也不要求 remote 已选择。CloudRepository.withClient 里已有的
entity.remote.isEmpty() 校验被初始化链路(ResticRepository* → RcloneServe /
opendal → rcloneRpc)完全绕过。
3. 空 remote 时各后端行为不一致:formatSftpRoot("") = "",rclone SMB 后端把空
root 当成 share 枚举层(NewFs 直接返回、Mkdir 空 share 静默 return nil、
Object.Update 因 filename 为空返回 fs.ErrorIsDir),config 根本无处落地;
FTP/SFTP 会静默把仓库建到登录家目录,WebDAV / 对象存储经
formatOpenDALRoot("") = "/" 建到根。因此 SMB 必然触发那条误导性的兜底文案
(共 4 份:SMB / FTP / SFTP / WebDAV),把用户引向「认证失败」的猜测。
4. 校验缺口:8 个「继续」按钮都带 remote.isNotEmpty(),但 8 个「初始化状态」
Clickable 全部不校验、8 个「初始化」按钮仅 SFTP 校验;8 个
XxxResticViewModel.initializeXxxRepository 内部也没有 remotePath 守卫。
即 16 个初始化入口里 15 个可以在未选远程路径时发起建库。
5. 选完远程路径后 remote = uiState.cloudEntity!!.remote 读的是 Compose 捕获的
旧状态快照(甚至可能为 null),会把刚选中的路径写回空值,新增校验会被卡住。
6. WebDAV 配置页把「地址 + 端口」塞在同一个 URL 栏:updateWebDAVEntity 用
$scheme://$cleanHost 直接落库;WebDAVCertUtil.verifyPublicCa 本来就有
port: Int = 443,调用处却从不传,非标准 HTTPS 端口永远去连 443。
三、修复
1. 新增 core/restic/ResticPreflight.kt:集中 remotePath 非空校验、纯主机校验
(仅 FTP/SFTP/SMB,大小写敏感剥离 scheme,与各后端 removePrefix 对齐),
以及 config 复核兜底文案。core/common 的 values / values-zh-rCN 新增 4 个
双语字符串:restic_remote_path_required、restic_host_only、
restic_config_missing_hint、connection_established_no_remote。
2. 8 个云端后端建库入口统一接入 ResticPreflight.checkInit:SMB/FTP/SFTP/WebDAV
的 initXxxRepository 与 COS/AWS S3/Aliyun OSS/Huawei OBS 的 initRepository;
前 4 个 override 都委托到旧名方法,8 处即覆盖全部入口。4 条「init 报成功但
仓库 config 未写入 XXX(疑似 rclone serve/认证失败)」改为同一条可操作提示
「未检测到仓库 config:请确认远程路径指向的目录可写…」。
3. UI 全协议对齐:7 个初始化按钮补齐 remote.isNotEmpty()(对齐唯一已有的
SFTP),8 个初始化状态 Clickable 补齐;8 个「高级 → 远程路径」在未选时
显示明确提示文案;8 处 remote 回填改读 viewModel.uiState.value,修掉
旧快照 / NPE 隐患。
4. 测试连接统一加 host 校验(ResticPreflight.hostError,禁止把路径或大写
scheme 写进 URL 栏),并在未选 remote 时把成功 toast 改为「连接成功(仅验证
列目录)。初始化仓库前请先选择远程路径」。
5. WebDAV 端口拆分:IndexViewModel 新增 splitWebdavEndpoint /
buildWebdavEndpoint(端口插在 authority 之后、路径之前,兼容 nas/dav 子路径
与 [::1]:8080;非法或越界端口回落协议默认值),updateWebDAVEntity 增
port: String = ""。WebDAVSetup 新增独立端口输入框(Number 键盘、
R.string.port)、默认 HTTPS=443 / HTTP=80、切协议时仅在当前端口为默认值时
联动、编辑旧账户时从完整 host 拆出地址与端口。测试连接的证书预校验按新端口
握手;测试连接 / 远程路径 / 继续 / 两处初始化共 5 个入口统一走
buildWebdavEndpoint,保证建库 host 与落库 host 完全一致。
四、验证
- 真机复测:用户已实机测试,确认本次修改符合预期。
- 编译::core:common:processDebugResources、:core:restic:compileDebugKotlin、
:feature:main:cloud:compileDebugKotlin / processDebugResources、
:app:compileArm64-v8aFossDebugKotlin --offline 全部 BUILD SUCCESSFUL。
- lint::core:common:lintDebug、:feature:main:cloud:lintDebug 在线执行
BUILD SUCCESSFUL,新增双语字符串无 MissingTranslation;read_lints 0 诊断。
- git diff --check 干净;提交统计 20 files +237 -80(19 个修改 +
新增 ResticPreflight.kt 60 行);ResticPreflight.class 实际产出。
- 计数核对:8 个 checkInit、4 条 configMissingMessage、每个 Setup 3 处
remote.isNotEmpty()(共 24)、8 处状态同步;边界行为
192.168.10.10:8080 → host+8080、nas.example.com/dav → 无端口保留路径、
[::1]:8080 → IPv6 正确、纯主机 → 无端口。
- 签名变更:新增 2 个 helper;updateWebDAVEntity 仅新增带默认值的 port 参数
(全仓 3 个调用点均为命名参数,文本搜索确认),其余零签名变更。
- 门禁:impact CloudResticBackend.initRepository = MEDIUM(12 impacted)、
initSmbRepository = LOW(2 direct)、PageWebDAVSetup = LOW(1 direct);
TestConnection 与 updateWebDAVEntity 报 UNKNOWN,已用文本搜索补证
8 处 emitIntent(TestConnection) 与 3 处 updateWebDAVEntity 调用。
detect_changes scope=all = 19 files / 37 symbols / 6 processes / risk high,
来自 IndexViewModel.onEvent 中枢符号,6 个执行流均为 OnEvent → …,无无关
模块扩散,判为中枢符号虚报,按源码与全量编译放行。
- 索引:提交前已用 analyze --force --pdg 将索引对齐到当时的 HEAD 43bb2b3
(本次提交的父提交),status up-to-date
(268,282 nodes / 708,614 edges / 1872 clusters / 825 flows),
check --cycles = cycleCount 104 / componentCount 10,与历史基线一致;
MCP 响应仍带 staleness behind 属进程缓存旧元数据,以 CLI status 为准。
五、有意不改的部分
- 测试连接写探针(mkdir + delete)未实现:SMB/FTP/SFTP 的
removeDirectory / deleteRecursively 均抛 UnsupportedOperationException,
需要新增 rclone RPC 路径,风险大于收益;改为 toast 明确标注仅验证列目录。
- URL 字段语义不变:仍只填主机 / endpoint,不自动把 host/folderA 拆成两段,
避免误伤 WebDAV 与对象存储的路径语义。
- WebDAV 端口不写进 WebDAVExtra:host 始终保存完整 endpoint,避免旧配置
反序列化兼容问题与 core/network、core/restic 的跨模块改动。
- SFTP/FTP 的 remote 仍为登录家目录相对路径(无法表达绝对路径),
SMBExtra.share 仍只是元数据不参与连接串,均未动。1 parent 43bb2b3 commit 5a9dad3
20 files changed
Lines changed: 237 additions & 80 deletions
File tree
- source
- core
- common/src/main/res
- values-zh-rCN
- values
- restic/src/main/kotlin/com/xayah/core/restic
- feature/main/cloud/src/main/kotlin/com/xayah/feature/main/cloud/add
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | | - | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
0 commit comments