GlobInfo 实现 BackendProtocol.GlobInfo
(ctx context.Context, pattern, path string)
| 215 | |
| 216 | // GlobInfo 实现 BackendProtocol.GlobInfo |
| 217 | func (b *FilesystemBackend) GlobInfo(ctx context.Context, pattern, path string) ([]FileInfo, error) { |
| 218 | if path == "" { |
| 219 | path = "." |
| 220 | } |
| 221 | |
| 222 | // 使用 SandboxFS 的 Glob 功能 |
| 223 | searchPattern := filepath.Join(path, pattern) |
| 224 | files, err := b.fs.Glob(ctx, searchPattern, &sandbox.GlobOptions{ |
| 225 | Dot: true, |
| 226 | }) |
| 227 | if err != nil { |
| 228 | return nil, fmt.Errorf("glob files: %w", err) |
| 229 | } |
| 230 | |
| 231 | var results []FileInfo |
| 232 | for _, filePath := range files { |
| 233 | stat, err := b.fs.Stat(ctx, filePath) |
| 234 | if err != nil { |
| 235 | continue |
| 236 | } |
| 237 | |
| 238 | results = append(results, FileInfo{ |
| 239 | Path: filePath, |
| 240 | IsDirectory: stat.IsDir, |
| 241 | Size: stat.Size, |
| 242 | ModifiedTime: stat.ModTime, |
| 243 | CreatedTime: stat.ModTime, |
| 244 | }) |
| 245 | } |
| 246 | |
| 247 | return results, nil |
| 248 | } |