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

Method Write

pkg/backends/store_backend.go:137–165  ·  view source on GitHub ↗

Write 实现 BackendProtocol.Write

(ctx context.Context, path, content string)

Source from the content-addressed store, hash-verified

135
136// Write 实现 BackendProtocol.Write
137func (b *StoreBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) {
138 now := time.Now()
139 lines := strings.Split(content, "\n")
140
141 // 检查文件是否已存在
142 existingData, err := b.loadFileData(ctx, path)
143 createdAt := now
144 if err == nil && existingData != nil {
145 createdAt = existingData.CreatedAt
146 }
147
148 data := &FileData{
149 Lines: lines,
150 CreatedAt: createdAt,
151 ModifiedAt: now,
152 }
153
154 // 保存到 Store
155 if err := b.saveFileData(ctx, path, data); err != nil {
156 return nil, err
157 }
158
159 return &WriteResult{
160 Error: "", // 空字符串表示成功
161 Path: path,
162 BytesWritten: int64(len(content)),
163 FilesUpdate: nil, // StoreBackend 不需要返回状态更新
164 }, nil
165}
166
167// Edit 实现 BackendProtocol.Edit
168func (b *StoreBackend) Edit(ctx context.Context, path, oldStr, newStr string, replaceAll bool) (*EditResult, error) {

Callers

nothing calls this directly

Calls 2

loadFileDataMethod · 0.95
saveFileDataMethod · 0.95

Tested by

no test coverage detected