MCPcopy Create free account
hub / github.com/astercloud/aster / ListInfo

Method ListInfo

pkg/backends/filesystem.go:29–65  ·  view source on GitHub ↗

ListInfo 实现 BackendProtocol.ListInfo

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

27
28// ListInfo 实现 BackendProtocol.ListInfo
29func (b *FilesystemBackend) ListInfo(ctx context.Context, path string) ([]FileInfo, error) {
30 if path == "" {
31 path = "."
32 }
33
34 // 解析为绝对路径
35 absPath := b.fs.Resolve(path)
36
37 // 检查路径是否在沙箱内
38 if !b.fs.IsInside(absPath) {
39 return nil, fmt.Errorf("path outside sandbox: %s", path)
40 }
41
42 // 读取目录
43 entries, err := os.ReadDir(absPath)
44 if err != nil {
45 return nil, fmt.Errorf("read dir: %w", err)
46 }
47
48 var results []FileInfo
49 for _, entry := range entries {
50 info, err := entry.Info()
51 if err != nil {
52 continue
53 }
54
55 results = append(results, FileInfo{
56 Path: filepath.Join(path, entry.Name()),
57 IsDirectory: entry.IsDir(),
58 Size: info.Size(),
59 ModifiedTime: info.ModTime(),
60 CreatedTime: info.ModTime(), // Go 的 FileInfo 不提供创建时间
61 })
62 }
63
64 return results, nil
65}
66
67// Read 实现 BackendProtocol.Read
68func (b *FilesystemBackend) Read(ctx context.Context, path string, offset, limit int) (string, error) {

Callers

nothing calls this directly

Calls 6

ResolveMethod · 0.65
IsInsideMethod · 0.65
InfoMethod · 0.65
NameMethod · 0.65
JoinMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected