-
-
Notifications
You must be signed in to change notification settings - Fork 720
Open
Description
Windows 平台认证文件重复显示修复总结
1. 问题描述
在 Windows 平台上,文件系统对路径大小写不敏感(例如 Auths\file.json 和 auths\File.json 指向同一文件),但程序内部使用字符串路径作为唯一标识符(ID)且大小写敏感。
这导致:
Watcher自动扫描时使用系统返回的路径格式生成 ID。- 管理 API 或其他手动加载流程可能使用不同大小写的路径生成 ID。
- 结果导致同一个物理文件在内存中被注册为两个不同的认证条目,从而在管理页面和配额页面重复显示。
2. 修复方案
在生成认证 ID 的关键路径上,针对 Windows 平台强制进行路径规范化(统一转换为小写)。
3. 修改文件列表
3.1. internal/watcher/synthesizer/file.go
作用:负责扫描磁盘上的认证文件并生成内存对象。
修改内容:
在 Synthesize 方法中,计算出相对路径 ID 后,增加 Windows 平台检测并转为小写。
// 引入 runtime 包
import "runtime"
// ... 在 Synthesize 方法中 ...
// Use relative path under authDir as ID to stay consistent with the file-based token store
id := full
if rel, errRel := filepath.Rel(ctx.AuthDir, full); errRel == nil && rel != "" {
id = rel
}
// [新增] Windows 平台下强制转为小写,确保 ID 一致性
if runtime.GOOS == "windows" {
id = strings.ToLower(id)
}3.2. internal/api/handlers/management/auth_files.go
作用:处理管理 API 请求,包括手动上传、注册认证文件。
修改内容:
在 authIDForPath 辅助方法中,增加 Windows 平台检测并转为小写。
// 引入 runtime 包
import "runtime"
// ...
func (h *Handler) authIDForPath(path string) string {
// ... (前置逻辑)
if rel, err := filepath.Rel(authDir, path); err == nil && rel != "" {
// [新增]
if runtime.GOOS == "windows" {
return strings.ToLower(rel)
}
return rel
}
// [新增]
if runtime.GOOS == "windows" {
return strings.ToLower(path)
}
return path
}Metadata
Metadata
Assignees
Labels
No labels