globToRegex 将 glob 模式转换为正则表达式
(glob string)
| 317 | |
| 318 | // globToRegex 将 glob 模式转换为正则表达式 |
| 319 | func globToRegex(glob string) string { |
| 320 | // 简单实现,支持基本的 glob 语法 |
| 321 | pattern := regexp.QuoteMeta(glob) |
| 322 | // 先处理 ** (匹配任意路径) |
| 323 | pattern = strings.ReplaceAll(pattern, "\\*\\*", ".*") |
| 324 | // 再处理 * (匹配单层路径) |
| 325 | pattern = strings.ReplaceAll(pattern, "\\*", "[^/]*") |
| 326 | // 处理 ? (匹配单个字符) |
| 327 | pattern = strings.ReplaceAll(pattern, "\\?", ".") |
| 328 | // 注意:不要求必须从头匹配,允许部分匹配 |
| 329 | return pattern |
| 330 | } |
| 331 | |
| 332 | // GetFiles 获取所有文件数据 (用于调试) |
| 333 | func (b *StateBackend) GetFiles() map[string]*FileData { |